shnitsel.data.xr_io_compatibility#
Attributes#
Classes#
Definition of the protocol to support conversion of a type into |
|
Definition of the protocol to support instantiation from |
Module Contents#
- ResType#
- class SupportsToXrConversion#
Bases:
ProtocolDefinition 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:
- Raises:
ValueError – If the conversion failed for some reason.
- class SupportsFromXrConversion#
Bases:
ProtocolDefinition of the protocol to support instantiation from xarray dataset structs.
- classmethod from_xr_dataset(dataset, metadata)#
- Abstractmethod:
- Parameters:
dataset (xarray.Dataset)
metadata (MetaData)
- 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