lnPi data classes and routines (lnpidata
)#
Classes:
|
Wrapper on lnPi lnPiArray |
|
Masked array like wrapper for lnPi data. |
- class lnpy.lnpidata.lnPiArray(lnz, data, state_kws=None, extra_kws=None, fill_value=None, copy=False)[source]#
Bases:
object
Wrapper on lnPi lnPiArray
Methods:
new_like
([lnz, data, copy])Create new object with optional replacements.
pad
([axes, ffill, bfill, limit])Pad nan values in underlying data to values
zeromax
([mask])Shift values such that lnpi.max() == 0
- new_like(lnz=None, data=None, copy=False)[source]#
Create new object with optional replacements.
All parameters are optional. If not passed, use values in self
- Parameters:
{lnz}
{data}
{copy}
- Returns:
out (
lnPiArray
) – New object with optionally updated parameters.
- pad(axes=None, ffill=True, bfill=False, limit=None)[source]#
Pad nan values in underlying data to values
- Parameters:
- Returns:
out (
lnPiArray
) – object with padded data
- zeromax(mask=False)[source]#
Shift values such that lnpi.max() == 0
- Parameters:
mask (
bool
or array-like ofbool
) – Optional mask to apply to data. Where mask is True, data is excluded from calculating maximum.
- class lnpy.lnpidata.lnPiMasked(lnz, base, mask=None, copy=False)[source]#
Bases:
AccessorMixin
Masked array like wrapper for lnPi data.
This is the basic data structure for storing the output from a single TMMC simulation.
- Parameters:
Notes
Note that in most cases,
lnPiMasked
should not be called directly. Rather, a constructor likefrom_data()
should be used to construct the object.Note the the value of lnz is the value to reweight to.
Basic terminology:
T : temperature.
k : Boltzmann’s constant.
beta : Inverse temperature = 1/(k T).
mu : chemical potential.
lnz : log of activity = ln(z).
z : activity = beta * mu.
lnPi : log of macrostate distribution.
See also
Methods:
from_data
(lnz, lnz_data, data[, mask, ...])Create
lnPiMasked
object from raw data.filled
([fill_value])Filled view or reweighted data
local_argmax
(*args, **kwargs)Calculate index of maximum of masked data.
local_max
(*args, **kwargs)Calculate index of maximum of masked data.
local_maxmask
(*args, **kwargs)Calculate mask where
self.ma == self.local_max()
edge_distance
(ref, *args, **kwargs)Distance of local maximum value to nearest background point.
new_like
([lnz, base, mask, copy])Create new object with optional parameters
pad
([axes, ffill, bfill, limit])Pad nan values in underlying data to values
zeromax
()Shift so that lnpi.max() == 0 on reference
reweight
(lnz)Create new object at specified value of lnz
or_mask
(mask)New object with logical or of self.mask and mask
and_mask
(mask)New object with logical and of self.mask and mask
from_table
(path, lnz[, state_kws, sep, ...])Create lnPi object from text file table with columns [n_0,...,n_ndim, lnpi]
from_dataarray
(da[, state_as_attrs])Create a lnPi object from
xarray.DataArray
list_from_masks
(masks[, convention])Create list of lnpis corresponding to masks[i]
list_from_labels
(labels[, features, ...])Create sequence of lnpis from labels array.
decorate_accessor
(name[, single_create])Register a property name to class of type accessor(self).
register_accessor
(name, accessor[, ...])Register a property name to class of type accessor(self)
Attributes:
Type (dtype) of underling data
State variables.
Extra parameters.
Masked array view of data reweighted data
Reweighted data
Where True, values are masked out.
Shape of lnPiArray
Value of log(activity) evaluated at
Alias to self.lnz
Accessor to self.state_kws['volume'].
Accessor to self.state_kws['beta'].
Matrix of distance from each element to a background (i.e., masked) point.
Accessor to
xGrandCanonical
.Accessor to
xCanonical
.- classmethod from_data(lnz, lnz_data, data, mask=None, state_kws=None, extra_kws=None, fill_value=None, copy=False)[source]#
Create
lnPiMasked
object from raw data.
- property dtype#
Type (dtype) of underling data
- property state_kws#
State variables.
- property extra_kws#
Extra parameters.
- property ma#
Masked array view of data reweighted data
- property data#
Reweighted data
- property mask#
Where True, values are masked out.
- property shape#
Shape of lnPiArray
- property lnz#
Value of log(activity) evaluated at
- property betamu#
Alias to self.lnz
- property volume#
Accessor to self.state_kws[‘volume’].
- property beta#
Accessor to self.state_kws[‘beta’].
- local_argmax(*args, **kwargs)[source]#
Calculate index of maximum of masked data.
- Parameters:
*args – Positional arguments to argmax
**kwargs – Keyword arguments to argmax
- local_max(*args, **kwargs)[source]#
Calculate index of maximum of masked data.
- Parameters:
*args – Positional arguments to argmax
**kwargs – Keyword arguments to argmax
See also
- edge_distance_matrix[source]#
Matrix of distance from each element to a background (i.e., masked) point.
See also
- edge_distance(ref, *args, **kwargs)[source]#
Distance of local maximum value to nearest background point.
If edge_distance is too small, the value of properties calculated from this lnPi cannot be trusted. This usually is due to the data being reweighted to too high a value of lnz, or not sampled to sufficiently high values of N.
- new_like(lnz=None, base=None, mask=None, copy=False)[source]#
Create new object with optional parameters
- pad(axes=None, ffill=True, bfill=False, limit=None)[source]#
Pad nan values in underlying data to values
- Parameters:
- Returns:
out (
lnPiMasked
) – padded object
See also
- classmethod from_table(path, lnz, state_kws=None, sep='\\s+', names=None, csv_kws=None, **kwargs)[source]#
Create lnPi object from text file table with columns [n_0,…,n_ndim, lnpi]
- Parameters:
path (path-like) – file object to be read
lnz (array-like) – \(\beta \mu\) for each component
state_kws (
dict
, optional) – define state variables, like volume, betasep (
string
, optional) – separator for file readcsv_kws (
dict
, optional) – optional arguments to pandas.read_csv**kwargs – Passed to lnPi constructor
- classmethod from_dataarray(da, state_as_attrs=None, **kwargs)[source]#
Create a lnPi object from
xarray.DataArray
- Parameters:
da (
DataArray
) – DataArray containing the lnPi datastate_as_attrs (
bool
, optional) – If True, get state_kws fromda.attrs
.**kwargs – Extra arguments to
from_data()
- Returns:
See also
- list_from_masks(masks, convention='image')[source]#
Create list of lnpis corresponding to masks[i]
- Parameters:
masks (sequence of
None
orndarray
ofbool
) – Masks using “masked” convention. Where mask[i] is True, values are excluded for sample i.convention (
string
orbool
) – Convention for mask. Allowable values are:- ‘image’ or TrueTrue values included, False values excluded.
This is the normal convention in
scipy.ndimage
.
- ‘masked’ or False: False values are included, True values are excluded.
This is the convention in
numpy.ma
- Returns:
lnpis (
list
) – list of lnpis corresponding to each mask
See also
- list_from_labels(labels, features=None, include_boundary=False, check_features=True, **kwargs)[source]#
Create sequence of lnpis from labels array.
- Parameters:
labels (
ndarray
ofint
) – Each unique value i in labels indicates a mask. That islabels == i
is a mask for feature i.features (sequence of
int
) – If specified, extract only those locations wherelabels == feature
for all valuesfeature in features
. That is, select a subset of unique label values.include_boundary (
bool
) – if True, include boundary regions in output maskcheck_features (
bool
) – if True, then make sure each feature is in labels**kwargs – Extra arguments to to
labels_to_masks()
- Returns:
outputs (
list
oflnPiMasked
)
- xge[source]#
Accessor to
xGrandCanonical
.
- xce[source]#
Accessor to
xCanonical
.
- classmethod decorate_accessor(name, single_create=False)[source]#
Register a property name to class of type accessor(self).
Examples
>>> class parent(AccessorMixin): ... pass
>>> @parent.decorate_accessor("hello") ... class hello(AccessorMixin): ... def __init__(self, parent): ... self._parent = parent ... ... def there(self): ... return f"{type(self._parent)}"
>>> x = parent() >>> x.hello.there() "<class 'lnpy.extensions.parent'>"
- classmethod register_accessor(name, accessor, single_create=False)[source]#
Register a property name to class of type accessor(self)
Examples
>>> class parent(AccessorMixin): ... pass >>> class hello(AccessorMixin): ... def __init__(self, parent): ... self._parent = parent ... ... def there(self): ... return f"{type(self._parent)}"
>>> parent.register_accessor("hello", hello) >>> x = parent() >>> x.hello.there() "<class 'lnpy.extensions.parent'>"