forked from crowellbw/SNIVEL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SNIVEL_filedownloader.py
234 lines (225 loc) · 11.8 KB
/
SNIVEL_filedownloader.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/env python
import wget
import os
import urllib
import SNIVEL_tools
from ftplib import FTP_TLS
#####################################################################################
#SNIVEL_filedownloader.py
#This code will download any RINEX, nav or UNR
#time series file requested
#Written by Brendan Crowell, University of Washington
#Last edited January 8, 2021
#Broadcast navigation messages are only downloaded from CDDIS
#RINEX files will try to download from UNAVCO, then CWU, then CDDIS, then SOPAC
#Time Series files will only download from UNR, cartesian positions
#VARIABLES
#year - 4 digit string of year
#doy - 3 digit string of day of year
#site - 4 digit string of site id
#####################################################################################
#This subroutine downloads the any sp3 file for a given day from CDDIS
def getsp3file(year, doy):
if not os.path.exists('nav'): #if nav folder doesn't exist, make it
os.makedirs('nav')
[gpsweek,gpsdow]=SNR_tools.gpsweekdow(int(year),int(doy))
week = str(int(gpsweek))
dow = str(int(gpsdow))
fname = 'nav/igs' + week + dow + '.sp3.Z'
fname2 = 'nav/igs' + week + dow + '.sp3'
fname3 = 'nav/GBM0MGXRAP_' + year + doy + '0000_01D_05M_ORB.SP3'
if (os.path.isfile(fname2) == True):
print ('Final orbit file ' + fname2 + ' already exists')
else:
try:
ftps = FTP_TLS(host = 'gdc.cddis.eosdis.nasa.gov')
ftps.login(user='anonymous', passwd='[email protected]')
ftps.prot_p()
ftps.cwd('gnss/products/' + week + '/')
ftps.retrbinary("RETR " + 'igs' + week + dow + '.sp3.Z', open('igs'+ week + dow + '.sp3.Z', 'wb').write)
#url = 'ftp://cddis.gsfc.nasa.gov/gnss/products/' + week + '/igs' + week + dow + '.sp3.Z'
print('Downloading final orbit file '+fname2)
os.system('mv igs'+ week + dow + '.sp3.Z nav')
os.system('gunzip' + ' ' + fname)
os.system('cp' + ' ' + fname2 + ' ' + fname3 )
except Exception:
print ('Final orbit not available, trying rapid orbits')
#This subroutine downloads the broadcast navigation message for a given day from CDDIS
def getbcorbit(year, doy):
if not os.path.exists('nav'): #if nav folder doesn't exist, make it
os.makedirs('nav')
fnameZ = 'nav/brdc' + doy + '0.' + year[-2:] + 'n.Z'
fnamegz = 'nav/brdc' + doy + '0.' + year[-2:] + 'n.gz'
fname2 = 'nav/brdc' + doy + '0.' + year[-2:] + 'n'
if (os.path.isfile(fname2) == True):
print ('Navigation file ' + fname2 + ' already exists')
else:
if (int(year) > 2020):
ftps = FTP_TLS(host = 'gdc.cddis.eosdis.nasa.gov')
ftps.login(user='anonymous', passwd='[email protected]')
ftps.prot_p()
ftps.cwd('gnss/data/daily/' + year + '/' + doy + '/' + year[-2:] + 'n/')
ftps.retrbinary("RETR " + 'brdc' + doy + '0.' + year[-2:] + 'n.gz', open('brdc' + doy + '0.' + year[-2:] + 'n.gz', 'wb').write)
os.system('mv '+ 'brdc' + doy + '0.' + year[-2:] + 'n.gz nav')
os.system('gunzip' + ' ' + fnamegz)
elif (int(year) == 2020 and int(doy) >334):
ftps = FTP_TLS(host = 'gdc.cddis.eosdis.nasa.gov')
ftps.login(user='anonymous', passwd='[email protected]')
ftps.prot_p()
ftps.cwd('gnss/data/daily/' + year + '/' + doy + '/' + year[-2:] + 'n/')
ftps.retrbinary("RETR " + 'brdc' + doy + '0.' + year[-2:] + 'n.gz', open('brdc' + doy + '0.' + year[-2:] + 'n.gz', 'wb').write)
os.system('mv '+ 'brdc' + doy + '0.' + year[-2:] + 'n.gz nav')
os.system('gunzip' + ' ' + fnamegz)
else:
ftps = FTP_TLS(host = 'gdc.cddis.eosdis.nasa.gov')
ftps.login(user='anonymous', passwd='[email protected]')
ftps.prot_p()
ftps.cwd('gnss/data/daily/' + year + '/' + doy + '/' + year[-2:] + 'n/')
ftps.retrbinary("RETR " + 'brdc' + doy + '0.' + year[-2:] + 'n.Z', open('brdc' + doy + '0.' + year[-2:] + 'n.Z', 'wb').write)
os.system('mv '+ 'brdc' + doy + '0.' + year[-2:] + 'n.Z nav')
os.system('gunzip' + ' ' + fnameZ)
#This subroutine downloads the any sp3 file for a given day from CDDIS
def getsp3file(year, doy):
if not os.path.exists('nav'): #if nav folder doesn't exist, make it
os.makedirs('nav')
[gpsweek,gpsdow]=SNIVEL_tools.gpsweekdow(int(year),int(doy))
week = str(int(gpsweek))
dow = str(int(gpsdow))
fname = 'nav/igs' + week + dow + '.sp3.Z'
fname2 = 'nav/igs' + week + dow + '.sp3'
if (os.path.isfile(fname2) == True):
print ('Final orbit file ' + fname2 + ' already exists')
else:
try:
url = 'ftp://cddis.gsfc.nasa.gov/gnss/products/' + week + '/igs' + week + dow + '.sp3.Z'
print('Downloading final orbit file '+fname2)
wget.download(url, out='nav/')
os.system('gunzip' + ' ' + fname)
os.system('cp' + ' ' + fname2 + ' > nav/SNIVEL'+ week + dow + '.sp3' )
except Exception:
print ('Final orbit not available, trying rapid orbits')
fname = 'nav/igr' + week + dow + '.sp3.Z'
fname2 = 'nav/igr' + week + dow + '.sp3'
if (os.path.isfile(fname2) == True):
print ('Rapid orbit file ' + fname2 + ' already exists')
else:
try:
url = 'ftp://cddis.gsfc.nasa.gov/gnss/products/' + week + '/igr' + week + dow + '.sp3.Z'
print('Dpwnloading rapid orbit file '+fname2)
wget.download(url, out='nav/')
os.system('gunzip' + ' ' + fname)
os.system('cp' + ' ' + fname2 + ' > nav/SNIVEL'+ week + dow + '.sp3' )
except Exception:
print ('Rapid orbit not available, trying ultra-rapid orbits')
fname = 'nav/igu' + week + dow + '_12.sp3.Z'
fname2 = 'nav/igu' + week + dow + '_12.sp3'
if (os.path.isfile(fname2) == True):
print ('Ultra-rapid orbit file ' + fname2 + ' already exists')
else:
url = 'ftp://cddis.gsfc.nasa.gov/gnss/products/' + week + '/igu' + week + dow + '_12.sp3.Z'
print('Dpwnloading ultra-rapid orbit file '+fname2)
wget.download(url, out='nav/')
os.system('gunzip' + ' ' + fname)
os.system('mv' + ' ' + fname2 + ' > nav/SNIVEL'+ week + dow + '.sp3' )
#This subroutine downloads the ultra rapid sp3 file for a given day from CDDIS
def getsp3urfile(year, doy):
if not os.path.exists('nav'): #if nav folder doesn't exist, make it
os.makedirs('nav')
[gpsweek,gpsdow]=SNIVEL_tools.gpsweekdow(int(year),int(doy))
week = str(int(gpsweek))
dow = str(int(gpsdow))
fname = 'nav/igu' + week + dow + '_12.sp3.Z'
fname2 = 'nav/igu' + week + dow + '_12.sp3'
if (os.path.isfile(fname2) == True):
print ('Ultra-rapid orbit file ' + fname2 + ' already exists')
else:
url = 'ftp://cddis.gsfc.nasa.gov/gnss/products/' + week + '/igu' + week + dow + '_12.sp3.Z'
print('Downloading final orbit file '+fname2)
wget.download(url, out='nav/')
os.system('gunzip' + ' ' + fname)
#This subroutine will download RINEX files given the station, year and day of year.
def getrinex(site, year, doy):
if not os.path.exists('rinex'): #if rinex folder doesn't exist, make it
os.makedirs('rinex')
fnameZ = 'rinex/' + site + doy + '0.' + year[-2:] + 'd.Z'
fnamebz2 = 'rinex/' + site + doy + '0.' + year[-2:] + 'd.bz2'
fnamed = 'rinex/' + site + doy + '0.' + year[-2:] + 'd'
fnameo = 'rinex/' + site + doy + '0.' + year[-2:] + 'o'
if (os.path.isfile(fnameo) == True):
print ('Rinex file ' + fnameo + ' already exists')
else:
try:
url = 'ftp://data-out.unavco.org/pub/rinex/obs/' + year + '/' + doy + '/' + site + doy + '0.' + year[-2:] + 'd.Z'
print ('Attempting to download ' + fnamed + ' from UNAVCO')
wget.download(url, out='rinex/')
os.system('gunzip' + ' ' + fnameZ)
os.system('./crx2rnx' + ' ' + fnamed)
os.remove(fnamed)
except Exception:
print ('File not at UNAVCO, checking CWU')
try:
url = 'https://www.geodesy.cwu.edu/data_ftp_pub/data/' + year+ '/' + doy + '/30sec/' + site + doy + '0.' + year[-2:] + 'd.bz2'
print ('Attempting to download ' + fnamed + ' from CWU')
wget.download(url, out='rinex/')
os.system('bzip2 -d' + ' ' + fnamebz2)
os.system('./crx2rnx' + ' ' + fnamed)
os.remove(fnamed)
except Exception:
print ('File not at CWU, checking CDDIS')
try:
url = 'ftp://cddis.nasa.gov/gnss/data/daily/' + year+ '/' + doy + '/' + year[-2:] + 'd/' + site + doy + '0.' + year[-2:] + 'd.Z'
print ('Attempting to download ' + fnamed + ' from CDDIS')
wget.download(url, out='rinex/')
os.system('gunzip' + ' ' + fnameZ)
os.system('./crx2rnx' + ' ' + fnamed)
os.remove(fnamed)
except Exception:
print ('File not at CDDIS, checking SOPAC')
try:
url = 'ftp://garner.ucsd.edu/pub/rinex/' + year+ '/' + doy + '/' + site + doy + '0.' + year[-2:] + 'd.Z'
print ('Attempting to download ' + fnamed + ' from SOPAC')
wget.download(url, out='rinex/')
os.system('gunzip' + ' ' + fnameZ)
os.system('./crx2rnx' + ' ' + fnamed)
os.remove(fnamed)
except Exception:
print ('File not found at SOPAC, moving onto next station')
#This subroutine will download highrate (1-Hz) RINEX files
def getrinexhr(site, year, doy):
if not os.path.exists('rinex_hr'): #if rinex highrate folder doesn't exist, make it
os.makedirs('rinex_hr')
fnameZ = 'rinex_hr/' + site + doy + '0.' + year[-2:] + 'd.Z'
fnamebz2 = 'rinex_hr/' + site + doy + 'i.' + year[-2:] + 'd.bz2'
fnamecwuo = 'rinex_hr/' + site + doy + 'i.' + year[-2:] + 'o'
fnamecwud = 'rinex_hr/' + site + doy + 'i.' + year[-2:] + 'd'
fnamed = 'rinex_hr/' + site + doy + '0.' + year[-2:] + 'd'
fnameo = 'rinex_hr/' + site + doy + '0.' + year[-2:] + 'o'
if (os.path.isfile(fnameo) == True):
print ('Rinex file ' + fnameo + ' already exists')
else:
try:
url = 'https://data.unavco.org/archive/gnss/highrate/1-Hz/rinex/' + year + '/' + doy + '/' + site + '/' + site + doy + '0.' + year[-2:] + 'd.Z'
print ('Attempting to download ' + fnamed + ' from UNAVCO')
wget.download(url, out='rinex_hr/')
os.system('gunzip' + ' ' + fnameZ)
os.system('./crx2rnx' + ' ' + fnamed)
os.remove(fnamed)
except Exception:
print ('File not at UNAVCO checking CWU')
try:
url = 'https://www.geodesy.cwu.edu/data_ftp_pub/data/' + year+ '/' + doy + '/01sec/' + site + doy + 'i.' + year[-2:] + 'd.bz2'
print ('Attempting to download ' + fnamed + ' from CWU')
wget.download(url, out='rinex_hr/')
os.system('bzip2 -d' + ' ' + fnamebz2)
os.system('./crx2rnx' + ' ' + fnamecwud)
os.rename(fnamecwuo, fnameo)
os.remove(fnamecwud)
except Exception:
print ('File not at CWU, moving on')
#Examples
##getrinexhr('lwck','2018','002')
##getrinex('p494','2018','002')
##getbcorbit('2018','002')
##gettseries('p494')
##
#getsp3file('2018','002')