xarray.DataArray.rolling (original) (raw)

DataArray.rolling(dim=None, min_periods=None, center=False, **window_kwargs)[source]#

Rolling window object for DataArrays.

Parameters:

Returns:

computation.rolling.DataArrayRolling

Examples

Create rolling seasonal average of monthly data e.g. DJF, JFM, …, SON:

da = xr.DataArray( ... np.linspace(0, 11, num=12), ... coords=[ ... pd.date_range( ... "1999-12-15", ... periods=12, ... freq=pd.DateOffset(months=1), ... ) ... ], ... dims="time", ... ) da <xarray.DataArray (time: 12)> Size: 96B array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.]) Coordinates:

Remove the NaNs using dropna():

da.rolling(time=3, center=True).mean().dropna("time") <xarray.DataArray (time: 10)> Size: 80B array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) Coordinates: