Skip to content

Commit

Permalink
fetchOrbit.py: allow reading SLC zip files from a given folder, -d op…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
yuankailiu committed Nov 18, 2023
1 parent 0dbb167 commit 00810b8
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions contrib/stack/topsStack/fetchOrbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import requests
import re
import os
import sys
import glob
import argparse
import datetime
from html.parser import HTMLParser
Expand All @@ -27,8 +29,10 @@ def cmdLineParse():
'''

parser = argparse.ArgumentParser(description='Fetch orbits corresponding to given SAFE package')
parser.add_argument('-i', '--input', dest='input', type=str, required=True,
parser.add_argument('-i', '--input', dest='input', type=str, default=None,
help='Path to SAFE package of interest')
parser.add_argument('-d', '--indir', dest='indir', type=str, default=None,
help='Directory to SAFE package(s) of interest')
parser.add_argument('-o', '--output', dest='outdir', type=str, default='.',
help='Path to output directory')

Expand Down Expand Up @@ -120,13 +124,15 @@ def fileToRange(fname):
return (start, stop, mission)


if __name__ == '__main__':
def run_main(inps, input_file=None):
'''
Main driver.
Run the major thing
'''

inps = cmdLineParse()
if input_file:
inps.input = input_file

print('Fetching for: ', inps.input)
fileTS, satName, fileTSStart = FileToTimeStamp(inps.input)
print('Reference time: ', fileTS)
print('Satellite name: ', satName)
Expand Down Expand Up @@ -156,6 +162,7 @@ def fileToRange(fname):

if match is not None:
success = True
print('fetch success, orbit type: ', oType)
except:
pass

Expand All @@ -169,3 +176,20 @@ def fileToRange(fname):
print('Failed to download URL: ', match)
else:
print('Failed to find {1} orbits for tref {0}'.format(fileTS, satName))


if __name__ == '__main__':
'''
Main driver.
'''

inps = cmdLineParse()
if (inps.input is None) and (inps.indir is None):
sys.exit('Both input files and input folder is missing!')

if inps.indir:
input_files = glob.glob(os.path.join(inps.indir, '*.zip'))
for infile in input_files:
run_main(inps, input_file=infile)
else:
run_main(inps)

0 comments on commit 00810b8

Please sign in to comment.