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.

Functions§

gradient3x3
Back-compat alias for the 3x3 gradient.
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.
morphological_gradient
(2k+1)x(2k+1) max - min gradient with in-bounds neighborhoods only (skimage rank filters ignore out-of-image samples — verified against skimage/filters/rank/core_cy.pyx::_core, which skips out-of-bounds positions via is_in_mask). k = 1 is the 3x3 gradient.
percentile_linear
Numpy’s default (‘linear’) percentile on a non-empty slice.
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.