pyflwdir.gis_utils.spread2d#

pyflwdir.gis_utils.spread2d(obs: ndarray, msk: ndarray | None = None, nodata: float = 0, frc: ndarray | None = None, latlon: bool = False, transform: ndarray = array([1., 0., 0., 0., -1., 0.])) → tuple[ndarray, ndarray, ndarray][source]#

Fill no-data cells with the nearest observation and return source and distance maps.

Distances are accumulated through valid cells. The default friction is 1 per cell; diagonal steps use the hypotenuse of the horizontal and vertical distances.

Parameters:
  • obs (2D array) – Input observations. Cells equal to nodata are candidates for filling.

  • msk (2D array of bool, optional) – Valid-cell mask. Observations and fill paths are restricted to True cells.

  • nodata (int or float, optional) – Missing-data value in obs, by default 0.

  • frc (2D array of float, optional) – Per-cell friction multiplier for distance accumulation, by default 1 everywhere.

  • latlon (bool, optional) – Whether coordinates are geographic. If True, transform units are interpreted as degrees and distances are converted to metres, by default False.

  • transform (np.ndarray, optional) – Six affine transform coefficients mapping pixel coordinates to map coordinates.

Returns:

  • out (2D array of obs.dtype) – Copy of obs with fillable no-data cells assigned the nearest observation.

  • src (2D array of int32) – Linear index of the nearest observation, or -1 where no observation is reachable.

  • dst (2D array of float32) – Accumulated friction distance to the nearest observation.