Skip to main content

preprocessing.compute_dem_gradient_magnitude

preprocessing.compute_dem_gradient_magnitude(dem)

Per-pixel terrain slope proxy: sqrt((dy)^2 + (dx)^2) in metres.

Encodes “is this flat or sloped” without referring to absolute elevation, so the result transfers across cities without retraining. Pairs naturally with the mean_subtract recipe on the elevation band, which gives a city-relative DEM as the first channel.

NaN-safe: when the input has missing pixels, fills them with the finite mean before computing the gradient and restores NaN afterwards.