Skip to content

Commit 3ff03e2

Browse files
committed
fix some tests
1 parent 23f286e commit 3ff03e2

File tree

5 files changed

+50
-15
lines changed

5 files changed

+50
-15
lines changed

mapchete_eo/cli/static_catalog.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
from mapchete_eo.cli import options_arguments
1111
from mapchete_eo.platforms.sentinel2 import S2Metadata
1212
from mapchete_eo.platforms.sentinel2.types import Resolution
13+
from mapchete_eo.platforms.sentinel2.preconfigured_sources import (
14+
DEPRECATED_ARCHIVES,
15+
)
1316
from mapchete_eo.search import STACSearchCatalog, STACStaticCatalog
1417
from mapchete_eo.search.base import CatalogSearcher
1518
from mapchete_eo.types import TimeRange
@@ -117,6 +120,8 @@ def get_catalog(
117120
else:
118121
raise ValueError("collection must be provided")
119122
elif known_archive:
120-
raise NotImplementedError()
123+
return STACSearchCatalog.from_collection_url(
124+
DEPRECATED_ARCHIVES[known_archive]["collection"]
125+
)
121126
else:
122127
raise TypeError("cannot determine catalog")

mapchete_eo/platforms/sentinel2/metadata_parser/s2metadata.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ def from_stac_item(
157157
item: pystac.Item,
158158
metadata_xml_asset_name: List[str] = ["metadata", "granule_metadata"],
159159
boa_offset_field: Optional[str] = None,
160-
processing_baseline_field: Optional[str] = None,
160+
processing_baseline_field: Union[str, List[str]] = [
161+
"s2:processing_baseline",
162+
"sentinel2:processing_baseline",
163+
"processing:version",
164+
],
161165
**kwargs,
162166
) -> S2Metadata:
163-
metadata_xml_asset_name = metadata_xml_asset_name
164-
if processing_baseline_field is None:
165-
raise NotImplementedError()
167+
# try to find path to metadata.xml
166168
for metadata_asset in metadata_xml_asset_name:
167169
if metadata_asset in item.assets:
168170
metadata_path = MPath(item.assets[metadata_asset].href)
@@ -172,16 +174,28 @@ def from_stac_item(
172174
f"could not find path to metadata XML file in assets: {', '.join(item.assets.keys())}"
173175
)
174176

177+
# maek path absolute
175178
if metadata_path.is_remote() or metadata_path.is_absolute():
176179
metadata_xml = metadata_path
177180
else:
178181
metadata_xml = MPath(item.self_href).parent / metadata_path
179-
try:
180-
processing_baseline = item.properties[processing_baseline_field]
181-
except KeyError:
182+
183+
# try to find information on processing baseline version
184+
for field in (
185+
processing_baseline_field
186+
if isinstance(processing_baseline_field, list)
187+
else [processing_baseline_field]
188+
):
189+
try:
190+
processing_baseline = item.properties[field]
191+
break
192+
except KeyError:
193+
pass
194+
else: # pragma: no cover
182195
raise KeyError(
183196
f"could not find processing baseline version in item properties: {item.properties}"
184197
)
198+
185199
return S2Metadata.from_metadata_xml(
186200
metadata_xml=metadata_xml,
187201
processing_baseline=processing_baseline,

mapchete_eo/platforms/sentinel2/preconfigured_sources/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
"data_archive": "AWSCOG",
4141
},
4242
"S2AWS_JP2": {
43-
"collection": "https://stac.dataspace.copernicus.eu/v1collections/sentinel-2-l2a",
43+
"collection": "https://stac.dataspace.copernicus.eu/v1/collections/sentinel-2-l2a",
4444
"data_archive": "AWSJP2",
4545
},
4646
"S2CDSE_AWSJP2": {
47-
"collection": "https://stac.dataspace.copernicus.eu/v1collections/sentinel-2-l2a",
47+
"collection": "https://stac.dataspace.copernicus.eu/v1/collections/sentinel-2-l2a",
4848
"data_archive": "AWSJP2",
4949
},
5050
"S2CDSE_JP2": {
51-
"collection": "https://stac.dataspace.copernicus.eu/v1collections/sentinel-2-l2a",
51+
"collection": "https://stac.dataspace.copernicus.eu/v1/collections/sentinel-2-l2a",
5252
},
5353
}
5454
MetadataArchive = Literal["roda"]

mapchete_eo/search/stac_search.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
from datetime import datetime
35
from functools import cached_property
@@ -202,6 +204,13 @@ def get_collections(self):
202204
for collection_name in self.collections:
203205
yield self.client.get_collection(collection_name)
204206

207+
@staticmethod
208+
def from_collection_url(collection_url: str) -> STACSearchCatalog:
209+
return STACSearchCatalog(
210+
endpoint="/".join(collection_url.rstrip("/").split("/")[:-2]),
211+
collections=[collection_url.rstrip("/").split("/")[-1]],
212+
)
213+
205214

206215
class SpatialSearchChunks:
207216
bounds: Bounds

tests/test_cli.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def test_s2_mask(s2_stac_json_half_footprint, tmp_mpath):
2020
str(out_path),
2121
],
2222
)
23-
assert result.exit_code == 0
23+
if result.exit_code != 0:
24+
raise result.exception
25+
2426
assert out_path.exists()
2527
with rasterio_open(out_path) as src:
2628
assert src.read().any()
@@ -40,7 +42,9 @@ def test_s2_rgb(s2_stac_json_half_footprint, tmp_mpath):
4042
str(out_path),
4143
],
4244
)
43-
assert result.exit_code == 0
45+
if result.exit_code != 0:
46+
raise result.exception
47+
4448
assert out_path.exists()
4549
with rasterio_open(out_path) as src:
4650
assert not src.read(masked=True).mask.all()
@@ -63,7 +67,9 @@ def test_s2_brdf(s2_stac_json_half_footprint, tmp_mpath):
6367
str(out_path),
6468
],
6569
)
66-
assert result.exit_code == 0
70+
if result.exit_code != 0:
71+
raise result.exception
72+
6773
assert len(out_path.ls()) == 2
6874
for path in out_path.ls():
6975
with rasterio_open(path) as src:
@@ -100,5 +106,6 @@ def test_static_catalog(tmp_mpath, flag, value, collection):
100106
if collection:
101107
params.extend(["--collection", collection])
102108
result = runner.invoke(eo, params)
103-
assert result.exit_code == 0
109+
if result.exit_code != 0:
110+
raise result.exception
104111
assert out_path.ls()

0 commit comments

Comments
 (0)