xrspatial.classify.maximum_breaks#
- xrspatial.classify.maximum_breaks(agg: DataArray, k: int = 5, num_sample: int | None = 20000, name: str | None = 'maximum_breaks') DataArray[source]#
Classify data using the Maximum Breaks algorithm.
Finds the k-1 largest gaps between sorted unique values and uses midpoints of those gaps as bin edges.
- Parameters:
agg (xr.DataArray or xr.Dataset) – 2D NumPy, CuPy, NumPy-backed Dask, or CuPy-backed Dask array of values to be classified.
k (int, default=5) – Number of classes to be produced.
num_sample (int or None, default=20000) – Number of sample data points used to fit the model. For dask-backed arrays the sample is drawn lazily to avoid materialising the entire array into RAM.
Nonemeans use all data (safe for numpy/cupy, automatically capped for dask).name (str, default='maximum_breaks') – Name of output aggregate array.
- Returns:
max_breaks_agg – 2D aggregate array of maximum 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 maximum_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_maximum_breaks = maximum_breaks(agg_numpy) >>> print(numpy_maximum_breaks) <xarray.DataArray 'maximum_breaks' (dim_0: 5, dim_1: 5)> array([[nan, 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 1., 2., 3., 4., nan]], dtype=float32) Dimensions without coordinates: dim_0, dim_1 Attributes: res: (10.0, 10.0)