Hydrology#
Warning
NaN cells act as impassable barriers in all hydrology functions. Flow cannot cross them. If your DEM has NaN holes (e.g. water bodies masked out), fill or interpolate them first, or expect disconnected drainage networks.
Each family exposes a single public function. The routing algorithm
('d8', 'dinf', or 'mfd') is chosen with the routing keyword,
which defaults to 'd8':
import xrspatial
fdir = xrspatial.flow_direction(dem, routing='dinf')
acc = xrspatial.flow_accumulation(fdir, routing='dinf')
The wrapper dispatches to the per-routing implementations listed under each
family. Those implementations live in xrspatial.hydro and carry the full
parameter list and algorithm references.
Flow Direction#
- xrspatial.flow_direction(agg, *, routing='d8', **kwargs)#
Direction of steepest descent out of each cell.
routingselects'd8','dinf', or'mfd'(default'd8').
Routing variants:
Compute D8 flow direction for each cell. |
|
|
Compute D-infinity flow direction for each cell. |
Compute multiple flow direction fractions for each cell. |
Flow Accumulation#
- xrspatial.flow_accumulation(flow_dir, *, routing='d8', **kwargs)#
Upstream cells or area draining through each cell.
routingselects'd8','dinf', or'mfd'(default'd8').
Routing variants:
|
Compute flow accumulation from a D8 flow direction grid. |
|
Compute flow accumulation from a D-infinity flow direction grid. |
|
Compute flow accumulation from an MFD flow direction grid. |
Flow Length#
- xrspatial.flow_length(flow_dir, *, routing='d8', **kwargs)#
Distance along the flow path to the outlet or from the divide.
routingselects'd8','dinf', or'mfd'(default'd8').
Routing variants:
Compute D8 flow length from a flow direction grid. |
|
Compute flow length from a D-infinity flow direction grid. |
|
Compute flow length from an MFD flow direction grid. |
Flow Path#
- xrspatial.flow_path(flow_dir, start_points, *, routing='d8', **kwargs)#
Trace downstream flow paths from a set of start points.
routingselects'd8','dinf', or'mfd'(default'd8').
Routing variants:
Trace downstream flow paths from start points through a D8 grid. |
|
Trace downstream flow paths using D-infinity dominant neighbor. |
|
Trace downstream flow paths using MFD dominant neighbor. |
Watershed#
- xrspatial.watershed(flow_dir, pour_points, *, routing='d8', **kwargs)#
Label each cell with the pour point it drains to.
routingselects'd8','dinf', or'mfd'(default'd8').
Routing variants:
Label each cell with the pour point it drains to. |
|
Label each cell with the pour point it drains to (D-inf). |
|
Label each cell with the pour point it drains to (MFD). |
|
|
Backward-compatible wrapper; use |
Stream Link#
- xrspatial.stream_link(flow_dir, flow_accum, *, routing='d8', threshold=100, **kwargs)#
Assign unique IDs to stream segments above a flow-accumulation threshold.
routingselects'd8','dinf', or'mfd'(default'd8').
Routing variants:
Assign unique IDs to stream link segments. |
|
Assign unique IDs to stream link segments (D-infinity). |
|
Assign unique IDs to stream link segments (MFD). |
Stream Order#
- xrspatial.stream_order(flow_dir, flow_accum, *, routing='d8', ordering='strahler', threshold=100, **kwargs)#
Strahler or Shreve stream ordering of the stream network.
routingselects'd8','dinf', or'mfd'(default'd8');orderingselects'strahler'or'shreve'.
Routing variants:
Compute stream order from D8 flow direction and accumulation grids. |
|
Compute stream order from D-infinity flow direction and accumulation. |
|
Compute stream order from MFD flow direction and accumulation grids. |
Height Above Nearest Drainage (HAND)#
- xrspatial.hand(flow_dir, flow_accum, elevation, *, routing='d8', threshold=100, **kwargs)#
Height above the nearest drainage.
routingselects'd8','dinf', or'mfd'(default'd8').
Routing variants:
|
Compute Height Above Nearest Drainage (HAND). |
|
Compute HAND using D-infinity flow direction. |
|
Compute HAND using MFD flow direction. |
D8-only functions#
These families currently implement D8 routing only. They take the same
routing keyword for forward compatibility, where 'd8' is the only
accepted value.
|
Fill depressions in a DEM using Planchon-Darboux iterative flooding. |
|
Identify and label depression cells in a D8 flow direction grid. |
|
Delineate drainage basins: every cell labeled with its outlet ID. |
Snap pour points to the highest-accumulation cell within a radius. |
|
|
Compute the Topographic Wetness Index. |