@@ -218,6 +218,8 @@ def get_file_name_tokens(zip_path: str) -> [str, list[datetime.datetime]]:
218
218
# lambda to check if file exists if desired sat_id in basename
219
219
item_valid = lambda item , sat_id : os .path .isfile (item ) and sat_id in os .path .basename (item )
220
220
221
+
222
+
221
223
def get_orbit_file_from_dir (zip_path : str , orbit_dir : str , auto_download : bool = False ) -> str :
222
224
'''Get orbit state vector list for a given swath.
223
225
@@ -255,6 +257,53 @@ def get_orbit_file_from_dir(zip_path: str, orbit_dir: str, auto_download: bool =
255
257
256
258
# search for orbit file
257
259
orbit_file_list = glob .glob (os .path .join (orbit_dir , 'S1*.EOF' ))
260
+
261
+ orbit_file = get_orbit_file_from_list (zip_path , orbit_file_list )
262
+
263
+ if orbit_file :
264
+ return orbit_file
265
+
266
+ if not auto_download :
267
+ msg = (f'No orbit file was found for { os .path .basename (zip_path )} '
268
+ f'from the directory provided: { orbit_dir } ' )
269
+ warnings .warn (msg )
270
+ return
271
+
272
+ # Attempt auto download
273
+ orbit_file = download_orbit (zip_path , orbit_dir )
274
+ return orbit_file
275
+
276
+
277
+
278
+ def get_orbit_file_from_list (zip_path : str , orbit_file_list : list ) -> str :
279
+ '''Get orbit file for a given S-1 swath from a list of files
280
+
281
+ Parameters:
282
+ -----------
283
+ zip_path : string
284
+ Path to Sentinel1 SAFE zip file. Base names required to adhere to the
285
+ format described here:
286
+ https://sentinel.esa.int/web/sentinel/user-guides/sentinel-1-sar/naming-conventions
287
+ orbit_file_list : list
288
+ List of the orbit files that exists in the system.
289
+
290
+ Returns:
291
+ --------
292
+ orbit_file : str
293
+ Path to the orbit file.
294
+ '''
295
+
296
+ # check the existence of input file path and directory
297
+ if not os .path .exists (zip_path ):
298
+ raise FileNotFoundError (f"{ zip_path } does not exist" )
299
+
300
+ # extract platform id, start and end times from swath file name
301
+ platform_id , t_swath_start_stop = get_file_name_tokens (zip_path )
302
+
303
+ # initiate output
304
+ orbit_file_final = ''
305
+
306
+ # search for orbit file
258
307
for orbit_file in orbit_file_list :
259
308
# check if file validity
260
309
if not item_valid (orbit_file , platform_id ):
@@ -273,17 +322,12 @@ def get_orbit_file_from_dir(zip_path: str, orbit_dir: str, auto_download: bool =
273
322
# 1. swath start and stop time > orbit file start time
274
323
# 2. swath start and stop time < orbit file stop time
275
324
if all ([t_orbit_start < t < t_orbit_stop for t in t_swath_start_stop ]):
325
+ orbit_file_final = orbit_file
276
326
break
277
- else :
278
- orbit_file = ''
279
327
280
- if not orbit_file :
281
- if auto_download :
282
- orbit_file = download_orbit ( zip_path , orbit_dir )
328
+ if not orbit_file_final :
329
+ msg = 'No orbit file was found in the file list provided.'
330
+ warnings . warn ( msg )
283
331
284
- else :
285
- msg = f'No orbit file found for { os .path .basename (zip_path )} !'
286
- msg += f'\n Orbit directory: { orbit_dir } '
287
- warnings .warn (msg )
332
+ return orbit_file_final
288
333
289
- return orbit_file
0 commit comments