Skip to content

Commit

Permalink
Add netcdf4 and cfgrib dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
amarandon committed Nov 8, 2024
1 parent 0846023 commit e47feb1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"rasterio",
"xarray",
"rioxarray",
"netcdf4",
"cfgrib",
],
extras_require={
"dev": [
Expand Down
11 changes: 11 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@
RESOURCES_PATH = jp(dirn(__file__), "..", "eodag", "resources")
TESTS_DOWNLOAD_PATH = "/tmp/eodag_tests"

TEST_GRIB_PRODUCT = (
"CAMS_EAC4_20210101_20210102_4d792734017419d1719b53f4d5b5d4d6888641de"
)
TEST_GRIB_FILENAME = f"{TEST_GRIB_PRODUCT}.grib"
TEST_GRIB_PRODUCT_PATH = os.path.join(
TEST_RESOURCES_PATH,
"products",
TEST_GRIB_PRODUCT,
)
TEST_GRIB_FILE_PATH = os.path.join(TEST_GRIB_PRODUCT_PATH, TEST_GRIB_FILENAME)


class EODagTestCase(unittest.TestCase):
def setUp(self):
Expand Down
13 changes: 12 additions & 1 deletion tests/units/test_eoproduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import xarray as xr
from rasterio.session import AWSSession

from tests import EODagTestCase
from tests import TEST_GRIB_FILE_PATH, TEST_GRIB_FILENAME, EODagTestCase
from tests.context import (
DEFAULT_PROJ,
Authentication,
Expand Down Expand Up @@ -75,6 +75,17 @@ def test_get_data_local_product_ok(self):
self.assertIsInstance(data, xr.DataArray)
self.assertNotEqual(data.values.size, 0)

def test_get_data_local_grib_product_ok(self):
"""A call to get_data on a local product in GRIB format must succeed""" # noqa
product = EOProduct(self.provider, self.eoproduct_props)
product.driver = mock.MagicMock(spec_set=NoDriver())
product.driver.get_data_address.return_value = TEST_GRIB_FILE_PATH
data = product.get_data(band=TEST_GRIB_FILENAME)
self.assertEqual(product.driver.get_data_address.call_count, 1)

self.assertIsInstance(data, xr.DataArray)
self.assertEqual(data.attrs["GRIB_COMMENT"], "Temperature [C]")

def test_get_data_download_on_unsupported_dataset_address_scheme_error(self):
"""If a product is not on the local filesystem, it must download itself before returning the data""" # noqa
product = EOProduct(
Expand Down
21 changes: 8 additions & 13 deletions tests/units/test_eoproduct_driver_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,20 @@
import os
from contextlib import contextmanager

from tests import TEST_RESOURCES_PATH, EODagTestCase
from tests import (
TEST_GRIB_FILE_PATH,
TEST_GRIB_FILENAME,
TEST_GRIB_PRODUCT_PATH,
TEST_RESOURCES_PATH,
EODagTestCase,
)
from tests.context import (
AddressNotFound,
EOProduct,
GenericDriver,
UnsupportedDatasetAddressScheme,
)

TEST_GRIB_PRODUCT = (
"CAMS_EAC4_20210101_20210102_4d792734017419d1719b53f4d5b5d4d6888641de"
)
TEST_GRIB_FILENAME = f"{TEST_GRIB_PRODUCT}.grib"
TEST_GRIB_PRODUCT_PATH = os.path.join(
TEST_RESOURCES_PATH,
"products",
TEST_GRIB_PRODUCT,
)


class TestEOProductDriverGeneric(EODagTestCase):
def setUp(self):
Expand Down Expand Up @@ -74,8 +70,7 @@ def test_driver_get_local_grib_dataset_address_ok(self):

address = self.product.driver.get_data_address(product, TEST_GRIB_FILENAME)

grib_path = os.path.join(TEST_GRIB_PRODUCT_PATH, TEST_GRIB_FILENAME)
self.assertEqual(address, grib_path)
self.assertEqual(address, TEST_GRIB_FILE_PATH)

def test_driver_get_http_remote_dataset_address_fail(self):
"""Driver must raise UnsupportedDatasetAddressScheme if location scheme is http or https"""
Expand Down

0 comments on commit e47feb1

Please sign in to comment.