-
Notifications
You must be signed in to change notification settings - Fork 27
/
test_rinex_nav.py
222 lines (170 loc) · 6.52 KB
/
test_rinex_nav.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
"""Tests for the ephemeris class that returns satellite ephemerides.
"""
__authors__ = "Ashwin Kanhere"
__date__ = "30 Aug 2022"
import os
from datetime import datetime, timezone
import pytest
import numpy as np
from gnss_lib_py.navdata.navdata import NavData
from gnss_lib_py.parsers.rinex_nav import RinexNav, get_time_cropped_rinex
from gnss_lib_py.utils.time_conversions import gps_millis_to_tow
from gnss_lib_py.utils.time_conversions import datetime_to_gps_millis
@pytest.fixture(name="ephem_path", scope='session')
def fixture_ephem_path():
"""Location of ephemeris files for unit test
Returns
-------
ephem_path : string
Location where ephemeris files are stored/to be downloaded.
"""
root_path = os.path.dirname(
os.path.dirname(
os.path.dirname(
os.path.realpath(__file__))))
ephem_path = os.path.join(root_path, 'data/unit_test')
return ephem_path
def test_rinex_nav_init(ephem_path):
"""Test across multiple files.
Parameters
----------
ephem_path : string
Location where ephemeris files are stored/to be downloaded.
"""
no_iono = [
"BRDM00DLR_R_20130010000_01D_MN.rnx",
"VOIM00MDG_R_20140010000_01D_MN.rnx",
"BRDC00WRD_S_20230730000_01D_MN.rnx",
"WTZS00DEU_R_20230800000_01D_MN.rnx",
]
rinex_nav_dir = os.path.join(ephem_path,"rinex","nav")
rinex_paths = []
for file in os.listdir(rinex_nav_dir):
rinex_path = os.path.join(rinex_nav_dir,file)
rinex_paths.append(rinex_path)
if file in no_iono:
# no iono
with pytest.warns(RuntimeWarning) as warns:
RinexNav(rinex_path)
assert len(warns) == 1
else:
RinexNav(rinex_path)
def test_rinex_nav_init_multi(ephem_path):
"""Test across multiple files.
Parameters
----------
ephem_path : string
Location where ephemeris files are stored/to be downloaded.
"""
files = [
"brdc1360.20n",
"brdc1370.20n",
"brdc1370.20g",
]
rinex_nav_dir = os.path.join(ephem_path,"rinex","nav")
rinex_paths = []
for file in files:
rinex_path = os.path.join(rinex_nav_dir,file)
rinex_paths.append(rinex_path)
RinexNav(rinex_paths)
@pytest.mark.parametrize('satellites',
[
['G02'],
['R01'],
])
@pytest.mark.parametrize('ephem_time',
[
datetime(2020, 5, 16, 11, 47, 48, tzinfo=timezone.utc),
])
def test_get_time_cropped_rinex(ephem_path, ephem_time, satellites):
"""Create instance of Ephemeris manager and fetch ephemeris file.
Check type and rows.
Parameters
----------
ephem_path : string
Location where ephemeris files are stored/to be downloaded to.
ephem_time : datetime.datetime
Time at which state estimation is starting, the most recent ephemeris
file before the start time will be fetched.
satellites : List
List of satellites ['Const_IDSVID']
"""
ephem_time = datetime_to_gps_millis(ephem_time)
ephem = get_time_cropped_rinex(ephem_time, satellites, ephem_path,
verbose=True)
# Test that ephem is of type gnss_lib_py.navdata.navdata.NavData
assert isinstance(ephem, NavData)
# check that there's one row per satellite
assert len(ephem) == len(satellites)
# time check for GPS and Galileo
if "gps_week" in ephem.rows:
for timestep in range(len(ephem)):
if not np.isnan(ephem["gps_week",timestep]):
gps_week, _ = gps_millis_to_tow(ephem["gps_millis",timestep])
assert gps_week == ephem["gps_week",timestep]
# Tests that NavData specific rows are present in ephem
navdata_rows = ['gps_millis', 'sv_id', 'gnss_id']
ephem.in_rows(navdata_rows)
@pytest.mark.parametrize('satellites',
[
['G99'],
])
@pytest.mark.parametrize('ephem_time',
[
datetime(2020, 5, 15, 3, 47, 48, tzinfo=timezone.utc),
])
def test_get_ephem_fails(ephem_path, ephem_time, satellites):
"""Test when ephemeris manager should fail.
Check type and rows.
Parameters
----------
ephem_path : string
Location where ephemeris files are stored/to be downloaded to.
ephem_time : datetime.datetime
Time at which state estimation is starting, the most recent ephemeris
file before the start time will be fetched.
satellites : List
List of satellites ['Const_IDSVID']
"""
ephem_time = datetime_to_gps_millis(ephem_time)
with pytest.raises(RuntimeError) as excinfo:
get_time_cropped_rinex(ephem_time, satellites, ephem_path)
assert "ephemeris data" in str(excinfo.value)
def test_load_leapseconds(ephem_path):
"""Test load leapseconds.
Parameters
----------
ephem_path : string
Location where ephemeris files are stored/to be downloaded to.
"""
rinex_path = os.path.join(ephem_path,"rinex","nav",
"brdc1370.20n")
rinex_data = RinexNav(rinex_path)
np.testing.assert_array_equal(rinex_data['leap_seconds'],
np.array([18]*6))
# check what happens when a file with an incomplete header is passed
none_path = os.path.join(ephem_path,"rinex","nav",
"brdc1370_no_leapseconds.20n")
rinex_data = RinexNav(none_path)
assert len(rinex_data.where('leap_seconds',np.nan)) == 1
def test_no_iono_params(ephem_path):
"""Test no iono params.
Parameters
----------
ephem_path : string
Location where ephemeris files are stored/to be downloaded to.
"""
rinex_path = os.path.join(ephem_path,"rinex","nav",
"BRDM00DLR_S_20230730000_01D_MN_no_gps_iono.rnx")
RinexNav(rinex_path)
def test_nan_removal(ephem_path):
"""Test that NaN values are being removed appropriately.
Parameters
----------
ephem_path : string
Location where ephemeris files are stored/to be downloaded to.
"""
rinex_path = os.path.join(ephem_path,"rinex","nav",
"brdc0730.17n")
rinex_data = RinexNav(rinex_path)
assert rinex_data.shape == (36,4)