-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAPI_download_S1_SLC.py
113 lines (97 loc) · 5.04 KB
/
API_download_S1_SLC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
###########################################################################
# Header information
###########################################################################
"""API_download_S1_SLC.py: Script to download Sentinel-1 SLC images from the ASF mirror"""
__author__ = "Alexis Hrysiewicz"
__copyright__ = "Copyright 2022"
__credits__ = ["Alexis Hrysiewicz"]
__license__ = "GPL"
__version__ = "1.0.0"
__maintainer__ = "Alexis Hrysiewicz"
__status__ = "Production"
__date__ = "Jan. 2022"
###########################################################################
# Python packages
###########################################################################
import os
import sys
import pandas as pd
import datetime
import os.path
import optparse
###########################################################################
###########################################################################
class OptionParser (optparse.OptionParser):
def check_required(self, opt):
option = self.get_option(opt)
if getattr(self.values, option.dest) is None:
self.error("%s option not supplied" % option)
###########################################################################
###########################################################################
if len(sys.argv) != 25:
prog = os.path.basename(sys.argv[0])
print("example: python3 %s -u username -p password -s . -r . -b -10.78,51.27,-5.03,55.70 -i 2017-01-01T00:00:00 -j 2023-12-31T00:00 -o 1 -f a -q IW -m csv -w n" %
sys.argv[0])
sys.exit(-1)
else:
usage = "usage: %prog [options] "
parser = OptionParser(usage=usage)
parser.add_option("-u", "--username", action="store", type="string", default='username')
parser.add_option("-p", "--password", action="store", type="string", default='password')
parser.add_option("-s", "--path_SLC", action="store", type="string", default='.')
parser.add_option("-r", "--path_RSLC", action="store", type="string", default='.') # Only available for GAMMA stack
parser.add_option("-b", "--bbox", action="store", type="string", default='-10.78,51.27,-5.03,55.70')
parser.add_option("-i", "--date_start", action="store", type="string", default='2017-01-01T00:00:00')
parser.add_option("-j", "--date_end", action="store", type="string", default='2024-01-01T00:00:00')
parser.add_option("-o", "--orbit_relative", action="store", type="float", default='1')
parser.add_option("-f", "--flight_direction", action="store", type="string", default='a')
parser.add_option("-q", "--q_acqui_mode", action="store", type="string", default='IW')
parser.add_option("-m", "--mode", action="store", type="string", default='csv')
parser.add_option("-w", "--write", action="store", type="string", default='n')
(options, args) = parser.parse_args()
###########################################################################
# Main
###########################################################################
date_format = "%Y-%m-%d"
cmd1 = 'curl "https://api.daac.asf.alaska.edu/services/search/param?platform=s1&bbox=%s&start=%sUTC&end=%sUTC&relativeOrbit=%d&flightDirection=%s&processingLevel=SLC&maxResults=10000&output=%s" > SLC_list.%s' % (options.bbox,options.date_start,options.date_end,int(options.orbit_relative),options.flight_direction.upper(),options.mode.upper(),options.mode.lower())
if options.mode.upper() == 'KML':
os.system(cmd1)
elif options.mode.upper() == 'CSV':
os.system(cmd1)
else:
print('Please, select a correct mode (csv or kml)...')
# Correction of list according the beam mode
os.rename("SLC_list.csv","SLC_list_orig.csv")
h = 0
fout = open("SLC_list.csv",'w')
with open("SLC_list_orig.csv") as fi:
for li in fi:
if h > 0:
if options.q_acqui_mode.upper() == 'all':
fout.write(li)
elif options.q_acqui_mode.upper() in li:
fout.write(li)
else:
fout.write(li)
h = h + 1
fout.close()
os.remove("SLC_list_orig.csv")
# Download
if options.mode.upper() == 'CSV' and options.write.upper() == 'Y':
listSLC = pd.read_csv("SLC_list.csv")
print(listSLC)
h = 0
for slci in listSLC['Granule Name']:
print('Checking if the SLC %s is stored or processed (.zip or .rslc from GAMMA)\n\t The url is %s' % (slci,listSLC['URL'][h]))
datei = datetime.datetime.strptime(listSLC['Acquisition Date'][h].split('.')[0], '%Y-%m-%dT%H:%M:%S').strftime("%Y%m%d")
if os.path.exists(options.path_SLC+'/'+slci+'.zip') == 1 or os.path.exists(options.path_RSLC+'/'+datei+'.vv.rslc') == 1:
print('\t\tThe SLC has been stored or processed.')
else:
print('\t\tThe SLC has not been stored or processed. Downloading needed...')
cmd1 = 'wget -c --http-user=%s --http-password=%s "%s" -P %s' % (options.username,options.password,listSLC['URL'][h],options.path_SLC)
os.system(cmd1)
h+=1
elif options.mode.upper() == 'KML' and options.write.upper() == 'Y':
print('Please, select a CSV mode to download..')