Skip to content

Add D-inf and MFD stream ordering and link segmentation#984

Merged
brendancol merged 2 commits into
masterfrom
issue-983
Mar 6, 2026
Merged

Add D-inf and MFD stream ordering and link segmentation#984
brendancol merged 2 commits into
masterfrom
issue-983

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #983.

Summary

  • stream_order_dinf and stream_link_dinf for D-infinity (Tarboton 1997) flow direction grids
  • stream_order_mfd and stream_link_mfd for Multiple Flow Direction fraction grids
  • All four functions support NumPy, CuPy, Dask+NumPy, and Dask+CuPy backends
  • Strahler and Shreve methods for both ordering functions

What changed

New modules (4):

  • xrspatial/stream_order_dinf.py -- D-inf angle -> two bracketing neighbors with fractional weights, then Kahn's BFS same as D8
  • xrspatial/stream_order_mfd.py -- MFD (8, H, W) fraction grid -> all downslope neighbors, then Kahn's BFS
  • xrspatial/stream_link_dinf.py -- link segmentation using D-inf topology
  • xrspatial/stream_link_mfd.py -- link segmentation using MFD topology

Tests (4 files, 31 tests):

  • Y-confluence, cascade junctions, split-flow/split-angle, NaN handling, threshold filtering, single-cell, dask-vs-numpy parity

Docs and examples:

  • hydrology.rst updated with 4 new API entries
  • README.md feature matrix updated
  • New user guide notebook: 25_Stream_Analysis_Dinf_MFD.ipynb

Design notes

The topology construction differs per routing model, but the BFS ordering and link segmentation logic is identical to the existing D8 implementations. D-inf decomposes each angle into two bracketing neighbors. MFD reads directly from the 8-band fraction array. Once the flow graph is built, Strahler/Shreve ordering and link ID assignment work the same way.

Test plan

  • 31 new tests pass (pytest xrspatial/tests/test_stream_{order,link}_{dinf,mfd}.py)
  • 47 existing D8 stream tests still pass (no regressions)
  • GPU tests (need CUDA hardware)

Four new public functions:
- stream_order_dinf: Strahler/Shreve ordering on D-inf angle grids
- stream_order_mfd: Strahler/Shreve ordering on MFD fraction grids
- stream_link_dinf: link segmentation on D-inf angle grids
- stream_link_mfd: link segmentation on MFD fraction grids

All four support NumPy, CuPy, Dask+NumPy, and Dask+CuPy backends.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Mar 6, 2026
Upstream added a Source column to the feature matrix. Kept the upstream
format and added the 4 new stream analysis rows with Source references.
@brendancol brendancol merged commit 001db21 into master Mar 6, 2026
11 checks passed
@brendancol brendancol deleted the issue-983 branch May 4, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add D-inf and MFD variants of stream_order and stream_link

1 participant