xrspatial.classify.box_plot#

xrspatial.classify.box_plot(agg: DataArray, hinge: float = 1.5, name: str | None = 'box_plot') DataArray[source]#

Classify data using box plot breakpoints.

Uses Q1, median (Q2), Q3, and the whiskers (Q1 - hinge*IQR, Q3 + hinge*IQR) as class boundaries.

Parameters:
  • agg (xr.DataArray or xr.Dataset) – 2D NumPy, CuPy, NumPy-backed Dask, or CuPy-backed Dask array of values to be classified.

  • hinge (float, default=1.5) – Multiplier for the IQR to determine whisker extent.

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

Returns:

box_plot_agg – 2D aggregate array of box plot 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 box_plot
>>> 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_box_plot = box_plot(agg_numpy)
>>> print(numpy_box_plot)
<xarray.DataArray 'box_plot' (dim_0: 5, dim_1: 5)>
array([[nan,  1.,  1.,  1.,  1.],
       [ 1.,  1.,  2.,  2.,  2.],
       [ 2.,  2.,  2.,  3.,  3.],
       [ 3.,  3.,  3.,  4.,  4.],
       [ 4.,  4.,  4.,  4., nan]], dtype=float32)
Dimensions without coordinates: dim_0, dim_1
Attributes:
    res:      (10.0, 10.0)