xrspatial.terrain_metrics.tpi#
- xrspatial.terrain_metrics.tpi(agg: DataArray, name: str | None = 'tpi', boundary: str = 'nan') DataArray[source]#
Compute the Topographic Position Index (TPI) for each cell.
TPI is the difference between the elevation of the center cell and the mean elevation of its 8 neighbors in a 3x3 window (Weiss 2001). Positive values indicate ridgetops, negative values indicate valleys, and near-zero values indicate flat areas or mid-slope positions.
- 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='tpi') – 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 TPI values with the same shape, coords, dims, and attrs as the input.
- Return type:
xarray.DataArray or xr.Dataset
References
Weiss, A. (2001). Topographic Position and Landforms Analysis. Poster presentation, International User Conference, San Diego, CA.