Skip to content

Commit b3073c2

Browse files
committed
Extract D-inf flow accumulation into dedicated module and update hydrology API
- Move D-inf flow accumulation from flow_accumulation.py into flow_accumulation_dinf.py with its own test file - Update basin, watershed, stream_order, and stream_order_mfd to use D8 flow direction consistently - Add flow_accumulation_dinf to public API and docs - Simplify flow_accumulation.py to D8-only logic
1 parent e857705 commit b3073c2

File tree

10 files changed

+1284
-1109
lines changed

10 files changed

+1284
-1109
lines changed

docs/source/reference/hydrology.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ Flow Accumulation
3232

3333
xrspatial.flow_accumulation.flow_accumulation
3434

35+
Flow Accumulation (D-infinity)
36+
===============================
37+
.. autosummary::
38+
:toctree: _autosummary
39+
40+
xrspatial.flow_accumulation_dinf.flow_accumulation_dinf
41+
3542
Flow Accumulation (MFD)
3643
=======================
3744
.. autosummary::

xrspatial/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from xrspatial.flood import inundation # noqa
4040
from xrspatial.flood import travel_time # noqa
4141
from xrspatial.flow_accumulation import flow_accumulation # noqa
42+
from xrspatial.flow_accumulation_dinf import flow_accumulation_dinf # noqa
4243
from xrspatial.flow_accumulation_mfd import flow_accumulation_mfd # noqa
4344
from xrspatial.flow_direction import flow_direction # noqa
4445
from xrspatial.flow_direction_dinf import flow_direction_dinf # noqa

xrspatial/basin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ def basin(flow_dir: xr.DataArray,
364364
fd = data.astype(np.float64)
365365
h, w = fd.shape
366366
labels = _basins_init_labels(fd, h, w, h, w, 0, 0)
367-
out = _watershed_cpu(fd, labels, h, w)
367+
# Build state array: 0=nodata(NaN), 1=unresolved(-1), 3=resolved
368+
state = np.where(np.isnan(labels), 0,
369+
np.where(labels == -1.0, 1, 3)).astype(np.int8)
370+
out = _watershed_cpu(fd, labels, state, h, w)
368371

369372
elif has_cuda_and_cupy() and is_cupy_array(data):
370373
out = _basins_cupy(data)

0 commit comments

Comments
 (0)