Skip to main content

Module preprocess

Module preprocess 

Source
Expand description

Replicates RidgeMap.preprocess: water/lake masking + vertical scaling.

Upstream, in order:

  1. NaN -> array min, then min-max normalize to [0, 1].
  2. water mask: value below the water_ntile percentile.
  3. lake mask: 3x3 morphological gradient (max - min) of the u8-quantized image (skimage.util.img_as_ubyte -> skimage.filters.rank.gradient with a 3x3 footprint) below lake_flatness.
  4. restore NaNs, apply both masks as NaN.
  5. flip rows (south becomes the “front” of the picture) and multiply by vertical_ratio.

Re-exports§

pub use crate::upstream::numpy::percentile_linear;
pub use crate::upstream::skimage::gradient3x3;
pub use crate::upstream::skimage::morphological_gradient;

Functions§

masked_gradient3x3
3x3 max - min gradient that IGNORES excluded cells (water/NaN): the neighborhood keeps only in-bounds, non-excluded samples, and a cell with no valid neighbors gets 0 (flat). Mirrors skimage’s masked rank filters (is_in_mask), which upstream never used.
preprocess
flatness_scale density-compensates the lake-flatness test: it multiplies the normalized threshold (lake_flatness/255). 1.0 = naive upstream semantics at the grid’s own sampling. For a disc grid viewed through a coarser anisotropic window, pass (disc_step / display_row_step) so the test measures the same terrain slope at any sampling density.