@@ -425,7 +425,8 @@ def _is_zip_annotation_xml(path: str, id_str: str) -> bool:
425
425
return True
426
426
return False
427
427
428
- def load_bursts (path : str , orbit_path : str , swath_num : int , pol : str = 'vv' ):
428
+ def load_bursts (path : str , orbit_path : str , swath_num : int , pol : str = 'vv' ,
429
+ burst_ids : list [str ]= None ):
429
430
'''Find bursts in a Sentinel-1 zip file or a SAFE structured directory.
430
431
431
432
Parameters:
@@ -438,16 +439,27 @@ def load_bursts(path: str, orbit_path: str, swath_num: int, pol: str = 'vv'):
438
439
Integer of subswath of desired burst. {1, 2, 3}
439
440
pol : str
440
441
Polarization of desired burst. {hh, vv, hv, vh}
442
+ burst_ids : list[str]
443
+ List of burst IDs for which their Sentinel1BurstSlc objects will be
444
+ returned. Default of None returns all bursts. Empty list returned if
445
+ none of the burst IDs are found. If not all burst IDs are found, a list
446
+ containing found bursts will be returned.
441
447
442
448
Returns:
443
449
--------
444
450
bursts : list
445
451
List of Sentinel1BurstSlc objects found in annotation XML.
446
452
'''
447
-
448
453
if swath_num < 1 or swath_num > 3 :
449
454
raise ValueError ("swath_num not <1 or >3" )
450
455
456
+ if burst_ids is None :
457
+ burst_ids = []
458
+
459
+ # ensure burst IDs is a list
460
+ if not isinstance (burst_ids , list ):
461
+ burst_ids = [burst_ids ]
462
+
451
463
# lower case polarity to be consistent with file naming convention
452
464
pol = pol .lower ()
453
465
pols = ['vv' , 'vh' , 'hh' , 'hv' ]
@@ -459,12 +471,30 @@ def load_bursts(path: str, orbit_path: str, swath_num: int, pol: str = 'vv'):
459
471
if not os .path .exists (path ):
460
472
raise FileNotFoundError (f'{ path } not found' )
461
473
elif os .path .isdir (path ):
462
- return _burst_from_safe_dir (path , id_str , orbit_path )
474
+ bursts = _burst_from_safe_dir (path , id_str , orbit_path )
463
475
elif os .path .isfile (path ):
464
- return _burst_from_zip (path , id_str , orbit_path )
476
+ bursts = _burst_from_zip (path , id_str , orbit_path )
465
477
else :
466
478
raise ValueError (f'{ path } is unsupported' )
467
479
480
+ if burst_ids :
481
+ bursts = [b for b in bursts if b .burst_id in burst_ids ]
482
+
483
+ burst_ids_found = set ([b .burst_id for b in bursts ])
484
+
485
+ if not burst_ids_found :
486
+ warnings .warn ("None of provided bursts IDs found" )
487
+
488
+ set_burst_ids = set (burst_ids )
489
+ if burst_ids_found != set_burst_ids :
490
+ diff = set_burst_ids .difference (burst_ids_found )
491
+ warn_str = f'Not all burst IDs found. Not found: { diff } . '
492
+ warn_str += f'Found: { burst_ids_found } '
493
+ warnings .warn (warn_str )
494
+
495
+ return bursts
496
+
497
+
468
498
def _burst_from_zip (zip_path : str , id_str : str , orbit_path : str ):
469
499
'''Find bursts in a Sentinel-1 zip file.
470
500
0 commit comments