From 4bef824599841276c502bb06fa606647020df3b4 Mon Sep 17 00:00:00 2001 From: Sandor Kertesz Date: Fri, 6 Jun 2025 15:39:25 +0100 Subject: [PATCH 1/2] Remove geotiff dependency from all (#718) * Remove geotiff dependency from all --- docs/release_notes/version_0.14_updates.rst | 10 ++++++++++ pyproject.toml | 2 +- tests/grib/test_grib_summary.py | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/release_notes/version_0.14_updates.rst b/docs/release_notes/version_0.14_updates.rst index 4950a4724..1e644d71b 100644 --- a/docs/release_notes/version_0.14_updates.rst +++ b/docs/release_notes/version_0.14_updates.rst @@ -1,6 +1,16 @@ Version 0.14 Updates ///////////////////////// + +Version 0.14.4 +=============== + +Fixes +++++++ + +- Now, dependencies for GeoTIFF support are not installed when earthkit-data is installed with ``pip install earthkit-data[all]``. This step was necessary to make installation work when GDAL is not available. These dependencies need to be installed separately with ``pip install earthkit-data[geotiff]``. See :ref:`install`. + + Version 0.14.3 =============== diff --git a/pyproject.toml b/pyproject.toml index 803d32709..003f7ef87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,7 @@ dependencies = [ "xarray>=0.19", ] optional-dependencies.all = [ - "earthkit-data[cds,covjsonkit,ecmwf-opendata,fdb,geo,geopandas,geotiff,mars,odb,polytope,projection,s3,wekeo]", + "earthkit-data[cds,covjsonkit,ecmwf-opendata,fdb,geo,geopandas,mars,odb,polytope,projection,s3,wekeo]", ] optional-dependencies.cds = [ "cdsapi>=0.7.2" ] optional-dependencies.ci = [ "numpy" ] diff --git a/tests/grib/test_grib_summary.py b/tests/grib/test_grib_summary.py index e0c187043..c52e92b2b 100644 --- a/tests/grib/test_grib_summary.py +++ b/tests/grib/test_grib_summary.py @@ -475,7 +475,7 @@ def test_grib_dump(fl_type): "data": { # "Ni": 12, # "Nj": 7, - "bitmapPresent": 0, + # "bitmapPresent": 0, "latitudeOfFirstGridPointInDegrees": 90.0, "longitudeOfFirstGridPointInDegrees": 0.0, "latitudeOfLastGridPointInDegrees": -90.0, @@ -547,6 +547,7 @@ def test_grib_dump(fl_type): if ns == "geography": d["data"].pop("Ni", None) d["data"].pop("Nj", None) + d["data"].pop("bitmapPresent", None) if ns not in ("default", "statistics"): assert d == [x for x in ref if x["title"] == ns][0], ns From 9068e2f3f94af19cab28caa3409e5275f18b6703 Mon Sep 17 00:00:00 2001 From: Sandor Kertesz Date: Fri, 6 Jun 2025 17:58:44 +0100 Subject: [PATCH 2/2] Fix crash when getting gridSpec GRIB metadata key (#719) * Fix crash when getting gridSpec GRIB metadata key --- docs/release_notes/version_0.14_updates.rst | 3 ++- src/earthkit/data/readers/grib/codes.py | 10 ++++++++++ tests/grib/test_grib_metadata.py | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/release_notes/version_0.14_updates.rst b/docs/release_notes/version_0.14_updates.rst index 1e644d71b..c9099834f 100644 --- a/docs/release_notes/version_0.14_updates.rst +++ b/docs/release_notes/version_0.14_updates.rst @@ -8,7 +8,8 @@ Version 0.14.4 Fixes ++++++ -- Now, dependencies for GeoTIFF support are not installed when earthkit-data is installed with ``pip install earthkit-data[all]``. This step was necessary to make installation work when GDAL is not available. These dependencies need to be installed separately with ``pip install earthkit-data[geotiff]``. See :ref:`install`. +- Fixed issue when getting the "gridSpec" GRIB metadata key with a default value caused a crash when ecCodes 2.41.0 was used. (:pr:`719`). +- Now, dependencies for GeoTIFF support are not installed when earthkit-data is installed with ``pip install earthkit-data[all]``. This step was necessary to make installation work when GDAL is not available. These dependencies need to be installed separately with ``pip install earthkit-data[geotiff]``. See :ref:`install`. (:pr:`718`). Version 0.14.3 diff --git a/src/earthkit/data/readers/grib/codes.py b/src/earthkit/data/readers/grib/codes.py index 597f81916..4a6ba94e6 100644 --- a/src/earthkit/data/readers/grib/codes.py +++ b/src/earthkit/data/readers/grib/codes.py @@ -151,6 +151,16 @@ def get(self, name, ktype=None, **kwargs): return self.get_values() elif name == "md5GridSection": return self.get_md5GridSection() + elif name == "gridSpec": + # Temporary measure because from ecCodes 2.41.0, when we ask for the gridSpec + # ecCodes raises a gribapi.errors.FunctionNotImplementedError exception, which is + # not caught by the high level eccodes API even if a default value is provided. + if "default" in kwargs: + try: + return super().get(name, ktype, **kwargs) + except Exception as e: + if "FunctionNotImplementedError" in str(type(e)): + return kwargs.get("default", None) return super().get(name, ktype, **kwargs) diff --git a/tests/grib/test_grib_metadata.py b/tests/grib/test_grib_metadata.py index 9e7eaac55..6d5a5e7ce 100644 --- a/tests/grib/test_grib_metadata.py +++ b/tests/grib/test_grib_metadata.py @@ -544,6 +544,13 @@ def test_grib_tilde_shortname(fl_type): assert f[0].metadata(namespace="parameter")["shortName"] == "106" +def test_grib_gridspec_key(): + ds = from_source("file", earthkit_examples_file("test.grib")) + + ds[0].metadata("gridSpec", default=None) # Should not raise an error + ds.metadata("gridSpec", default=None) # Should not raise an error + + if __name__ == "__main__": from earthkit.data.testing import main