@@ -534,6 +534,7 @@ def metadata_from_stac(url: str) -> CubeMetadata:
534
534
"""
535
535
536
536
def get_band_metadata (eo_bands_location : dict ) -> List [Band ]:
537
+ # TODO: return None iso empty list when no metadata?
537
538
return [
538
539
Band (name = band ["name" ], common_name = band .get ("common_name" ), wavelength_um = band .get ("center_wavelength" ))
539
540
for band in eo_bands_location .get ("eo:bands" , [])
@@ -547,15 +548,12 @@ def is_band_asset(asset: pystac.Asset) -> bool:
547
548
548
549
stac_object = pystac .read_file (href = url )
549
550
550
- bands = []
551
- collection = None
552
-
553
551
if isinstance (stac_object , pystac .Item ):
554
552
item = stac_object
555
553
if "eo:bands" in item .properties :
556
554
eo_bands_location = item .properties
557
555
elif item .get_collection () is not None :
558
- collection = item . get_collection ()
556
+ # TODO: Also do asset based band detection (like below)?
559
557
eo_bands_location = item .get_collection ().summaries .lists
560
558
else :
561
559
eo_bands_location = {}
@@ -574,12 +572,13 @@ def is_band_asset(asset: pystac.Asset) -> bool:
574
572
for asset_band in asset_bands :
575
573
if asset_band .name not in get_band_names (bands ):
576
574
bands .append (asset_band )
577
-
578
- else :
579
- assert isinstance (stac_object , pystac .Catalog )
575
+ elif isinstance (stac_object , pystac .Catalog ):
580
576
catalog = stac_object
581
577
bands = get_band_metadata (catalog .extra_fields .get ("summaries" , {}))
578
+ else :
579
+ raise ValueError (stac_object )
582
580
581
+ # TODO: conditionally include band dimension when there was actual indication of band metadata?
583
582
band_dimension = BandDimension (name = "bands" , bands = bands )
584
583
metadata = CubeMetadata (dimensions = [band_dimension ])
585
584
return metadata
0 commit comments