PlasmaCalcs.tools.xarray_tools.xarray_io.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.
__init__()

Methods

__init__()

deserialize(serial)

from_dict(d)

register_type(cls_to_register[, ...])

serialize()

to_dict()

Attributes

SERIAL_TYPES

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