xrspatial.focal.mean

xrspatial.focal.mean(agg: xarray.core.dataarray.DataArray, passes: int = 1, excludes: list = [nan], name: Optional[str] = 'mean')xarray.core.dataarray.DataArray[source]

Returns Mean filtered array using a 3x3 window.

aggxarray.DataArray

2D array of input values to be filtered.

passesint (default = 1)

Number of times to run mean.

namestr, optional (default = ‘mean’)

output xr.DataArray.name property

data: xarray.DataArray

2D array of filtered values.

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 Mean >>> focal.mean(agg) array([[0.5488135 , 0.71518937, 0.60276338, 0.54488318],

[0.4236548 , 0.64589411, 0.43758721, 0.891773 ], [0.96366276, 0.38344152, 0.79172504, 0.52889492], [0.56804456, 0.92559664, 0.07103606, 0.0871293 ]])