Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning msg if no orbit file found for zip file #46

Merged
merged 2 commits into from
May 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/s1reader/s1_orbit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import datetime
import glob
import os
import warnings


# date format used in file names
FMT = "%Y%m%dT%H%M%S"
Expand Down Expand Up @@ -71,7 +74,7 @@ def get_orbit_file_from_list(zip_path: str, orbit_file_list: list[str]) -> str:

for orbit_file in orbit_file_list:
# check if file validity
if not item_valid(orbit_file, platform_id):
if not item_valid(orbit_file, platform_id):
continue

# get file name and extract state vector start/end time strings
Expand All @@ -90,6 +93,10 @@ def get_orbit_file_from_list(zip_path: str, orbit_file_list: list[str]) -> str:
all([t < t_orbit_end for t in t_swath_start_stop]):
return orbit_file

msg = f'No orbit file found for {os.path.basename(zip_path)}!'
msg += f'\nOrbit directory: {os.path.dirname(orbit_file_list[0])}'
warnings.warn(msg)

return ''

def get_orbit_file_from_dir(path: str, orbit_dir: str) -> str:
Expand Down Expand Up @@ -117,7 +124,10 @@ def get_orbit_file_from_dir(path: str, orbit_dir: str) -> str:
if not os.path.isdir(orbit_dir):
raise NotADirectoryError(f"{orbit_dir} not found")

orbit_path = get_orbit_file_from_list(
path, [f'{orbit_dir}/{item}' for item in os.listdir(orbit_dir)])
orbit_file_list = glob.glob(os.path.join(orbit_dir, 'S1*.EOF'))
if not orbit_file_list:
raise FileNotFoundError(f'No S1*.EOF file found in directory: {orbit_dir}')

orbit_path = get_orbit_file_from_list(path, orbit_file_list)

return orbit_path