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.
        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.
        >>> import geowombat as gw
        >>> # Calculate the mean within a 5x5 window
        >>> with'image.tif') as src:
        >>>     res = gw.moving(ds, stat='mean', w=5, nodata=32767.0)
        >>> # Calculate the 90th percentile within a 15x15 window
        >>> with'image.tif') as src:
        >>>     res = gw.moving(stat='perc', w=15, perc=90, nodata=32767.0)


Calculate the local average within a 5x5 pixel window.

import geowombat as gw
from import rgbn

with, chunks=512) as src:

    res ='mean', w=5, nodata=0)

    # Compute results
    # or save to file
    #'output.tif', num_workers=4)