xrspatial.classify.head_tail_breaks#
- xrspatial.classify.head_tail_breaks(agg: DataArray, name: str | None = 'head_tail_breaks') DataArray[source]#
Classify data using the Head/Tail Breaks algorithm.
Iteratively partitions data around the mean. Values below the mean form a class, and values above continue to be split until the head proportion exceeds 40%.
- Parameters:
agg (xr.DataArray or xr.Dataset) – 2D NumPy, CuPy, NumPy-backed Dask, or CuPy-backed Dask array of values to be classified.
name (str, default='head_tail_breaks') – Name of output aggregate array.
- Returns:
head_tail_agg – 2D aggregate array of head/tail break classifications. All other input attributes are preserved. If agg is a Dataset, returns a Dataset with each variable classified independently.
- Return type:
xr.DataArray or xr.Dataset
References
Examples
>>> import numpy as np >>> import xarray as xr >>> from xrspatial.classify import head_tail_breaks >>> elevation = np.array([ [np.nan, 1., 2., 3., 4.], [ 5., 6., 7., 8., 9.], [10., 11., 12., 13., 14.], [15., 16., 17., 18., 19.], [20., 21., 22., 23., np.inf] ]) >>> agg_numpy = xr.DataArray(elevation, attrs={'res': (10.0, 10.0)}) >>> numpy_head_tail_breaks = head_tail_breaks(agg_numpy) >>> print(numpy_head_tail_breaks) <xarray.DataArray 'head_tail_breaks' (dim_0: 5, dim_1: 5)> array([[nan, 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., nan]], dtype=float32) Dimensions without coordinates: dim_0, dim_1 Attributes: res: (10.0, 10.0)