@@ -533,15 +533,21 @@ def metadata_from_stac(url: str) -> CubeMetadata:
533
533
:return: A :py:class:`CubeMetadata` containing the DataCube band metadata from the url.
534
534
"""
535
535
536
- def get_band_names (asst : pystac .Asset ) -> List [Band ]:
537
- return [Band (eo_band ["name" ]) for eo_band in asst .extra_fields ["eo:bands" ]]
536
+ def get_band_metadata (eo_bands_location : dict ) -> List [Band ]:
537
+ return [
538
+ Band (name = band ["name" ], common_name = band .get ("common_name" ), wavelength_um = band .get ("center_wavelength" ))
539
+ for band in eo_bands_location .get ("eo:bands" , [])
540
+ ]
541
+
542
+ def get_band_names (bands : List [Band ]) -> List [str ]:
543
+ return [band .name for band in bands ]
538
544
539
545
def is_band_asset (asset : pystac .Asset ) -> bool :
540
546
return "eo:bands" in asset .extra_fields
541
547
542
548
stac_object = pystac .read_file (href = url )
543
549
544
- band_names = []
550
+ bands = []
545
551
collection = None
546
552
547
553
if isinstance (stac_object , pystac .Item ):
@@ -553,11 +559,11 @@ def is_band_asset(asset: pystac.Asset) -> bool:
553
559
eo_bands_location = item .get_collection ().summaries .lists
554
560
else :
555
561
eo_bands_location = {}
556
- band_names = [ Band ( b [ "name" ]) for b in eo_bands_location . get ( "eo:bands" , [])]
562
+ bands = get_band_metadata ( eo_bands_location )
557
563
558
564
elif isinstance (stac_object , pystac .Collection ):
559
565
collection = stac_object
560
- band_names = [ Band ( b [ "name" ]) for b in collection .summaries .lists . get ( "eo:bands" , [])]
566
+ bands = get_band_metadata ( collection .summaries .lists )
561
567
562
568
# Summaries is not a required field in a STAC collection, so also check the assets
563
569
for itm in collection .get_items ():
@@ -568,16 +574,16 @@ def is_band_asset(asset: pystac.Asset) -> bool:
568
574
}
569
575
570
576
for asset in band_assets .values ():
571
- asset_band_names = get_band_names (asset )
572
- for asset_band_name in asset_band_names :
573
- if asset_band_name not in band_names :
574
- band_names .append (asset_band_name )
577
+ asset_bands = get_band_metadata (asset . extra_fields )
578
+ for asset_band in asset_bands :
579
+ if asset_band . name not in get_band_names ( bands ) :
580
+ bands .append (asset_band )
575
581
576
582
else :
577
583
assert isinstance (stac_object , pystac .Catalog )
578
584
catalog = stac_object
579
- band_names = [ Band ( b [ "name" ]) for b in catalog .extra_fields .get ("summaries" , {}). get ( "eo:bands" , [])]
585
+ bands = get_band_metadata ( catalog .extra_fields .get ("summaries" , {}))
580
586
581
- band_dimension = BandDimension (name = "bands" , bands = band_names )
587
+ band_dimension = BandDimension (name = "bands" , bands = bands )
582
588
metadata = CubeMetadata (dimensions = [band_dimension ])
583
589
return metadata
0 commit comments