priority_flow.drainage_area
Calculated drainage area.
Line-by-line translation of drainage_area.R (drainageArea) from the R PriorityFlow package. Calculates the number of cells draining to any cell given a flow direction file. R uses 1-based indexing; we use 0-based.
Functions
|
Calculate drainage area (number of upstream cells) for each grid cell given a flow direction file. |
Module Contents
- priority_flow.drainage_area.drainage_area(direction: numpy.ndarray, mask: numpy.ndarray | None = None, d4: Tuple[int, int, int, int] = (1, 2, 3, 4), printflag: bool = False) numpy.ndarray[source]
Calculate drainage area (number of upstream cells) for each grid cell given a flow direction file.
- Parameters:
direction (np.ndarray) – 2D array of D4 flow directions for each cell. Direction codes follow the
d4numbering scheme.mask (np.ndarray, optional) – 2D mask with ones for cells to be processed and zeros for everything else. Cells outside the mask are excluded from the drainage-area computation. If
None, a mask of all ones with the same shape asdirectionis 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.printflag (bool, optional) – If
True, print basic progress information as the algorithm walks downstream through the queue of cells.
- Returns:
2D array of drainage areas with the same shape as
direction. Each entry gives the number of cells (including itself) that drain to that cell, multiplied bymaskso cells outside the mask have value 0.- Return type:
np.ndarray