pub fn curvatures_core(
dem: ArrayView2<'_, f32>,
cellsize: f32,
profile_out: &mut Array2<f32>,
planform_out: &mut Array2<f32>,
)Expand description
Compute profile and planform curvature of a DEM.
Profile curvature is curvature in the direction of steepest slope
(affects flow acceleration); planform curvature is curvature
perpendicular to it (affects flow convergence). Both use the
Zevenbergen & Thorne sign convention of derivatives.py.
§Arguments
dem-ArrayView2<f32>, shape (H, W): elevations. Must be NaN-free (see module docs). Any memory layout. H and W should each be at least 2; see Edge cases.cellsize-f32: grid spacing, in the same units as the elevations, applied to both axes.profile_out-&mut Array2<f32>, shape (H, W), C-contiguous: overwritten with profile curvature.planform_out-&mut Array2<f32>, shape (H, W), C-contiguous: overwritten with planform curvature.
Flat cells and any non-finite results are written as 0.0.
Runs serially below PARALLEL_THRESHOLD
elements and in parallel at or above it. The gradient passes
themselves always run serially.
§Edge cases
Where numpy’s np.gradient would raise ValueError because an axis
has length 1, this treats that axis’s derivatives as zero instead.
§Panics
- If
profile_outorplanform_outis not C-contiguous. Arrays made withArray2::zeros(shape)always are. - If
profile_outorplanform_outhas more elements thandem. - If exactly one of H and W is 0.
Output shapes are not otherwise checked: outputs with fewer elements
than dem are partly filled, and a different shape with the same
element count is filled in the wrong layout. Always allocate both
outputs with dem.raw_dim().
§Example
use ndarray::Array2;
use terra_texture_rs::curvatures_core;
// a uniformly tilted plane has no curvature anywhere
let dem = Array2::from_shape_fn((5, 5), |(i, j)| (i + 2 * j) as f32);
let mut profile = Array2::<f32>::zeros(dem.raw_dim());
let mut planform = Array2::<f32>::zeros(dem.raw_dim());
curvatures_core(dem.view(), 1.0, &mut profile, &mut planform);
assert!(profile.iter().all(|&v| v.abs() < 1e-6));
assert!(planform.iter().all(|&v| v.abs() < 1e-6));