xrspatial.terrain_metrics.roughness#

xrspatial.terrain_metrics.roughness(agg: DataArray, name: str | None = 'roughness', boundary: str = 'nan') DataArray[source]#

Compute the roughness for each cell.

Roughness is the difference between the maximum and minimum elevation values in a 3x3 window (including the center cell). This is the same definition used by GDAL’s gdaldem roughness.

Parameters:
  • agg (xarray.DataArray or xr.Dataset) – 2D NumPy, CuPy, NumPy-backed Dask, or CuPy-backed Dask xarray DataArray of elevation values. If a Dataset is passed, the operation is applied to each data variable independently.

  • name (str, default='roughness') – Name of output DataArray.

  • boundary (str, default='nan') – How to handle edges where the kernel extends beyond the raster. 'nan' - fill missing neighbours with NaN (default). 'nearest' - repeat edge values. 'reflect' - mirror at boundary. 'wrap' - periodic / toroidal.

Returns:

2D array of roughness values with the same shape, coords, dims, and attrs as the input.

Return type:

xarray.DataArray or xr.Dataset

References

GDAL/OGR contributors (2024). GDAL/OGR Geospatial Data Abstraction software Library. Open Source Geospatial Foundation. https://gdal.org/programs/gdaldem.html