Skip to content

Commit 352f0f4

Browse files
committed
unified conftest for all modules
1 parent 9444c8a commit 352f0f4

23 files changed

Lines changed: 537 additions & 1321 deletions

docs/source/reference/test_navdata/conftest.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/source/reference/test_navdata/modules.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ navdata
44
.. toctree::
55
:maxdepth: 4
66

7-
conftest
87
test_navdata
98
test_operations

docs/source/reference/test_utils/conftest.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/source/reference/test_utils/modules.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ utils
44
.. toctree::
55
:maxdepth: 4
66

7-
conftest
87
test_coordinates
98
test_dop
109
test_ephemeris_downloader

docs/source/reference/test_visualizations/conftest.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/source/reference/test_visualizations/modules.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ visualizations
44
.. toctree::
55
:maxdepth: 4
66

7-
conftest
87
test_plot_map
98
test_plot_metric
109
test_plot_skyplot

tests/algorithms/test_fde.py

Lines changed: 12 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -11,113 +11,43 @@
1111
import numpy as np
1212

1313
from gnss_lib_py.navdata.navdata import NavData
14-
from gnss_lib_py.parsers.google_decimeter import AndroidDerived2022
1514
from gnss_lib_py.algorithms.fde import solve_fde, evaluate_fde
1615

17-
@pytest.fixture(name="root_path_2022")
18-
def fixture_root_path_2022():
19-
"""Location of measurements for unit test.
20-
21-
Returns
22-
-------
23-
root_path_2022 : string
24-
Folder location containing measurements.
25-
26-
"""
27-
root_path = os.path.dirname(
28-
os.path.dirname(
29-
os.path.dirname(
30-
os.path.realpath(__file__))))
31-
root_path_2022 = os.path.join(root_path, 'data','unit_test','google_decimeter_2022')
32-
return root_path_2022
33-
34-
@pytest.fixture(name="derived_2022_path")
35-
def fixture_derived_2022_path(root_path_2022):
36-
"""Filepath of Android Derived measurements.
37-
38-
Parameters
39-
----------
40-
root_path_2022 : string
41-
Folder location containing measurements.
42-
43-
Returns
44-
-------
45-
derived_2022_path : string
46-
Location for the unit_test Android derived 2022 measurements.
47-
48-
Notes
49-
-----
50-
Test data is a subset of the Android Raw Measurement Dataset [1]_,
51-
from the 2022 Decimeter Challenge. Particularly, the
52-
train/2021-04-29-MTV-2/SamsungGalaxyS20Ultra trace. The dataset
53-
was retrieved from
54-
https://www.kaggle.com/competitions/smartphone-decimeter-2022/data
55-
56-
References
57-
----------
58-
.. [1] Fu, Guoyu Michael, Mohammed Khider, and Frank van Diggelen.
59-
"Android Raw GNSS Measurement Datasets for Precise Positioning."
60-
Proceedings of the 33rd International Technical Meeting of the
61-
Satellite Division of The Institute of Navigation (ION GNSS+
62-
2020). 2020.
63-
64-
"""
65-
derived_2022_path = os.path.join(root_path_2022, 'device_gnss.csv')
66-
return derived_2022_path
67-
68-
@pytest.fixture(name="derived")
69-
def fixture_load_derived(derived_2022_path):
70-
"""Load instance of AndroidDerived2022.
71-
72-
Parameters
73-
----------
74-
derived_2022_path : pytest.fixture
75-
String with location of Android derived measurement file.
76-
77-
Returns
78-
-------
79-
derived : AndroidDerived2022
80-
Instance of AndroidDerived2022 for testing.
81-
82-
"""
83-
derived = AndroidDerived2022(derived_2022_path)
84-
return derived
85-
8616
@pytest.mark.parametrize('method',
8717
[
8818
"residual",
8919
"edm",
9020
])
91-
def test_solve_fde(derived, method):
21+
def test_solve_fde(derived_2022, method):
9222
"""Test residual-based FDE.
9323
9424
Parameters
9525
----------
96-
derived : AndroidDerived2022
26+
derived_2022 : AndroidDerived2022
9727
Instance of AndroidDerived2022 for testing.
9828
method : string
9929
Method for fault detection and exclusion.
10030
10131
"""
10232

