Skip to content

Add MFD flow direction and accumulation (#946)#956

Merged
brendancol merged 5 commits intomasterfrom
issue-946
Mar 4, 2026
Merged

Add MFD flow direction and accumulation (#946)#956
brendancol merged 5 commits intomasterfrom
issue-946

Conversation

@brendancol
Copy link
Contributor

Summary

  • Adds flow_direction_mfd -- partitions flow from each cell to all downslope neighbors using the MFD algorithm with an adaptive exponent (Qin et al. 2007). Output is a 3-D (8, H, W) array of flow fractions.
  • Adds flow_accumulation_mfd -- accumulates upstream contributing area through all MFD flow paths, weighted by directional fractions. Each cell starts at 1 and distributes its value downstream proportionally.
  • Both functions support all four backends: numpy, cupy, dask+numpy, dask+cupy.
  • 69 tests total (46 for direction, 23 for accumulation), including cross-backend and dask multi-chunk correctness checks.

Test plan

  • pytest xrspatial/tests/test_flow_direction_mfd.py -- 46 tests pass
  • pytest xrspatial/tests/test_flow_accumulation_mfd.py -- 23 tests pass
  • Dask multi-chunk results match single-chunk numpy for both functions
  • Verify notebook renders correctly (examples/user_guide/11_Hydrology.ipynb)

Closes #946

Implements Qin et al. (2007) multiple flow direction algorithm that
partitions flow from each cell to all downslope neighbors. The
adaptive exponent adjusts based on the ratio of maximum to mean
downslope gradient. Supports all four backends.
46 tests covering correctness, NaN handling, boundary modes,
fixed vs adaptive exponent, cross-backend equality (numpy, dask,
cupy, dask+cupy), dtype acceptance, and Dataset support.
Adds flow_direction_mfd to the hydrology reference docs, the README
feature matrix, and the hydrology user guide notebook with adaptive
vs fixed exponent comparison plots.
Adds side-by-side comparison of all three flow direction algorithms
and MFD exponent mode comparison (p=1 vs adaptive vs p=8).
Accumulates upstream contributing area through all MFD flow paths,
weighted by directional fractions from flow_direction_mfd. Supports
numpy, cupy, dask+numpy, and dask+cupy backends.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 4, 2026
@brendancol brendancol merged commit 583883e into master Mar 4, 2026
11 checks passed
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 multiple flow direction (MFD) with adaptive exponent (Qin et al. 2007)

1 participant