eradiate.converters#

eradiate.converters.auto_or(wrapped_converter)[source]#

A converter that allows an attribute to be set to AUTO.

Parameters:

wrapped_converter (callable()) – The converter that is used for non-AUTO values.

Returns:

callable()

eradiate.converters.convert_absorption_data(value)[source]#

Converter for atmosphere absorption coefficient data.

eradiate.converters.convert_thermoprops(value)[source]#

Converter for atmosphere thermophysical properties specifications.

eradiate.converters.on_quantity(wrapped_converter)[source]#

Apply a converter to the magnitude of a pint.Quantity.

Parameters:

wrapped_converter (callable()) – The converter which will be applied to the magnitude of a pint.Quantity.

Returns:

callable()

eradiate.converters.to_dataset(load_from_id=None)[source]#

Generates a converter that converts a value to a xarray.Dataset.

Parameters:

load_from_id (callable(), optional) – A callable with the signature f(x: str) -> Dataset used to interpret dataset identifiers. Set this parameter to handle dataset identifiers. If unset, dataset identifiers are not supported.

Returns:

A dataset converter.

Notes

The conversion logic is as follows:

  1. If the value is an xarray dataset, it is returned directly.

  2. If the value is a path-like object ending with the .nc extension, the converter tries to load a dataset from that location, first locally, then (should that fail) from the Eradiate data store.

  3. If the value is a string and load_from_id is not None, it is

    interpreted as a dataset identifier and load_from_id(value) is returned.

  4. Otherwise, a ValueError is raised.

Examples

A converter with basic dataset identifier interpretation (the passed callable may implement more complex logic, e.g. with identifier fallback substitution):

>>> aerosol_converter = to_dataset(
...     lambda x: data.load_dataset(f"spectra/particles/{x}.nc")
... )

A converter without dataset identifier interpretation:

>>> aerosol_converter = to_dataset()