-
Notifications
You must be signed in to change notification settings - Fork 27
/
test_clk.py
169 lines (133 loc) · 4.54 KB
/
test_clk.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
"""Tests for Clk data loader.
"""
__authors__ = "Sriramya Bhamidipati"
__date__ = "25 August 2022"
import os
import random
import pytest
import numpy as np
from gnss_lib_py.parsers.clk import Clk
import gnss_lib_py.utils.constants as consts
# Define the no. of samples to test functions:test_gps_sp3_funcs,
# test_gps_clk_funcs, test_glonass_sp3_funcs, test_glonass_clk_funcs
NUMSAMPLES = 4
# Define the keys relevant for satellite information
SV_KEYS = ['x_sv_m', 'y_sv_m', 'z_sv_m', \
'vx_sv_mps','vy_sv_mps','vz_sv_mps', \
'b_sv_m', 'b_dot_sv_mps']
@pytest.fixture(name="clk_path")
def fixture_clk_path(root_path):
"""Filepath of valid .clk measurements
Parameters
----------
root_path : string
Folder location containing measurements
Returns
-------
clk_path : string
String with location for the unit_test clk measurements
Notes
-----
Downloaded the relevant .clk files from either CORS website [1]_ or
CDDIS website [2]_
References
----------
.. [1] https://geodesy.noaa.gov/UFCORS/ Accessed as of August 2, 2022
.. [2] https://cddis.nasa.gov/Data_and_Derived_Products/GNSS/gnss_mgex.html
Accessed as of August 2, 2022
"""
clk_path = os.path.join(root_path, 'clk/grg21553.clk')
return clk_path
@pytest.fixture(name="clkdata")
def fixture_load_clkdata(clk_path):
"""Load instance of clk data.
Parameters
----------
clk_path : pytest.fixture
String with location for the unit_test clk measurements
Returns
-------
clkdata : list
Instances of Clk class for each satellite
"""
clkdata = Clk(clk_path)
return clkdata
@pytest.fixture(name="clk_path_missing")
def fixture_clk_path_missing(root_path):
"""Filepath of invalid/missing .clk measurements
Parameters
----------
root_path : string
Folder location containing measurements
Returns
-------
clk_path_missing : string
String with location for the unit_test clk measurements
"""
clk_path_missing = os.path.join(root_path, 'clk/grg21553_missing.clk')
return clk_path_missing
def test_load_clkdata_missing(clk_path_missing):
"""Load instance of clk for GPS constellation from missing file
Parameters
----------
clk_path_missing : pytest.fixture
String with invalid location for unit_test clk
measurements
"""
# Create a sp3 class for each expected satellite
with pytest.raises(FileNotFoundError):
Clk(clk_path_missing)
# raises exception if input not string or path-like
with pytest.raises(TypeError):
Clk([1])
@pytest.fixture(name="clk_path_nodata")
def fixture_clk_path_nodata(root_path):
"""Filepath for .clk measurements with no data
Parameters
----------
root_path : string
Folder location containing measurements
Returns
-------
clk_path_nodata : string
String with location for the empty clk measurements
"""
clk_path_nodata = os.path.join(root_path, 'clk/grg21553_nodata.clk')
return clk_path_nodata
def test_load_clkdata_nodata(clk_path_nodata):
"""Load clk instance from file with no data
Parameters
----------
clk_path_nodata : pytest.fixture
String with no available data for unit_test clk
measurements
"""
clkdata_nodata = Clk(clk_path_nodata)
assert len(clkdata_nodata) == 0
@pytest.mark.parametrize('row_name, prn, index, exp_value',
[('b_sv_m', 'G15', 0, -0.00015303409205*consts.C),
('gps_millis', 'G05', 5, 1303668150000.0),
('b_sv_m', 'R08', 16, -5.87550990462e-05*consts.C),
('gps_millis', 'R14', 10, 1303668300000.0),
]
)
def test_clkgps_value_check(clkdata, prn, row_name, index, exp_value):
"""Check Clk array entries of GPS constellation against
known/expected values using test matrix
Parameters
----------
clkdata : gnss_lib_py.parsers.clk.Clk
CLK data.
prn : int
Satellite PRN for test example
row_name : string
Row key for test example
index : int
Index to query data at
exp_value : float/datetime
Expected value at queried indices
"""
assert len(np.unique(clkdata.where("gnss_id","gps")["sv_id"])) == 31
assert len(np.unique(clkdata.where("gnss_id","glonass")["sv_id"])) == 20
curr_value = clkdata.where("gnss_sv_id",prn)[row_name][index]
np.testing.assert_equal(curr_value, exp_value)