Skip to content

Commit

Permalink
Get orbit file (#79)
Browse files Browse the repository at this point in the history
* 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 <liangjyu@gmail.com>

* Update src/s1reader/s1_annotation.py

Removing commented out code

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* Update src/s1reader/s1_annotation.py

Reverting the docstring to be split into two lines for PEP8 compliance

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* Update src/s1reader/s1_annotation.py

Improving docstring of the code copied from isce2

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* Update src/s1reader/s1_burst_slc.py

Removing the commented out codes

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* Update src/s1reader/s1_burst_slc.py

improvement on code brevity

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* Update src/s1reader/s1_burst_slc.py

renaming variable for better clarity

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* Update src/s1reader/s1_burst_slc.py

renaming variable name for clarity

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* Update src/s1reader/s1_burst_slc.py

variable name revised for clarity

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* Update src/s1reader/s1_burst_slc.py

variable renamed for clarity

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* Update src/s1reader/s1_burst_slc.py

improvement on docstring

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* Update src/s1reader/s1_burst_slc.py

Readability improvement of equation

Co-authored-by: Liang Yu <liangjyu@gmail.com>

* 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 <52007211+gshiroma@users.noreply.github.com>

* Update src/s1reader/s1_orbit.py

Co-authored-by: Gustavo H. X. Shiroma <52007211+gshiroma@users.noreply.github.com>

* Update src/s1reader/s1_orbit.py

Co-authored-by: Gustavo H. X. Shiroma <52007211+gshiroma@users.noreply.github.com>

* Update src/s1reader/s1_orbit.py

Co-authored-by: Gustavo H. X. Shiroma <52007211+gshiroma@users.noreply.github.com>

* Update src/s1reader/s1_orbit.py

Co-authored-by: Gustavo H. X. Shiroma <52007211+gshiroma@users.noreply.github.com>

* Update src/s1reader/s1_orbit.py

Co-authored-by: Gustavo H. X. Shiroma <52007211+gshiroma@users.noreply.github.com>

* addressing comments from @gshiroma

* trailing white spaces are removed

* trailing white space removed

Co-authored-by: Seongsu Jeong <seongsu.jeong@jpl.nasa.gov>
Co-authored-by: Liang Yu <liangjyu@gmail.com>
Co-authored-by: Gustavo H. X. Shiroma <52007211+gshiroma@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 15, 2022
1 parent c60035a commit 578d936
Showing 1 changed file with 54 additions and 10 deletions.
64 changes: 54 additions & 10 deletions src/s1reader/s1_orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def get_file_name_tokens(zip_path: str) -> [str, list[datetime.datetime]]:
# lambda to check if file exists if desired sat_id in basename
item_valid = lambda item, sat_id: os.path.isfile(item) and sat_id in os.path.basename(item)



def get_orbit_file_from_dir(zip_path: str, orbit_dir: str, auto_download: bool = False) -> str:
'''Get orbit state vector list for a given swath.
Expand Down Expand Up @@ -255,6 +257,53 @@ def get_orbit_file_from_dir(zip_path: str, orbit_dir: str, auto_download: bool =

# search for orbit file
orbit_file_list = glob.glob(os.path.join(orbit_dir, 'S1*.EOF'))

orbit_file = get_orbit_file_from_list(zip_path, orbit_file_list)

if orbit_file:
return orbit_file

if not auto_download:
msg = (f'No orbit file was found for {os.path.basename(zip_path)} '
f'from the directory provided: {orbit_dir}')
warnings.warn(msg)
return

# Attempt auto download
orbit_file = download_orbit(zip_path, orbit_dir)
return orbit_file



def get_orbit_file_from_list(zip_path: str, orbit_file_list: list) -> str:
'''Get orbit file for a given S-1 swath from a list of files
Parameters:
-----------
zip_path : string
Path to Sentinel1 SAFE zip file. Base names required to adhere to the
format described here:
https://sentinel.esa.int/web/sentinel/user-guides/sentinel-1-sar/naming-conventions
orbit_file_list : list
List of the orbit files that exists in the system.
Returns:
--------
orbit_file : str
Path to the orbit file.
'''

# check the existence of input file path and directory
if not os.path.exists(zip_path):
raise FileNotFoundError(f"{zip_path} does not exist")

# extract platform id, start and end times from swath file name
platform_id, t_swath_start_stop = get_file_name_tokens(zip_path)

# initiate output
orbit_file_final = ''

# search for orbit file
for orbit_file in orbit_file_list:
# check if file validity
if not item_valid(orbit_file, platform_id):
Expand All @@ -273,17 +322,12 @@ def get_orbit_file_from_dir(zip_path: str, orbit_dir: str, auto_download: bool =
# 1. swath start and stop time > orbit file start time
# 2. swath start and stop time < orbit file stop time
if all([t_orbit_start < t < t_orbit_stop for t in t_swath_start_stop]):
orbit_file_final = orbit_file
break
else:
orbit_file = ''

if not orbit_file:
if auto_download:
orbit_file = download_orbit(zip_path, orbit_dir)
if not orbit_file_final:
msg = 'No orbit file was found in the file list provided.'
warnings.warn(msg)

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

return orbit_file

0 comments on commit 578d936

Please sign in to comment.