PlasmaCalcs.dimensions.behavior.BehaviorQuantity

class PlasmaCalcs.dimensions.behavior.BehaviorQuantity(value, behavior, *, MB=None, ukey=None, **kw__behavior)

Bases: object

quantity, with value and associated behavior.
behavior: dict or Behavior
this BehaviorQuantity is relevant only when behavior.compatible(obj.behavior).
E.g., behavior = dict(snap=0, units=’si’),
- relevant if obj.behavior = dict(snap=0, units=’si’, …).
- irrelevant if obj.behavior = dict(snap=1, …).
- irrelevant if obj.behavior = dict(units=’raw’, …)
note: if ukey is not None, and behavior is a Behavior,
self will store a COPY of behavior, not the original object;
this is to prevent popping ‘units’ from the original Behavior object.
MB: None or number
number of megabytes this BehaviorQuantity takes up in memory.
if None, will be calculated from self.value, if possible.
ukey: None, or str
if provided (not None), pop ‘units’ from stored behavior, and store self.uinfo = (ukey, units).
None –> don’t pop ‘units’ from stored behavior.
str –> value [any unit system] = self.value * u_convert, where
u_convert = UnitsHaver.u(self.uinfo[0], (that unit system), convert_from=self.uinfo[0])
Note, for a dimensionless value, use ukey=’’ or ukey=’1’.
The benefit of using this is that ‘units’ won’t be in self.behavior,
so self.compatible(other_behavior) won’t need to check units.
(The downside is that you must be careful to properly handle the units. see also: self.get_value.)
Every BehaviorQuantity has a unique identifier, self.id, which is a number.
BehaviorQuantity.NEXT_UNIQUE_ID is the next number to be assigned.
__init__(value, behavior, *, MB=None, ukey=None, **kw__behavior)

Methods

__init__(value, behavior, *[, MB, ukey])

compatible(behavior, *[, lenient, subdims])

get_value([units_manager])

list_points()

matches_behavior(behavior)

relevant(behavior)

Attributes

MB

NEXT_UNIQUE_ID

uinfo

property MB
number of megabytes this cached quantity takes up in memory.
if self._entered_MB is None, will be calculated from self.value.
if self.value.nbytes is not available, will be 0.
Saves value to self._MB to avoid recalculating.
compatible(behavior, *, lenient=False, subdims=False)
tells whether this cached quantity is compatible to obj with this behavior.
returns self.behavior.compatible(behavior, lenient=lenient, subdims=subdims)
get_value(units_manager=None)
return self.value; if units_manager is provided return value in units_manager.units unit system.
if self.uinfo[1] != units_manager.units, and value is an xarray with ‘units’ attr,
result will have units attr assigned to units_manager.units.
raise UnitsError if ALL of the following are True:
- units_manager was provided
- self.uinfo is None
- units_manager.units!=self.behavior[‘units’]
list_points()
returns a list of CachedQuantity objects, each with a single point (in dimension space) from self.
dimension space includes dimensions but not maindims, e.g. fluid, snap, but not x,y,z.
matches_behavior(behavior)
tells whether this cached quantity matches this behavior.
returns self.compatible(behavior, lenient=True, subdims=False).
relevant(behavior)
tells whether this cached quantity is relevant to this behavior.
‘relevant’ when self[key] == other[key] for all keys in self,
and self.dims[d] equals or is inside other.dims[d], for all d in self.dims.
only tests keys in self; other can have more keys than those in self.
returns self.compatible(behavior, lenient=True, subdims=True).
property uinfo
(ukey, units), indicating units of self.value;
self.value [any unit system] = self.value * u_convert, where
u_convert = UnitsHaver.u(ukey, (that unit system), convert_from=ukey)