-
Notifications
You must be signed in to change notification settings - Fork 42
/
igs_ftp.py
266 lines (211 loc) · 9.01 KB
/
igs_ftp.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
"""
This file is part of ppp-tools, https://github.com/aewallin/ppp-tools
GPLv2 license.
Library for downloading GPS products (orbits & clocks) from
an IGS datacenter.
Anders Wallin, 2013-2015
"""
import ftplib
import datetime
import sys
import os
import ftp_tools
import gpstime
# ftp://cddis.gsfc.nasa.gov/gnss/data/daily/
# YYYY/DDD/YYn/brdcDDD0.YYn.Z (merged GPS broadcast ephemeris file)
def cddis_brdc_file(dt, prefixdir=""):
"""
This was used previously for rtklib runs.
Could be replaced with a nav-file from the station?
"""
server = "cddis.gsfc.nasa.gov"
remotedir = "gnss/data/daily/%d/brdc" % dt.year
doy = dt.timetuple().tm_yday
f = "brdc%03d0.%dn.Z" % (doy, dt.year-2000)
# YYYY/brdc/brdcDDD0.YYn.Z
localdir = prefixdir + "/stations/brdc/"
ftp_tools.check_dir(localdir)
ftp_tools.ftp_download(server, username="anonymous", password="",
remotedir=remotedir, remotefile=f, localdir=localdir)
return localdir+f
def get_IGS_rapid(dt, prefixdir=""):
(server, username, password, directory, files,
localdir) = IGS_rapid_files(dt, prefixdir)
(clk1, eph1, erp1) = download(
server, username, password, directory, files, localdir)
return (clk1, eph1, erp1)
def get_IGS_final(dt, prefixdir=""):
(server, username, password, directory, files,
localdir) = IGS_final_files(dt, prefixdir)
(clk1, eph1, erp1) = download(
server, username, password, directory, files, localdir)
return (clk1, eph1, erp1)
def get_CODE_final(dt, prefixdir=""):
(server, username, password, directory, files,
localdir) = CODE_final_files(dt, prefixdir)
(clk1, eph1, erp1) = download(
server, username, password, directory, files, localdir)
return (clk1, eph1, erp1)
def get_CODE_rapid(dt, prefixdir=""):
(server, username, password, directory, files,
localdir) = CODE_rapid_files(dt, prefixdir)
(clk1, eph1, erp1) = download(
server, username, password, directory, files, localdir)
return (clk1, eph1, erp1)
def CODE_rapid_files(dt, prefixdir=""):
"""
retrieve rapid CODE products for the datetime dt
Products are stored in <prefixdir>/products/CODE_rapid/
Examples of Rapid files: (FIXME: old paths!)
ftp://ftp.unibe.ch/aiub/CODE/COD17840.EPH_R ephemeris aka orbits
ftp://ftp.unibe.ch/aiub/CODE/COD17840.ERP_R erp, earth rotation parameters
ftp://ftp.unibe.ch/aiub/CODE/COD17840.CLK_R clk, clocks
updated working link (as of 2021 July)
ftp://ftp.aiub.unibe.ch/CODE/
"""
server = "ftp.aiub.unibe.ch"
remotedir = "CODE/"
week = gpstime.gpsWeek(dt.year, dt.month, dt.day)
dow = gpstime.dayOfWeek(dt.year, dt.month, dt.day)
clk = "COD%s%s.CLK_R" % (week, dow)
sp3 = "COD%s%s.EPH_R" % (week, dow)
erp = "COD%s%s.ERP_R" % (week, dow)
print("CODE rapid products for %d-%02d-%0d" % (dt.year, dt.month, dt.day))
print("CLK = ", clk)
print("SP3 = ", sp3)
print("ERP = ", erp)
ftp_tools.check_dir(prefixdir + "/products/")
localdir = prefixdir + "/products/CODE_rapid/"
print("local dir = ", localdir)
# return CODE_download(server, directory, [clk, sp3, erp], localdir)
return (server, "", "", remotedir, [clk, sp3, erp], localdir)
def CODE_final_files(dt, prefixdir=""):
"""
retrieve final CODE products for the datetime dt
files are in:
ftp://ftp.aiub.unibe.ch/CODE/2021/
"""
server = "ftp.aiub.unibe.ch"
remotedir = "CODE/%s/" % (dt.year)
week = gpstime.gpsWeek(dt.year, dt.month, dt.day)
dow = gpstime.dayOfWeek(dt.year, dt.month, dt.day)
clk = "COD%s%s.CLK.Z" % (week, dow) # clock
sp3 = "COD%s%s.EPH.Z" % (week, dow) # orbit
erp = "COD%s%s.ERP.Z" % (week, dow) # earth
print("CODE final products for %d-%02d-%0d" % (dt.year, dt.month, dt.day))
print("CLK = ", clk)
print("SP3 = ", sp3)
print("ERP = ", erp)
ftp_tools.check_dir(prefixdir + "/products/")
localdir = prefixdir + "/products/CODE_final/"
print("local dir = ", localdir)
return (server, "", "", remotedir, [clk, sp3, erp], localdir)
def IGS_rapid_files(dt, prefixdir=""):
"""
retrieve rapid IGS products for the datetime dt
files are in:
ftp://gssc.esa.int/gnss/products/<gpsWeek>/
WWWW/igrWWWWD.sp3.Z Satellite orbit solution
WWWW/igrWWWWD.erp.Z Earth orientation parameter solution
WWWW/igrWWWWd.clk_30.Z Satellite and station clock solution (30 second)
"""
week = gpstime.gpsWeek(dt.year, dt.month, dt.day)
dow = gpstime.dayOfWeek(dt.year, dt.month, dt.day)
#server = "gssc.esa.int"
#remotedir = "gnss/products/%d/" % (week)
server = "igs.ensg.ign.fr"
remotedir = "pub/igs/products/%d/" % (week)
#clk = "igs%s%s.clk_30s.Z" % (week, dow) # clock, 30s interval
#clk = "igs%s%s.clk.Z" % (week, dow) # clock, (5 minute interval?)
#server = "gssc.esa.int"
#week = gpstime.gpsWeek(dt.year, dt.month, dt.day)
#dow = gpstime.dayOfWeek(dt.year, dt.month, dt.day)
#remotedir = "gnss/products/%d/" % (week)
clk = "igr%s%s.clk.Z" % (week, dow) # clock
sp3 = "igr%s%s.sp3.Z" % (week, dow) # orbit
erp = "igr%s%s.erp.Z" % (week, dow) # earth rotation parameters, 7 = weeklys
print("IGS rapid products for %d-%02d-%0d" % (dt.year, dt.month, dt.day))
print("CLK = ", clk)
print("SP3 = ", sp3)
print("ERP = ", erp)
ftp_tools.check_dir(prefixdir + "/products/")
localdir = prefixdir + "/products/IGS_rapid/"
print("local dir = ", localdir)
return (server, "", "", remotedir, [clk, sp3, erp], localdir)
def IGS_final_files(dt, prefixdir=""):
"""
retrieve final IGS products for the datetime dt
files are in:
ftp://gssc.esa.int/gnss/products/<gpsWeek>/
ftp://igs.ensg.ign.fr/pub/igs/products/2160/
WWWW/igsWWWWD.sp3.Z Satellite orbit solution
WWWW/igsWWWWD.erp.Z Earth orientation parameter solution
WWWW/igsWWWWd.clk_30.Z Satellite and station clock solution (30 second)
"""
week = gpstime.gpsWeek(dt.year, dt.month, dt.day)
dow = gpstime.dayOfWeek(dt.year, dt.month, dt.day)
#server = "gssc.esa.int"
#remotedir = "gnss/products/%d/" % (week)
server = "igs.ensg.ign.fr"
remotedir = "pub/igs/products/%d/" % (week)
clk = "igs%s%s.clk_30s.Z" % (week, dow) # clock, 30s interval
#clk = "igs%s%s.clk.Z" % (week, dow) # clock, (5 minute interval?)
sp3 = "igs%s%s.sp3.Z" % (week, dow) # orbit
erp = "igs%s%s.erp.Z" % (week, 7) # earth rotation parameters, 7 = weeklys
print("IGS final products for %d-%02d-%0d" % (dt.year, dt.month, dt.day))
print("CLK = ", clk)
print("SP3 = ", sp3)
print("ERP = ", erp)
ftp_tools.check_dir(prefixdir + "/products/")
localdir = prefixdir + "/products/IGS_final/"
print("local dir = ", localdir)
return (server, "", "", remotedir, [clk, sp3, erp], localdir)
def download(server, username, password, remotedir, files, localdir):
"""
Download a list of files from given ftp server
Return list of local downloaded files
"""
print("download start ", datetime.datetime.now())
ftp_tools.check_dir(localdir)
for f in files:
local_file = localdir+f
ftp_tools.ftp_download(
server, username, password, remotedir, f, localdir)
print("download Done ", datetime.datetime.now())
sys.stdout.flush()
output = []
for f in files:
output.append(localdir+f)
return output # returns list of local files: [CLK, EPH, ERP]
def example_igs_ftp():
current_dir = os.getcwd()
# example of how to use the functions:
# rapid products avaible with 2(?) days latency
dt_rapid = datetime.datetime.now() - datetime.timedelta(days=3)
# final product worst case latency 14 days ?
dt_final = datetime.datetime.now() - datetime.timedelta(days=15)
(server, username, password, directory, files,
localdir) = CODE_final_files(dt_final, prefixdir=current_dir)
files = download(server, username, password,
directory, files, localdir)
print(files) # [CLK, EPH, ERP] note that final products are zipped
(server, username, password, directory, files,
localdir) = CODE_rapid_files(dt_rapid, prefixdir=current_dir)
files = download(server, username, password,
directory, files, localdir)
print(files) # [CLK, EPH, ERP] rapid products are unzipped
"""
sample output:
CODE final products for 2015 - 5 - 25
CLK = COD18461.CLK.Z
SP3 = COD18461.EPH.Z
ERP = COD18461.ERP.Z
local dir = /home/anders/ppp-tools/CODE_final/
CODE rapid products for 2015 - 5 - 25
CLK = COD18461.CLK_R
SP3 = COD18461.EPH_R
ERP = COD18461.ERP_R
local dir = /home/anders/ppp-tools/CODE_rapid/
"""
if __name__ == "__main__":
example_igs_ftp()