priority_flow.peak_distance

Peak Distance functions for PriorityFlow.

This module provides functions to calculate the maximum and minimum distance from headwater cells to topographic peaks using a topological sorting approach.

Functions

peak_dist(, printflag, numpy.ndarray])

Calculate distance to topographic peaks.

Module Contents

priority_flow.peak_distance.peak_dist(direction: numpy.ndarray, mask: numpy.ndarray | None = None, d4: Tuple[int, int, int, int] = (1, 2, 3, 4), printflag: bool = False) Dict[str, numpy.ndarray][source]

Calculate distance to topographic peaks.

Calculates the maximum and minimum distance from a headwater cell to topographic peaks using a topological sorting approach. This function identifies headwater cells and propagates distance information downstream following flow directions.

NOTE: This function has not yet been tested and is not fully implemented.

Parameters:
  • direction (np.ndarray) – Flow direction matrix

  • mask (np.ndarray, optional) – Processing mask. Defaults to processing everything

  • d4 (Tuple[int, int, int, int], optional) – Directional numbering system: down, left, top, right. Defaults to (1, 2, 3, 4)

  • printflag (bool, optional) – Whether to print progress information. Defaults to False

Returns:

A dictionary containing: - ‘mindist’: Matrix containing the minimum distance from headwaters to each cell - ‘maxdist’: Matrix containing the maximum distance from headwaters to each cell

Return type:

Dict[str, np.ndarray]

Notes

This function implements a distance calculation algorithm that: 1. Identifies headwater cells (cells with no upstream neighbors) 2. Uses topological sorting to process cells in correct order 3. Propagates distance information downstream following flow directions 4. Tracks both minimum and maximum distances from headwaters

The algorithm handles: - Border detection and processing - D4 neighbor connectivity - Upstream neighbor counting - Topological sorting for correct distance propagation - Masked area handling