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 from Rolling, whose default is the size of the window).

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:
 * time (time) datetime64[us] 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[us] 96B 1999年12月15日 2000年01月15日 ... 2000年11月15日
On this page