cumulatives

xarray extensions to cumsum and cumprod

xarray_extras.cumulatives.cummean(x, dim, skipna=None)
\[y_{i} = mean(x_{0}, x_{1}, ... x_{i})\]
Parameters:
  • x – any xarray object
  • dim (str) – dimension along which to calculate the mean
  • skipna (bool) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
xarray_extras.cumulatives.compound_sum(x, c, xdim, cdim)

Compound sum on arbitrary points of x along dim.

Parameters:
  • x – Any xarray object containing the data to be compounded
  • c (xarray.DataArray) – array where every row contains elements of x.coords[xdim] and is used to build a point of the output. The cells in the row are matched against x.coords[dim] and perform a sum. If different rows of c require different amounts of points from x, they must be padded on the right with NaN, NaT, or ‘’ (respectively for numbers, datetimes, and strings).
  • xdim (str) – dimension of x to acquire data from. The coord associated to it must be monotonic ascending.
  • cdim (str) – dimension of c that represent the vector of points to be compounded for every point of dim
Returns:

DataArray with all dims from x and c, except xdim and cdim, and the same dtype as x.

example:

>>> x = xarray.DataArray(
>>>     [10, 20, 30],
>>>     dims=['x'], coords={'x': ['foo', 'bar', 'baz']})
>>> c = xarray.DataArray(
>>>     [['foo', 'baz', None],
>>>      ['bar', 'baz', 'baz']],
>>>      dims=['y', 'c'], coords={'y': ['new1', 'new2']})
>>> compound_sum(x, c, 'x', 'c')
<xarray.DataArray (y: 2)>
array([40, 80])
Coordinates:
  * y        (y) <U4 'new1' 'new2'
xarray_extras.cumulatives.compound_prod(x, c, xdim, cdim)

Compound product among arbitrary points of x along dim See compound_sum().

xarray_extras.cumulatives.compound_mean(x, c, xdim, cdim)

Compound mean among arbitrary points of x along dim See compound_sum().