xrspatial.hydro.basin_d8.basin_d8#

xrspatial.hydro.basin_d8.basin_d8(flow_dir: DataArray, name: str = 'basin') DataArray[source]#

Delineate drainage basins: every cell labeled with its outlet ID.

Automatically identifies all outlets (pits and edge-exit cells) and assigns each a unique ID. Every valid cell is then labeled with the ID of the outlet it drains to. NaN flow_dir cells produce NaN.

Parameters:
  • flow_dir (xarray.DataArray or xr.Dataset) – 2D D8 flow direction grid (codes 0/1/2/4/8/16/32/64/128; NaN for nodata).

  • name (str, default='basin') – Name of output DataArray.

Returns:

2D float64 array where each cell = unique ID of its outlet. NaN for nodata cells.

Return type:

xarray.DataArray or xr.Dataset