Data handlers (data)

Contents

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:

DataCallback()

Basic version of DataCallbackABC.

DataCallbackABC()

Base class for handling callbacks to adjust data.

DataCentralMoments(dxduave, *, meta[, ...])

Data class using cmomy.xCentralMoments to handle central moments.

DataCentralMomentsVals(uv, xv, *, meta[, ...])

Data object based on central co-moments array.

DataValues(uv, xv, order, *, meta[, ...])

Class to hold uv/xv data.

DataValuesCentral(uv, xv, order, *, meta[, ...])

Data class using values and central moments.

Functions:

factory_data_values(order, uv, xv[, ...])

Factory function to produce a DataValues object.

resample_indices(size, nrep[, rec_dim, ...])

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).

check(data)[source]#

Perform any consistency checks between self and data.

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

block(data, meta_kws, **kws)[source]#

Block averaging.

reduce(data, meta_kws, **kws)[source]#

Reduce along dimension.

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

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 check(data)[source]#

Perform any consistency checks between self and data.

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

block(data, meta_kws, **kws)[source]#

Block averaging.

reduce(data, meta_kws, **kws)[source]#

Reduce along dimension.

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

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_meta

  • umom_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, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • central (bool) – If True, Use central moments. Otherwise, use raw moments.

  • x_is_u (bool, default False) – 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:

central

Whether central or raw moments are used

deriv_dim

Derivative with respect to alpha dimension

derivs_args

Arguments to be passed to derivative function.

du

Averages of du ** n.

du_selector

Selector for du_selector[n] = du ** n.

dxdu

Averages of form dx * dx ** n.

dxdu_selector

Selector for dxdu_selector[n] = dx * du ** n.

dxduave

cmomy.xCentralMoments object

meta

Callback

order

Order of expansion.

rec_dim

Records dimension

u

Averages of form u ** n.

u_selector

Indexer for u_selector[n] = u ** n.

umom_dim

Energy moment dimension

values

Data underlying dxduave.

x_is_u

Whether observable x is same as energy u

xalpha

Whether X has explicit dependence on alpha.

xave

Averages of form observable x.

xave_selector

Selector for xave.

xmom_dim

Overvable moment dimension

xu

Averages of form x * u ** n.

