Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunato committed Jun 25, 2024
2 parents 91ed2ce + 086deeb commit 799fa13
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 160 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Release history
---------------

0.5.0b1 (2024-06-25)
++++++++++++++++++++

- Adapt to `eodag v3` search API (#59)
- Drivers harmonized regex address retrieval mechanism (#56)
- Fixed `Asset` and `AssetsDict` import (#54)
- Tests: context imports cleanup (#53), removed unused method (#57)

0.4.1 (2024-02-29)
++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Example usage for interacting with the api in your Python code:
product_type = 'S2_MSI_L2A_COG'
footprint = {'lonmin': 1, 'latmin': 43.5, 'lonmax': 2, 'latmax': 44}
start, end = '2020-06-04', '2020-06-05'
search_results, _ = dag.search(productType=product_type, geom=footprint, start=start, end=end)
search_results = dag.search(productType=product_type, geom=footprint, start=start, end=end)
data = search_results[0].get_data(
crs=CRS.from_epsg(4326),
resolution=0.0006,
Expand Down
4 changes: 2 additions & 2 deletions docs/notebooks/get_data_basic.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion eodag_cube/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

__title__ = "eodag-cube"
__description__ = "Data access for EODAG"
__version__ = "0.4.1"
__version__ = "0.5.0b1"
__author__ = "CS GROUP - France (CSSI)"
__author_email__ = "eodag@csgroup.space"
__url__ = "https://github.com/CS-SI/eodag-cube"
Expand Down
1 change: 1 addition & 0 deletions eodag_cube/api/product/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""EODAG product package"""
from ._assets import Asset, AssetsDict # noqa
from ._product import EOProduct # noqa
33 changes: 24 additions & 9 deletions eodag_cube/api/product/drivers/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# limitations under the License.
from __future__ import annotations

import logging
import re
from pathlib import Path
from typing import TYPE_CHECKING

Expand All @@ -29,6 +31,8 @@
if TYPE_CHECKING:
from eodag.api.product._product import EOProduct

logger = logging.getLogger("eodag-cube.driver.generic")


class GenericDriver(DatasetDriver):
"""Generic Driver for products that need to be downloaded"""
Expand All @@ -48,16 +52,27 @@ def get_data_address(self, eo_product: EOProduct, band: str) -> str:
product_location_scheme = eo_product.location.split("://")[0]
if product_location_scheme == "file":

filenames = Path(uri_to_path(eo_product.location)).glob(f"**/*{band}*")
p = re.compile(rf"{band}", re.IGNORECASE)
matching_files = []
for f_path in Path(uri_to_path(eo_product.location)).glob("**/*"):
f_str = str(f_path.resolve())
if p.search(f_str):
try:
# files readable by rasterio
rasterio.drivers.driver_from_extension(f_path)
matching_files.append(f_str)
logger.debug(f"Matching band: {f_str}")
except ValueError:
pass

if len(matching_files) == 1:
return matching_files[0]

raise AddressNotFound(
rf"Please adapt given band parameter ('{band}') to match only file: "
rf"{len(matching_files)} files found matching {p}"
)

for filename in filenames:
try:
# return the first file readable by rasterio
rasterio.drivers.driver_from_extension(filename)
return str(filename.resolve())
except ValueError:
pass
raise AddressNotFound
raise UnsupportedDatasetAddressScheme(
"eo product {} is accessible through a location scheme that is not yet "
"supported by eodag: {}".format(eo_product, product_location_scheme)
Expand Down
49 changes: 14 additions & 35 deletions eodag_cube/api/product/drivers/stac_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.
from __future__ import annotations

import logging
import re
from typing import TYPE_CHECKING

Expand All @@ -26,6 +27,8 @@
if TYPE_CHECKING:
from eodag.api.product._product import EOProduct

logger = logging.getLogger("eodag-cube.driver.stac_assets")


class StacAssets(DatasetDriver):
"""Driver for Stac Assets"""
Expand All @@ -42,47 +45,23 @@ def get_data_address(self, eo_product: EOProduct, band: str) -> str:
:raises: :class:`~eodag.utils.exceptions.AddressNotFound`
:raises: :class:`~eodag.utils.exceptions.UnsupportedDatasetAddressScheme`
"""
error_message = ""

# try using exact
p = re.compile(rf"^{band}$", re.IGNORECASE)
matching_keys = [
s
for s in eo_product.assets.keys()
p = re.compile(rf"{band}", re.IGNORECASE)
matching_keys = []
for s in eo_product.assets.keys():
if (
(
"roles" in eo_product.assets[s]
and "data" in eo_product.assets[s]["roles"]
)
or ("roles" not in eo_product.assets[s])
)
and p.match(s)
]
) and p.search(s):
matching_keys.append(s)
logger.debug(f"Matching asset key: {s}")

if len(matching_keys) == 1:
return str(eo_product.assets[matching_keys[0]]["href"])
else:
error_message += (
rf"{len(matching_keys)} assets keys found matching {p} AND "
)

# try to find keys containing given band
p = re.compile(rf"^.*{band}.*$", re.IGNORECASE)
matching_keys = [
s
for s in eo_product.assets.keys()
if (
(
"roles" in eo_product.assets[s]
and "data" in eo_product.assets[s]["roles"]
)
or ("roles" not in eo_product.assets[s])
)
and p.match(s)
]
if len(matching_keys) == 1:
return str(eo_product.assets[matching_keys[0]]["href"])
else:
raise AddressNotFound(
rf"Please adapt given band parameter ('{band}') to match only one asset: {error_message}"
rf"{len(matching_keys)} assets keys found matching {p}"
)
raise AddressNotFound(
rf"Please adapt given band parameter ('{band}') to match only one asset: "
rf"{len(matching_keys)} assets keys found matching {p}"
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package_data={"": ["LICENSE", "NOTICE"], "eodag_cube": ["py.typed"]},
include_package_data=True,
install_requires=[
"eodag >= 2.12.0",
"eodag >= 3.0.0b1",
"numpy",
"rasterio",
"xarray",
Expand Down
100 changes: 0 additions & 100 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@
# limitations under the License.

import os
import random
import shutil
import unittest
from collections import OrderedDict, namedtuple
from io import StringIO
from unittest import mock # PY3

from owslib.etree import etree
from owslib.ows import ExceptionReport
from shapely import wkt

from eodag.api.product.metadata_mapping import DEFAULT_METADATA_MAPPING
Expand Down Expand Up @@ -182,98 +177,3 @@ def _tuples_to_lists(shapely_mapping):

coords[j] = list(pair)
return shapely_mapping

def compute_csw_records(self, mock_catalog, raise_error_for="", *args, **kwargs):
if raise_error_for:
for constraint in kwargs["constraints"]:
if constraint.propertyname == raise_error_for:
exception_report = etree.parse(
StringIO(
'<ExceptionReport xmlns="http://www.opengis.net/ows/1.1" '
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=' # noqa
'"http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd" version="1.0.0" language="en">' # noqa
'<Exception exceptionCode="NoApplicableCode"><ExceptionText>Unknown exception</ExceptionText>' # noqa
"</Exception></ExceptionReport>"
)
)
raise ExceptionReport(exception_report)
bbox_wgs84 = random.choice(
[
None,
(
self.footprint["lonmin"],
self.footprint["latmin"],
self.footprint["lonmax"],
self.footprint["latmax"],
),
]
)
Record = namedtuple(
"CswRecord",
[
"identifier",
"title",
"creator",
"publisher",
"abstract",
"subjects",
"date",
"references",
"bbox_wgs84",
"bbox",
"xml",
],
)
BBox = namedtuple("BBox", ["minx", "miny", "maxx", "maxy", "crs"])
Crs = namedtuple("Crs", ["code", "id"])
mock_catalog.records = OrderedDict(
{
"id ent ifier": Record(
identifier="id ent ifier",
title="MyRecord",
creator="eodagUnitTests",
publisher="eodagUnitTests",
abstract="A dumb CSW record for testing purposes",
subjects=[],
date="",
references=[
{
"scheme": "WWW:DOWNLOAD-1.0-http--download",
"url": "http://www.url.eu/dl",
}
],
bbox_wgs84=bbox_wgs84,
bbox=BBox(
minx=self.footprint["lonmin"],
miny=self.footprint["latmin"],
maxx=self.footprint["lonmax"],
maxy=self.footprint["latmax"],
crs=Crs(code=4326, id="EPSG"),
),
xml="""
<csw:Record xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/" # noqa
xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml" # noqa
xmlns:ows="http://www.opengis.net/ows" xmlns:xs="http://www.w3.org/2001/XMLSchema" # noqa
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dc:identifier>urn:x-gs:resource:localhost::52</dc:identifier>
<dc:title>S2 mosaic on Madrid</dc:title>
<dc:format/>
<dct:references scheme="WWW:LINK-1.0-http--link">
http://localhost:8000/admin/storm_csw/resource/52/change/
</dct:references>
<dct:modified>2017-05-05 13:02:35.548758+00:00</dct:modified>
<dct:abstract/>
<dc:date>2017-05-05 13:02:35.139807+00:00</dc:date>
<dc:creator> </dc:creator>
<dc:coverage/>
<ows:BoundingBox dimensions="2" crs="EPSG">
<ows:LowerCorner>40.405012373 -3.70433905592</ows:LowerCorner>
<ows:UpperCorner>40.420696583 -3.67011406889</ows:UpperCorner>
</ows:BoundingBox>
</csw:Record>
""",
)
}
)
return mock.DEFAULT
13 changes: 2 additions & 11 deletions tests/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,21 @@

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))

from eodag import EODataAccessGateway, api, config
from eodag.api.core import DEFAULT_ITEMS_PER_PAGE
from eodag import config
from eodag.api.product import EOProduct
from eodag.api.product.drivers import DRIVERS
from eodag.api.product.drivers.base import NoDriver
from eodag.config import PluginConfig
from eodag_cube.api.product.drivers.generic import GenericDriver
from eodag_cube.api.product.drivers.sentinel2_l1c import Sentinel2L1C
from eodag_cube.api.product.drivers.stac_assets import StacAssets
from eodag.api.search_result import SearchResult
from eodag.cli import download, eodag, list_pt, search_crunch
from eodag.plugins.authentication.base import Authentication
from eodag.plugins.authentication.aws_auth import AwsAuth
from eodag.plugins.download.base import Download
from eodag.plugins.download.aws import AwsDownload
from eodag.plugins.search.base import Search
from eodag.rest import server as eodag_http_server
from eodag.rest.utils import eodag_api, get_date
from eodag.utils import DEFAULT_PROJ, makedirs, path_to_uri
from eodag.utils import DEFAULT_PROJ, path_to_uri
from eodag.utils.exceptions import (
AddressNotFound,
DownloadError,
UnsupportedDatasetAddressScheme,
UnsupportedProvider,
ValidationError,
)
from tests import TEST_RESOURCES_PATH

0 comments on commit 799fa13

Please sign in to comment.