earthkit.data.field.component.ensemble¶
Attributes¶
Classes¶
Empty ensemble component, representing the absence of ensemble information. |
|
Ensemble component representing ensemble information. |
|
Base class for the ensemble component of a field. |
Functions¶
Create a EnsembleBase object from a dictionary. |
Module Contents¶
- earthkit.data.field.component.ensemble.EMPTY_ENSEMBLE¶
- class earthkit.data.field.component.ensemble.EmptyEnsemble¶
Bases:
EnsembleBaseEmpty ensemble component, representing the absence of ensemble information.
- aliases()¶
Return the aliases in the component.
- classmethod from_dict(d)¶
Create an EmptyEnsemble object from a dictionary.
- 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_missingis True and the key is not found.
- keys()¶
Return the available keys in the component.
- member()¶
Return the ensemble member.
An EmptyEnsemble does not contain any ensemble information, and this method returns None.
- realisation()¶
Return the ensemble member (alias of member).
- realization()¶
Return the ensemble member (alias of member).
- set(*args, **kwargs)¶
Create a new instance with updated data.
An EmptyEnsemble object cannot be updated, and this method raises a ValueError.
- to_dict()¶
Return a dictionary representation of the EmptyEnsemble.
- class earthkit.data.field.component.ensemble.Ensemble(member=None)¶
Bases:
EnsembleBaseEnsemble component representing ensemble information.
- Parameters:
member (
str,int, optional) – The ensemble member, by default None. Internally stored as a string, valid non-string values will be converted to a string.
- 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.
The dictionary can contain the following keys:
”member”: The ensemble member.
- Returns:
The created Ensemble instance.
- Return type:
- 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_missingis True and the key is not found.
- keys()¶
Return the available keys in the component.
- member()¶
Return the ensemble member.
- realisation()¶
Return the ensemble member (alias of member).
- realization()¶
Return the ensemble member (alias of member).
- set(*args, **kwargs)¶
Create a new instance with updated data.
- Parameters:
args (
tuple) – Positional arguments containing time data. Only dictionaries are allowed.kwargs (
dict) – Keyword arguments containing time data.
The following keys can be provided to update the ensemble information:
“member”: The ensemble member.
- to_dict()¶
Return a dictionary representation of the Ensemble.
- class earthkit.data.field.component.ensemble.EnsembleBase¶
Bases:
earthkit.data.field.component.component.SimpleFieldComponentBase class for the ensemble component of a field.
This class defines the interface for ensemble components, which can represent different types of ensemble information.
The ensemble information can be accessed by methods like
member(). Each of these methods has an associated key that can be used in theget()method to retrieve the corresponding information. The list of supported keys are as follows:“member”
“realization” (alias of “member”)
“realisation” (alias of “member”)
Typically, this object is used as a component of a field, and can be accessed via the
ensembleattribute of a field. The keys above can also be accessed via theget()method of the field, using the “ensemble.” prefix.The following example demonstrates how to access the ensemble information from a field using various methods and keys:
>>> import earthkit.data as ekd >>> field = = ekd.from_source("sample", "ens_cf_pf.grib").to_fieldlist()[2] >>> field.ensemble.member() '1' >>> field.ensemble.get("member") '1' >>> field.get("ensemble.member") '1'
The ensemble component is immutable. The
set()method to create a new instance with updated values. For example, the following code creates a new ensemble component with an updated member:>>> new_ensemble = field.ensemble.set(member="2") >>> new_ensemble.member() '2'
We can also call the Field’s
set()method to create a new field with an updated ensemble component:>>> new_field = field.set({"ensemble.member": "2"}) >>> new_field.ensemble.member() '2'
- Parameters:
member (
str,int, optional) – The ensemble member, by default None.
- 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_missingis True and the key is not found.
- keys()¶
Return the available keys in the component.
- abstractmethod member()¶
Return the ensemble member.
- realisation()¶
Return the ensemble member (alias of member).
- realization()¶
Return the ensemble member (alias of member).
- 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 to_dict()¶
Convert the object to a dictionary.
- Returns:
Dictionary representation of the object.
- Return type:
dict
- earthkit.data.field.component.ensemble.create_ensemble(d)¶
Create a EnsembleBase object from a dictionary.
- Parameters:
d (
dict) – Dictionary containing parameter data.- Returns:
The created EnsembleBase instance.
- Return type: