LoadablePattern

class PlasmaCalcs.quantities.quantity_tools.LoadablePattern(fname, *, deps=[], attr_deps=[], value_deps=[], dims=None, ignores_dims=[], reduces_dims=[], **kw_super)

Bases: LoadableQuantity

quantity which can be loaded from a QuantityLoader.

QuantityLoader.KNOWN_PATTERNS will be a dict of {Pattern: LoadablePattern} pairs.
fname: str
name of the callable used to calculate this quantity,
via getattr(obj,fname)(…), where obj is a QuantityLoader.
deps: list of str/int/tuple/dict/callable
list of dependencies for this quant. Each dependency is one of the following:
- a str, indicating a known var or pattern name,
- an int, indicating a group index from a pattern match,
- a 2-tuple of (non-tuple-dep, dict),
where dict tells any values essential to set via quantity_loader.using(**dict),
in order to properly determine deps.
E.g. (‘n’, {‘fluid’: ELECTRON}) for ‘depends on n when self.fluid=electron’.
Note: mostly intended for internal use (in value_deps). It’s usually preferable to
just define a different variable, e.g. ‘ne’ which will set values appropriately.
- a dict with length 1, with
key = int or tuple of ints, specifying which groups are relevant.
dep will utilize info about groups = _match.groups().
val = str, or callable f -> str or iterable.
str –> val.format(**group_info), where
group_info = {f’group{i}’: groups[i] for i in key},
replacing groups[i] with ‘’ if groups[i] is None.
callable f –> f(group_info), where
group_info = {i: groups[i] for i in key}
- a callable of the form f(quantity_loader, var, groups) -> str or iterable,
which tells the var name(s) associated with this dependency,
where: quantity_loader is a QuantityLoader instance,
var is the matched var,
and groups=_match.groups() if _match provided else None.
attr_deps: list of 2-tuples of (str, dict or str)
list of attr-based dependencies for this quant. Each dependency is:
(attr, lookup), where lookup.get(v, []) tells str or list of deps associated with v,
where v=quantity_loader.attr.
if ‘__default__’ in lookup, use lookup.get(v, lookup[‘__default__’]) instead.
str lookup –> lookup = getattr(quantity_loader, lookup).
value_deps: list of 2-tuples of (str, dict or str)
list of value-based dependencies for this quant. Each dependency is:
(var, lookup), where lookup.get(val, []) tells str or list of deps associated with val,
for all unique vals in quantity_loader(var).
Each dep associated with val may be str/int/callable, similar to deps.
if ‘__default__’ in lookup, use lookup.get(v, lookup[‘__default__’]) instead.
str lookup –> lookup = getattr(quantity_loader, lookup).
dims: None or list of strings
dimensions associated directly with this quantity. E.g. [‘fluid’, ‘snap’]
None –> this quant is not directly associated with any dims.
ignores_dims: list of strings
dimensions which the result ignores, even if the dependencies don’t ignore.
E.g. ‘mod_(.+)’ has ignores_dims=[‘component’],
because it provides the same result regardless of obj.component.
reduces_dims: list of strings
dimensions which the result reduces along.
E.g. ‘ldebye_subset’ has reduces_dims=[‘fluid’],
because the result doesn’t have ‘fluid’ dim even though it depends on obj.fluid.

Methods

__getitem__(key)

returns self.{key}, if key in self.keys().

get_f(quantity_loader)

returns the callable to use to calculate this quantity, for this quantity_loader.

get_f_module(quantity_loader)

returns the module in which this quantity is defined, for this quantity_loader.

items()

returns (key, self[key]) for key in self.keys().

keys()

returns keys whose values can be accessed via self[key].

_repr_contents(*[, _skip_fname_if])

return contents for __repr__.

_repr_deps()

return repr for deps in self.

_repr_special_deps(special_deps)

return repr for attr_deps or value_deps in self.

__getitem__(key)

returns self.{key}, if key in self.keys().

_repr_contents(*, _skip_fname_if=None)

return contents for __repr__.

_repr_deps()

return repr for deps in self.

_repr_special_deps(special_deps)

return repr for attr_deps or value_deps in self.

get_f(quantity_loader)

returns the callable to use to calculate this quantity, for this quantity_loader.

get_f_module(quantity_loader)

returns the module in which this quantity is defined, for this quantity_loader.

items()

returns (key, self[key]) for key in self.keys().

keys()

returns keys whose values can be accessed via self[key].

i.e.: (‘fname’, ‘deps’, ‘attr_deps’, ‘value_deps’, ‘dims’, ‘ignores_dims’, ‘reduces_dims’).