10333
# test without removing outliers
104-
navdata = derived.copy()
34+
navdata = derived_2022.copy()
10535
navdata = solve_fde(navdata, method=method)
10636
assert "fault_" + method in navdata.rows
10737

10838
# max thresholds shouldn't remove any
109-
navdata = derived.copy()
39+
navdata = derived_2022.copy()
11040
navdata = solve_fde(navdata, threshold=np.inf, method=method)
11141
assert sum(navdata.where("fault_" + method,1)["fault_" + method]) == 0
11242

11343
# min threshold should remove most all
114-
navdata = derived.copy()
44+
navdata = derived_2022.copy()
11545
navdata = solve_fde(navdata, threshold=-np.inf, method=method)
11646
print(sum(navdata.where("fault_" + method,1)["fault_" + method]))
11747
assert len(navdata.where("fault_" + method,0)) == 24
11848
num_unknown = len(navdata.where("fault_" + method,2))
11949

120-
navdata = derived.copy()
50+
navdata = derived_2022.copy()
12151
original_length = len(navdata)
12252
navdata = solve_fde(navdata,
12353
threshold=-np.inf,
@@ -130,38 +60,38 @@ def test_solve_fde(derived, method):
13060
np.array([0]))
13161
assert len(navdata) == original_length - num_unknown - 6
13262

133-
def test_fde_fails(derived):
63+
def test_fde_fails(derived_2022):
13464
"""Test that solve_fde fails when it should.
13565
13666
Parameters
13767
----------
138-
derived : AndroidDerived2022
68+
derived_2022 : AndroidDerived2022
13969
Instance of AndroidDerived2022 for testing.
14070
14171
"""
14272

14373
with pytest.raises(ValueError) as excinfo:
144-
solve_fde(derived, method="perfect_method")
74+
solve_fde(derived_2022, method="perfect_method")
14575
assert "invalid method" in str(excinfo.value)
14676

14777
@pytest.mark.parametrize('method',
14878
[
14979
"residual",
15080
"edm",
15181
])
152-
def test_evaluate_fde(derived, method):
82+
def test_evaluate_fde(derived_2022, method):
15383
"""Evaluate FDE methods.
15484
15585
Parameters
15686
----------
157-
derived : AndroidDerived2022
87+
derived_2022 : AndroidDerived2022
15888
Instance of AndroidDerived2022 for testing.
15989
method : string
16090
Method for fault detection and exclusion.
16191
16292
"""
16393

