1515import copy
1616
1717from gnss_lib_py .navdata .navdata import NavData
18+ from gnss_lib_py .navdata .operations import loop_time
19+
1820from gnss_lib_py .utils .dop import \
19- get_dop , calculate_dop , _calculate_enut_matrix
21+ get_enu_dop_labels , get_dop , calculate_dop , \
22+ splat_dop_matrix , unsplat_dop_matrix , \
23+ _calculate_enut_matrix
2024
2125
2226#####################################################################
@@ -218,10 +222,7 @@ def test_simple_get_dop(navdata, expected_dop, which_dop):
218222
219223 if 'dop_matrix' in dop_navdata :
220224 # Handle the splatting of the DOP matrix
221- dop_labels = ['ee' , 'en' , 'eu' , 'et' ,
222- 'nn' , 'nu' , 'nt' ,
223- 'uu' , 'ut' ,
224- 'tt' ]
225+ dop_labels = get_enu_dop_labels ()
225226
226227 for label in dop_labels :
227228 assert f"dop_{ label } " in dop_navdata .rows
@@ -235,7 +236,61 @@ def test_simple_get_dop(navdata, expected_dop, which_dop):
235236 dop_navdata [f"dop_{ dop_labels [ind ]} " ],
236237 expected_dop ['dop_matrix' ][r , c ])
237238 ind += 1
238-
239+
240+
241+ @pytest .mark .parametrize ('navdata, expected_dop' ,
242+ [
243+ (lazy_fixture ('simple_sat_scenario' ),
244+ lazy_fixture ('simple_sat_expected_dop' ))
245+ ])
246+ def test_splat_dop_matrix (navdata , expected_dop ):
247+ """
248+ Test that the splat_dop_matrix function works correctly.
249+ """
250+ # Perform the function under test
251+ dop_matrix = calculate_dop (navdata )['dop_matrix' ]
252+ dop_matrix_splat = splat_dop_matrix (dop_matrix )
253+
254+ # Check the splatting is correct
255+ # edopmat is 'expected dop matrix'
256+ edopmat = expected_dop ['dop_matrix' ]
257+ expected_dop_matrix_splat = np .array (
258+ [
259+ edopmat [0 , 0 ], edopmat [0 , 1 ], edopmat [0 , 2 ], edopmat [0 , 3 ],
260+ edopmat [1 , 1 ], edopmat [1 , 2 ], edopmat [1 , 3 ],
261+ edopmat [2 , 2 ], edopmat [2 , 3 ],
262+ edopmat [3 , 3 ]
263+ ])
264+
265+ np .testing .assert_array_almost_equal (
266+ dop_matrix_splat , expected_dop_matrix_splat )
267+
268+
269+ @pytest .mark .parametrize ('navdata, expected_dop' ,
270+ [
271+ (lazy_fixture ('simple_sat_scenario' ),
272+ lazy_fixture ('simple_sat_expected_dop' ))
273+ ])
274+ def test_unsplat_dop_matrix (navdata , expected_dop ):
275+ """
276+ Test that the unsplat_dop_matrix function works correctly.
277+ """
278+ # Perform the function under test
279+ dop_matrix = calculate_dop (navdata )['dop_matrix' ]
280+ dop_matrix_splat = splat_dop_matrix (dop_matrix )
281+ dop_matrix_unsplat = unsplat_dop_matrix (dop_matrix_splat )
282+
283+ # Check that the unsplatted matrix is symmetric
284+ np .testing .assert_array_almost_equal (
285+ dop_matrix_unsplat .T , dop_matrix_unsplat )
286+
287+ # Check the unsplatting values are correct
288+ np .testing .assert_array_almost_equal (
289+ dop_matrix_unsplat , expected_dop ['dop_matrix' ])
290+ np .testing .assert_array_almost_equal (
291+ dop_matrix_unsplat , dop_matrix )
292+
293+
239294#############################################
240295# Singularity issues and edge cases
241296
@@ -371,10 +426,7 @@ def test_dop_across_time_with_selection(navdata, which_dop):
371426
372427 if 'dop_matrix' in dop_navdata :
373428 # Handle the splatting of the DOP matrix
374- dop_labels = ['ee' , 'en' , 'eu' , 'et' ,
375- 'nn' , 'nu' , 'nt' ,
376- 'uu' , 'ut' ,
377- 'tt' ]
429+ dop_labels = get_enu_dop_labels ()
378430
379431 for label in dop_labels :
380432 assert f"dop_{ label } " in dop_navdata .rows
@@ -406,3 +458,41 @@ def test_dop_across_time_with_selection(navdata, which_dop):
406458 dop_navdata ['TDOP' ],
407459 np .sqrt (dop_navdata ['dop_tt' ]))
408460
461+
462+ @pytest .mark .parametrize ('navdata' ,
463+ [
464+ lazy_fixture ('android_derived' )
465+ ])
466+ def test_splat_unsplat_dop_matrix_across_time (navdata ):
467+ """
468+ Test that we can splat and unsplat the DOP matrix across time.
469+ """
470+
471+ # Run through the data, calculate the DOP, and store as navdata
472+ dop_navdata = get_dop (navdata , dop_matrix = True )
473+
474+ # Check we have the dop_matrix entries
475+ dop_labels = get_enu_dop_labels ()
476+
477+ for label in dop_labels :
478+ assert f"dop_{ label } " in dop_navdata .rows
479+
480+ for _ , _ , dop_navdata_subset in loop_time (dop_navdata , 'gps_millis' ):
481+ # Extract the dop matrix
482+ dop_matrix_splat = np .array ([dop_navdata_subset [f"dop_{ label } " ]
483+ for label in dop_labels ])
484+
485+ # Unsplat the DOP matrix
486+ dop_matrix_unsplat = unsplat_dop_matrix (dop_matrix_splat )
487+
488+ # Check that the unsplatted matrix is symmetric
489+ np .testing .assert_array_almost_equal (
490+ dop_matrix_unsplat .T , dop_matrix_unsplat )
491+
492+ # Resplat the DOP matrix
493+ dop_matrix_resplat = splat_dop_matrix (dop_matrix_unsplat )
494+
495+ # Check the unsplatting is correct
496+ np .testing .assert_array_almost_equal (
497+ dop_matrix_splat , dop_matrix_resplat )
498+
0 commit comments