xrspatial.classify.equal_interval

xrspatial.classify.equal_interval(agg: xarray.core.dataarray.DataArray, k: int = 5, name: Optional[str] = 'equal_interval') xarray.core.dataarray.DataArray[source]

Reclassifies data for array agg into new values based on intervals of equal width.

Parameters
  • agg (xarray.DataArray) – 2D NumPy, CuPy, NumPy-backed Dask, or Cupy-backed Dask array of values to be reclassified.

  • k (int, default=5) – Number of classes to be produced.

  • name (str, default='equal_interval') – Name of output aggregate.

Returns

equal_interval_agg – 2D aggregate array of equal interval allocations. All other input attributes are preserved.

Return type

xarray.DataArray of the same type as agg

References

Examples

import numpy as np
import xarray as xr
import dask.array as da
from xrspatial.classify import equal_interval

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]
])
data = xr.DataArray(elevation, attrs={'res': (10.0, 10.0)})
data_equal_interval = equal_interval(data, k=5)
>>> print(data)
<xarray.DataArray (dim_0: 5, dim_1: 5)>
array([[nan,  1.,  2.,  3.,  4.],
       [ 5.,  6.,  7.,  8.,  9.],
       [10., 11., 12., 13., 14.],
       [15., 16., 17., 18., 19.],
       [20., 21., 22., 23., inf]])
Dimensions without coordinates: dim_0, dim_1
Attributes:
    res:      (10.0, 10.0)

>>> print(data_equal_interval)
<xarray.DataArray 'equal_interval' (dim_0: 5, dim_1: 5)>
array([[nan,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  1.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 1.,  2.,  2.,  2.,  2.],
       [ 2.,  2.,  2.,  2., nan]], dtype=float32)
Dimensions without coordinates: dim_0, dim_1
Attributes:
    res:      (10.0, 10.0)