xrspatial.hydro.watershed_d8.watershed_d8#

xrspatial.hydro.watershed_d8.watershed_d8(flow_dir: DataArray, pour_points: DataArray, name: str = 'watershed') DataArray[source]#

Label each cell with the pour point it drains to.

Follows each cell downstream through the D8 flow direction grid until it reaches a pour point. The cell is then labeled with that pour point’s value. Cells that do not reach any pour point are assigned 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).

  • pour_points (xarray.DataArray) – 2D raster where non-NaN cells are pour points and their values become the labels. Must have the same shape as flow_dir.

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

Returns:

2D float64 array where each cell = label of its pour point. NaN for nodata or cells not reaching any pour point.

Return type:

xarray.DataArray or xr.Dataset