earthkit.data.field.handler.core

Attributes

Classes

FieldComponentHandler

Abstract base class for Field component handlers.

LazyFieldComponentHandler

SimpleFieldComponentHandler

A FieldComponent that wraps a specification object.

Module Contents

type earthkit.data.field.handler.core.FieldComponent = Any
class earthkit.data.field.handler.core.FieldComponentHandler

Abstract base class for Field component handlers.

A FieldComponent represents a component of a Field, such as time, vertical level, or processing information. It stores a specification object, the “spec”, and provides methods to access and manipulate the specification data.

It is meant to be used internally by the Field class and its members.

KEYS

A tuple of keys from the “spec” that can be accessed as properties on the FieldComponent.

Type:

tuple

ALIASES

An Aliases object that maps alternative key names to their canonical names.

Type:

Aliases

ALL_KEYS

A tuple of all keys, including aliases, that can be accessed from the FieldComponent.

Type:

tuple

NAME

The name of the FieldComponent to be used as an identifier in the Field. It is also the name of the corresponding namespace in the Field.

Type:

str

DUMP_KEYS

A tuple of keys that should be included in the namespace represented by the FieldComponent.

Type:

tuple

KEYS = ()
NAME = None
abstractmethod check(owner)

Check the FieldComponent for consistency with the owner Field.

property component: FieldComponent
Abstractmethod:

Return the FieldComponent.

abstractmethod dump(*args, **kwargs)

Populate the namespace dictionary for this FieldComponent.

classmethod from_any(**kwargs)
Abstractmethod:

Create a FieldComponentHandler instance from any allowed input types.

Parameters:

kwargs (dict) – Keyword arguments containing specification data.

Returns:

The created FieldComponentHandler instance.

Return type:

FieldComponentHandler

classmethod from_dict(d)
Abstractmethod:

Create a FieldComponentHandler instance from a dictionary.

Parameters:

d (dict) – Dictionary containing specification data.

Returns:

The created FieldComponentHandler instance.

Return type:

FieldComponentHandler

abstractmethod get(key, default=None, *, astype=None, raise_on_missing=False)

Return the value for key.

Parameters:
  • key (str) – Key

  • default (value) – Specify the default value for key. Returned when key is not found or its value is a missing value and raise_on_missing is False.

  • astype (type as str, int or float) – Return/access type for key. When it is supported astype is passed to the underlying accessor as an option. Otherwise the value is cast to astype after it is taken from the accessor.

  • raise_on_missing (bool) – When it is True raises an exception if key is not found or it has a missing value.

Returns:

Returns the key value. Returns default if key is not found or it has a missing value and raise_on_missing is False.

Return type:

value

Raises:

KeyError – If raise_on_missing is True and key is not found or it has a missing value.

abstractmethod get_grib_context(context)

Populate the GRIB context dictionary for this FieldComponent.

abstractmethod set(*args, **kwargs)

Create a new FieldComponent instance with updated data.

Parameters:
  • *args – Positional arguments.

  • **kwargs – Keyword arguments.

Returns:

The created FieldComponent instance.

Return type:

FieldComponent

class earthkit.data.field.handler.core.LazyFieldComponentHandler
class earthkit.data.field.handler.core.SimpleFieldComponentHandler(component)

Bases: FieldComponentHandler

A FieldComponent that wraps a specification object.

Parameters:

component (Component) – The type of the specification object wrapped by the FieldComponent. To be defined in subclasses.

Notes

This class is still abstract and cannot be instantiated directly. Subclasses must define the SPEC_CLS attribute to specify the type of the specification object they wrap. They also need to implement the get_grib_context method.

COMPONENT_CLS = None
COMPONENT_MAKER = None
KEYS = ()
NAME = None
check(owner)

Default check implementation.

property component: Any

Return the component object.

classmethod create_empty()
Abstractmethod:

dump(owner, name, result, prefix_keys=False)

Populate the namespace dictionary for this SpecFieldComponent.

classmethod from_any(data, dict_kwargs=None)

Create a SimpleFieldComponent object from any input.

Parameters:
  • data (Any) – The input data from which to create the SimpleFieldComponent instance.

  • dict_kwargs (dict, optional) – Additional keyword arguments to be passed when creating the instance from a dictionary.

Returns:

An instance of SimpleFieldComponentHandler. If the input is already an instance of SimpleFieldComponentHandler, it is returned as is. Otherwise, it is assumed to be a component object and a new SimpleFieldComponentHandler instance is created from it.

Return type:

SimpleFieldComponentHandler

classmethod from_component(component)
Abstractmethod:

Create a SimpleFieldComponent object from a component object.

classmethod from_dict(d, **kwargs)

Create a SimpleFieldComponent object from a dictionary.

get(key, default=None, *, astype=None, raise_on_missing=False)

Return the value for key.

Parameters:
  • key (str) – Key

  • default (value) – Specify the default value for key. Returned when key is not found or its value is a missing value and raise_on_missing is False.

  • astype (type as str, int or float) – Return/access type for key. When it is supported astype is passed to the underlying accessor as an option. Otherwise the value is cast to astype after it is taken from the accessor.

  • raise_on_missing (bool) – When it is True raises an exception if key is not found or it has a missing value.

Returns:

Returns the key value. Returns default if key is not found or it has a missing value and raise_on_missing is False.

Return type:

value

Raises:

KeyError – If raise_on_missing is True and key is not found or it has a missing value.

abstractmethod get_grib_context(context)

Populate the GRIB context dictionary for this FieldComponent.

set(*args, **kwargs)

Create a new SimpleFieldComponentHandler instance with updated component data.