BehaviorQuantity
- class PlasmaCalcs.dimensions.behavior.BehaviorQuantity(value, behavior, *, MB=None, ukey=None, **kw__behavior)
Bases:
objectquantity, with value and associated behavior.
behavior: dict or Behaviorthis 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 numbernumber of megabytes this BehaviorQuantity takes up in memory.if None, will be calculated from self.value, if possible.ukey: None, or strif 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, whereu_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.Methods
compatible(behavior, *[, lenient, subdims])tells whether this cached quantity is compatible to obj with this behavior.
get_value([units_manager])return self.value; if units_manager is provided return value in units_manager.units unit system.
returns a list of CachedQuantity objects, each with a single point (in dimension space) from self.
matches_behavior(behavior)tells whether this cached quantity matches this behavior.
relevant(behavior)tells whether this cached quantity is relevant to this behavior.
_new_with_dims(dims, **kw_init)return new BehaviorQuantity like self but with dims instead of self.behavior.dims.
return list of contents to put in repr of self.
Attributes
number of megabytes this cached quantity takes up in memory.
NEXT_UNIQUE_ID(ukey, units), indicating units of self.value;
- 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.
- _new_with_dims(dims, **kw_init)
return new BehaviorQuantity like self but with dims instead of self.behavior.dims.
- _repr_contents()
return list of contents to put in repr of self.
- 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, whereu_convert = UnitsHaver.u(ukey, (that unit system), convert_from=ukey)