Skip to content

Commit

Permalink
Merge branch 'develop' into feature/downstream-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
sandorkertesz committed Dec 11, 2023
2 parents 7f0a6be + 5d19686 commit 2ca3d13
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 12 additions & 0 deletions earthkit/data/readers/grib/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ def update_metadata(self, handle, metadata, compulsory):
except ValueError:
metadata["shortName"] = param

# levtype is a readOnly key in ecCodes >= 2.33.0
levtype_remap = {
"pl": "isobaricInhPa",
"ml": "hybrid",
"pt": "theta",
"pv": "potentialVorticity",
"sfc": "surface",
}
if "levtype" in metadata:
v = metadata.pop("levtype")
metadata["typeOfLevel"] = levtype_remap[v]

def handle_from_metadata(self, values, metadata, compulsory):
from .codes import GribCodesHandle # Lazy loading of eccodes

Expand Down
7 changes: 5 additions & 2 deletions tests/grib/test_grib_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,17 @@ def test_grib_output_mars_labeling():
sys.version_info < (3, 10),
reason="ignore_cleanup_errors requires Python 3.10 or later",
)
def test_grib_output_pl():
@pytest.mark.parametrize("levtype", [{}, {"levtype": "pl"}])
def test_grib_output_pl(levtype):
data = np.random.random((40320,))

with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp:
path = os.path.join(tmp, "a.grib")

f = earthkit.data.new_grib_output(path, date=20010101)
f.write(data, param="t", level=850)
_kwargs = dict(param="t", level=850)
_kwargs.update(levtype)
f.write(data, **_kwargs)
f.close()

ds = earthkit.data.from_source("file", path)
Expand Down

0 comments on commit 2ca3d13

Please sign in to comment.