Skip to content

Commit 5cddb33

Browse files
committed
Issue #527/#548 minor metadata_from_stac fine-tuning
1 parent 59655b8 commit 5cddb33

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

openeo/metadata.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ def metadata_from_stac(url: str) -> CubeMetadata:
534534
"""
535535

536536
def get_band_metadata(eo_bands_location: dict) -> List[Band]:
537+
# TODO: return None iso empty list when no metadata?
537538
return [
538539
Band(name=band["name"], common_name=band.get("common_name"), wavelength_um=band.get("center_wavelength"))
539540
for band in eo_bands_location.get("eo:bands", [])
@@ -547,15 +548,12 @@ def is_band_asset(asset: pystac.Asset) -> bool:
547548

548549
stac_object = pystac.read_file(href=url)
549550

550-
bands = []
551-
collection = None
552-
553551
if isinstance(stac_object, pystac.Item):
554552
item = stac_object
555553
if "eo:bands" in item.properties:
556554
eo_bands_location = item.properties
557555
elif item.get_collection() is not None:
558-
collection = item.get_collection()
556+
# TODO: Also do asset based band detection (like below)?
559557
eo_bands_location = item.get_collection().summaries.lists
560558
else:
561559
eo_bands_location = {}
@@ -574,12 +572,13 @@ def is_band_asset(asset: pystac.Asset) -> bool:
574572
for asset_band in asset_bands:
575573
if asset_band.name not in get_band_names(bands):
576574
bands.append(asset_band)
577-
578-
else:
579-
assert isinstance(stac_object, pystac.Catalog)
575+
elif isinstance(stac_object, pystac.Catalog):
580576
catalog = stac_object
581577
bands = get_band_metadata(catalog.extra_fields.get("summaries", {}))
578+
else:
579+
raise ValueError(stac_object)
582580

581+
# TODO: conditionally include band dimension when there was actual indication of band metadata?
583582
band_dimension = BandDimension(name="bands", bands=bands)
584583
metadata = CubeMetadata(dimensions=[band_dimension])
585584
return metadata

tests/test_metadata.py

+2
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ def filter_bbox(self, bbox):
806806
},
807807
["B01", "B02"],
808808
),
809+
# TODO: test asset handling in collection?
809810
(
810811
{
811812
"type": "Catalog",
@@ -830,6 +831,7 @@ def filter_bbox(self, bbox):
830831
},
831832
["SCL", "B08"],
832833
),
834+
# TODO: test asset handling in item?
833835
],
834836
)
835837
def test_metadata_from_stac(tmp_path, test_stac, expected):

0 commit comments

Comments
 (0)