ProxySnap
- class PlasmaCalcs.dimensions.snaps.ProxySnap(s=UNSET, i=None, *, proxies=None, **kw_super)
Bases:
Snapsnap which is a proxy for one point in time but possibly different snap indices for different runs.
- proxies: dict or None
- {proxy_id(calculator): snap} pairs indicating the snap for each calculator.if None, make an empty dict.
additional args & kwargs are passed to super().__init__.Methods
__eq__(v)return self==v.
__init_subclass__(*[, _serial_typename])register cls as a subclass of XarrayIoSerializable.
copy(**kw_init)return a copy of self.
copy_add_t(t_add)create a copy of self but with t increased by t_add.
deserialize(serial)creates an XarrayIoSerializable object from a serialized representation.
returns whether self == v (another DimensionValue), ignoring i.
exists_for(calculator)returns whether this snap exists for this calculator.
file_path(calculator)returns the abspath to the file associated with this snap for this calculator.
file_s(calculator)returns the str used when determining file related to this snap.
file_snap(calculator)returns the snap which self.proxies points at for this calculator.
from_calculators(calculators, t, *[, mode, ...])return ProxySnap with proxies for each calculator at time t.
from_dict(d, *[, ignore_dt])return cls from dict d.
returns dict for looking up self within a DimensionValueList, given int, str, or self.
proxy_id(calculator)return the unique id used to identify this calculator in a ProxySnap.
register_type(cls_to_register[, ...])register cls_to_register as a serializable subclass of XarrayIoSerializable.
registry()returns dict of all defined {proxy_id: calculator} pairs.
return dict of info about self, including 'typename' key.
to_dict()return dictionary of info about self.
with_i(i)return copy of self with i=i, or self if self.i==i already.
_assign_proxy_id(calculator)assign unique calculator._proxy_id.
return the next unique proxy_id.
return simple repr for self: Classname(s, i).
return common s from proxies, if any.
Attributes
SERIAL_TYPESndims associated with this ProxySnap.
size- __eq__(v)
return self==v. Equal if:
- v is an instance of type(self), andall kw from both self._kw_eq and v._kw_eq have the same values.(any kw missing attrs will be treated as UNSET.)For DimensionValue, just compares self.s==v.s and self.i==v.i.Subclasses may add more kwargs to compare by altering _kw_def.- or, self.s == v or self.i == v, and v is not another DimensionValue- or, v is a DimensionSingleValueSpecifier and v.checker(self) gives True.Not equal if v is a DimensionValue but not an instance of type(self),e.g. class Fluid(DimensionValue):…; class Snap(DimensionValue):…;Fluid(‘H’, 0) != Snap(‘H’, 0).
- classmethod __init_subclass__(*, _serial_typename=None, **kw)
register cls as a subclass of XarrayIoSerializable.
- _serial_typename: None or str
- name to use for this type, for serialization purposes.None –> use cls.__name__.This method also sets cls._serial_typename = _serial_typename.
- classmethod _assign_proxy_id(calculator)
assign unique calculator._proxy_id.
- _dimension_value_error
alias of
SnapValueError
- classmethod _get_next_proxy_id()
return the next unique proxy_id.
- _repr_simple()
return simple repr for self: Classname(s, i).
if s is None, use Classname(i) instead.if i is None, use Classname(s, i=None) instead.Called when using PlasmaCalcs.tools.repr_simple.
- _s_from_proxies()
return common s from proxies, if any. Else, return None.
- copy(**kw_init)
return a copy of self. Can provide new kwargs here to override old values in result.
E.g. self.copy(i=7) makes a copy of self but with i=7 instead of self.i.
- copy_add_t(t_add)
create a copy of self but with t increased by t_add.
Equivalent to self.copy(t=self.t + t_add).Provided separately for convenience; shifting t can be quite useful.
- static deserialize(serial)
creates an XarrayIoSerializable object from a serialized representation.
- serial: dict or str
- str –> convert to dict via ast.literal_eval.dict must contain ‘typename’ key.
The output here will be an instance of XarrayIoSerializable.SERIAL_TYPES[typename]
- equal_except_i(v)
returns whether self == v (another DimensionValue), ignoring i.
equal if v is an instance of type(self) andall kw from both self._kw_eq and v._kw_eq have the same values.(any kw missing attrs will be treated as UNSET.)For DimensionValue: self.s==v.s and self.i==v.i. Subclasses may add more.
- exists_for(calculator)
returns whether this snap exists for this calculator.
equivalent to self.proxies[self.proxy_id(calculator)].exists_for(calculator).
- file_path(calculator)
returns the abspath to the file associated with this snap for this calculator.
Here, just return calculator.snap_filepath(self).
- file_s(calculator)
returns the str used when determining file related to this snap.
equivalent to self.proxies[self.proxy_id(calculator)].s
- file_snap(calculator)
returns the snap which self.proxies points at for this calculator.
equivalent to self.proxies[self.proxy_id(calculator)].
- classmethod from_calculators(calculators, t, *, mode='isclose', missing_ok=False, **kw_init)
return ProxySnap with proxies for each calculator at time t.
- t: number
- time, same units as snaps from calculators.
- mode: ‘isclose’ or ‘exact’
- how to determine which snap to use, if any.‘isclose’ –> np.isclose(snap.t, t). ‘exact’ –> snap.t == t.
- missing_ok: bool
- if any snap matches are not found, tells whether to raise error or use MISSING_SNAP.True –> raise SnapValueError. False –> use MISSING_SNAP for any missing snaps.
- classmethod from_dict(d, *, ignore_dt=True)
return cls from dict d. d should NOT have ‘typename’ key.
Use cls.deserialize(d) instead if d has ‘typname’ key.- ignore_dt: bool
- whether to ignore ‘dt’ key from d.This exists for backwards compatibility when reading older files;Snap previously accepted ‘dt’ key but doesn’t anymore.
- lookup_dict()
returns dict for looking up self within a DimensionValueList, given int, str, or self.
(used by DimensionValueList.lookup_dict)
- classmethod proxy_id(calculator)
return the unique id used to identify this calculator in a ProxySnap.
unique id guaranteed to be hashable.
- static register_type(cls_to_register, _serial_typename=None)
register cls_to_register as a serializable subclass of XarrayIoSerializable.
- _serial_typename: str or None
- name to use for serialization. if None, use cls_to_register.__name__.
- static registry()
returns dict of all defined {proxy_id: calculator} pairs.
(To avoid circular dependencies, this dict is stored outside of the ProxySnap class,but can be looked up here when requested.)
- property s
s associated with this ProxySnap. if UNSET, infer from self.proxies.values().
if all proxies values have the same s, use it. Else, use None.
- serialize()
return dict of info about self, including ‘typename’ key.
- to_dict()
return dictionary of info about self. Attribute values for keys in self._kw_def.
e.g. if _kw_def={‘s’, ‘i’}: result = {‘s’: self.s, ‘i’: self.i}
- with_i(i)
return copy of self with i=i, or self if self.i==i already.