xrspatial.hydro.flow_direction_mfd.flow_direction_mfd#

xrspatial.hydro.flow_direction_mfd.flow_direction_mfd(agg: DataArray, p: float = None, name: str = 'flow_direction_mfd', boundary: str = 'nan') DataArray[source]#

Compute multiple flow direction fractions for each cell.

Partitions flow from each cell to all downslope neighbors using the MFD algorithm. An adaptive flow-partition exponent (Qin et al. 2007) adjusts automatically based on local terrain so that steep convergent areas concentrate flow while gentle slopes spread it out.

The output is a 3-D array of shape (8, H, W) where each band holds the fraction of flow directed to one of the 8 neighbors (E, SE, S, SW, W, NW, N, NE). Fractions sum to 1.0 at each cell.

Parameters:
  • agg (xarray.DataArray or xr.Dataset) – 2-D NumPy, CuPy, NumPy-backed Dask, or CuPy-backed Dask xarray DataArray of elevation values. If a Dataset is passed, the operation is applied to each data variable independently.

  • p (float or None, default=None) – Flow-partition exponent. None uses the adaptive exponent from Qin et al. (2007): p = max_slope / mean_slope across downslope neighbors. A positive float sets a fixed exponent (e.g. p=1.0 for Quinn et al. 1991, p=1.1 for Holmgren 1994).

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

  • boundary (str, default='nan') – How to handle edges where the kernel extends beyond the raster. 'nan' - fill missing neighbours with NaN (default). 'nearest' - repeat edge values. 'reflect' - mirror at boundary. 'wrap' - periodic / toroidal.

Returns:

3-D array with dimensions ('neighbor', <ydim>, <xdim>) and a neighbor coordinate labelled ['E', 'SE', 'S', 'SW', 'W', 'NW', 'N', 'NE']. Values are flow fractions in [0, 1] that sum to 1.0 at each cell (0.0 everywhere for pits/flats, NaN at edges or where any neighbor is NaN).

Return type:

xarray.DataArray or xr.Dataset

References

Qin, C., Zhu, A.X., Pei, T., Li, B., Zhou, C., and Yang, L. (2007). An adaptive approach to selecting a flow-partition exponent for a multiple-flow-direction algorithm. International Journal of Geographical Information Science, 21(4), 443-458.

Quinn, P., Beven, K., Chevallier, P., and Planchon, O. (1991). The prediction of hillslope flow paths for distributed hydrological modelling using digital terrain models. Hydrological Processes, 5(1), 59-79.