Skip to content

Commit 5790c58

Browse files
committed
Move hydrology modules into xrspatial/hydrology subpackage
Moves 30 hydrology source modules and 30 test files into xrspatial/hydrology/ and xrspatial/hydrology/tests/ respectively. Also moves _boundary_store.py which is used exclusively by hydrology code. All internal cross-references updated. Top-level imports (from xrspatial import flow_direction, etc.) still work via xrspatial/__init__.py re-exports. The new xrspatial.hydrology subpackage also provides direct access (from xrspatial.hydrology import flow_direction). 457 hydrology tests pass, 2050 non-hydrology tests pass.
1 parent 4a8813a commit 5790c58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+195
-158
lines changed

examples/flood_simulation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
from matplotlib.animation import FuncAnimation
4141

4242
from xrspatial import generate_terrain, slope
43-
from xrspatial.flow_direction import flow_direction
44-
from xrspatial.flow_accumulation import flow_accumulation
45-
from xrspatial.flow_length import flow_length
46-
from xrspatial.hand import hand
43+
from xrspatial.hydrology.flow_direction import flow_direction
44+
from xrspatial.hydrology.flow_accumulation import flow_accumulation
45+
from xrspatial.hydrology.flow_length import flow_length
46+
from xrspatial.hydrology.hand import hand
4747
from xrspatial.flood import (
4848
curve_number_runoff,
4949
flood_depth,

examples/landslide_risk.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343

4444
from xrspatial import generate_terrain, slope
4545
from xrspatial.curvature import curvature
46-
from xrspatial.flow_direction import flow_direction
47-
from xrspatial.flow_accumulation import flow_accumulation
48-
from xrspatial.twi import twi
46+
from xrspatial.hydrology.flow_direction import flow_direction
47+
from xrspatial.hydrology.flow_accumulation import flow_accumulation
48+
from xrspatial.hydrology.twi import twi
4949
from xrspatial.terrain_metrics import tpi
5050

5151
# -- Tunable parameters -----------------------------------------------------

examples/watershed_explorer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
import matplotlib.colors as mcolors
3535

3636
from xrspatial import generate_terrain
37-
from xrspatial.flow_direction import flow_direction
38-
from xrspatial.flow_accumulation import flow_accumulation
39-
from xrspatial.stream_order import stream_order
40-
from xrspatial.snap_pour_point import snap_pour_point
41-
from xrspatial.watershed import watershed
42-
from xrspatial.basin import basin
37+
from xrspatial.hydrology.flow_direction import flow_direction
38+
from xrspatial.hydrology.flow_accumulation import flow_accumulation
39+
from xrspatial.hydrology.stream_order import stream_order
40+
from xrspatial.hydrology.snap_pour_point import snap_pour_point
41+
from xrspatial.hydrology.watershed import watershed
42+
from xrspatial.hydrology.basin import basin
4343

4444
# -- Tunable parameters -----------------------------------------------------
4545
CELL_SIZE = 30.0 # metres per pixel

xrspatial/__init__.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from xrspatial.curvature import curvature # noqa
2424
from xrspatial.emerging_hotspots import emerging_hotspots # noqa
2525
from xrspatial.erosion import erode # noqa
26-
from xrspatial.fill import fill # noqa
26+
from xrspatial.hydrology.fill import fill # noqa
2727
from xrspatial.interpolate import idw # noqa
2828
from xrspatial.interpolate import kriging # noqa
2929
from xrspatial.interpolate import spline # noqa
@@ -38,27 +38,27 @@
3838
from xrspatial.flood import flood_depth # noqa
3939
from xrspatial.flood import inundation # noqa
4040
from xrspatial.flood import travel_time # noqa
41-
from xrspatial.flow_accumulation import flow_accumulation # noqa
42-
from xrspatial.flow_accumulation_dinf import flow_accumulation_dinf # noqa
43-
from xrspatial.flow_accumulation_mfd import flow_accumulation_mfd # noqa
44-
from xrspatial.flow_direction import flow_direction # noqa
45-
from xrspatial.flow_direction_dinf import flow_direction_dinf # noqa
46-
from xrspatial.flow_direction_mfd import flow_direction_mfd # noqa
47-
from xrspatial.flow_length import flow_length # noqa
48-
from xrspatial.flow_length_dinf import flow_length_dinf # noqa
49-
from xrspatial.flow_length_mfd import flow_length_mfd # noqa
50-
from xrspatial.flow_path import flow_path # noqa
51-
from xrspatial.flow_path_dinf import flow_path_dinf # noqa
52-
from xrspatial.flow_path_mfd import flow_path_mfd # noqa
41+
from xrspatial.hydrology.flow_accumulation import flow_accumulation # noqa
42+
from xrspatial.hydrology.flow_accumulation_dinf import flow_accumulation_dinf # noqa
43+
from xrspatial.hydrology.flow_accumulation_mfd import flow_accumulation_mfd # noqa
44+
from xrspatial.hydrology.flow_direction import flow_direction # noqa
45+
from xrspatial.hydrology.flow_direction_dinf import flow_direction_dinf # noqa
46+
from xrspatial.hydrology.flow_direction_mfd import flow_direction_mfd # noqa
47+
from xrspatial.hydrology.flow_length import flow_length # noqa
48+
from xrspatial.hydrology.flow_length_dinf import flow_length_dinf # noqa
49+
from xrspatial.hydrology.flow_length_mfd import flow_length_mfd # noqa
50+
from xrspatial.hydrology.flow_path import flow_path # noqa
51+
from xrspatial.hydrology.flow_path_dinf import flow_path_dinf # noqa
52+
from xrspatial.hydrology.flow_path_mfd import flow_path_mfd # noqa
5353
from xrspatial.focal import mean # noqa
5454
from xrspatial.glcm import glcm_texture # noqa
5555
from xrspatial.morphology import morph_closing # noqa
5656
from xrspatial.morphology import morph_dilate # noqa
5757
from xrspatial.morphology import morph_erode # noqa
5858
from xrspatial.morphology import morph_opening # noqa
59-
from xrspatial.hand import hand # noqa
60-
from xrspatial.hand_dinf import hand_dinf # noqa
61-
from xrspatial.hand_mfd import hand_mfd # noqa
59+
from xrspatial.hydrology.hand import hand # noqa
60+
from xrspatial.hydrology.hand_dinf import hand_dinf # noqa
61+
from xrspatial.hydrology.hand_mfd import hand_mfd # noqa
6262
from xrspatial.hillshade import hillshade # noqa
6363
from xrspatial.mahalanobis import mahalanobis # noqa
6464
from xrspatial.multispectral import arvi # noqa
@@ -80,14 +80,14 @@
8080
from xrspatial.proximity import great_circle_distance # noqa
8181
from xrspatial.proximity import manhattan_distance # noqa
8282
from xrspatial.proximity import proximity # noqa
83-
from xrspatial.sink import sink # noqa
84-
from xrspatial.snap_pour_point import snap_pour_point # noqa
85-
from xrspatial.stream_link import stream_link # noqa
86-
from xrspatial.stream_link_dinf import stream_link_dinf # noqa
87-
from xrspatial.stream_link_mfd import stream_link_mfd # noqa
88-
from xrspatial.stream_order import stream_order # noqa
89-
from xrspatial.stream_order_dinf import stream_order_dinf # noqa
90-
from xrspatial.stream_order_mfd import stream_order_mfd # noqa
83+
from xrspatial.hydrology.sink import sink # noqa
84+
from xrspatial.hydrology.snap_pour_point import snap_pour_point # noqa
85+
from xrspatial.hydrology.stream_link import stream_link # noqa
86+
from xrspatial.hydrology.stream_link_dinf import stream_link_dinf # noqa
87+
from xrspatial.hydrology.stream_link_mfd import stream_link_mfd # noqa
88+
from xrspatial.hydrology.stream_order import stream_order # noqa
89+
from xrspatial.hydrology.stream_order_dinf import stream_order_dinf # noqa
90+
from xrspatial.hydrology.stream_order_mfd import stream_order_mfd # noqa
9191
from xrspatial.sky_view_factor import sky_view_factor # noqa
9292
from xrspatial.slope import slope # noqa
9393
from xrspatial.surface_distance import surface_allocation # noqa
@@ -99,14 +99,14 @@
9999
from xrspatial.terrain_metrics import roughness # noqa
100100
from xrspatial.terrain_metrics import tpi # noqa
101101
from xrspatial.terrain_metrics import tri # noqa
102-
from xrspatial.twi import twi # noqa
102+
from xrspatial.hydrology.twi import twi # noqa
103103
from xrspatial.polygonize import polygonize # noqa
104104
from xrspatial.viewshed import viewshed # noqa
105-
from xrspatial.basin import basin # noqa
106-
from xrspatial.watershed import basins # noqa
107-
from xrspatial.watershed import watershed # noqa
108-
from xrspatial.watershed_dinf import watershed_dinf # noqa
109-
from xrspatial.watershed_mfd import watershed_mfd # noqa
105+
from xrspatial.hydrology.basin import basin # noqa
106+
from xrspatial.hydrology.watershed import basins # noqa
107+
from xrspatial.hydrology.watershed import watershed # noqa
108+
from xrspatial.hydrology.watershed_dinf import watershed_dinf # noqa
109+
from xrspatial.hydrology.watershed_mfd import watershed_mfd # noqa
110110
from xrspatial.zonal import apply as zonal_apply # noqa
111111
from xrspatial.zonal import crop # noqa
112112
from xrspatial.zonal import trim # noqa

xrspatial/hydrology/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Hydrology analysis modules for xarray-spatial.
2+
3+
Includes flow direction, flow accumulation, flow length, flow path,
4+
watershed delineation, basin labeling, HAND, stream ordering, and
5+
related utilities for D8, D-infinity, and MFD routing.
6+
"""
7+
8+
from xrspatial.hydrology.basin import basin # noqa
9+
from xrspatial.hydrology.fill import fill # noqa
10+
from xrspatial.hydrology.flow_accumulation import flow_accumulation # noqa
11+
from xrspatial.hydrology.flow_accumulation_dinf import flow_accumulation_dinf # noqa
12+
from xrspatial.hydrology.flow_accumulation_mfd import flow_accumulation_mfd # noqa
13+
from xrspatial.hydrology.flow_direction import flow_direction # noqa
14+
from xrspatial.hydrology.flow_direction_dinf import flow_direction_dinf # noqa
15+
from xrspatial.hydrology.flow_direction_mfd import flow_direction_mfd # noqa
16+
from xrspatial.hydrology.flow_length import flow_length # noqa
17+
from xrspatial.hydrology.flow_length_dinf import flow_length_dinf # noqa
18+
from xrspatial.hydrology.flow_length_mfd import flow_length_mfd # noqa
19+
from xrspatial.hydrology.flow_path import flow_path # noqa
20+
from xrspatial.hydrology.flow_path_dinf import flow_path_dinf # noqa
21+
from xrspatial.hydrology.flow_path_mfd import flow_path_mfd # noqa
22+
from xrspatial.hydrology.hand import hand # noqa
23+
from xrspatial.hydrology.hand_dinf import hand_dinf # noqa
24+
from xrspatial.hydrology.hand_mfd import hand_mfd # noqa
25+
from xrspatial.hydrology.sink import sink # noqa
26+
from xrspatial.hydrology.snap_pour_point import snap_pour_point # noqa
27+
from xrspatial.hydrology.stream_link import stream_link # noqa
28+
from xrspatial.hydrology.stream_link_dinf import stream_link_dinf # noqa
29+
from xrspatial.hydrology.stream_link_mfd import stream_link_mfd # noqa
30+
from xrspatial.hydrology.stream_order import stream_order # noqa
31+
from xrspatial.hydrology.stream_order_dinf import stream_order_dinf # noqa
32+
from xrspatial.hydrology.stream_order_mfd import stream_order_mfd # noqa
33+
from xrspatial.hydrology.twi import twi # noqa
34+
from xrspatial.hydrology.watershed import basins # noqa
35+
from xrspatial.hydrology.watershed import watershed # noqa
36+
from xrspatial.hydrology.watershed_dinf import watershed_dinf # noqa
37+
from xrspatial.hydrology.watershed_mfd import watershed_mfd # noqa
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def _basins_dask_iterative(flow_dir_da):
272272
Constructs basin pour_points lazily, then delegates to the
273273
watershed dask infrastructure.
274274
"""
275-
from xrspatial.watershed import _watershed_dask_iterative
275+
from xrspatial.hydrology.watershed import _watershed_dask_iterative
276276

277277
chunks_y = flow_dir_da.chunks[0]
278278
chunks_x = flow_dir_da.chunks[1]
@@ -300,7 +300,7 @@ def _basins_make_pp_block(flow_dir_block, block_info=None):
300300
def _basins_dask_cupy(flow_dir_da):
301301
"""Dask+CuPy basins: native GPU via watershed infrastructure."""
302302
import cupy as cp
303-
from xrspatial.watershed import _watershed_dask_cupy
303+
from xrspatial.hydrology.watershed import _watershed_dask_cupy
304304

305305
chunks_y = flow_dir_da.chunks[0]
306306
chunks_x = flow_dir_da.chunks[1]
@@ -360,7 +360,7 @@ def basin(flow_dir: xr.DataArray,
360360
data = flow_dir.data
361361

362362
if isinstance(data, np.ndarray):
363-
from xrspatial.watershed import _watershed_cpu
363+
from xrspatial.hydrology.watershed import _watershed_cpu
364364
fd = data.astype(np.float64)
365365
h, w = fd.shape
366366
labels = _basins_init_labels(fd, h, w, h, w, 0, 0)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class cupy: # type: ignore[no-redef]
3636
is_dask_cupy,
3737
ngjit,
3838
)
39-
from xrspatial._boundary_store import BoundaryStore
39+
from xrspatial.hydrology._boundary_store import BoundaryStore
4040
from xrspatial.dataset_support import supports_dataset
4141

4242

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class cupy: # type: ignore[no-redef]
3838
is_dask_cupy,
3939
ngjit,
4040
)
41-
from xrspatial._boundary_store import BoundaryStore
41+
from xrspatial.hydrology._boundary_store import BoundaryStore
4242
from xrspatial.dataset_support import supports_dataset
4343

4444

xrspatial/flow_accumulation_dinf.py renamed to xrspatial/hydrology/flow_accumulation_dinf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class cupy: # type: ignore[no-redef]
3737
is_dask_cupy,
3838
ngjit,
3939
)
40-
from xrspatial._boundary_store import BoundaryStore
40+
from xrspatial.hydrology._boundary_store import BoundaryStore
4141
from xrspatial.dataset_support import supports_dataset
42-
from xrspatial.flow_accumulation import (
42+
from xrspatial.hydrology.flow_accumulation import (
4343
_find_ready_and_finalize,
4444
_preprocess_tiles,
4545
)

0 commit comments

Comments
 (0)