Skip to content

Commit

Permalink
Fix unknown param in grib namespaces (#477)
Browse files Browse the repository at this point in the history
* Fix unknown param in grib namespaces
  • Loading branch information
sandorkertesz authored Oct 8, 2024
1 parent 7849651 commit b047a25
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/release_notes/version_0.10_updates.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Version 0.10 Updates
/////////////////////////

Version 0.10.7
===============

Fixes
++++++

- When "param" or "shortName" in a namespace is "~" in the GRIB header :func:`metadata` now returns the value of "paramId" as a str for both these keys in the relevant namespaces. Previously "~" was returned.


Version 0.9.0

Version 0.10.4
===============
Expand Down
9 changes: 8 additions & 1 deletion src/earthkit/data/readers/grib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,14 @@ def as_namespace(self, namespace=None):

if namespace == "default" or namespace == "":
namespace = None
return self._handle.as_namespace(namespace)
r = self._handle.as_namespace(namespace)

# special case when "param" is "~".
if r is not None:
for k in ("shortName", "param"):
if k in r and r[k] == "~":
r[k] = self.get(k)
return r

@property
def geography(self):
Expand Down
3 changes: 3 additions & 0 deletions tests/grib/test_grib_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ def test_grib_tilde_shortname(fl_type, array_backend):
assert f[0].metadata("paramId", astype=int) == 106
assert f[0].metadata("param") == "106"

assert f[0].metadata(namespace="mars")["param"] == "106"
assert f[0].metadata(namespace="parameter")["shortName"] == "106"


if __name__ == "__main__":
from earthkit.data.testing import main
Expand Down

0 comments on commit b047a25

Please sign in to comment.