EbysusMhdinSnap
- class PlasmaCalcs.hookups.ebysus.ebysus_dimensions.EbysusMhdinSnap(s=None, i=None, *, t=None, params=None)
Bases:
EbysusSnapEbysusSnap but corresponding to mhd.in, only.
Methods
__eq__(v)return self==v.
__getitem__(key)equivalent to self.params[key]
__init_subclass__(*[, _serial_typename])register cls as a subclass of XarrayIoSerializable.
__iter__()raises TypeError; use .keys(), .values(), or .items() instead.
array_equals(other)return whether self == other (which is assumed to be a numpy array or xarray.DataArray).
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.
datetimestamp(calculator, **kw_datetimestamp)returns the datetime associated with this snap for this calculator.
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 used when determining file related to this snap.
from_dict(d, *[, ignore_dt])return cls from dict d.
from_idl_file(filename, *[, i])return instance of cls (e.g. BifrostlikeSnap) based on idl file.
get(key[, default])return self[key].
items()return tuple of (key, value) pairs corresponding to self.keys() and self.values().
keys()return tuple of keys of self.params
returns dict for looking up self within a DimensionValueList, given int, str, or self.
register_type(cls_to_register[, ...])register cls_to_register as a serializable subclass of XarrayIoSerializable.
return dict of info about self, including 'typename' key.
to_dict()return dictionary of info about self.
values()return tuple of values corresponding to self.keys().
var_paths_manager(calculator)return var paths manager for this snap.
with_i(i)return copy of self with i=i, or self if self.i==i already.
_assert_array_equals(other)raise DimensionValueError unless self.array_equals(other).
_assert_single(vals, *[, meaning])assert len(vals)==1.
_idl_filename_to_snap_s(*args_None, **kw_None)return s for snap, based on filename.
return simple repr for self: Classname(s, i).
Attributes
SERIAL_TYPESfilename of file for this snap: 'mhd' for this class.
ndimsizereturn snapname of this snap: self.params["snapname"]
- __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).
- __getitem__(key)
equivalent to self.params[key]
- 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.
- __iter__()
raises TypeError; use .keys(), .values(), or .items() instead.
- _assert_array_equals(other)
raise DimensionValueError unless self.array_equals(other).
- classmethod _assert_single(vals, *, meaning='value')
assert len(vals)==1. Raise DimensionKeyError if len==0; DimensionValueError if len>=2.
meaning can be provided to clarify what vals should represent, in case of crash;error message will be ‘expected exactly 1 {meaning}, but got {len(vals)}’.This check tends to make more sense coming from a DimensionValueList,but it is convenient to attach here too in case of using isel from an array.
- _dimension_key_error
alias of
SnapKeyError
- _dimension_value_error
alias of
SnapValueError
- classmethod _idl_filename_to_snap_s(*args_None, **kw_None)
return s for snap, based on filename. For this class, always return ‘mhd.in’.
(The args and kwargs are unused here, but included to match parent’s call signature.)
- _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.
- array_equals(other)
return whether self == other (which is assumed to be a numpy array or xarray.DataArray).
return False if other.size != 1. Else, compare to other.item().(Extremely convenient if comparing to xarray DataArray or numpy array,with potentially unknown size / dimensionality.Also, convenient if “self” might be DimensionValueList instead,because DimensionValueList also provides an array_equals method.)
- 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.
- datetimestamp(calculator, **kw_datetimestamp)
returns the datetime associated with this snap for this calculator.
Here, just return datetimestamp(self.file_path(calculator)).
- 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.
Here, just return self is not MISSING_SNAP. subclass should override if desired.
- 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=None)
returns the str used when determining file related to this snap.
For mhd.in snap, this is ‘’ (same result as for EbysusSnap ‘0’).(Thecalculatorinput is unused here, but included to match parent’s file_s call signature.)
- file_snap(calculator)
returns the snap used when determining file related to this snap.
Here, just returns self. Subclasses might override.
- property filename
filename of file for this snap: ‘mhd’ for this class.
- 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: boolwhether to ignore ‘dt’ key from d.This exists for backwards compatibility when reading older files;Snap previously accepted ‘dt’ key but doesn’t anymore.
- classmethod from_idl_file(filename, *, i=None)
return instance of cls (e.g. BifrostlikeSnap) based on idl file.
filename: str.file to read from. Like snapname_NNN.idl.will use s=NNN as label. E.g. snapname_071.idl –> s=’071’.snapname determined from file contents (one of the params should be “snapname”)i: None or intindex of this snapshot in a SnapList.
- get(key, default=UNSET)
return self[key]. if default is provided and self[key] doesn’t exist, return default.
- items()
return tuple of (key, value) pairs corresponding to self.keys() and self.values().
- keys()
return tuple of keys of self.params
- lookup_dict()
returns dict for looking up self within a DimensionValueList, given int, str, or self.
(used by DimensionValueList.lookup_dict)
- static register_type(cls_to_register, _serial_typename=None)
register cls_to_register as a serializable subclass of XarrayIoSerializable.
_serial_typename: str or Nonename to use for serialization. if None, use cls_to_register.__name__.
- serialize()
return dict of info about self, including ‘typename’ key.
- property snapname
return snapname of this snap: self.params[“snapname”]
- 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}
- values()
return tuple of values corresponding to self.keys().
- var_paths_manager(calculator)
return var paths manager for this snap.
calculator gets passed directly to self.var_paths_manager_cls.
- var_paths_manager_cls
alias of
EbysusVarPathsManager
- with_i(i)
return copy of self with i=i, or self if self.i==i already.