Skip to content

Add MFD flow length computation#1011

Merged
brendancol merged 2 commits intomasterfrom
issue-1009
Mar 16, 2026
Merged

Add MFD flow length computation#1011
brendancol merged 2 commits intomasterfrom
issue-1009

Conversation

@brendancol
Copy link
Contributor

Summary

  • New flow_length_mfd() function: proportion-weighted flow path lengths from MFD fraction grids
  • Downstream mode gives the weighted-average distance from each cell to its outlet
  • Upstream mode gives the longest flow path from any divide to each cell
  • NumPy, CuPy, Dask+NumPy, Dask+CuPy backends
  • 29 tests for correctness, edge cases, NaN handling, and cross-backend consistency
  • User guide notebook (32) with terrain generation, visualization, and D8 vs MFD comparison

The MFD pipeline had direction, accumulation, stream ordering, and stream links but no flow length. Now it does.

Closes #1009

Test plan

  • 15 correctness tests (linear, diagonal, split, chain, pit, NaN, rectangular cells, shape validation, integration with flow_direction_mfd)
  • 8 Dask cross-backend tests (4 chunk sizes x 2 directions)
  • 2 Dask cross-tile boundary tests
  • 2 CuPy cross-backend tests
  • 2 Dask+CuPy cross-backend tests
  • Manual review of notebook output

New flow_length_mfd() computes proportion-weighted flow path lengths
from MFD fraction grids. Downstream mode gives the expected distance
to outlet weighted by MFD fractions; upstream mode gives the longest
path from any divide to each cell.

All four backends: NumPy, CuPy, Dask+NumPy, Dask+CuPy.
29 tests covering correctness, edge cases, and cross-backend consistency.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 16, 2026
@brendancol brendancol merged commit 6571c33 into master Mar 16, 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 MFD flow length computation

1 participant