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

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, umom_dim='umom', deriv_dim=None, x_is_u=False)[source]#

Bases: MyAttrsMixin

Abstract class for data.

Attributes:

meta

Callback

umom_dim

Energy moments dimension

deriv_dim

Derivative dimension

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.

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

umom_dim#

Energy moments dimension

deriv_dim#

Derivative dimension

x_is_u#

Whether the observable x is the same as energy u

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', deriv_dim=None, xmom_dim='xmom', rec_dim='rec', central=False, x_is_u=None, use_cache=True)[source]#

Bases: AbstractData

Data object based on central co-moments array.

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

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

  • use_cache (bool) – If True (default), cache intermediate result. Speeds up calculations, but can lead to large objects.

Attributes:

dxduave

cmomy.CentralMomentsData object

xmom_dim

Overvable moment dimension

rec_dim

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

deriv_dim

Derivative dimension

meta

Callback

umom_dim

Energy moments dimension

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.CentralMomentsData object

xmom_dim#

Overvable moment dimension

rec_dim#

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

deriv_dim#

Derivative dimension

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

umom_dim#

Energy moments dimension

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, umom_dim='umom', deriv_dim=None, x_is_u=False, rec_dim='rec')[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) – Name of dimension for ‘records’, i.e., multiple observations.

  • umom_dim (str, default 'umom') – Name of dimension for moment of energy u.

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

  • 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

  • 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

Attributes:

uv

Energy values

xv

Obervable values

order

Expansion order

rec_dim

Records dimension

central

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

deriv_dim

Derivative dimension

derivs_args

Sequence of arguments to derivative calculation function.

meta

Callback

umom_dim

Energy moments dimension

x_is_u

Whether the observable x is the same as energy u

xalpha

Whether X has explicit dependence on alpha.

Methods:

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

Constructor from arrays.

resample(sampler, *[, rep_dim, meta_kws])

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

classmethod from_vals(uv, xv, *, order, rec_dim='rec', umom_dim='umom', deriv_dim=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) – 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

  • 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(sampler, *, rep_dim='rep', meta_kws=None)[source]#

Resample object.

Parameters:
  • sampler (int or array-like or IndexSampler or mapping) – Passed through resample.factory_sampler() to create an IndexSampler. Value can either be nrep (the number of replicates), freq (frequency array), a IndexSampler object, or a mapping of parameters. The mapping can have form of FactoryIndexSamplerKwargs. Allowable keys are freq, indices, ndat, nrep, nsamp, paired, rng, replace, shuffle.

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

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

asdict()[source]#

Convert object to dictionary.

assign(**kws)[source]#

Alias to new_like().

deriv_dim#

Derivative dimension

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

umom_dim#

Energy moments dimension

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