shnitsel.data.xr_io_compatibility#

Attributes#

Classes#

SupportsToXrConversion

Definition of the protocol to support conversion of a type into

SupportsFromXrConversion

Definition of the protocol to support instantiation from

Module Contents#

ResType#
type MetaData = dict[str, str]#
class SupportsToXrConversion#

Bases: Protocol

Definition of the protocol to support conversion of a type into xarray Dataset structs mostly for io purposes

abstractmethod as_xr_dataset()#

Base function to implement by classes supporting this protocol to allow for standardized conversion to a dataset

Returns:

A tuple of the io_type_tag under which the deserializer is registered with the Shnitsel Tools framework (or None if no deserialization is desired/supported)/ Then the `xr.Dataset that is the result of the conversion. And lastly a dict of metadata that might help with deserialization later on.

Return type:

tuple[str, xr.Dataset, MetaData]

Raises:

ValueError – If the conversion failed for some reason.

class SupportsFromXrConversion#

Bases: Protocol

Definition of the protocol to support instantiation from xarray dataset structs.

classmethod get_type_marker()#
Abstractmethod:

Return type:

str

classmethod from_xr_dataset(dataset, metadata)#
Abstractmethod:

Parameters:
Return type:

ResType

Class method to support standardized deserialization of arbitrary classes. Implemented as a class method to avoid need to construct instance for deserialization.

Parameters:
  • cls (type[ResType]) – The class executing the deserialization.

  • dataset (xr.Dataset) – The dataset to be deserialized into the output type.

  • metadata (MetaData) – Metdatata from the serialization process.

Returns:

The deserialized instance of the target class.

Return type:

instance of cls

Raises:

TypeError – If deserialization of the object was not possible