priority_flow.slope_calc_standard
Calculate slopes from a DEM.
Line-by-line translation of Slope_Calc_Standard.R (SlopeCalStan) from the R PriorityFlow package. R uses 1-based indexing; we use 0-based.
Functions
|
Calculate the slopes from a DEM. |
Module Contents
- priority_flow.slope_calc_standard.slope_calc_standard(dem: numpy.ndarray, direction: numpy.ndarray, dx: float, dy: float, mask: numpy.ndarray | None = None, d4: Tuple[int, int, int, int] = (1, 2, 3, 4), minslope: float = 0, maxslope: float = -1, secondary_th: float = -1, printflag: bool = False) Dict[str, numpy.ndarray][source]
Calculate the slopes from a DEM.
This function will calculate slopes using standard or upwinding options and apply a range of smoothing options.
- Parameters:
dem (np.ndarray) – 2D array of elevations in HydroFrame layout.
direction (np.ndarray) – 2D array of D4 flow directions for each cell, using the convention encoded in
d4.dx (float) – Lateral grid cell resolutions in the x and y directions, respectively.
dy (float) – Lateral grid cell resolutions in the x and y directions, respectively.
mask (np.ndarray, optional) – 2D mask defining the domain extent to be considered. Cells with value 0 are excluded from slope calculations. If
None, the full rectangular domain ofdemis used.d4 (tuple of int, optional) – Direction numbering system for the D4 neighbors, given as
(down, left, up, right). Defaults to(1, 2, 3, 4)to match the original R implementation.minslope (float, optional) – Minimum absolute slope to enforce on primary-direction slopes. If
minslope >= 0, primary slopes with magnitude less than this value are adjusted up tominslope(with sign preserved). Defaults to0.maxslope (float, optional) – Maximum absolute slope to enforce. If
maxslope >= 0, slopes with magnitude greater than this value are limited to±maxslope. If set to-1, no maximum is applied.secondary_th (float, optional) – Secondary threshold - maximum ratio of |secondary|/|primary| to be enforced. NOTE - this scaling occurs after any max threholds are applied. Currently this is only working for two options: (1) If this is set to -1 no scaling will be applied, (2) If this is set to zero all seconeary slopes will be zero
printflag (bool, optional) – If True, print progress information and details about slope limiting and secondary-slope handling.
Notes
River methods:
0: default value, no special treatment for river cells.1: scale secondary slopes along the river (requires a river mask and a river-specific secondary threshold).2: apply watershed mean slope to each river reach (requires river mask and subbasins).3: apply the stream mean slope to each reach (requires river mask and subbasins).
NOTE: The river mask can differ from the rivers used to create the subbasins (for example, using a higher threshold to define subbasins and a lower threshold to define river cells).
- Returns:
Dictionary containing:
"slopex": 2D array of adjusted x-direction face-centered slopes."slopey": 2D array of adjusted y-direction face-centered slopes."direction": the (possibly renumbered) flow-direction array used when constructing primary/secondary masks."Sinks": 1D array of linear indices (flattened) marking locations where slope signs were flipped to remove sinks.
- Return type:
Dict[str, np.ndarray]