164-
navdata = derived.copy()
94+
navdata = derived_2022.copy()
16595
evaluate_fde(navdata,
16696
method=method,
16797
fault_truth_row="MultipathIndicator",

tests/algorithms/test_gnss_filters.py

Lines changed: 8 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -98,78 +98,16 @@ def test_stationary_filter(init_dict, params_dict, motion_type):
9898
pos_ekf = gnss_ekf.state[:3]
9999
np.testing.assert_allclose(pos_ekf, init_dict['state_0'][:3], atol=0.1)
100100

101-
@pytest.fixture(name="root_path")
102-
def fixture_root_path():
103-
"""Location of measurements for unit test
104-
105-
Returns
106-
-------
107-
root_path : string
108-
Folder location containing measurements
109-
"""
110-
root_path = os.path.dirname(
111-
os.path.dirname(
112-
os.path.dirname(
113-
os.path.realpath(__file__))))
114-
root_path = os.path.join(root_path, 'data/unit_test/google_decimeter_2021/')
115-
return root_path
116-
117-
118-
@pytest.fixture(name="derived_path")
119-
def fixture_derived_path(root_path):
120-
"""Filepath of Android Derived measurements
121-
122-
Returns
123-
-------
124-
derived_path : string
125-
Location for the unit_test Android derived measurements
126-
127-
Notes
128-
-----
129-
Test data is a subset of the Android Raw Measurement Dataset [2]_,
130-
particularly the train/2020-05-14-US-MTV-1/Pixel4 trace. The dataset
131-
was retrieved from
132-
https://www.kaggle.com/c/google-smartphone-decimeter-challenge/data
133-
134-
References
135-
----------
136-
.. [2] Fu, Guoyu Michael, Mohammed Khider, and Frank van Diggelen.
137-
"Android Raw GNSS Measurement Datasets for Precise Positioning."
138-
Proceedings of the 33rd International Technical Meeting of the
139-
Satellite Division of The Institute of Navigation (ION GNSS+
140-
2020). 2020.
141-
"""
142-
derived_path = os.path.join(root_path, 'Pixel4_derived.csv')
143-
return derived_path
144-
145-
146-
@pytest.fixture(name="derived")
147-
def fixture_load_derived(derived_path):
148-
"""Load instance of AndroidDerived2021
149-
150-
Parameters
151-
----------
152-
derived_path : pytest.fixture
153-
String with location of Android derived measurement file
154-
155-
Returns
156-
-------
157-
derived : AndroidDerived2021
158-
Instance of AndroidDerived2021 for testing
159-
"""
160-
derived = AndroidDerived2021(derived_path)
161-
return derived
162-
163-
def test_solve_gnss_ekf(derived):
101+
def test_solve_gnss_ekf(derived_2021):
164102
"""Test that solving for GNSS EKF doesn't fail
165103
166104
Parameters
167105
----------
168-
derived : AndroidDerived2021
106+
derived_2021 : AndroidDerived2021
169107
Instance of AndroidDerived2021 for testing.
170108
171109
"""
172-
state_estimate = solve_gnss_ekf(derived)
110+
state_estimate = solve_gnss_ekf(derived_2021)
173111

174112
# result should be a NavData Class instance
175113
assert isinstance(state_estimate,type(NavData()))
@@ -191,29 +129,27 @@ def test_solve_gnss_ekf(derived):
191129
assert "alt_rx_ekf_m" in state_estimate.rows
192130

193131
# should have the same length as the number of unique timesteps
194-
assert len(state_estimate) == sum(1 for _ in loop_time(derived,"gps_millis"))
195-
196-
# len(np.unique(derived["gps_millis",:]))
132+
assert len(state_estimate) == sum(1 for _ in loop_time(derived_2021,"gps_millis"))
197133

198134
# test what happens when rows down't exist
199135
for row_index in ["gps_millis","x_sv_m","y_sv_m","z_sv_m","corr_pr_m"]:
200-
derived_no_row = derived.remove(rows=row_index)
136+
derived_no_row = derived_2021.remove(rows=row_index)
201137
with pytest.raises(KeyError) as excinfo:
202138
solve_gnss_ekf(derived_no_row)
203139
assert row_index in str(excinfo.value)
204140

205141

206-
def test_solve_gnss_ekf_fails(derived):
142+
def test_solve_gnss_ekf_fails(derived_2021):
207143
"""Test expected fails for the GNSS EKF.
208144
209145
Parameters
210146
----------
211-
derived : AndroidDerived2021
147+
derived_2021 : AndroidDerived2021
212148
Instance of AndroidDerived2021 for testing
213149
214150
"""
215151

216-
navdata = derived.remove(cols=list(range(len(derived))))
152+
navdata = derived_2021.remove(cols=list(range(len(derived_2021))))
217153

218154
with pytest.warns(RuntimeWarning) as warns:
219155
solve_gnss_ekf(navdata)

0 commit comments

Comments
 (0)