-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathstation.py
More file actions
325 lines (282 loc) · 12 KB
/
station.py
File metadata and controls
325 lines (282 loc) · 12 KB
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
"""
This file is part of ppp-tools, https://github.com/aewallin/ppp-tools
GPLv2 license.
"""
import os
import datetime
import shutil
import subprocess
import bipm_ftp
import ftp_tools
import wget
class Station():
"""
Class to represent a GPS station/receiver producing RINEX files.
We get RINEX files by downloading them from an FTP site.
May be modified later to include 'local' stations where we find the RINEX
on disk rather than via FTP.
"""
def __init__(self):
self.name = "" # station name e.g. "USNO"
# when name is more than 4 characters, BIPM abbreviates with 4 chars, e.g. "MIKE"
self.utctag = ""
self.ftp_server = "" # e.g. "my.ftp-server.com"
self.ftp_dir = "" # the directory/ for RINEX files on the ftp server
self.ftp_username = ""
self.ftp_password = ""
self.lz = False # do we need an LZ file or not?
self.receiver = "" # receiver name, e.g. "MI02", used in the RINEX filename
self.rinex_filename = self.rinex1
self.hatanaka = False # flag is True for Hatanaka compressed RINEX
self.antex = True # receiver antenna in ANTEX file?
self.rinex3 = False # RINEX version 3, requiring conversion to version 2
self.ref_dly = 0.0 # delay of PPS-cable from reference plane to GNSS receiver input
self.cab_dly = 0.0 # antenna cable delay from GNSS-receiver to antenna
self.int_dly_p1 = 0.0 # internal GNSS receiver delay for L1
self.int_dly_p2 = 0.0 # internal GNSS receiver delay for L2
# raw PPP results are corrected with the calibrated delays as follows:
# RX_clk_corrected = RX_clk_raw - station.cab_dly - station.int_dly_p3() + station.ref_dly
def int_dly_p3(self):
"""
ionosphere-free P3 internal delay.
linear combination of calibrated P1 and P3 delays
see e.g. https://gssc.esa.int/navipedia/index.php/Combination_of_GNSS_Measurements
"""
return 2.5457*self.int_dly_p1 - 1.5457*self.int_dly_p2
# the RINEX naming convention is that there is no convention...
# we define rinex_filename() in the constructor, which calls one of rinex1(), rinex2(), etc.
def rinex1(self, dt): # NIST style name, with capital "O"
fname = "%s%03d0.%02dO.Z" % (
self.receiver, dt.timetuple().tm_yday, dt.year-2000)
return fname
def rinex2(self, dt): # USNO style name, with small "o"
fname = "%s%03d0.%02do.Z" % (
self.receiver, dt.timetuple().tm_yday, dt.year-2000)
return fname
def rinex3(self, dt): # OP style name, compressed with "d"
fname = "%s%03d0.%02dd.Z" % (
self.receiver, dt.timetuple().tm_yday, dt.year-2000)
self.hatanaka = True
return fname
def rinex4(self, dt): # PTB style name, compressed with "D"
fname = "%s%03d0.%02dD.Z" % (
self.receiver, dt.timetuple().tm_yday, dt.year-2000)
self.hatanaka = True
return fname
def rinex5(self, dt): # PTBG 2019 style name, compressed with "D", ending "gz"
fname = "%s%03d0.%02dD.gz" % (
self.receiver, dt.timetuple().tm_yday, dt.year-2000)
self.hatanaka = True
return fname
def rinex6(self, dt): # "o", ending "gz"
fname = "%s%03d0.%02do.gz" % (
self.receiver, dt.timetuple().tm_yday, dt.year-2000)
self.hatanaka = False
return fname
def rinex7(self, dt): # "O", ending "gz"
fname = "%s%03d0.%02dO.gz" % (
self.receiver, dt.timetuple().tm_yday, dt.year-2000)
self.hatanaka = False
return fname
def antex(self):
return self.antex
def get_rinex(self, dt):
"""
Retrieve RINEX file using wget
dt is the datetime for the file we want
return filename (including path) of RINEX
this is usually in the form:
/stations/MYSTATION/rinex_filename.gz
"""
current_dir = os.getcwd()
ftp_tools.check_dir(current_dir+'/stations/') # create directory, if it doesn't exist
localdir = current_dir + '/stations/' + self.name + '/'
ftp_tools.check_dir(localdir)
localfile = localdir + self.rinex_filename(dt)
if os.path.isfile(localfile):
print(localfile, ' already exists, not downloading')
return localfile
else:
print('wget from ', self.ftp_server+self.ftp_dir+self.rinex_filename(dt))
return wget.download(self.ftp_server+self.ftp_dir+self.rinex_filename(dt), out=localdir)
def get_multiday_rinex(self, dtend, num_days=2):
"""
get multiple 24h RINEX files
splice them together with gfzrnx
dtend is the datetime of the last day
num_days is the number of days
return filename (including path) of spliced RINEX
"""
dtlist = [dtend - datetime.timedelta(days=n) for n in reversed(range(num_days))]
day_files = []
print(dtlist)
for day in dtlist:
day_files.append( self.get_rinex(day) )
print('splicing files: ' + str(day_files))
# we now have a list of zipped v2 or v3 files
# we do processing in a temp directory
current_dir = os.getcwd()
tempdir = current_dir + "/temp/"
ftp_tools.check_dir(tempdir)
# move files to the temp-directory
moved_files=[]
for f in day_files:
shutil.copy2(f, tempdir)
(tmp, fn) = os.path.split(f)
moved_files.append(tempdir + fn)
print(moved_files)
# now unzip the files
# unzip zipped files. this may include the RINEX, CLK, EPH files.
for f in moved_files:
if f[-1] == "Z" or f[-1] == "z": # compressed .z or .Z file
cmd = '/bin/gunzip'
cmd = cmd + " -f " + f # -f overwrites existing file
print("unzipping: ", cmd)
p = subprocess.Popen(cmd, shell=True)
p.communicate()
# figure out the unzipped rinex file name
unzipped_files =[]
#print("rinex= ", rinex)
for f in moved_files:
(tmp, rinexfile) = os.path.split(f)
inputfile = rinexfile[:-2] # strip off ".Z"
if inputfile[-1] == ".": # ends in a dot
inputfile = inputfile[:-1] # strip off
unzipped_files.append(inputfile)
print("unzipped files: ", str(unzipped_files))
# if files are Hatanaka compressed, uncompress
rnx_files=[]
for inputfile in unzipped_files:
if inputfile[-1] == "d" or inputfile[-1] == "D":
cmd = "CRX2RNX " + tempdir+inputfile
print("Hatanaka uncompress: ", cmd)
p = subprocess.Popen(cmd, shell=True)
p.communicate()
rnx_files.append( inputfile[:-1]+"O" ) # CRX2RNX changes ending to "O"
else:
rnx_files.append( inputfile )
print("rinex files to splice: ", len(rnx_files), " ", str(rnx_files))
# now splice files together
cmd = "gfzrnx -finp "
for f in rnx_files:
cmd += tempdir+f+" "
# kv option to keep rinex version of splice same as input files
# f option to overwrite output file, if it already exists
cmd += " -fout " + tempdir+"splice.rnx" + " -kv -f"
print("splice command: ",cmd)
p = subprocess.Popen(cmd, shell=True)
p.communicate()
# return the resulting spliced RINEX filename
return dtlist, tempdir+"splice.rnx", moved_files
########################################################################
# example stations
#
# these are from the varous ftp-servers, usually UTC-laboratories.
#
########################################################################
#bipm_server = '5.144.141.242'
# NOTE: as of 2021 BIPM does not make public RINEX files anymore!
# bipm_server = 'ftp2.bipm.org'
# bipm_username = 'labotai'
# bipm_password = 'dataTAI'
mikes_server = "monitor.mikes.fi"
anonymous_username = "anonymous"
anonymous_password = "ppp-tools"
# MI04, VTT MIKES timing receiver
mi04 = Station()
mi04.name = "MI04"
mi04.utctag = "MI04"
mi04.ftp_server = "https://monitor.mikes.fi/ftp"
mi04.ftp_username = anonymous_username
mi04.ftp_password = anonymous_password
mi04.ftp_dir = "/GNSS/MI04/RINEX/"
mi04.receiver = "MI04" # start of the RINEX filename
mi04.rinex_filename = mi04.rinex4 # naming style is MI040040.21D.Z
# MI05, VTT MIKES timing receiver, RINEX v2 files
# Information: https://monitor.mikes.fi/ftp/GNSS/MI05/MI05_info.txt
# RINEX v2 files: ftp://monitor.mikes.fi/GNSS/MI05/RINEX_v2_24h/
# Cal_ID: 1016-2019 https://webtai.bipm.org/ftp/pub/tai/publication/time-calibration/Current/1016-2019_GPSP3C1_MIKES_V1-0.pdf
mi05 = Station()
mi05.name = "MI05"
mi05.utctag = "MI05"
#mi05.ftp_server = mikes_server
mi05.ftp_server = "https://monitor.mikes.fi/ftp"
mi05.ftp_username = anonymous_username
mi05.ftp_password = anonymous_password
mi05.ftp_dir = "/GNSS/MI05/RINEX_v3_24h/"
mi05.receiver = "MI05" # start of the RINEX filename
mi05.rinex_filename = mi05.rinex6 # naming style is MI050020.21o.gz
mi05.ref_dly = 5.092 # ns
mi05.cab_dly = 96.2 # ns
mi05.int_dly_p1 = 20.17 # ns, see Cal_ID: 1016-2019
mi05.int_dly_p2 = 18.18 # ns
mi05.rinex3 = True
# MI02, VTT MIKES timing receiver, RINEX v2 files
mi02 = Station()
mi02.name = "MI02"
mi02.utctag = "MI02"
mi02.ftp_server = mikes_server
mi02.ftp_username = anonymous_username
mi02.ftp_password = anonymous_password
mi02.ftp_dir = "/GNSS/MI02/RINEX/"
mi02.receiver = "MI02" # start of the RINEX filename
mi02.rinex_filename = mi02.rinex1 # naming style is MI021690.21O.Z
# MI06, VTT MIKES timing receiver, RINEX v3 files
# https://monitor.mikes.fi/ftp/GNSS/MI06/
mi06 = Station()
mi06.name = "MI06"
mi06.utctag = "MI06"
#mi06.ftp_server = mikes_server
mi06.ftp_server = "https://monitor.mikes.fi/ftp"
mi06.ftp_username = anonymous_username
mi06.ftp_password = anonymous_password
mi06.ftp_dir = "/GNSS/MI06/"
mi06.receiver = "MI06" # start of the RINEX filename
mi06.rinex_filename = mi06.rinex6 # naming style is .o.gz
mi06.rinex3 = True
mi06.ref_dly = 10.348 # ns
mi06.cab_dly = 95.715 # ns (label on cable)
mi06.int_dly_p1 = 20.17+1.7 # ns, MI05 Cal_ID: 1016-2019 - this applies for MI06 also?
mi06.int_dly_p2 = 18.18+1.7 # ns, NOTE 1.7ns added to make MI05 - MI06 results match
# MI06 tests with local files (not on FTP-site)
mi06local = Station() # using local files, not on ftp-server
mi06local.name = "MI06local"
mi06local.utctag = "MI06local"
#mi06.ftp_server = mikes_server
#mi06.ftp_username = anonymous_username
#mi06.ftp_password = anonymous_password
#mi06.ftp_dir = "/GNSS/MI06/RINEX_v3_24h/"
mi06local.receiver = "MI06" # start of the RINEX filename
mi06local.rinex_filename = mi06.rinex6 # naming style is .o.gz
mi06local.rinex3 = True # RINEX v3
mi06local.ref_dly = 10.348 # ns
mi06local.cab_dly = 95.715 # ns
mi06local.int_dly_p1 = 20.17+1.7 # ns
mi06local.int_dly_p2 = 18.18+1.7 # ns
# PTB, see ftp.ptb.de
# ftp://ftp.ptb.de/pub/time/GNSS/GNSS_readme_20200129.pdf
ptb_server = "ftp.ptb.de"
ptbb = Station()
ptbb.name = "PTBB" # PolaRx5_TR
ptbb.utctag = "pt13"
ptbb.ftp_server = ptb_server
ptbb.ftp_username = anonymous_username
ptbb.ftp_password = anonymous_password
ptbb.ftp_dir = "pub/time/GNSS/PT13/RINEX3/"
ptbb.refdelay = 335.6+132.0
ptbb.receiver = "PTBB"
ptbb.rinex_filename = ptbb.rinex7 # PTBB0880.21O.gz
ptbb.rinex3 = True
# PT10, Dicom/Mesit receiver
pt09 = Station()
pt09.name = "PT09" # mesit/Dicom
pt09.utctag = "PT09"
pt09.receiver = "PT09" # start of the RINEX filename
pt09.rinex_filename = pt09.rinex7 # naming style is "O", ending "gz"
pt09.rinex3 = True
########################################################################
if __name__ == "__main__":
# an example of how to retrieve a RINEX file
dt = datetime.datetime.utcnow() - datetime.timedelta(days=5) # some days back from now
print(mi05.get_rinex(dt))
print(mi04.get_multiday_rinex(dt, 2))