Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/geo as optional dependency #569

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Alternatively, you can install the following components:
- fdb: provides access to the :ref:`data-sources-fdb` source
- polytope: provides access to the :ref:`data-sources-polytope` source
- odb: provides full support for the :ref:`odb` data type
- geo: enables to use Field.points_unrotated()
- geopandas: adds GeoJSON/GeoPandas support
- projection: adds projection support
- covjsonkit: provides access to CoverageJSON data served by the :ref:`data-sources-polytope` source
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dependencies = [
"array-api-compat",
"cfgrib>=0.9.10.1",
"dask",
"earthkit-geo>=0.2",
"earthkit-meteo>=0.0.1",
"eccodes>=1.7",
"entrypoints",
Expand All @@ -50,6 +49,7 @@ optional-dependencies.all = [
"cartopy",
"cdsapi>=0.7.2",
"covjsonkit>=0.0.28",
"earthkit-geo>=0.2",
"ecmwf-api-client>=1.6.1",
"ecmwf-opendata>=0.3.3",
"geopandas",
Expand All @@ -66,6 +66,7 @@ optional-dependencies.dev = [
"cdsapi>=0.7.2",
"covjsonkit>=0.0.28",
"earthkit-data-demo-source",
"earthkit-geo>=0.2",
"ecmwf-api-client>=1.6.1",
"ecmwf-opendata>=0.3.3",
"geopandas",
Expand All @@ -92,6 +93,7 @@ optional-dependencies.docs = [
]
optional-dependencies.ecmwf-opendata = [ "ecmwf-opendata>=0.3.3" ]
optional-dependencies.fdb = [ "pyfdb>=0.1" ]
optional-dependencies.geo = [ "earthkit-geo>=0.2" ]
optional-dependencies.geopandas = [ "geopandas" ]
optional-dependencies.geotiff = [ "pyproj", "rasterio", "rioxarray" ]
optional-dependencies.mars = [ "ecmwf-api-client>=1.6.1" ]
Expand Down
14 changes: 12 additions & 2 deletions src/earthkit/data/readers/grib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,12 @@ def latitudes_unrotated(self, **kwargs):
return self.latitudes(**kwargs)

if not self.rotated_iterator:
from earthkit.geo.rotate import unrotate
try:
from earthkit.geo.rotate import unrotate
except ImportError:
raise ImportError(
"GribFieldGeography.latitudes_unrotated requires 'earthkit-geo' to be installed"
)

grid_type = self.metadata.get("gridType")
warnings.warn(f"ecCodes does not support rotated iterator for {grid_type}")
Expand All @@ -240,7 +245,12 @@ def longitudes_unrotated(self, **kwargs):
return self.longitudes(**kwargs)

if not self.rotated_iterator:
from earthkit.geo.rotate import unrotate
try:
from earthkit.geo.rotate import unrotate
except ImportError:
raise ImportError(
"GribFieldGeography.longitudes_unrotated requires 'earthkit-geo' to be installed"
)

grid_type = self.metadata.get("gridType")
warnings.warn(f"ecCodes does not support rotated iterator for {grid_type}")
Expand Down
1 change: 1 addition & 0 deletions src/earthkit/data/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def modules_installed(*modules):
NO_CUPY = True

NO_S3_AUTH = not modules_installed("aws_requests_auth")
NO_GEO = not modules_installed("earthkit-data")


def MISSING(*modules):
Expand Down
3 changes: 3 additions & 0 deletions tests/grib/test_grib_geography.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pytest

import earthkit.data
from earthkit.data.testing import NO_GEO
from earthkit.data.testing import check_array_type
from earthkit.data.testing import earthkit_examples_file
from earthkit.data.testing import earthkit_test_data_file
Expand Down Expand Up @@ -291,6 +292,7 @@ def test_grib_mars_grid(path, expected_value):
assert np.allclose(np.asarray(ds[0].mars_grid), np.asarray(expected_value))


@pytest.mark.skipif(NO_GEO, reason="No earthkit-geo support")
def test_grib_grid_points_rotated_ll():
"""The"""
ds = earthkit.data.from_source("file", earthkit_test_data_file("rotated_wind_20x20.grib"))
Expand Down Expand Up @@ -320,6 +322,7 @@ def test_grib_grid_points_rotated_ll():
assert np.allclose(res[1], ref[1])


@pytest.mark.skipif(NO_GEO, reason="No earthkit-geo support")
def test_grib_grid_points_rotated_rgg():
ds = earthkit.data.from_source("file", earthkit_test_data_file("rotated_N32_subarea.grib"))

Expand Down
Loading