xu_selector

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 together

  • dim (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:
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 and size = self.shape[axis]. freq is the weight that each sample contributes to resamples values. See randsamp_freq()

  • indices (array of int, optional) – Array of shape (nrep, size). If passed, create freq from indices. See randsamp_freq().

  • nrep (int, optional) – Number of replicates. Create freq with this many replicates. See randsamp_freq()

  • dim (hashable, optional) – Dimension to reduce along.

  • axis (int) – Axis to reduce along.

  • rep_dim (hashable, optional) – Name of new ‘replicated’ dimension:

  • parallel (bool, default True) – flags to numba.njit

  • 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 if i = 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, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • central (bool) – If True, Use central moments. Otherwise, use raw moments.

  • mom (int or tuple of int) – Order or moments. If integer or length one tuple, then moments are for a single variable. If length 2 tuple, then comoments of two variables

  • val_shape (tuple, optional) – Shape of values part of data. That is, the non-moment dimensions.

  • dtype (dtype, optional) – Optional dtype 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_meta

  • x_is_u (bool, default False) – if True, treat xv = uv and do adjust u/du accordingly

Returns:

output (DataCentralMoments)

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 calculate

  • 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.

  • rec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.

  • deriv_dim (str, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • central (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, and x=(x0, x1), then perform ‘smart’ broadcasting. In this case, if x1.ndim = 1 and len(x1) == x0.shape[axis], then broadcast x1 to x0.shape.

  • val_shape (tuple, optional) – Shape of values part of data. That is, the non-moment dimensions.

  • dtype (dtype, optional) – Optional dtype 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_meta

  • x_is_u (bool, default False) – if True, treat xv = uv and do adjust u/du accordingly

Returns:

output (DataCentralMoments)

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, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • central (bool) – If True, Use central moments. Otherwise, use raw moments.

  • mom (int or tuple of int) – Order or moments. If integer or length one tuple, then moments are for a single variable. If length 2 tuple, then comoments of two variables

  • val_shape (tuple, optional) – Shape of values part of data. That is, the non-moment dimensions.

  • dtype (dtype, optional) – Optional dtype 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_meta

  • x_is_u (bool, default False) – if True, treat xv = uv and do adjust u/du accordingly

Returns:

output (DataCentralMoments)

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 object

  • xumom_axis (int, optional) – axis of xu array corresponding to moments Ignored if xu is an xarray.DataArray object

  • axis (int, default -1) – if umom_axis or xumom_axis is None, set to axis Ignored if xu is an xarray.DataArray object

  • 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, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • central (bool) – If True, Use central moments. Otherwise, use raw moments.

  • mom (int or tuple of int) – Order or moments. If integer or length one tuple, then moments are for a single variable. If length 2 tuple, then comoments of two variables

  • dtype (dtype, optional) – Optional dtype 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_meta

  • x_is_u (bool, default False) – if True, treat xv = uv and do adjust u/du accordingly

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 object

  • xumom_axis (int, optional) – axis of xu array corresponding to moments Ignored if xu is an xarray.DataArray object

  • axis (int, default -1) – if umom_axis or xumom_axis is None, set to axis Ignored if xu is an xarray.DataArray object

  • 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, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • central (bool) – If True, Use central moments. Otherwise, use raw moments.

  • mom (int or tuple of int) – Order or moments. If integer or length one tuple, then moments are for a single variable. If length 2 tuple, then comoments of two variables

  • val_shape (tuple, optional) – Shape of values part of data. That is, the non-moment dimensions.

  • dtype (dtype, optional) – Optional dtype 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_meta

  • x_is_u (bool, default False) – if True, treat xv = uv and do adjust u/du accordingly

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

central#

Whether central or raw moments are used

cmom()[source]#

Central co-moments.

deriv_dim#

Derivative with respect to alpha dimension

property derivs_args#

Arguments to be passed to derivative function.

For example, derivs(*self.derivs_args).

du[source]#

Averages of du ** n.

du_selector[source]#

Selector for du_selector[n] = du ** n.

dxdu[source]#

Averages of form dx * dx ** n.

dxdu_selector[source]#

Selector for dxdu_selector[n] = dx * du ** n.

dxduave#

cmomy.xCentralMoments object

meta#

Callback

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

property order#

Order of expansion.

rec_dim#

Records dimension

rmom()[source]#

Raw co-moments.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

u[source]#

Averages of form u ** n.

u_selector[source]#

Indexer for u_selector[n] = u ** n.

umom_dim#

Energy moment dimension

property values#

Data underlying dxduave.

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

xave[source]#

Averages of form observable x.

xave_selector[source]#

Selector for xave.

xmom_dim#

Overvable moment dimension

xu[source]#

Averages of form x * u ** n.

xu_selector[source]#

Indexer for xu_select[n] = x * u ** n.

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_meta

  • umom_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, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • central (bool) – If True, Use central moments. Otherwise, use raw moments.

  • x_is_u (bool, default False) – if True, treat xv = uv and do adjust u/du accordingly

Attributes:

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

central

Whether central or raw moments are used

deriv_dim

Derivative with respect to alpha dimension

derivs_args

Arguments to be passed to derivative function.

du

Averages of du ** n.

du_selector

Selector for du_selector[n] = du ** n.

dxdu

Averages of form dx * dx ** n.

dxdu_selector

Selector for dxdu_selector[n] = dx * du ** n.

meta

Callback

rec_dim

Records dimension

u

Averages of form u ** n.

u_selector

Indexer for u_selector[n] = u ** n.

umom_dim

Energy moment dimension

values

Data underlying dxduave.

x_is_u

Whether observable x is same as energy u

xalpha

Whether X has explicit dependence on alpha.

xave

Averages of form observable x.

xave_selector

Selector for xave.

xmom_dim

Overvable moment dimension

xu

Averages of form x * u ** n.

xu_selector

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 calculate

  • 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.

  • rec_dim (hashable, optional) – Name of dimension for ‘records’, i.e., multiple observations.

  • deriv_dim (str, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • central (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, and x=(x0, x1), then perform ‘smart’ broadcasting. In this case, if x1.ndim = 1 and len(x1) == x0.shape[axis], then broadcast x1 to x0.shape.

  • val_shape (tuple, optional) – Shape of values part of data. That is, the non-moment dimensions.

  • dtype (dtype, optional) – Optional dtype 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_meta

  • x_is_u (bool, default False) – if True, treat xv = uv and do adjust u/du accordingly

Returns:

output (DataCentralMomentsVals)

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. See randsamp_freq()

  • freq (array of int, optional) – Array of shape (nrep, size) where nrep is the number of replicates and size = self.shape[axis]. freq is the weight that each sample contributes to resamples values. See randsamp_freq()

  • indices (array of int, optional) – Array of shape (nrep, size). If passed, create freq from indices. See randsamp_freq().

  • dim (hashable, optional) – Dimension to reduce along.

  • axis (int) – Axis to reduce along.

  • rep_dim (hashable, optional) – Name of new ‘replicated’ dimension:

  • parallel (bool, default True) – flags to numba.njit

  • 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()

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

central#

Whether central or raw moments are used

cmom()[source]#

Central co-moments.

deriv_dim#

Derivative with respect to alpha dimension

property derivs_args#

Arguments to be passed to derivative function.

For example, derivs(*self.derivs_args).

du[source]#

Averages of du ** n.

du_selector[source]#

Selector for du_selector[n] = du ** n.

dxdu[source]#

Averages of form dx * dx ** n.

dxdu_selector[source]#

Selector for dxdu_selector[n] = dx * du ** n.

meta#

Callback

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

rec_dim#

Records dimension

rmom()[source]#

Raw co-moments.

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

u[source]#

Averages of form u ** n.

u_selector[source]#

Indexer for u_selector[n] = u ** n.

umom_dim#

Energy moment dimension

property values#

Data underlying dxduave.

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

xave[source]#

Averages of form observable x.

xave_selector[source]#

Selector for xave.

xmom_dim#

Overvable moment dimension

xu[source]#

Averages of form x * u ** n.

xu_selector[source]#

Indexer for xu_select[n] = x * u ** n.

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 calculate

  • 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_meta

  • 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.

  • deriv_dim (str, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • skipna (bool, default False) – if True, skip nan values

  • chunk (bool, optional) – chunking of xarray objects

  • compute (bool, optional) – whether to perform compute step on xarray outputs

  • build_aves_kws (Mapping | None) – The description is missing.

  • x_is_u (bool, default False) – if True, treat xv = uv and do adjust u/du accordingly

Attributes:

xu

Average of x * u ** n.

u

Average of u ** n.

u_selector

Indexer for self.u.

xu_selector

Indexer for self.xu.

derivs_args

Sequence of arguments to derivative calculation function.

build_aves_kws

Arguments to building the averages

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

meta

Callback

order

Expansion order

rec_dim

Records dimension

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

xalpha

Whether X has explicit dependence on alpha.

xv

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).

xu[source]#

Average of x * u ** n.

u[source]#

Average of u ** n.

u_selector[source]#

Indexer for self.u.

xu_selector[source]#

Indexer for self.xu.

property derivs_args#

Sequence of arguments to derivative calculation function.

asdict()[source]#

Convert object to dictionary.

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_xv

  • order (int) – maximum order of moments/expansion to calculate

  • 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 of str) – Names of extra dimensions

  • deriv_dim (str, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • skipna (bool, default False) – if True, skip nan values

  • chunk (bool, optional) – chunking of xarray objects

  • 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_meta

  • x_is_u (bool, default False) – 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:

**kwsattribute, 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. See randsamp_freq().

  • nrep (int, optional) – Number of replicates. Create freq with this many replicates. See randsamp_freq()

  • rep_dim (hashable, optional) – Name of new ‘replicated’ dimension:

  • chunk (bool, optional) – chunking of xarray objects

  • compute (bool, optional) – whether to perform compute step on xarray outputs

  • meta_kws (mapping, optional) – Optional parameters for meta.

  • rng (Generator, optional) – Random number generator object. Defaults to result of cmomy.random.default_rng().

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

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 calculate

  • 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_meta

  • 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.

  • deriv_dim (str, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • skipna (bool, default False) – if True, skip nan values

  • chunk (bool, optional) – chunking of xarray objects

  • compute (bool, optional) – whether to perform compute step on xarray outputs

  • build_aves_kws (Mapping | None) – The description is missing.

  • x_is_u (bool, default False) – if True, treat xv = uv and do adjust u/du accordingly

Attributes:

xave

Averages of x.

dxdu

Averages of dx * du ** n.

du

Averages of du ** n.

derivs_args

Sequence of arguments to derivative calculation function.

build_aves_kws

Arguments to building the averages

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

meta

Callback

order

Expansion order

rec_dim

Records dimension

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

xalpha

Whether X has explicit dependence on alpha.

xv

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).

xave[source]#

Averages of x.

dxdu[source]#

Averages of dx * du ** n.

du[source]#

Averages of du ** n.

property derivs_args#

Sequence of arguments to derivative calculation function.

asdict()[source]#

Convert object to dictionary.

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_xv

  • order (int) – maximum order of moments/expansion to calculate

  • 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 of str) – Names of extra dimensions

  • deriv_dim (str, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • skipna (bool, default False) – if True, skip nan values

  • chunk (bool, optional) – chunking of xarray objects

  • 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_meta

  • x_is_u (bool, default False) – 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:

**kwsattribute, 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. See randsamp_freq().

  • nrep (int, optional) – Number of replicates. Create freq with this many replicates. See randsamp_freq()

  • rep_dim (hashable, optional) – Name of new ‘replicated’ dimension:

  • chunk (bool, optional) – chunking of xarray objects

  • compute (bool, optional) – whether to perform compute step on xarray outputs

  • meta_kws (mapping, optional) – Optional parameters for meta.

  • rng (Generator, optional) – Random number generator object. Defaults to result of cmomy.random.default_rng().

set_params(**kws)[source]#

Set parameters of self, and return self (for chaining).

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_xv

  • central (bool) – If True, Use central moments. Otherwise, use raw moments.

  • xalpha (bool, default False) – 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 of str) – Names of extra dimensions

  • rep_dim (hashable, optional) – Name of new ‘replicated’ dimension:

  • deriv_dim (str, default None) – if deriv_dim is a string, then this is the name of the derivative dimension and xarray objects will have a derivative

  • skipna (bool, default False) – if True, skip nan values

  • chunk (bool, optional) – chunking of xarray objects

  • compute (bool, optional) – whether to perform compute step on xarray outputs

  • x_is_u (bool, default False) – if True, treat xv = uv and do adjust u/du accordingly

  • **kws – Extra arguments passed to constructor

Returns:

output (DataValues or DataValuesCentral)

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 along

  • nrep (int, optional) – Number of replicates. Create freq with this many replicates. See randsamp_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, default True) – If True, sample with replacement.

  • rng (Generator, optional) – Random number generator object. Defaults to result of cmomy.random.default_rng().

Returns:

indices (DataArray) – if transpose, shape=(size, nrep) else, shape=(nrep, size)