xrspatial.focal.hotspots

xrspatial.focal.hotspots(raster: xarray.core.dataarray.DataArray, kernel: xarray.core.dataarray.DataArray, x: Optional[str] = 'x', y: Optional[str] = 'y')xarray.core.dataarray.DataArray[source]

Identify statistically significant hot spots and cold spots in an input raster. To be a statistically significant hot spot, a feature will have a high value and be surrounded by other features with high values as well. Neighborhood of a feature defined by the input kernel, which currently support a shape of circle, annulus, or custom kernel.

The result should be a raster with the following 7 values:

90 for 90% confidence high value cluster 95 for 95% confidence high value cluster 99 for 99% confidence high value cluster

-90 for 90% confidence low value cluster -95 for 95% confidence low value cluster -99 for 99% confidence low value cluster

0 for no significance

raster: xarray.DataArray

2D Input raster image with shape = (height, width).

kernel: Numpy Array

2D array where values of 1 indicate the kernel.

xarray.DataArray

2D array of hotspots with values indicating confidence level.

Imports

>>> import numpy as np
>>> import xarray as xr
>>> from xrspatial import focal

Create Data Array >>> agg = xr.DataArray(np.array([[0, 0, 0, 0, 0, 0, 0], >>> [0, 0, 0, 0, 0, 0, 0], >>> [0, 0, 10, 10, 10, 0, 0], >>> [0, 0, 10, 10, 10, 0, 0], >>> [0, 0, 10, 10, 10, 0, 0], >>> [0, 0, 0, 0, 0, 0, 0], >>> [0, 0, 0, 0, 0, 0, 0]]), >>> 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

Create Kernel

>>> kernel = focal.circle_kernel(1, 1, 1)

Create Hotspot Data Array

>>> focal.hotspots(agg, kernel, x = 'lon', y = 'lat')
<xarray.DataArray (lat: 7, lon: 7)>
array([[ 0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0, 95,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0]], dtype=int8)
Coordinates:
  * lon      (lon) float64 0.0 1.0 2.0 3.0 4.0 5.0 6.0
  * lat      (lat) float64 0.0 1.0 2.0 3.0 4.0 5.0 6.0