cmomy.wrap

Contents

cmomy.wrap#

cmomy.wrap(obj, *, mom_ndim=None, mom_axes=None, mom_dims=None, mom_params=None, dtype=None, copy=False, fastpath=False)[source]#

Wrap object with central moments class.

This will choose the correct wrapper class given the type of array (ndarray or xarray object).

Parameters:
  • obj (array-like or DataArray or Dataset) – Central Moments array.

  • mom_ndim ({1, 2}, optional) – Value indicates if moments (mom_ndim = 1) or comoments (mom_ndim=2). If not specified and data is an xarray object attempt to infer mom_ndim from mom_dims. Otherwise, default to mom_ndim = 1.

  • mom_dims (hashable or tuple of hashable) – Name of moment dimensions. If specified, infer mom_ndim from mom_dims. If also pass mom_ndim, check that mom_dims is consistent with mom_dims. If not specified, defaults to data.dims[-mom_ndim:]. This is primarily used if data is a Dataset, or if mom_dims are not the last dimensions.

  • dtype (dtype) – Optional dtype for output data.

  • copy (bool, optional) – If True, copy the data. If None or False, attempt to use view. Note that False values will be converted to None for numpy versions >2.0. This will be changed to reflect the new behavior of the copy parameter to numpy.array() when the minimum numpy version >2.0.

  • fastpath (bool) – Internal variable.

Returns:

wrapped (CentralMomentsArray or CentralMomentsData) – Wrapped object. If input data is an xarray object, then return CentralMomentsData instance. Otherwise, return CentralMomentsArray instance.

Examples

>>> data = [10.0, 2.0, 3.0]
>>> wrap(data)
<CentralMomentsArray(mom_ndim=1)>
array([10.,  2.,  3.])
>>> xdata = xr.DataArray(data, dims="mom")
>>> wrap(xdata)
<CentralMomentsData(mom_ndim=1)>
<xarray.DataArray (mom: 3)> Size: 24B
array([10.,  2.,  3.])
Dimensions without coordinates: mom