earthkit.data.field.handler.labels

Classes

Labels

Abstract base class for Field component handlers.

SimpleLabels

dict() -> new empty dictionary

Module Contents

class earthkit.data.field.handler.labels.Labels

Bases: 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 = 'labels'
abstractmethod check(owner)

Check the FieldComponent for consistency with the owner Field.

property component

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 items()

Return the metadata items.

Return type:

Iterable of (key,value) pairs

abstractmethod keys()

Return the metadata keys.

Return type:

Iterable of str

abstractmethod remove(*args)
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.labels.SimpleLabels

Bases: dict, Labels

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

KEYS = ()
NAME = 'labels'
check(owner)

Check the FieldComponent for consistency with the owner Field.

property component

Return the FieldComponent.

abstractmethod dump(*args, **kwargs)

Populate the namespace dictionary for this FieldComponent.

classmethod from_any(data, dict_kwargs=None)

Create a SimpleLabels object from any input.

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

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

Returns:

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

Return type:

SimpleLabels

classmethod from_dict(d)

Create a SimpleLabels object from a dictionary.

Parameters:

d (dict) – Dictionary containing parameter data.

Returns:

The created SimpleLabels instance.

Return type:

SimpleLabels

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

Return the value for key if key is in the dictionary, else default.

get_grib_context(context)

Populate the GRIB context dictionary for this FieldComponent.

pop(key, default=None)

D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise, raise a KeyError.

remove(*args)
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

to_dict()