Add MFD flow direction and accumulation (#946)#956
Merged
brendancol merged 5 commits intomasterfrom Mar 4, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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.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.Test plan
pytest xrspatial/tests/test_flow_direction_mfd.py-- 46 tests passpytest xrspatial/tests/test_flow_accumulation_mfd.py-- 23 tests passexamples/user_guide/11_Hydrology.ipynb)Closes #946