cumulatives

Advanced cumulative sum/productory/mean functions

xarray_extras.cumulatives.compound_mean(x: xarray_extras.cumulatives.T, c: xarray.DataArray, xdim: collections.abc.Hashable, cdim: collections.abc.Hashable) xarray_extras.cumulatives.T

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

xarray_extras.cumulatives.compound_prod(x: xarray_extras.cumulatives.T, c: xarray.DataArray, xdim: collections.abc.Hashable, cdim: collections.abc.Hashable) xarray_extras.cumulatives.T

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

xarray_extras.cumulatives.compound_sum(x: xarray_extras.cumulatives.T, c: xarray.DataArray, xdim: collections.abc.Hashable, cdim: collections.abc.Hashable) xarray_extras.cumulatives.T

Compound sum on arbitrary points of x along dim.

Parameters
  • xDataArray or Dataset 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 (hashable) – dimension of x to acquire data from. The coord associated to it must be monotonic ascending.

  • cdim (hashable) – dimension of c that represent the vector of points to be compounded for every point of dim

Returns

xarray object of the same type and dtype as x, with all dims from x and c except xdim and cdim.

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.cummean(x: T, dim: Hashable, skipna: bool | None = None) T
\[y_{i} = mean(x_{0}, x_{1}, ... x_{i})\]
Parameters
  • xDataArray or Dataset

  • dim (hashable) – 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).

Returns

xarray object of the same type, dtype, and shape as x