xrspatial.normalize.standardize#
- xrspatial.normalize.standardize(agg, ddof=0, name='standardize')[source]#
Z-score normalization of a raster.
Subtracts the mean and divides by the standard deviation of finite values. NaN and infinite values pass through unchanged. If all finite values are identical (std == 0), the output is filled with 0.0 for those cells.
- Parameters:
agg (xr.DataArray or xr.Dataset) – 2D NumPy, CuPy, NumPy-backed Dask, or CuPy-backed Dask array.
ddof (int, default=0) – Delta degrees of freedom for standard deviation. Use 0 for population std, 1 for sample std.
name (str, default='standardize') – Name of the output DataArray.
- Returns:
standardized – Z-score normalized raster with the same shape, dims, coords, and attrs. If agg is a Dataset, each variable is standardized independently.
- Return type:
xr.DataArray or xr.Dataset
Examples
>>> import numpy as np >>> import xarray as xr >>> from xrspatial.normalize import standardize >>> data = np.array([ [np.nan, 1., 2.], [3., 4., 5.], ], dtype=np.float64) >>> agg = xr.DataArray(data) >>> standardize(agg) <xarray.DataArray 'standardize' (dim_0: 2, dim_1: 3)> array([[ nan, -1.41421356, -0.70710678], [ 0. , 0.70710678, 1.41421356]]) Dimensions without coordinates: dim_0, dim_1