Expand description
Replicates RidgeMap.preprocess: water/lake masking + vertical scaling.
Upstream, in order:
- NaN -> array min, then min-max normalize to [0, 1].
- water mask: value below the
water_ntilepercentile. - lake mask: 3x3 morphological gradient (max - min) of the u8-quantized
image (
skimage.util.img_as_ubyte->skimage.filters.rank.gradientwith a 3x3 footprint) belowlake_flatness. - restore NaNs, apply both masks as NaN.
- 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
rankfilters ignore out-of-image samples — verified againstskimage/filters/rank/core_cy.pyx::_core, which skips out-of-bounds positions viais_in_mask).k = 1is the 3x3 gradient. - percentile_
linear - Numpy’s default (‘linear’) percentile on a non-empty slice.
- preprocess
flatness_scaledensity-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.