priority_flow.slope_calc_standard ================================= .. py:module:: priority_flow.slope_calc_standard .. autoapi-nested-parse:: 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 --------- .. autoapisummary:: priority_flow.slope_calc_standard.slope_calc_standard Module Contents --------------- .. py:function:: slope_calc_standard(dem: numpy.ndarray, direction: numpy.ndarray, dx: float, dy: float, mask: Optional[numpy.ndarray] = 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] Calculate the slopes from a DEM. This function will calculate slopes using standard or upwinding options and apply a range of smoothing options. :param dem: 2D array of elevations in **HydroFrame** layout. :type dem: np.ndarray :param direction: 2D array of D4 flow directions for each cell, using the convention encoded in ``d4``. :type direction: np.ndarray :param dx: Lateral grid cell resolutions in the x and y directions, respectively. :type dx: float :param dy: Lateral grid cell resolutions in the x and y directions, respectively. :type dy: float :param mask: 2D mask defining the domain extent to be considered. Cells with value 0 are excluded from slope calculations. If ``None``, the full rectangular domain of ``dem`` is used. :type mask: np.ndarray, optional :param d4: 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. :type d4: tuple of int, optional :param minslope: Minimum absolute slope to enforce on primary-direction slopes. If ``minslope >= 0``, primary slopes with magnitude less than this value are adjusted up to ``minslope`` (with sign preserved). Defaults to ``0``. :type minslope: float, optional :param maxslope: 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. :type maxslope: float, optional :param secondary_th: 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 :type secondary_th: float, optional :param printflag: If True, print progress information and details about slope limiting and secondary-slope handling. :type printflag: bool, optional .. rubric:: 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. :rtype: Dict[str, np.ndarray]