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]

Groups data for array (agg) by distributing values into at equal intervals. The result is an xarray.DataArray.

agg: xarray.DataArray

2D array of values to bin. NumPy, CuPy, NumPy-backed Dask, or Cupy-backed Dask array

k: int

Number of classes to be produced.

name: str, optional (default = “equal_interval”)

Name of output aggregate.

equal_interval_agg: xarray.DataArray

2D array, of the same type as the input, of class allocations.

Intervals defined to have equal width:

PySal: - PySAL, Source code for mapclassify.classifiers, https://pysal.org/mapclassify/_modules/mapclassify/classifiers.html#EqualInterval, Accessed Apr. 21, 2021. # noqa SciKit: - scikit-learn, Classifier comparison, https://scikit-learn.org/stable/auto_examples/classification/plot_classifier_comparison.html#sphx-glr-auto-examples-classification-plot-classifier-comparison-py, Accessed Apr. 21, 2021. # noqa

Imports >>> import numpy as np >>> import xarray as xr >>> from xrspatial.classify import equal_interval, natural_breaks

Create Initial DataArray

>>> np.random.seed(1)
>>> agg = xr.DataArray(np.random.randint(2, 8, (4, 4)),
>>>                    dims = ["lat", "lon"])
>>> height, width = agg.shape
>>> _lon = np.linspace(0, width - 1, width)
>>> _lat = np.linspace(0, height - 1, height)
>>> agg["lon"] = _lon
>>> agg["lat"] = _lat
>>> print(agg)
<xarray.DataArray (lat: 4, lon: 4)>
array([[7, 5, 6, 2],
       [3, 5, 7, 2],
       [2, 3, 6, 7],
       [6, 3, 4, 6]])
Coordinates:
  * lon      (lon) float64 0.0 1.0 2.0 3.0
  * lat      (lat) float64 0.0 1.0 2.0 3.0

Create Equal Interval DataArray >>> equal_interval_agg = equal_interval(agg, k = 5) >>> print(equal_interval_agg) <xarray.DataArray ‘equal_interval’ (lat: 4, lon: 4)> array([[4., 2., 3., 0.],

[0., 2., 4., 0.], [0., 0., 3., 4.], [3., 0., 1., 3.]], dtype=float32)

Coordinates:
  • lon (lon) float64 0.0 1.0 2.0 3.0

  • lat (lat) float64 0.0 1.0 2.0 3.0