shnitsel.data.dataset_containers.xr_conversion#
Functions#
|
Support function to convert simple, non-hierarchical data structures (that could be in trees) |
|
Function to support abstract deserialization of various types that could appear |
Module Contents#
- data_to_xarray_dataset(raw_data, metadata)#
Support function to convert simple, non-hierarchical data structures (that could be in trees) to xarray datasets.
- Parameters:
raw_data (xr.DataArray | xr.Dataset | Trajectory | Frames | InterState | PerState | None | SupportsToXrConversion) – Any type of raw data that should be converted. See type hints for supported types. All explicitly listed types will also be supported by deserialization. If the type is only supported through the SupportsToXrConversion interface, the type needs to be registered using the xr_io_compatibility.register_custom_xr_input_type() function before the conversion is attempted. Types not explicitly listed and not supporting the io conversion protocol will trigger an error.
metadata (dict[str, Any]) – Metadata attributes to update according to the performed conversion.
- Returns:
xr.Dataset | None – The converted dataset result or none if no conversion was possible
dict[str, Any] – The updated metadata dictionary
- Raises:
ValueError – If an unsupported type is provided for conversion.
- Return type:
tuple[xarray.Dataset | None, dict[str, Any]]
- xr_dataset_to_shnitsel_format(raw_data, metadata)#
Function to support abstract deserialization of various types that could appear in a shnitsel style hierarchical tree structure.
Will attempt to read type information from the metadata dict
- Parameters:
raw_data (xr.Dataset) – The raw dataset input that should be deserialized.
metadtata (dict[str, Any]) – Metadata dictionary for this entry. Should have a field _shnitsel_data_type with a type tag identifying the type that has been serialized in the provided raw_data parameter. For custom types, should also have a field _shnitsel_data_type_meta if metadata is required for deserialization but will be initialized to an empty dict if not provided.
- Returns:
A deserialized object of a core shnitsel tools type, core xarray type or a type registered with xr_io_compatibility.register_custom_xr_input_type(). If deserialization failed, will be returned as dataset
- Return type:
Trajectory | Frames | InterState | PerState | xr.Dataset | xr.DataArray | SupportsFromXrConversion