From 5cddb33c2319f312e4a82363ae6e43a53119666a Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Tue, 26 Mar 2024 07:47:34 +0100 Subject: [PATCH] Issue #527/#548 minor `metadata_from_stac` fine-tuning --- openeo/metadata.py | 13 ++++++------- tests/test_metadata.py | 2 ++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/openeo/metadata.py b/openeo/metadata.py index af15a913d..9e1e55650 100644 --- a/openeo/metadata.py +++ b/openeo/metadata.py @@ -534,6 +534,7 @@ def metadata_from_stac(url: str) -> CubeMetadata: """ def get_band_metadata(eo_bands_location: dict) -> List[Band]: + # TODO: return None iso empty list when no metadata? return [ Band(name=band["name"], common_name=band.get("common_name"), wavelength_um=band.get("center_wavelength")) for band in eo_bands_location.get("eo:bands", []) @@ -547,15 +548,12 @@ def is_band_asset(asset: pystac.Asset) -> bool: stac_object = pystac.read_file(href=url) - bands = [] - collection = None - if isinstance(stac_object, pystac.Item): item = stac_object if "eo:bands" in item.properties: eo_bands_location = item.properties elif item.get_collection() is not None: - collection = item.get_collection() + # TODO: Also do asset based band detection (like below)? eo_bands_location = item.get_collection().summaries.lists else: eo_bands_location = {} @@ -574,12 +572,13 @@ def is_band_asset(asset: pystac.Asset) -> bool: for asset_band in asset_bands: if asset_band.name not in get_band_names(bands): bands.append(asset_band) - - else: - assert isinstance(stac_object, pystac.Catalog) + elif isinstance(stac_object, pystac.Catalog): catalog = stac_object bands = get_band_metadata(catalog.extra_fields.get("summaries", {})) + else: + raise ValueError(stac_object) + # TODO: conditionally include band dimension when there was actual indication of band metadata? band_dimension = BandDimension(name="bands", bands=bands) metadata = CubeMetadata(dimensions=[band_dimension]) return metadata diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 9a23fd9f0..e90d21558 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -806,6 +806,7 @@ def filter_bbox(self, bbox): }, ["B01", "B02"], ), + # TODO: test asset handling in collection? ( { "type": "Catalog", @@ -830,6 +831,7 @@ def filter_bbox(self, bbox): }, ["SCL", "B08"], ), + # TODO: test asset handling in item? ], ) def test_metadata_from_stac(tmp_path, test_stac, expected):