@@ -145,7 +145,7 @@ def load_collection(
145
145
connection : Optional [Connection ] = None ,
146
146
spatial_extent : Union [Dict [str , float ], Parameter , None ] = None ,
147
147
temporal_extent : Union [Sequence [InputDate ], Parameter , str , None ] = None ,
148
- bands : Union [None , List [str ], Parameter ] = None ,
148
+ bands : Union [Iterable [str ], Parameter , str , None ] = None ,
149
149
fetch_metadata : bool = True ,
150
150
properties : Union [
151
151
None , Dict [str , Union [str , PGNode , typing .Callable ]], List [CollectionProperty ], CollectionProperty
@@ -198,10 +198,9 @@ def load_collection(
198
198
metadata : Optional [CollectionMetadata ] = (
199
199
connection .collection_metadata (collection_id ) if connection and fetch_metadata else None
200
200
)
201
- if bands :
202
- if isinstance (bands , str ):
203
- bands = [bands ]
204
- elif isinstance (bands , Parameter ):
201
+ if bands is not None :
202
+ bands = cls ._get_bands (bands , process_id = "load_collection" )
203
+ if isinstance (bands , Parameter ):
205
204
metadata = None
206
205
if metadata :
207
206
bands = [b if isinstance (b , str ) else metadata .band_dimension .band_name (b ) for b in bands ]
@@ -272,7 +271,7 @@ def load_stac(
272
271
url : str ,
273
272
spatial_extent : Union [Dict [str , float ], Parameter , None ] = None ,
274
273
temporal_extent : Union [Sequence [InputDate ], Parameter , str , None ] = None ,
275
- bands : Optional [ List [str ]] = None ,
274
+ bands : Union [ Iterable [str ], Parameter , str , None ] = None ,
276
275
properties : Optional [Dict [str , Union [str , PGNode , Callable ]]] = None ,
277
276
connection : Optional [Connection ] = None ,
278
277
) -> DataCube :
@@ -379,7 +378,8 @@ def load_stac(
379
378
arguments ["spatial_extent" ] = spatial_extent
380
379
if temporal_extent :
381
380
arguments ["temporal_extent" ] = DataCube ._get_temporal_extent (extent = temporal_extent )
382
- if bands :
381
+ bands = cls ._get_bands (bands , process_id = "load_stac" )
382
+ if bands is not None :
383
383
arguments ["bands" ] = bands
384
384
if properties :
385
385
arguments ["properties" ] = {
@@ -388,7 +388,7 @@ def load_stac(
388
388
graph = PGNode ("load_stac" , arguments = arguments )
389
389
try :
390
390
metadata = metadata_from_stac (url )
391
- if bands :
391
+ if isinstance ( bands , list ) :
392
392
# TODO: also apply spatial/temporal filters to metadata?
393
393
metadata = metadata .filter_bands (band_names = bands )
394
394
except Exception :
@@ -429,6 +429,24 @@ def convertor(d: Any) -> Any:
429
429
get_temporal_extent (* args , start_date = start_date , end_date = end_date , extent = extent , convertor = convertor )
430
430
)
431
431
432
+ @staticmethod
433
+ def _get_bands (
434
+ bands : Union [Iterable [str ], Parameter , str , None ], process_id : str
435
+ ) -> Union [None , List [str ], Parameter ]:
436
+ """Normalize band array for processes like load_collection, load_stac"""
437
+ if bands is None :
438
+ pass
439
+ elif isinstance (bands , str ):
440
+ bands = [bands ]
441
+ elif isinstance (bands , Parameter ):
442
+ pass
443
+ else :
444
+ # Coerce to list
445
+ bands = list (bands )
446
+ if len (bands ) == 0 :
447
+ raise OpenEoClientException (f"Bands array should not be empty (process { process_id !r} )" )
448
+ return bands
449
+
432
450
@openeo_process
433
451
def filter_temporal (
434
452
self ,
0 commit comments