earthkit.data.field.component.proc

Classes

EmptyProc

An empty processing component, which represents the absence of any processing information.

Proc

A class to describe post-processing operations related to a field.

ProcBase

Base class to describe post-processing operations related to a field.

ProcItem

A base class for field processing items.

TimeProcItem

A time processing item, which consists of a time span value and a time processing method.

Module Contents

class earthkit.data.field.component.proc.EmptyProc

Bases: ProcBase

An empty processing component, which represents the absence of any processing information.

aliases()

Return the aliases in the component.

classmethod from_dict(d)

Create a FieldComponent instance from a dictionary.

Parameters:

d (dict) – Dictionary containing specification data.

Returns:

The created FieldComponent instance.

Return type:

FieldComponent

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

Return the value for the specified key.

Parameters:
  • key (str) – The key to retrieve.

  • default (Any, optional) – The default value to return if the key is not found. Default is None.

  • astype (type, optional) – The type to which the value should be cast. Default is None.

  • raise_on_missing (bool, optional) – If True, raise a KeyError if the key is not found. Default is False.

Returns:

The value for the specified key.

Return type:

Any

Raises:

KeyError – If raise_on_missing is True and the key is not found.

items()
keys()

Return the available keys in the component.

set(*args, **kwargs)

Create a new instance with updated data.

Parameters:
  • *args – Positional arguments.

  • **kwargs – Keyword arguments.

Returns:

The created FieldComponent instance.

Return type:

FieldComponent

Raises:

KeyError – If any of the keys to be set are not supported.

time()

Return the first time processing item.

Returns:

The first time processing item or None if not available.

Return type:

TimeProcItem, None

time_method()

Return the processing method from the first time processing item.

Returns:

The processing method from the first time processing item or None if not available.

Return type:

str, None

time_value()

Return the processing value from the first time processing item.

Returns:

The processing value from the first time processing item or None if not available.

Return type:

str, None

to_dict()

Convert the object to a dictionary.

Returns:

Dictionary representation of the object.

Return type:

dict

class earthkit.data.field.component.proc.Proc(items)

Bases: ProcBase

A class to describe post-processing operations related to a field.

Parameters:

items (list of ProcItem) – A list of processing items, which can include different types of processing items. Currently, the only supported type of processing item is TimeProcItem, which represents certain time processing operations.

aliases()

Return the aliases in the component.

classmethod from_dict(d)

Create a Ensemble object from a dictionary.

Parameters:

d (dict) – Dictionary containing parameter data.

Returns:

The created Realisation instance.

Return type:

Realisation

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

Return the value for the specified key.

Parameters:
  • key (str) – The key to retrieve.

  • default (Any, optional) – The default value to return if the key is not found. Default is None.

  • astype (type, optional) – The type to which the value should be cast. Default is None.

  • raise_on_missing (bool, optional) – If True, raise a KeyError if the key is not found. Default is False.

Returns:

The value for the specified key.

Return type:

Any

Raises:

KeyError – If raise_on_missing is True and the key is not found.

items()
keys()

Return the available keys in the component.

abstractmethod set(*args, **kwargs)

Set new values for the processing component and return a new instance.

This method is currently not implemented, and raises a NotImplementedError.

time()

Return the time processing item.

time_method()

Return the time processing method.

time_value()

Return the time processing value.

to_dict()

Convert the object to a dictionary.

Returns:

Dictionary representation of the object.

Return type:

dict

class earthkit.data.field.component.proc.ProcBase

Bases: earthkit.data.field.component.component.SimpleFieldComponent

Base class to describe post-processing operations related to a field.

This class defines the interface for processing components, which can represent different types of temporal or spatial processing operations.

Please note this is interface is still under development and and its final form is not yet fully defined.

The processing information is stored as a list of ProcItem instances, which can include different types of processing items. Currently, the only supported type of processing item is TimeProcItem, which represents certain time processing operations.

The current interface only allows access to the first temporal processing item in the list of processing items (if any), and its associated value and method. Each of these methods has an associated key that can be used in the get() method to retrieve the corresponding information. The list of supported keys are as follows:

  • “time”

  • “time_value”

  • “time_method”

Typically, this object is used as a component of a field, and can be accessed via the time attribute of a field. The keys above can also be accessed via the get() method of the field, using the “proc.” prefix.

The following example demonstrates how to access the time information from a field using various methods and keys:

>>> import earthkit.data as ekd
>>> field = ekd.from_source("file", "lsp_step_range.grib2").to_fieldlist()[0]
>>> field.proc.time()
TimeProcItem(datetime.timedelta(hours=72), <TimeMethods.ACCUM: 'accum
>>> field.proc.time_value()
datetime.timedelta(hours=72)
>>> field.proc.get("time_value")
datetime.timedelta(hours=72)
>>> field.proc.get("time_method")
<TimeMethods.ACCUM: 'accum'>

The time component is immutable. Currently, no set method is implemented, but in the future, a set method will be added to create a new instance with updated values.

aliases()

Return the aliases in the component.

classmethod from_dict(d)
Abstractmethod:

Create a FieldComponent instance from a dictionary.

Parameters:

d (dict) – Dictionary containing specification data.

Returns:

The created FieldComponent instance.

Return type:

FieldComponent

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

Return the value for the specified key.

Parameters:
  • key (str) – The key to retrieve.

  • default (Any, optional) – The default value to return if the key is not found. Default is None.

  • astype (type, optional) – The type to which the value should be cast. Default is None.

  • raise_on_missing (bool, optional) – If True, raise a KeyError if the key is not found. Default is False.

Returns:

The value for the specified key.

Return type:

Any

Raises:

KeyError – If raise_on_missing is True and the key is not found.

abstractmethod items()
keys()

Return the available keys in the component.

abstractmethod set(*args, **kwargs)

Create a new instance with updated data.

Parameters:
  • *args – Positional arguments.

  • **kwargs – Keyword arguments.

Returns:

The created FieldComponent instance.

Return type:

FieldComponent

Raises:

KeyError – If any of the keys to be set are not supported.

abstractmethod time()

Return the first time processing item.

Returns:

The first time processing item or None if not available.

Return type:

TimeProcItem, None

abstractmethod time_method()

Return the processing method from the first time processing item.

Returns:

The processing method from the first time processing item or None if not available.

Return type:

str, None

abstractmethod time_value()

Return the processing value from the first time processing item.

Returns:

The processing value from the first time processing item or None if not available.

Return type:

str, None

abstractmethod to_dict()

Convert the object to a dictionary.

Returns:

Dictionary representation of the object.

Return type:

dict

class earthkit.data.field.component.proc.ProcItem(value, method)

A base class for field processing items.

Parameters:
  • value (Any) – The value associated with the processing item. The type of this value depends on the specific type.

  • method (Any) – The method of the processing item, which can be used to identify the type of processing.

method
value
class earthkit.data.field.component.proc.TimeProcItem(value=datetime.timedelta(), method=TimeMethods.INSTANT)

Bases: ProcItem

A time processing item, which consists of a time span value and a time processing method.

Parameters:
  • value (Union[datetime.timedelta, str, int]) – The time span value, which can be a datetime.timedelta or any value that can be converted to a datetime.timedelta using the to_timedelta function.

  • method (TimeMethod, str) – The time processing method, which can be a string that identifies the method or a TimeMethod

classmethod from_dict(d)

Create a TimeProcItem object from a dictionary.

method
set(*, value=None, method=None)
value