xrspatial.focal.calc_cellsize

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

Calculates cell size of an array based on its attributes. Default = meters. If lat-lon units are converted to meters.

raster: xarray.DataArray

2D array of input values.

x: str (Default = “x”)

Name of input x-axis.

y: str (Default = “y”)

Name of input y-axis

cellsize_x: float

Size of cells in x direction.

cellsize_y: float

Size of cells in y direction.

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

Create Data Array >>> np.random.seed(0) >>> agg = xr.DataArray(np.random.rand(4,4),

dims = [“lat”, “lon”])

>>> height, width = nir_agg.shape
>>> _lat = np.linspace(0, height - 1, height)
>>> _lon = np.linspace(0, width - 1, width)
>>> nir_agg["lat"] = _lat
>>> nir_agg["lon"] = _lon

Calculate Cell Size >>> focal.calc_cellsize(agg, ‘lon’, ‘lat’) (1, 1)