Base classes

Contents

Base classes#

class thermoextrap.core._attrs_utils.MyAttrsMixin[source]#

Bases: object

Baseclass for adding some sugar to attrs.derived classes.

Methods:

asdict()

Convert object to dictionary.

new_like(**kws)

Create a new object with optional parameters.

assign(**kws)

Alias to new_like().

set_params(**kws)

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

asdict()[source]#

Convert object to dictionary.

new_like(**kws)[source]#

Create a new object with optional parameters.

Parameters:

**kwsattribute, value pairs.

assign(**kws)[source]#

Alias to new_like().

set_params(**kws)[source]#

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

class thermoextrap.models.PiecewiseMixin[source]#

Bases: object

Provide methods for Piecewise state collection.

class thermoextrap.models.SymDerivBase(func, args=None, expand=True, post_func=None)[source]#

Bases: object

Base class for working with recursive derivatives in expansions.

Parameters:
  • func (Function) – Function to differentiate. This should (most likely) be an instance of thermoextrap.models.SymFuncBase

  • args (sequence of Symbol) – Arguments to func

  • expand (bool) – If True, apply expand()

  • post_func (str or callable()) – Transformation of base function. For example, post_fuc = -sympy.log is equivalent to passing minus_log=True If a string, then apply the following standard functions

    • minus_log : post_func = -sympy.log

    • pow_i : post_func = lambda f: pow(f, i). E.g., pow_2 => pow(f, 2)

class thermoextrap.models.SymFuncBase(beta)[source]#

Bases: Function

Base class to define a sympy function for user defined deriatives.

Methods:

deriv_args()

Symbol arguments of function.

fdiff([argindex])

Derivative of function.

eval(beta)

Evaluate function.

classmethod deriv_args()[source]#

Symbol arguments of function.

This is used by Data class to create a ‘lambdfied’ callable function.

fdiff(argindex=1)[source]#

Derivative of function. This will be used by thermoextrap.models.SymDerivBase.

classmethod eval(beta)[source]#

Evaluate function.

We use the convention of passing in beta=’None’ to evaluate the function to an indexed variable.

class thermoextrap.data.AbstractData(*, meta)[source]#

Bases: MyAttrsMixin

Abstract class for data.

Attributes:

meta

Callback

central

Whether central (True) or raw (False) moments are used.

derivs_args

Sequence of arguments to derivative calculation function.

xalpha

Whether X has explicit dependence on alpha.

Methods:

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

meta#

Callback

abstract property central#

Whether central (True) or raw (False) moments are used.

abstract property derivs_args#

Sequence of arguments to derivative calculation function.

property xalpha#

Whether X has explicit dependence on alpha.

That is, if self.deriv_dim is not None

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.DataCentralMomentsBase(dxduave, *, meta, umom_dim='umom', xmom_dim='xmom', rec_dim='rec', deriv_dim=None, central=False, x_is_u=None)[source]#

Bases: AbstractData

Data object based on central co-moments array.

Parameters:
  • dxduave (xCentralMoments) – Central moments object.

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

  • xmom_dim (str, default 'xmom') – Name of dimension for moments of observable x.

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

  • 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

Attributes:

dxduave

cmomy.xCentralMoments object

umom_dim

Energy moment dimension

xmom_dim

Overvable moment dimension

rec_dim

Records dimension

deriv_dim

Derivative with respect to alpha dimension

central

Whether central or raw moments are used

x_is_u

Whether observable x is same as energy u

order

Order of expansion.

values

Data underlying dxduave.

xu

Averages of form x * u ** n.

u

Averages of form u ** n.

xave

Averages of form observable x.

dxdu

Averages of form dx * dx ** n.

du

Averages of du ** n.

u_selector

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

xu_selector

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

xave_selector

Selector for xave.

du_selector

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

dxdu_selector

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

derivs_args

Arguments to be passed to derivative function.

meta

Callback

xalpha

Whether X has explicit dependence on alpha.

Methods:

rmom()

Raw co-moments.

cmom()

Central co-moments.

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

dxduave#

cmomy.xCentralMoments object

umom_dim#

Energy moment dimension

xmom_dim#

Overvable moment dimension

rec_dim#

Records dimension

deriv_dim#

Derivative with respect to alpha dimension

central#

Whether central or raw moments are used

x_is_u#

Whether observable x is same as energy u

property order#

Order of expansion.

property values#

Data underlying dxduave.

rmom()[source]#

Raw co-moments.

cmom()[source]#

Central co-moments.

xu[source]#

Averages of form x * u ** n.

u[source]#

Averages of form u ** n.

xave[source]#

Averages of form observable x.

dxdu[source]#

Averages of form dx * dx ** n.

du[source]#

Averages of du ** n.

u_selector[source]#

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

xu_selector[source]#

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

xave_selector[source]#

Selector for xave.

du_selector[source]#

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

dxdu_selector[source]#

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

property derivs_args#

Arguments to be passed to derivative function.

For example, derivs(*self.derivs_args).

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

meta#

Callback

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

property xalpha#

Whether X has explicit dependence on alpha.

That is, if self.deriv_dim is not None

class thermoextrap.data.DataValuesBase(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: AbstractData

Base class to work with data based on values (non-cmomy).

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

  • 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

  • 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

Attributes:

uv

Energy values

xv

Obervable values

order

Expansion order

rec_dim

Records dimension

umom_dim

Energy moments dimension

deriv_dim

Derivative dimension

skipna

Whether to skip NAN values

chunk

Whether to chunk the xarray objects

compute

Whether to compute the chunked data

build_aves_kws

Arguments to building the averages

x_is_u

Whether the observable x is the same as energy u

central

Whether central (True) or raw (False) moments are used.

derivs_args

Sequence of arguments to derivative calculation function.

meta

Callback

xalpha

Whether X has explicit dependence on alpha.

Methods:

from_vals(xv, uv, order[, rec_dim, ...])

Constructor from arrays.

resample([indices, nrep, rep_dim, chunk, ...])

Resample object.

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

uv#

Energy values

xv#

Obervable values

order#

Expansion order

rec_dim#

Records dimension

umom_dim#

Energy moments dimension

deriv_dim#

Derivative dimension

skipna#

Whether to skip NAN values

chunk#

Whether to chunk the xarray objects

compute#

Whether to compute the chunked data

build_aves_kws#

Arguments to building the averages

x_is_u#

Whether the observable x is the same as energy u

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

property central#

Whether central (True) or raw (False) moments are used.

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

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

abstract property derivs_args#

Sequence of arguments to derivative calculation function.

meta#

Callback

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

property xalpha#

Whether X has explicit dependence on alpha.

That is, if self.deriv_dim is not None