Skip to content

Commit 578d936

Browse files
seongsujeongLiangJYugshiroma
authored
Get orbit file (#79)
* Replacing the loaders in Burst* class into class methods, with further implementation for thermal and EAP correction * fix on determining beta_naught; addressing PEP8 issues * Bug fix and feature addition to BurstEAP; restructuring LUT exportation * Readibility improvement; removing unnecessary imports * Format change on `burst_id`; keeping the absolute orbit number inside `Sentinel1BurstSlc` * updates on test_bursts.py * keeping the basename of the CADS and NADS for populating RTC metadata * Update src/s1reader/s1_annotation.py Readability improvement on equation Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_annotation.py Removing commented out code Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_annotation.py Reverting the docstring to be split into two lines for PEP8 compliance Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_annotation.py Improving docstring of the code copied from isce2 Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_burst_slc.py Removing the commented out codes Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_burst_slc.py improvement on code brevity Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_burst_slc.py renaming variable for better clarity Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_burst_slc.py renaming variable name for clarity Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_burst_slc.py variable name revised for clarity Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_burst_slc.py variable renamed for clarity Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_burst_slc.py improvement on docstring Co-authored-by: Liang Yu <[email protected]> * Update src/s1reader/s1_burst_slc.py Readability improvement of equation Co-authored-by: Liang Yu <[email protected]> * addressing comments bt @LiangJYu * docstring fix; variables renamed for clarity * implemented s1_annotation.AucCal.load_from_zip_file() * readability improvement * s1_annotation.py - code cleanup; excention handling for AUX_CAL; PEP8 compliance * docstring for `s1_burst_slc.eap_compensation_lut()` * class import scheme changed * PEP8 compliance * initial structure of modification * less mod compared to the branch fork * Update src/s1reader/s1_orbit.py Co-authored-by: Gustavo H. X. Shiroma <[email protected]> * Update src/s1reader/s1_orbit.py Co-authored-by: Gustavo H. X. Shiroma <[email protected]> * Update src/s1reader/s1_orbit.py Co-authored-by: Gustavo H. X. Shiroma <[email protected]> * Update src/s1reader/s1_orbit.py Co-authored-by: Gustavo H. X. Shiroma <[email protected]> * Update src/s1reader/s1_orbit.py Co-authored-by: Gustavo H. X. Shiroma <[email protected]> * Update src/s1reader/s1_orbit.py Co-authored-by: Gustavo H. X. Shiroma <[email protected]> * addressing comments from @gshiroma * trailing white spaces are removed * trailing white space removed Co-authored-by: Seongsu Jeong <[email protected]> Co-authored-by: Liang Yu <[email protected]> Co-authored-by: Gustavo H. X. Shiroma <[email protected]>
1 parent c60035a commit 578d936

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

src/s1reader/s1_orbit.py

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ def get_file_name_tokens(zip_path: str) -> [str, list[datetime.datetime]]:
218218
# lambda to check if file exists if desired sat_id in basename
219219
item_valid = lambda item, sat_id: os.path.isfile(item) and sat_id in os.path.basename(item)
220220

221+
222+
221223
def get_orbit_file_from_dir(zip_path: str, orbit_dir: str, auto_download: bool = False) -> str:
222224
'''Get orbit state vector list for a given swath.
223225
@@ -255,6 +257,53 @@ def get_orbit_file_from_dir(zip_path: str, orbit_dir: str, auto_download: bool =
255257

256258
# search for orbit file
257259
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
258307
for orbit_file in orbit_file_list:
259308
# check if file validity
260309
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 =
273322
# 1. swath start and stop time > orbit file start time
274323
# 2. swath start and stop time < orbit file stop time
275324
if all([t_orbit_start < t < t_orbit_stop for t in t_swath_start_stop]):
325+
orbit_file_final = orbit_file
276326
break
277-
else:
278-
orbit_file = ''
279327

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)
283331

284-
else:
285-
msg = f'No orbit file found for {os.path.basename(zip_path)}!'
286-
msg += f'\nOrbit directory: {orbit_dir}'
287-
warnings.warn(msg)
332+
return orbit_file_final
288333

289-
return orbit_file

0 commit comments

Comments
 (0)