py3dep.utils#

Utilities for Py3DEP.

Module Contents#

py3dep.utils.deg2mpm(slope)#

Convert slope from degrees to meter/meter.

Parameters:

slope (xarray.DataArray) – Slope in degrees.

Returns:

xarray.DataArray – Slope in meter/meter. The name is set to slope and the units attribute is set to m/m.

Return type:

xarray.DataArray

py3dep.utils.fill_depressions(elevtn, outlets='min', idxs_pit=None, nodata=np.nan, max_depth=-1.0, elv_max=None, connectivity=8)#

Fill local depressions in elevation data based on Wang and Liu (2006).

Note

This function is based on the fill_depressions function from the pyflwdir package. This function improves the performance of the original function by a factor of up to 2 and adds more input checks. Additionally, it works with xarray.DataArray objects.

Outlets are assumed to occur at the edge of valid elevation cells outlets='edge'; at the lowest valid edge cell to create one single outlet outlets='min'; or at user provided outlet cells idxs_pit.

Depressions elsewhere are filled based on its lowest pour point elevation. If the pour point depth is larger than the maximum pour point depth max_depth a pit is set at the depression local minimum elevation.

Wang, L., & Liu, H. (2006). https://doi.org/10.1080/13658810500433453

Parameters:
  • elevtn (numpy.ndarray or xarray.DataArray) – elevation raster as a 2D numpy.ndarray or xarray.DataArray.

  • outlets ({"edge", "min}, optional) – Initial basin outlet(s) at the edge of all cells (‘edge’) or only the minimum elevation edge cell (‘min’; default)

  • idxs_pit (1D array of int, optional) – Linear indices of outlet cells, in any, defaults to None.

  • nodata (float, optional) – nodata value, defaults to numpy.nan.

  • max_depth (float, optional) – Maximum pour point depth. Depressions with a larger pour point depth are set as pit. A negative value (default) equals an infitely large pour point depth causing all depressions to be filled. Defaults to -1.0.

  • elv_max, float, optional – Maximum elevation for outlets, only in combination with outlets='edge'. By default None.

  • connectivity ({4, 8}, optional) – Number of neighboring cells to consider, defaults to 8.

Returns:

elevtn_out (numpy.ndarray) – Depression filled elevation with type float32.

Return type:

DataArray