Moving windows#
Examine the geowombat.moving()
help.
In [1]: import geowombat as gw
In [2]: print(help(gw.moving))
Help on function moving in module geowombat.core.util:
moving(data: xarray.core.dataarray.DataArray, stat: str = 'mean', perc: Union[float, int] = 50, w: int = 3, nodata: Union[float, int, NoneType] = None, weights: Optional[bool] = False) -> xarray.core.dataarray.DataArray
Applies a moving window function over Dask array blocks.
Args:
data (DataArray): The ``xarray.DataArray`` to process.
stat (Optional[str]): The statistic to compute.
Choices are ['mean', 'std', 'var', 'min', 'max', 'perc'].
perc (Optional[int]): The percentile to return if ``stat`` = 'perc'.
w (Optional[int]): The moving window size (in pixels).
nodata (Optional[int or float]): A 'no data' value to ignore.
weights (Optional[bool]): Whether to weight values by distance from window center.
Returns:
``xarray.DataArray``
Examples:
>>> import geowombat as gw
>>>
>>> # Calculate the mean within a 5x5 window
>>> with gw.open('image.tif') as src:
>>> res = gw.moving(ds, stat='mean', w=5, nodata=32767.0)
>>>
>>> # Calculate the 90th percentile within a 15x15 window
>>> with gw.open('image.tif') as src:
>>> res = gw.moving(stat='perc', w=15, perc=90, nodata=32767.0)
>>> res.data.compute(num_workers=4)
None
Calculate the local average within a 5x5 pixel window.
import geowombat as gw
from geowombat.data import rgbn
with gw.open(rgbn, chunks=512) as src:
res = src.gw.moving(stat='mean', w=5, nodata=0)
# Compute results
res.data.compute(num_workers=4)
# or save to file
# res.gw.save('output.tif', num_workers=4)