XarrayIoSerializable

class PlasmaCalcs.tools.xarray_tools.xarray_io.XarrayIoSerializable

Bases: object

object that can be serialized when saving/reading xarrays.

obj == XarrayIoSerializable.deserialize(obj.serialize()).
obj.serialize() creates a dict d where ast.literal_eval(str(d)) == d,
and also d[‘typename’] == obj._serial_typename,
so that deserialize knows which type of object to create.

Methods

__init_subclass__(*[, _serial_typename])

register cls as a subclass of XarrayIoSerializable.

deserialize(serial)

creates an XarrayIoSerializable object from a serialized representation.

from_dict(d)

return cls from dict d.

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.

Attributes

SERIAL_TYPES

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 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]
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.
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__.
serialize()

return dict of info about self, including ‘typename’ key.

to_dict()

return dictionary of info about self.

subclass must override this or override self.serialize to avoid using self.to_dict