data.readers.grib.metadata
Classes
Represent the metadata of a GRIB field. |
|
GRIB metadata. |
|
Hide internal keys and namespaces in GRIB metadata. |
|
Represent standalone GRIB metadata owning an ecCodes GRIB handle. |
Module Contents
- class data.readers.grib.metadata.GribFieldMetadata(field, **kwargs)
Bases:
GribMetadataRepresent the metadata of a GRIB field.
GribFieldMetadatais created internally by aGribField. It does not own the ecCodes GRIB handle but can access it through theGribField. Callingmetadata()without arguments on aGribFieldreturns this object.- as_namespace(namespace=None)
Return all the keys/values from a namespace.
- Parameters:
namespace (
str,None) – The ecCodes namespace. earthkit-data also defines the “default” namespace, which contains all the GRIB keys that ecCodes can access without specifying a namespace. When namespace is None or an emptystrall the available keys/values are returned.- Returns:
All the keys/values from the namespace.
- Return type:
dict
- base_datetime()
- data_format()
Return the underlying data format.
- Return type:
str
- datetime()
Return the date and time of the field.
- Returns:
Dict with items “base_time” and “valid_time”.
- Return type:
dictofdatatime.datetime
Examples
>>> import earthkit.data >>> ds = earthkit.data.from_source("file", "tests/data/t_time_series.grib") >>> ds[4].datetime() {'base_time': datetime.datetime(2020, 12, 21, 12, 0), 'valid_time': datetime.datetime(2020, 12, 21, 18, 0)}
- describe_keys()
Return the keys to be used with the
describe()method.
- dump(namespace=all, **kwargs)
Generate dump with all the metadata keys belonging to
namespace.In a Jupyter notebook it is represented as a tabbed interface.
- Parameters:
namespace (
str,list,tuple,Noneorall) –The namespace to dump. Any ecCodes namespace can be used here. earthkit-data also defines the “default” namespace, which contains all the GRIB keys that ecCodes can access without specifying a namespace. The following namespace values have a special meaning:
all: all the available namespaces will be used (including “default”).None or empty str: the “default” namespace will be used.
**kwargs (
dict, optional) – Other keyword arguments used for testing only
- Returns:
Dict-like object with one item per namespace. In a Jupyter notebook represented as a tabbed interface to browse the dump contents.
- Return type:
NamespaceDump
Examples
- geography()
Geography: Get geography description.If it is not available None is returned.
- get(key, default=None, *, astype=None, raise_on_missing=False)
Return the value for
key.- Parameters:
key (
str) – Metadata keydefault (
value) – Specify the default value forkey. Returned whenkeyis not found or its value is a missing value and raise_on_missing isFalse.astype (
type as str,intorfloat) – Return/access type forkey. When it is supportedastypeis passed to the underlying metadata accessor as an option. Otherwise the value is cast toastypeafter it is taken from the accessor.raise_on_missing (
bool) – When it is True raises an exception ifkeyis not found or it has a missing value.
- Returns:
Returns the
keyvalue. Returnsdefaultifkeyis not found or it has a missing value andraise_on_missingis False.- Return type:
value- Raises:
KeyError – If
raise_on_missingis True andkeyis not found or it has a missing value.
- property grid_spec
- property gridspec
- index_keys()
Return the keys to be used with the
indices()method.
- indexing_datetime()
- items()
Return the metadata items.
- Return type:
Iterableof(key,value)pairs
- keys()
Return the metadata keys.
- Return type:
Iterableofstr
- ls_keys()
Return the keys to be used with the
ls()method.
- namespaces()
Return the available namespaces.
- Return type:
listofstr
- override(*args, headers_only_clone=True, **kwargs)
Create a new metadata object by cloning a new GRIB handle and setting the keys in it.
- Parameters:
*args (
tuple) – Positional arguments. When present must be a dict with the GRIB keys to set in the new GRIB handle.headers_only_clone (
bool, optional) – If True, the new GRIB handle will be created with headers_only=True to reduce the data section. With this the GRIB handle size will be significantly smaller, but the data section becomes unusable. Default is True.**kwargs (
dict, optional) – Other keyword arguments specifying the GRIB keys to set.
- Returns:
The new metadata object. There is always a
StandAloneGribMetadataobject created containing the new GRIB handle updated with the specified keys. It is then wrapped in aWrappedMetadataobject storing"bitsPerValue"as an extra key.- Return type:
WrappedMetadata
Notes
When
"bitsPerValue"is a key to set it is not written to the new handle. Instead, it is stored as an extra key in the resultingWrappedMetadataobject.
- param_level()
- reference_datetime()
- step_timedelta()
- valid_datetime()
- class data.readers.grib.metadata.GribMetadata(cache=None, **kwargs)
Bases:
earthkit.data.core.metadata.MetadataGRIB metadata.
GribMetadatais an abstract class and should not be instantiated directly. There are two concrete implementations:GribFieldMetadataandStandAloneGribMetadata.- as_namespace(namespace=None)
Return all the keys/values from a namespace.
- Parameters:
namespace (
str,None) – The ecCodes namespace. earthkit-data also defines the “default” namespace, which contains all the GRIB keys that ecCodes can access without specifying a namespace. When namespace is None or an emptystrall the available keys/values are returned.- Returns:
All the keys/values from the namespace.
- Return type:
dict
- base_datetime()
- data_format()
Return the underlying data format.
- Return type:
str
- datetime()
Return the date and time of the field.
- Returns:
Dict with items “base_time” and “valid_time”.
- Return type:
dictofdatatime.datetime
Examples
>>> import earthkit.data >>> ds = earthkit.data.from_source("file", "tests/data/t_time_series.grib") >>> ds[4].datetime() {'base_time': datetime.datetime(2020, 12, 21, 12, 0), 'valid_time': datetime.datetime(2020, 12, 21, 18, 0)}
- describe_keys()
Return the keys to be used with the
describe()method.
- dump(namespace=all, **kwargs)
Generate dump with all the metadata keys belonging to
namespace.In a Jupyter notebook it is represented as a tabbed interface.
- Parameters:
namespace (
str,list,tuple,Noneorall) –The namespace to dump. Any ecCodes namespace can be used here. earthkit-data also defines the “default” namespace, which contains all the GRIB keys that ecCodes can access without specifying a namespace. The following namespace values have a special meaning:
all: all the available namespaces will be used (including “default”).None or empty str: the “default” namespace will be used.
**kwargs (
dict, optional) – Other keyword arguments used for testing only
- Returns:
Dict-like object with one item per namespace. In a Jupyter notebook represented as a tabbed interface to browse the dump contents.
- Return type:
NamespaceDump
Examples
- geography()
Geography: Get geography description.If it is not available None is returned.
- get(key, default=None, *, astype=None, raise_on_missing=False)
Return the value for
key.- Parameters:
key (
str) – Metadata keydefault (
value) – Specify the default value forkey. Returned whenkeyis not found or its value is a missing value and raise_on_missing isFalse.astype (
type as str,intorfloat) – Return/access type forkey. When it is supportedastypeis passed to the underlying metadata accessor as an option. Otherwise the value is cast toastypeafter it is taken from the accessor.raise_on_missing (
bool) – When it is True raises an exception ifkeyis not found or it has a missing value.
- Returns:
Returns the
keyvalue. Returnsdefaultifkeyis not found or it has a missing value andraise_on_missingis False.- Return type:
value- Raises:
KeyError – If
raise_on_missingis True andkeyis not found or it has a missing value.
- property grid_spec
- property gridspec
- index_keys()
Return the keys to be used with the
indices()method.
- indexing_datetime()
- items()
Return the metadata items.
- Return type:
Iterableof(key,value)pairs
- keys()
Return the metadata keys.
- Return type:
Iterableofstr
- ls_keys()
Return the keys to be used with the
ls()method.
- namespaces()
Return the available namespaces.
- Return type:
listofstr
- override(*args, headers_only_clone=True, **kwargs)
Create a new metadata object by cloning a new GRIB handle and setting the keys in it.
- Parameters:
*args (
tuple) – Positional arguments. When present must be a dict with the GRIB keys to set in the new GRIB handle.headers_only_clone (
bool, optional) – If True, the new GRIB handle will be created with headers_only=True to reduce the data section. With this the GRIB handle size will be significantly smaller, but the data section becomes unusable. Default is True.**kwargs (
dict, optional) – Other keyword arguments specifying the GRIB keys to set.
- Returns:
The new metadata object. There is always a
StandAloneGribMetadataobject created containing the new GRIB handle updated with the specified keys. It is then wrapped in aWrappedMetadataobject storing"bitsPerValue"as an extra key.- Return type:
WrappedMetadata
Notes
When
"bitsPerValue"is a key to set it is not written to the new handle. Instead, it is stored as an extra key in the resultingWrappedMetadataobject.
- param_level()
- reference_datetime()
- step_timedelta()
- valid_datetime()
- class data.readers.grib.metadata.RestrictedGribMetadata(metadata)
Bases:
earthkit.data.core.metadata.WrappedMetadataHide internal keys and namespaces in GRIB metadata.
Examples
GRIB: using the metadata object
- as_namespace(namespace)
- dump(namespace=all, **kwargs)
- get(key, default=None, *, astype=None, raise_on_missing=False, **kwargs)
- items()
Return the metadata items.
- Return type:
Iterableof(key,value)pairs
- keys()
Return the metadata keys.
- Return type:
Iterableofstr
- static merge_list(v1, v2)
- namespaces()
- override(*args, **kwargs)
- class data.readers.grib.metadata.StandAloneGribMetadata(handle, **kwargs)
Bases:
GribMetadataRepresent standalone GRIB metadata owning an ecCodes GRIB handle.
StandAloneGribMetadatapossesses its own ecCodes handle. Callingoverride()onGribMetadataalways returns aStandAloneGribMetadataobject.>>> ds = earthkit.data.from_source("file", "docs/examples/test4.grib") >>> md = ds[0].metadata() >>> md["shortName"] 't' >>> md.get("shortName") 't' >>> md.get("nonExistentKey") >>> md.get("nonExistentKey", 12) 12
Examples
GRIB: using the metadata object
- as_namespace(namespace=None)
Return all the keys/values from a namespace.
- Parameters:
namespace (
str,None) – The ecCodes namespace. earthkit-data also defines the “default” namespace, which contains all the GRIB keys that ecCodes can access without specifying a namespace. When namespace is None or an emptystrall the available keys/values are returned.- Returns:
All the keys/values from the namespace.
- Return type:
dict
- base_datetime()
- data_format()
Return the underlying data format.
- Return type:
str
- datetime()
Return the date and time of the field.
- Returns:
Dict with items “base_time” and “valid_time”.
- Return type:
dictofdatatime.datetime
Examples
>>> import earthkit.data >>> ds = earthkit.data.from_source("file", "tests/data/t_time_series.grib") >>> ds[4].datetime() {'base_time': datetime.datetime(2020, 12, 21, 12, 0), 'valid_time': datetime.datetime(2020, 12, 21, 18, 0)}
- describe_keys()
Return the keys to be used with the
describe()method.
- dump(namespace=all, **kwargs)
Generate dump with all the metadata keys belonging to
namespace.In a Jupyter notebook it is represented as a tabbed interface.
- Parameters:
namespace (
str,list,tuple,Noneorall) –The namespace to dump. Any ecCodes namespace can be used here. earthkit-data also defines the “default” namespace, which contains all the GRIB keys that ecCodes can access without specifying a namespace. The following namespace values have a special meaning:
all: all the available namespaces will be used (including “default”).None or empty str: the “default” namespace will be used.
**kwargs (
dict, optional) – Other keyword arguments used for testing only
- Returns:
Dict-like object with one item per namespace. In a Jupyter notebook represented as a tabbed interface to browse the dump contents.
- Return type:
NamespaceDump
Examples
- geography()
Geography: Get geography description.If it is not available None is returned.
- get(key, default=None, *, astype=None, raise_on_missing=False)
Return the value for
key.- Parameters:
key (
str) – Metadata keydefault (
value) – Specify the default value forkey. Returned whenkeyis not found or its value is a missing value and raise_on_missing isFalse.astype (
type as str,intorfloat) – Return/access type forkey. When it is supportedastypeis passed to the underlying metadata accessor as an option. Otherwise the value is cast toastypeafter it is taken from the accessor.raise_on_missing (
bool) – When it is True raises an exception ifkeyis not found or it has a missing value.
- Returns:
Returns the
keyvalue. Returnsdefaultifkeyis not found or it has a missing value andraise_on_missingis False.- Return type:
value- Raises:
KeyError – If
raise_on_missingis True andkeyis not found or it has a missing value.
- property grid_spec
- property gridspec
- index_keys()
Return the keys to be used with the
indices()method.
- indexing_datetime()
- items()
Return the metadata items.
- Return type:
Iterableof(key,value)pairs
- keys()
Return the metadata keys.
- Return type:
Iterableofstr
- ls_keys()
Return the keys to be used with the
ls()method.
- namespaces()
Return the available namespaces.
- Return type:
listofstr
- override(*args, headers_only_clone=True, **kwargs)
Create a new metadata object by cloning a new GRIB handle and setting the keys in it.
- Parameters:
*args (
tuple) – Positional arguments. When present must be a dict with the GRIB keys to set in the new GRIB handle.headers_only_clone (
bool, optional) – If True, the new GRIB handle will be created with headers_only=True to reduce the data section. With this the GRIB handle size will be significantly smaller, but the data section becomes unusable. Default is True.**kwargs (
dict, optional) – Other keyword arguments specifying the GRIB keys to set.
- Returns:
The new metadata object. There is always a
StandAloneGribMetadataobject created containing the new GRIB handle updated with the specified keys. It is then wrapped in aWrappedMetadataobject storing"bitsPerValue"as an extra key.- Return type:
WrappedMetadata
Notes
When
"bitsPerValue"is a key to set it is not written to the new handle. Instead, it is stored as an extra key in the resultingWrappedMetadataobject.
- param_level()
- reference_datetime()
- step_timedelta()
- valid_datetime()