priority_flow.stream_traverse

Stream Traverse functions for PriorityFlow.

Line-by-line translation of Stream_Traverse.R (StreamTraverse) from the PriorityFlow R package.

This processes stream networks by walking upstream on D4 neighbors in a river mask. Where no D4 neighbors exist, it looks for D8 neighbors and creates D4 bridges to these diagonal cells.

Functions

stream_traverse(, printstep, epsilon, numpy.ndarray])

DEM processing of stream networks.

Module Contents

priority_flow.stream_traverse.stream_traverse(dem: numpy.ndarray, mask: numpy.ndarray, queue: numpy.ndarray, marked: numpy.ndarray, step: numpy.ndarray | None = None, direction: numpy.ndarray | None = None, basins: numpy.ndarray | None = None, d4: Tuple[int, int, int, int] = (1, 2, 3, 4), printstep: bool = False, epsilon: float = 0.0) Dict[str, numpy.ndarray][source]

DEM processing of stream networks.

Function to process stream networks walking upstream on d4 neigbors in a river mask. Where no D4 neigbhors exist it looks for d8 neigbors and creates d4 bridges to these diagonal cells.

Parameters:
  • dem (np.ndarray) – Digital Elevation Model matrix (nx x ny).

  • mask (np.ndarray) – Mask with zeros for non-river cells and 1 for river cells.

  • queue (np.ndarray) – Priority queue to start from; columns: x (row), y (col), elevation.

  • marked (np.ndarray) – Matrix of which cells have been marked already.

  • step (np.ndarray, optional) – Matrix of the step number for processed cells. Defaults to zeros.

  • direction (np.ndarray, optional) – Matrix of flow directions for processed cells. Defaults to NaN.

  • basins (np.ndarray, optional) – Matrix of basin numbers (e.g., from InitQueue). If provided, every newly added cell inherits the basin of the cell that adds it.

  • d4 (tuple of int, optional) – D4 direction numbering (down, left, up, right). Default (1,2,3,4).

  • printstep (bool, optional) – If True, print step number and queue size.

  • epsilon (float, optional) – Amount to add to filled areas to avoid creating flats.

Returns:

Dictionary with keys: “dem”, “mask”, “marked”, “step”, “direction”, and “basins”.

Return type:

Dict[str, np.ndarray]