xarray.DataArray.cumulative#
- DataArray.cumulative(dim, min_periods=1)[source]#
Accumulating object for DataArrays.
- Parameters
dims (iterable of hashable) – The name(s) of the dimensions to create the cumulative window along
min_periods (
int
, default:1
) – Minimum number of observations in window required to have a value (otherwise result is NA). The default is 1 (note this is different fromRolling
, whose default is the size of the window).
- Returns
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: * time (time) datetime64[ns] 96B 1999-12-15 2000-01-15 ... 2000-11-15
>>> da.cumulative("time").sum() <xarray.DataArray (time: 12)> Size: 96B array([ 0., 1., 3., 6., 10., 15., 21., 28., 36., 45., 55., 66.]) Coordinates: * time (time) datetime64[ns] 96B 1999-12-15 2000-01-15 ... 2000-11-15