forked from icsm-au/datum-modernisation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sinex.py
154 lines (139 loc) · 4.72 KB
/
sinex.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
#!/usr/bin/env python3
from numpy import zeros
import sys
def rd_snx_est(file):
"""This function reads in the SOLUTION/ESTIMATE block of a SINEX file. It
returns estimate, a list of tuples:
estimate = [(code, soln, refEpoch, staX, staY, staZ, staX_sd, staY_sd,
staZ_sd [, velX, velY, velZ, velX_sd, velY_sd, velZ_sd])...]
where:
* code is the stations's 4-character ID
* soln is the segment of the stations's time series
* refEpoch is the epoch of the solution in the form YY:DOY:SSSSS (YY
is the two digit year, DOY is day of year, and SSSSS is the time of
day in seconds
* sta[XYZ] is the station coordinates in the Cartesian reference frame
* sta[XYZ]_sd
* vel[XYZ] is the station velocity in the Cartesian reference frame
* vel[XYZ]_sd
Velocities are not included in all SINEX files and so are only returned if
present.
:param file: the input SINEX file
:return: estimate
"""
# Create data structures and set variables
lines = []
estimate = []
check_types = True
velocities = False
go = False
code = ''
soln = ''
epoch = ''
stax = ''
stay = ''
staz = ''
stax_sd = ''
stay_sd = ''
staz_sd = ''
velx = ''
vely = ''
velz = ''
velx_sd = ''
vely_sd = ''
velz_sd = ''
# Read the SOLUTION/ESTIMATE block into a list and determine if there is
# any velocity information
with open(file) as f:
for line in f:
if line[:18] == '-SOLUTION/ESTIMATE':
break
if go and line[:11] == '*INDEX TYPE':
pass
elif go:
if check_types:
if line[7:10] == 'VEL':
velocities = True
check_types = False
lines.append(line)
if line[:18] == '+SOLUTION/ESTIMATE':
go = True
if velocities:
for line in lines:
typ = line[7:11]
if typ == 'STAX':
code = line[14:18]
soln = line[23:26].lstrip()
epoch = line[27:39]
stax = float(line[47:68])
stax_sd = float(line[69:80])
elif typ == 'STAY':
stay = float(line[47:68])
stay_sd = float(line[69:80])
elif typ == 'STAZ':
staz = float(line[47:68])
staz_sd = float(line[69:80])
elif typ == 'VELX':
velx = float(line[47:68])
velx_sd = float(line[69:80])
elif typ == 'VELY':
vely = float(line[47:68])
vely_sd = float(line[69:80])
elif typ == 'VELZ':
velz = float(line[47:68])
velz_sd = float(line[69:80])
info = (code, soln, epoch, stax, stay, staz, stax_sd,
stay_sd, staz_sd, velx, vely, velz, velx_sd,
vely_sd, velz_sd)
estimate.append(info)
else:
for line in lines:
typ = line[7:11]
if typ == 'STAX':
code = line[14:18]
soln = line[23:26].lstrip()
epoch = line[27:39]
stax = float(line[47:68])
stax_sd = float(line[69:80])
elif typ == 'STAY':
stay = float(line[47:68])
stay_sd = float(line[69:80])
elif typ == 'STAZ':
staz = float(line[47:68])
staz_sd = float(line[69:80])
info = (code, soln, epoch, stax, stay, staz, stax_sd,
stay_sd, staz_sd)
estimate.append(info)
return estimate
def rd_snx_mat(file):
# Read in the codes (station names) and solutions, and check for velocities
data = rd_snx_est(file)
code_solns = []
for stat in data:
code_solns.append((stat[0], stat[1]))
if len(data[0]) == 15:
velocities = True
# Read the SOLUTION/MATRIX_ESTIMATE block into a list and determine if the
# matrix is upper or lower triangular
lines = []
go = False
with open(file) as f:
for line in f:
if line[:25] == '-SOLUTION/MATRIX_ESTIMATE':
break
if go and line[:12] == '*PARA1 PARA2':
pass
elif go:
lines.append(line)
if line[:25] == '+SOLUTION/MATRIX_ESTIMATE':
low_up = line[26]
go = True
# Create the VCV matrix
if velocities:
n = 6 * int(len(code_solns))
else:
n = 3 * int(len(code_solns))
vcv = zeros((n, n))
for line in lines:
print(line)
return code_solns