UniqueDimensionValue

class PlasmaCalcs.dimensions.dimension_tools.dimension_value.UniqueDimensionValue(name, repr=None, module_name=None, unique_includes_module=False)

Bases: Sentinel, SpecialDimensionValue

a unique dimension value, not corresponding to a usual value from a DimensionValueList.

E.g., INPUT_SNAP (defined in snaps.py) is the UniqueDimensionValue for the snap corresponding to the input deck.
Cannot provide any args or kwargs to __init__.
Equality with other dimension values only holds if the other value is a UniqueDimensionValue of the same type.
str(UniqueDimensionValue) will return the type name.
int(UniqueDimensionValue) will return None.

Methods

__init_subclass__(*[, _serial_typename])

register cls as a subclass of XarrayIoSerializable.

__new__(cls, name[, repr, module_name, ...])

return new Sentinel object.

array_equals(other)

return whether self == other (which is assumed to be a numpy array or xarray.DataArray).

copy(**kw__None)

return self; self is a Sentinel so there is only 1 instance.

deserialize(serial)

creates an XarrayIoSerializable object from a serialized representation.

equal_except_i(v)

returns whether self == v (another DimensionValue), ignoring i.

from_dict(d)

return cls from dict d.

getter(dlist)

get the value from dlist specified by self.

lookup_dict()

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.

serialize()

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.

_assert_array_equals(other)

raise DimensionValueError unless self.array_equals(other).

_assert_single(vals, *[, meaning])

assert len(vals)==1.

_getter_as_str()

returns str representation of self.getter.

_getter_from_str(dlist)

get the value from dlist specified by str self.getter.

_iseler_as_str()

returns str representation of self.iseler.

_iseler_from_str(dvals)

get the indexes from dlist specified by str self.iseler.

_iseler_when_none(dvals)

crash, because self was passed to xarray_isel or xarray_sel but self.iseler is None.

_repr_contents()

contents for repr; used by __repr__.

_repr_simple()

return simple repr for self: Classname(s, i).

Attributes

SERIAL_TYPES

i

name

ndim

s

alias to name

size

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.
static __new__(cls, name, repr=None, module_name=None, unique_includes_module=False)

return new Sentinel object.

_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 DimensionKeyError

_dimension_value_error

alias of DimensionValueError

_getter_as_str()

returns str representation of self.getter.

Use self.init_getter if it exists, else self.getter if it exists, else ‘UNKNOWN_GETTER’.
_getter_from_str(dlist)

get the value from dlist specified by str self.getter.

_iseler_as_str()

returns str representation of self.iseler.

Use self.init_iseler if it exists, else self.iseler if it exists, else ‘UNKNOWN_ISELER’.
_iseler_from_str(dvals)

get the indexes from dlist specified by str self.iseler.

_iseler_when_none(dvals)

crash, because self was passed to xarray_isel or xarray_sel but self.iseler is None.

_repr_contents()

contents for repr; used by __repr__.

_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__None)

return self; self is a Sentinel so there is only 1 instance.

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) and
all 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.
classmethod from_dict(d)

return cls from dict d.

If ‘d’ contains ‘typename’, result is like cls.deserialize(d) instead,
however, first require that result is an instance of cls (or subclass of cls).
E.g. Fluid.from_dict(dict(typename=’EppicDist’, …)) returns EppicDist,
but Snap.from_dict(dict(typename=’EppicDist’, …)) crashes with InputError.
Subclasses wishing to alter deserialize behavior will probably override this method instead.
getter(dlist)

get the value from dlist specified by self.

(Here, just returns self, the SpecialDimensionValue)
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 None
name to use for serialization. if None, use cls_to_register.__name__.
property s

alias to name

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.