Data handlers (data
)#
The general scheme is to use the following:
uv, xv -> samples (values) for u, x
u, xu -> averages of u and x*u
u[i] = <u**i>
xu[i] = <x * u**i>
xu[i, j] = <d^i x/d beta^i * u**j
Classes:
Basic version of DataCallbackABC. |
|
Base class for handling callbacks to adjust data. |
|
|
Data class using |
|
Data object based on central co-moments array. |
|
Class to hold uv/xv data. |
|
Data class using values and central moments. |
Functions:
|
Factory function to produce a DataValues object. |
|
Get indexing DataArray. |
- class thermoextrap.data.DataCallback[source]#
Bases:
DataCallbackABC
Basic version of DataCallbackABC.
Implemented to pass things through unchanged. Will be used for default construction
Methods:
check
(data)Perform any consistency checks between self and data.
derivs_args
(data, derivs_args)Adjust derivs args from data class.
resample
(data, meta_kws, **kws)Adjust create new object.
block
(data, meta_kws, **kws)Block averaging.
reduce
(data, meta_kws, **kws)Reduce along dimension.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.new_like
(**kws)Create a new object with optional parameters.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- resample(data, meta_kws, **kws)[source]#
Adjust create new object.
Should return new instance of class or self no change
- assign(**kws)[source]#
Alias to
new_like()
.
- class thermoextrap.data.DataCallbackABC[source]#
Bases:
MyAttrsMixin
Base class for handling callbacks to adjust data.
For some cases, the default Data classes don’t quite cut it. For example, for volume extrapolation, extrap parameters need to be included in the derivatives. To handle this generally, the Data class include self.meta which performs these actions.
DataCallback can be subclassed to fine tune things.
Methods:
check
(data)Perform any consistency checks between self and data.
derivs_args
(data, derivs_args)Adjust derivs args from data class.
resample
(data, meta_kws, **kws)Adjust create new object.
block
(data, meta_kws, **kws)Block averaging.
reduce
(data, meta_kws, **kws)Reduce along dimension.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.new_like
(**kws)Create a new object with optional parameters.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- abstract derivs_args(data, derivs_args)[source]#
Adjust derivs args from data class.
should return a tuple
- resample(data, meta_kws, **kws)[source]#
Adjust create new object.
Should return new instance of class or self no change
- assign(**kws)[source]#
Alias to
new_like()
.
- class thermoextrap.data.DataCentralMoments(dxduave, *, meta, umom_dim='umom', xmom_dim='xmom', rec_dim='rec', deriv_dim=None, central=False, x_is_u=None)[source]#
Bases:
DataCentralMomentsBase
Data class using
cmomy.xCentralMoments
to handle central moments.- Parameters:
dxduave (
xCentralMoments
) – Central moments object.meta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metaumom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.xmom_dim (
str
, default'xmom'
) – Name of dimension for moments of observable x.rec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativecentral (
bool
) – If True, Use central moments. Otherwise, use raw moments.x_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
Methods:
block
(block_size[, dim, axis, meta_kws])Block resample along axis.
reduce
([dim, axis, meta_kws])Reduce along axis.
resample
([nrep, freq, indices, dim, axis, ...])Resample data.
from_raw
(raw[, rec_dim, xmom_dim, umom_dim, ...])Convert raw moments to data object.
from_vals
(xv, uv, order[, xmom_dim, ...])Create DataCentralMoments object from individual (unaveraged) samples.
from_data
(data[, rec_dim, xmom_dim, ...])Create DataCentralMoments object from data.
from_resample_vals
(xv, uv, order[, freq, ...])Create DataCentralMoments object from unaveraged samples with resampling.
from_ave_raw
(u, xu[, w, axis, umom_axis, ...])Create object with <u**n>, <x * u**n> arrays.
from_ave_central
(du, dxdu[, w, xave, uave, ...])Constructor from central moments, with reduction along axis.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.cmom
()Central co-moments.
new_like
(**kws)Create a new object with optional parameters.
rmom
()Raw co-moments.
set_params
(**kws)Set parameters of self, and return self (for chaining).
Attributes:
Whether central or raw moments are used
Derivative with respect to alpha dimension
Arguments to be passed to derivative function.
Averages of
du ** n
.Selector for
du_selector[n] = du ** n
.Averages of form
dx * dx ** n
.Selector for
dxdu_selector[n] = dx * du ** n
.cmomy.xCentralMoments
objectCallback
Order of expansion.
Records dimension
Averages of form
u ** n
.Indexer for
u_selector[n] = u ** n
.Energy moment dimension
Data underlying
dxduave
.Whether observable x is same as energy u
Whether X has explicit dependence on alpha.
Averages of form observable
x
.Selector for
xave
.Overvable moment dimension
Averages of form
x * u ** n
.Indexer for
xu_select[n] = x * u ** n
.- block(block_size, dim=None, axis=None, meta_kws=None, **kwargs)[source]#
Block resample along axis.
- Parameters:
block_size (
int
) – number of sample to block average togetherdim (hashable, optional) – Dimension to reduce along.
axis (
int
) – Axis to reduce along.**kwargs – extra arguments to
cmomy.xCentralMoments.block()
- reduce(dim=None, axis=None, meta_kws=None, **kwargs)[source]#
Reduce along axis.
- Parameters:
dim (hashable, optional) – Dimension to reduce along.
axis (
int
) – Axis to reduce along.meta_kws (mapping, optional) – Optional parameters for meta.
**kwargs – Keyword arguments to
cmomy.xCentralMoments.reduce()
- resample(nrep=None, freq=None, indices=None, dim=None, axis=None, rep_dim='rep', parallel=True, resample_kws=None, meta_kws=None, **kwargs)[source]#
Resample data.
- Parameters:
freq (array of
int
, optional) – Array of shape(nrep, size)
where nrep is the number of replicates andsize = self.shape[axis]
. freq is the weight that each sample contributes to resamples values. Seerandsamp_freq()
indices (array of
int
, optional) – Array of shape(nrep, size)
. If passed, create freq from indices. Seerandsamp_freq()
.nrep (
int
, optional) – Number of replicates. Create freq with this many replicates. Seerandsamp_freq()
dim (hashable, optional) – Dimension to reduce along.
axis (
int
) – Axis to reduce along.rep_dim (hashable, optional) – Name of new ‘replicated’ dimension:
meta_kws (mapping, optional) – Parameters to self.meta.resample
resample_kws (mapping, optional) – dictionary of values to pass to self.dxduave.resample_and_reduce
- classmethod from_raw(raw, rec_dim='rec', xmom_dim='xmom', umom_dim='umom', deriv_dim=None, central=False, mom=None, val_shape=None, dtype=None, dims=None, attrs=None, coords=None, indexes=None, name=None, meta=None, x_is_u=False)[source]#
Convert raw moments to data object.
The raw moments have the form
raw[..., i, j] = weight
ifi = j = 0
. Otherwise,raw[..., i, j] = <x ** i * u ** j>
.- Parameters:
raw (array-like) – raw moments. The form of this array is such that The shape should be
(..., 2, order+1)
rec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
xmom_dim (
str
, default'xmom'
) – Name of dimension for moments of observable x.umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativecentral (
bool
) – If True, Use central moments. Otherwise, use raw moments.mom (
int
ortuple
ofint
) – Order or moments. If integer or length one tuple, then moments are for a single variable. If length 2 tuple, then comoments of two variablesval_shape (
tuple
, optional) – Shape of values part of data. That is, the non-moment dimensions.dtype (
dtype
, optional) – Optionaldtype
for output data.dims (hashable or sequence of hashable, optional) – Dimension of resulting
xarray.DataArray
.If
len(dims) == self.ndim
, then dims specifies all dimensions.If
len(dims) == self.val_ndim
,dims = dims + mom_dims
Default to
('dim_0', 'dim_1', ...)
attrs (mapping) – Attributes of output
coords (mapping) – Coordinates of output
name (hashable) – Name of output
indexes (
Any
) – indexes attribute. This is ignored.template (
DataArray
) – If present, output will have attributes of template. Overrides other options.meta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metax_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
- Returns:
output (
DataCentralMoments
)
See also
- classmethod from_vals(xv, uv, order, xmom_dim='xmom', umom_dim='umom', rec_dim='rec', deriv_dim=None, central=False, w=None, axis=None, dim=None, broadcast=True, val_shape=None, dtype=None, dims=None, attrs=None, coords=None, indexes=None, name=None, meta=None, x_is_u=False)[source]#
Create DataCentralMoments object from individual (unaveraged) samples.
- Parameters:
xv (
xarray.DataArray
) – raw values of x (observable)uv (
xarray.DataArray
) – raw values of u (energy)order (
int
) – maximum order of moments/expansion to calculatexmom_dim (
str
, default'xmom'
) – Name of dimension for moments of observable x.umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.rec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativecentral (
bool
) – If True, Use central moments. Otherwise, use raw moments.w (array-like, optional) – optional weight array. Note that this array/xarray must be conformable to uv, xv
dim (hashable, optional) – Dimension to reduce along.
axis (
int
) – Axis to reduce along.broadcast (
bool
, optional) – If True, andx=(x0, x1)
, then perform ‘smart’ broadcasting. In this case, ifx1.ndim = 1
andlen(x1) == x0.shape[axis]
, then broadcast x1 tox0.shape
.val_shape (
tuple
, optional) – Shape of values part of data. That is, the non-moment dimensions.dtype (
dtype
, optional) – Optionaldtype
for output data.dims (hashable or sequence of hashable, optional) – Dimension of resulting
xarray.DataArray
.If
len(dims) == self.ndim
, then dims specifies all dimensions.If
len(dims) == self.val_ndim
,dims = dims + mom_dims
Default to
('dim_0', 'dim_1', ...)
attrs (mapping) – Attributes of output
coords (mapping) – Coordinates of output
name (hashable) – Name of output
indexes (
Any
) – indexes attribute. This is ignored.template (
DataArray
) – If present, output will have attributes of template. Overrides other options.meta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metax_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
- Returns:
output (
DataCentralMoments
)
See also
- classmethod from_data(data, rec_dim='rec', xmom_dim='xmom', umom_dim='umom', deriv_dim=None, central=False, mom=None, val_shape=None, dtype=None, dims=None, attrs=None, coords=None, indexes=None, name=None, meta=None, x_is_u=False)[source]#
Create DataCentralMoments object from data.
- data[…, i, j] = weight i = j = 0
= < x > i = 1 and j = 0 = < u > i = 0 and j = 1 = <(x - <x>)**i * (u - <u>)**j > otherwise
- Parameters:
data (array-like)
rec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
xmom_dim (
str
, default'xmom'
) – Name of dimension for moments of observable x.umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativecentral (
bool
) – If True, Use central moments. Otherwise, use raw moments.mom (
int
ortuple
ofint
) – Order or moments. If integer or length one tuple, then moments are for a single variable. If length 2 tuple, then comoments of two variablesval_shape (
tuple
, optional) – Shape of values part of data. That is, the non-moment dimensions.dtype (
dtype
, optional) – Optionaldtype
for output data.dims (hashable or sequence of hashable, optional) – Dimension of resulting
xarray.DataArray
.If
len(dims) == self.ndim
, then dims specifies all dimensions.If
len(dims) == self.val_ndim
,dims = dims + mom_dims
Default to
('dim_0', 'dim_1', ...)
attrs (mapping) – Attributes of output
coords (mapping) – Coordinates of output
name (hashable) – Name of output
indexes (
Any
) – indexes attribute. This is ignored.template (
DataArray
) – If present, output will have attributes of template. Overrides other options.meta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metax_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
- Returns:
output (
DataCentralMoments
)
See also
- classmethod from_resample_vals(xv, uv, order, freq=None, indices=None, nrep=None, xmom_dim='xmom', umom_dim='umom', rep_dim='rep', deriv_dim=None, central=False, w=None, axis=None, dim=None, broadcast=True, dtype=None, dims=None, attrs=None, coords=None, indexes=None, name=None, resample_kws=None, parallel=True, meta=None, meta_kws=None, x_is_u=False)[source]#
Create DataCentralMoments object from unaveraged samples with resampling.
- Parameters:
{xv}
{uv}
{order}
{freq}
{indices}
{nrep}
{xmom_dim}
{umom_dim}
{rep_dim}
{deriv_dim}
{central}
w (array-like, optional) – Weights for each observation.
{axis}
{dim}
{broadcast}
{dtype}
{xr_params}
{resample_kws}
{meta}
{meta_kws}
{x_is_us}
- classmethod from_ave_raw(u, xu, w=None, axis=-1, umom_axis=None, xumom_axis=None, rec_dim='rec', xmom_dim='xmom', umom_dim='umom', deriv_dim=None, central=False, mom=None, val_shape=None, dtype=None, dims=None, attrs=None, coords=None, indexes=None, name=None, meta=None, x_is_u=False)[source]#
Create object with <u**n>, <x * u**n> arrays.
- Parameters:
u (array-like) – u[n] = <u**n>.
xu (array_like) – xu[n] = <x * u**n>.
w (array-like, optional) – sample weights
umom_axis (
int
, optional) – axis of u array corresponding to moments. Ignored if xu is an xarray.DataArray objectxumom_axis (
int
, optional) – axis of xu array corresponding to moments Ignored if xu is an xarray.DataArray objectaxis (
int
, default-1
) – if umom_axis or xumom_axis is None, set to axis Ignored if xu is an xarray.DataArray objectrec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
xmom_dim (
str
, default'xmom'
) – Name of dimension for moments of observable x.umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativecentral (
bool
) – If True, Use central moments. Otherwise, use raw moments.mom (
int
ortuple
ofint
) – Order or moments. If integer or length one tuple, then moments are for a single variable. If length 2 tuple, then comoments of two variablesdtype (
dtype
, optional) – Optionaldtype
for output data.dims (hashable or sequence of hashable, optional) – Dimension of resulting
xarray.DataArray
.If
len(dims) == self.ndim
, then dims specifies all dimensions.If
len(dims) == self.val_ndim
,dims = dims + mom_dims
Default to
('dim_0', 'dim_1', ...)
attrs (mapping) – Attributes of output
coords (mapping) – Coordinates of output
name (hashable) – Name of output
indexes (
Any
) – indexes attribute. This is ignored.template (
DataArray
) – If present, output will have attributes of template. Overrides other options.meta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metax_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
See also
- classmethod from_ave_central(du, dxdu, w=None, xave=None, uave=None, axis=-1, umom_axis=None, xumom_axis=None, rec_dim='rec', xmom_dim='xmom', umom_dim='umom', deriv_dim=None, central=False, mom=None, val_shape=None, dtype=None, dims=None, attrs=None, coords=None, indexes=None, name=None, meta=None, x_is_u=False)[source]#
Constructor from central moments, with reduction along axis.
- Parameters:
du (array-like) – du[0] = 1 or weight, du[1] = <u> or uave du[n] = <(u-<u>)**n>, n >= 2
dxdu (array-like) – dxdu[0] = <x> or xave, dxdu[n] = <(x-<x>) * (u - <u>)**n>, n >= 1
w (array-like, optional) – sample weights
xave (array-like, optional) – if present, set dxdu[0] to xave
uave (array-like, optional) – if present, set du[0] to uave
umom_axis (
int
, optional) – axis of u array corresponding to moments. Ignored if xu is an xarray.DataArray objectxumom_axis (
int
, optional) – axis of xu array corresponding to moments Ignored if xu is an xarray.DataArray objectaxis (
int
, default-1
) – if umom_axis or xumom_axis is None, set to axis Ignored if xu is an xarray.DataArray objectrec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
xmom_dim (
str
, default'xmom'
) – Name of dimension for moments of observable x.umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativecentral (
bool
) – If True, Use central moments. Otherwise, use raw moments.mom (
int
ortuple
ofint
) – Order or moments. If integer or length one tuple, then moments are for a single variable. If length 2 tuple, then comoments of two variablesval_shape (
tuple
, optional) – Shape of values part of data. That is, the non-moment dimensions.dtype (
dtype
, optional) – Optionaldtype
for output data.dims (hashable or sequence of hashable, optional) – Dimension of resulting
xarray.DataArray
.If
len(dims) == self.ndim
, then dims specifies all dimensions.If
len(dims) == self.val_ndim
,dims = dims + mom_dims
Default to
('dim_0', 'dim_1', ...)
attrs (mapping) – Attributes of output
coords (mapping) – Coordinates of output
name (hashable) – Name of output
indexes (
Any
) – indexes attribute. This is ignored.template (
DataArray
) – If present, output will have attributes of template. Overrides other options.meta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metax_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
See also
- assign(**kws)[source]#
Alias to
new_like()
.
- central#
Whether central or raw moments are used
- deriv_dim#
Derivative with respect to alpha dimension
- property derivs_args#
Arguments to be passed to derivative function.
For example,
derivs(*self.derivs_args)
.
- dxduave#
cmomy.xCentralMoments
object
- meta#
Callback
- new_like(**kws)[source]#
Create a new object with optional parameters.
- Parameters:
**kws – attribute, value pairs.
- property order#
Order of expansion.
- rec_dim#
Records dimension
- umom_dim#
Energy moment dimension
- x_is_u#
Whether observable x is same as energy u
- property xalpha#
Whether X has explicit dependence on alpha.
That is, if self.deriv_dim is not None
- xmom_dim#
Overvable moment dimension
- class thermoextrap.data.DataCentralMomentsVals(uv, xv, *, meta, umom_dim='umom', xmom_dim='xmom', rec_dim='rec', deriv_dim=None, central=False, x_is_u=None, order=None, w=None, from_vals_kws=None, dxduave=None)[source]#
Bases:
DataCentralMomentsBase
Data object based on central co-moments array.
- Parameters:
dxduave (
xCentralMoments
) – Central moments object.meta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metaumom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.xmom_dim (
str
, default'xmom'
) – Name of dimension for moments of observable x.rec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativecentral (
bool
) – If True, Use central moments. Otherwise, use raw moments.x_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
Attributes:
Stored energy values
Stored observable values
Expansion order
Stored weights
Optional parameters to
cmomy.xCentralMoments.from_vals()
cmomy.xCentralMoments
objectWhether central or raw moments are used
Derivative with respect to alpha dimension
Arguments to be passed to derivative function.
Averages of
du ** n
.Selector for
du_selector[n] = du ** n
.Averages of form
dx * dx ** n
.Selector for
dxdu_selector[n] = dx * du ** n
.Callback
Records dimension
Averages of form
u ** n
.Indexer for
u_selector[n] = u ** n
.Energy moment dimension
Data underlying
dxduave
.Whether observable x is same as energy u
Whether X has explicit dependence on alpha.
Averages of form observable
x
.Selector for
xave
.Overvable moment dimension
Averages of form
x * u ** n
.Indexer for
xu_select[n] = x * u ** n
.Methods:
from_vals
(xv, uv, order[, w, rec_dim, ...])Constructor from arrays.
resample
([nrep, freq, indices, dim, axis, ...])Resample data.
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.cmom
()Central co-moments.
new_like
(**kws)Create a new object with optional parameters.
rmom
()Raw co-moments.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- uv#
Stored energy values
- xv#
Stored observable values
- order#
Expansion order
- w#
Stored weights
- from_vals_kws#
Optional parameters to
cmomy.xCentralMoments.from_vals()
- dxduave#
cmomy.xCentralMoments
object
- classmethod from_vals(xv, uv, order, w=None, rec_dim='rec', umom_dim='umom', xmom_dim='xmom', rep_dim='rep', deriv_dim=None, val_dims='val', central=False, from_vals_kws=None, meta=None, x_is_u=False)[source]#
Constructor from arrays.
- Parameters:
xv (
xarray.DataArray
) – raw values of x (observable)uv (
xarray.DataArray
) – raw values of u (energy)order (
int
) – maximum order of moments/expansion to calculatexmom_dim (
str
, default'xmom'
) – Name of dimension for moments of observable x.umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.rec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativecentral (
bool
) – If True, Use central moments. Otherwise, use raw moments.w (array-like, optional) – optional weight array. Note that this array/xarray must be conformable to uv, xv
broadcast (
bool
, optional) – If True, andx=(x0, x1)
, then perform ‘smart’ broadcasting. In this case, ifx1.ndim = 1
andlen(x1) == x0.shape[axis]
, then broadcast x1 tox0.shape
.val_shape (
tuple
, optional) – Shape of values part of data. That is, the non-moment dimensions.dtype (
dtype
, optional) – Optionaldtype
for output data.dims (hashable or sequence of hashable, optional) – Dimension of resulting
xarray.DataArray
.If
len(dims) == self.ndim
, then dims specifies all dimensions.If
len(dims) == self.val_ndim
,dims = dims + mom_dims
Default to
('dim_0', 'dim_1', ...)
attrs (mapping) – Attributes of output
coords (mapping) – Coordinates of output
name (hashable) – Name of output
indexes (
Any
) – indexes attribute. This is ignored.template (
DataArray
) – If present, output will have attributes of template. Overrides other options.meta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metax_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
- Returns:
output (
DataCentralMomentsVals
)
See also
- resample(nrep=None, freq=None, indices=None, dim=None, axis=None, rep_dim='rep', parallel=True, resample_kws=None, meta_kws=None, **kwargs)[source]#
Resample data.
- Parameters:
nrep (
int
, optional) – Number of replicates. Create freq with this many replicates. Seerandsamp_freq()
freq (array of
int
, optional) – Array of shape(nrep, size)
where nrep is the number of replicates andsize = self.shape[axis]
. freq is the weight that each sample contributes to resamples values. Seerandsamp_freq()
indices (array of
int
, optional) – Array of shape(nrep, size)
. If passed, create freq from indices. Seerandsamp_freq()
.dim (hashable, optional) – Dimension to reduce along.
axis (
int
) – Axis to reduce along.rep_dim (hashable, optional) – Name of new ‘replicated’ dimension:
resample_kws (mapping) – Extra arguments to
resample_vals()
meta_kws (mapping, optional) – Optional parameters for meta.
**kwargs – Keyword arguments to
cmomy.xCentralMoments.from_resample_vals()
- assign(**kws)[source]#
Alias to
new_like()
.
- central#
Whether central or raw moments are used
- deriv_dim#
Derivative with respect to alpha dimension
- property derivs_args#
Arguments to be passed to derivative function.
For example,
derivs(*self.derivs_args)
.
- meta#
Callback
- new_like(**kws)[source]#
Create a new object with optional parameters.
- Parameters:
**kws – attribute, value pairs.
- rec_dim#
Records dimension
- umom_dim#
Energy moment dimension
- x_is_u#
Whether observable x is same as energy u
- property xalpha#
Whether X has explicit dependence on alpha.
That is, if self.deriv_dim is not None
- xmom_dim#
Overvable moment dimension
- class thermoextrap.data.DataValues(uv, xv, order, *, meta, rec_dim='rec', umom_dim='umom', deriv_dim=None, skipna=False, chunk=None, compute=None, build_aves_kws=None, x_is_u=False)[source]#
Bases:
DataValuesBase
Class to hold uv/xv data.
- Parameters:
uv (
xarray.DataArray
) – raw values of u (energy)xv (
xarray.DataArray
) – raw values of x (observable)order (
int
) – maximum order of moments/expansion to calculatemeta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metarec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativechunk (
bool
, optional) – chunking of xarray objectscompute (
bool
, optional) – whether to perform compute step on xarray outputsbuild_aves_kws (
Mapping | None
) – The description is missing.x_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
Attributes:
Average of x * u ** n.
Average of u ** n.
Indexer for self.u.
Indexer for self.xu.
Sequence of arguments to derivative calculation function.
Arguments to building the averages
Whether central (True) or raw (False) moments are used.
Whether to chunk the xarray objects
Whether to compute the chunked data
Derivative dimension
Callback
Expansion order
Records dimension
Whether to skip NAN values
Energy moments dimension
Energy values
Whether the observable x is the same as energy u
Whether X has explicit dependence on alpha.
Obervable values
Methods:
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.from_vals
(xv, uv, order[, rec_dim, ...])Constructor from arrays.
new_like
(**kws)Create a new object with optional parameters.
resample
([indices, nrep, rep_dim, chunk, ...])Resample object.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- property derivs_args#
Sequence of arguments to derivative calculation function.
- assign(**kws)[source]#
Alias to
new_like()
.
- build_aves_kws#
Arguments to building the averages
- property central#
Whether central (True) or raw (False) moments are used.
- chunk#
Whether to chunk the xarray objects
- compute#
Whether to compute the chunked data
- deriv_dim#
Derivative dimension
- classmethod from_vals(xv, uv, order, rec_dim='rec', umom_dim='umom', rep_dim='rep', deriv_dim=None, val_dims='val', skipna=False, chunk=None, compute=None, build_aves_kws=None, meta=None, x_is_u=False)[source]#
Constructor from arrays.
- Parameters:
uv (array-like) – raw values of u (energy) if not DataArray, wrap with xrwrap_uv
xv (
xarray.DataArray
) – raw values of x (observable) if not DataArray, wrap with xrwrap_xvorder (
int
) – maximum order of moments/expansion to calculaterec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.val_dims (
str
or sequence ofstr
) – Names of extra dimensionsderiv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativechunk (
bool
, optional) – chunking of xarray objectsmeta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metax_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
- meta#
Callback
- new_like(**kws)[source]#
Create a new object with optional parameters.
- Parameters:
**kws – attribute, value pairs.
- order#
Expansion order
- rec_dim#
Records dimension
- resample(indices=None, nrep=None, rep_dim='rep', chunk=None, compute='None', meta_kws=None, rng=None)[source]#
Resample object.
- Parameters:
indices (array of
int
, optional) – Array of shape(nrep, size)
. If passed, create freq from indices. Seerandsamp_freq()
.nrep (
int
, optional) – Number of replicates. Create freq with this many replicates. Seerandsamp_freq()
rep_dim (hashable, optional) – Name of new ‘replicated’ dimension:
chunk (
bool
, optional) – chunking of xarray objectscompute (
bool
, optional) – whether to perform compute step on xarray outputsmeta_kws (mapping, optional) – Optional parameters for meta.
rng (
Generator
, optional) – Random number generator object. Defaults to result ofcmomy.random.default_rng()
.
- skipna#
Whether to skip NAN values
- umom_dim#
Energy moments dimension
- uv#
Energy values
- x_is_u#
Whether the observable x is the same as energy u
- property xalpha#
Whether X has explicit dependence on alpha.
That is, if self.deriv_dim is not None
- xv#
Obervable values
- class thermoextrap.data.DataValuesCentral(uv, xv, order, *, meta, rec_dim='rec', umom_dim='umom', deriv_dim=None, skipna=False, chunk=None, compute=None, build_aves_kws=None, x_is_u=False)[source]#
Bases:
DataValuesBase
Data class using values and central moments.
- Parameters:
uv (
xarray.DataArray
) – raw values of u (energy)xv (
xarray.DataArray
) – raw values of x (observable)order (
int
) – maximum order of moments/expansion to calculatemeta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metarec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativechunk (
bool
, optional) – chunking of xarray objectscompute (
bool
, optional) – whether to perform compute step on xarray outputsbuild_aves_kws (
Mapping | None
) – The description is missing.x_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
Attributes:
Averages of x.
Averages of dx * du ** n.
Averages of du ** n.
Sequence of arguments to derivative calculation function.
Arguments to building the averages
Whether central (True) or raw (False) moments are used.
Whether to chunk the xarray objects
Whether to compute the chunked data
Derivative dimension
Callback
Expansion order
Records dimension
Whether to skip NAN values
Energy moments dimension
Energy values
Whether the observable x is the same as energy u
Whether X has explicit dependence on alpha.
Obervable values
Methods:
asdict
()Convert object to dictionary.
assign
(**kws)Alias to
new_like()
.from_vals
(xv, uv, order[, rec_dim, ...])Constructor from arrays.
new_like
(**kws)Create a new object with optional parameters.
resample
([indices, nrep, rep_dim, chunk, ...])Resample object.
set_params
(**kws)Set parameters of self, and return self (for chaining).
- property derivs_args#
Sequence of arguments to derivative calculation function.
- assign(**kws)[source]#
Alias to
new_like()
.
- build_aves_kws#
Arguments to building the averages
- property central#
Whether central (True) or raw (False) moments are used.
- chunk#
Whether to chunk the xarray objects
- compute#
Whether to compute the chunked data
- deriv_dim#
Derivative dimension
- classmethod from_vals(xv, uv, order, rec_dim='rec', umom_dim='umom', rep_dim='rep', deriv_dim=None, val_dims='val', skipna=False, chunk=None, compute=None, build_aves_kws=None, meta=None, x_is_u=False)[source]#
Constructor from arrays.
- Parameters:
uv (array-like) – raw values of u (energy) if not DataArray, wrap with xrwrap_uv
xv (
xarray.DataArray
) – raw values of x (observable) if not DataArray, wrap with xrwrap_xvorder (
int
) – maximum order of moments/expansion to calculaterec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.val_dims (
str
or sequence ofstr
) – Names of extra dimensionsderiv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativechunk (
bool
, optional) – chunking of xarray objectsmeta (
dict
, optional) – extra meta data/parameters to be carried along with object and child objects. if ‘checker’ in meta, then perform a callback of the form meta[‘checker](self, meta) this can also be used to override things like derivs_args. Values passed through method resample_metax_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly
- meta#
Callback
- new_like(**kws)[source]#
Create a new object with optional parameters.
- Parameters:
**kws – attribute, value pairs.
- order#
Expansion order
- rec_dim#
Records dimension
- resample(indices=None, nrep=None, rep_dim='rep', chunk=None, compute='None', meta_kws=None, rng=None)[source]#
Resample object.
- Parameters:
indices (array of
int
, optional) – Array of shape(nrep, size)
. If passed, create freq from indices. Seerandsamp_freq()
.nrep (
int
, optional) – Number of replicates. Create freq with this many replicates. Seerandsamp_freq()
rep_dim (hashable, optional) – Name of new ‘replicated’ dimension:
chunk (
bool
, optional) – chunking of xarray objectscompute (
bool
, optional) – whether to perform compute step on xarray outputsmeta_kws (mapping, optional) – Optional parameters for meta.
rng (
Generator
, optional) – Random number generator object. Defaults to result ofcmomy.random.default_rng()
.
- skipna#
Whether to skip NAN values
- umom_dim#
Energy moments dimension
- uv#
Energy values
- x_is_u#
Whether the observable x is the same as energy u
- property xalpha#
Whether X has explicit dependence on alpha.
That is, if self.deriv_dim is not None
- xv#
Obervable values
- thermoextrap.data.factory_data_values(order, uv, xv, central=False, xalpha=False, rec_dim='rec', umom_dim='umom', val_dims='val', rep_dim='rep', deriv_dim=None, skipna=False, chunk=None, compute=None, x_is_u=False, **kws)[source]#
Factory function to produce a DataValues object.
- Parameters:
order (
int
) – Highest moment <x * u ** order>. For the case x_is_u, highest order is <u ** (order+1)>uv (array-like) – raw values of u (energy) if not DataArray, wrap with xrwrap_uv
xv (
xarray.DataArray
) – raw values of x (observable) if not DataArray, wrap with xrwrap_xvcentral (
bool
) – If True, Use central moments. Otherwise, use raw moments.xalpha (
bool
, defaultFalse
) – Flag whether u depends on variable alpha.rec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
umom_dim (
str
, default'umom'
) – Name of dimension for moment of energy u.val_dims (
str
or sequence ofstr
) – Names of extra dimensionsrep_dim (hashable, optional) – Name of new ‘replicated’ dimension:
deriv_dim (
str
, defaultNone
) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivativechunk (
bool
, optional) – chunking of xarray objectscompute (
bool
, optional) – whether to perform compute step on xarray outputsx_is_u (
bool
, defaultFalse
) – if True, treat xv = uv and do adjust u/du accordingly**kws – Extra arguments passed to constructor
- Returns:
output (
DataValues
orDataValuesCentral
)
See also
- thermoextrap.data.resample_indices(size, nrep, rec_dim='rec', rep_dim='rep', replace=True, rng=None)[source]#
Get indexing DataArray.
- Parameters:
size (
int
) – size of axis to bootstrap alongnrep (
int
, optional) – Number of replicates. Create freq with this many replicates. Seerandsamp_freq()
rec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.
rep_dim (hashable, optional) – Name of new ‘replicated’ dimension:
replace (
bool
, defaultTrue
) – If True, sample with replacement.rng (
Generator
, optional) – Random number generator object. Defaults to result ofcmomy.random.default_rng()
.
- Returns:
indices (
DataArray
) – if transpose, shape=(size, nrep) else, shape=(nrep, size)