|
16 | 16 | from gnss_lib_py.utils.coordinates import ecef_to_el_az, add_el_az |
17 | 17 | from gnss_lib_py.utils.coordinates import geodetic_to_ecef |
18 | 18 | from gnss_lib_py.utils.coordinates import ecef_to_geodetic, LocalCoord |
| 19 | +from gnss_lib_py.utils.coordinates import wrap_0_to_2pi |
19 | 20 |
|
20 | 21 |
|
21 | 22 | @pytest.fixture(name="local_ecef") |
@@ -424,3 +425,35 @@ def test_add_el_az(navdata): |
424 | 425 | navdata["el_sv_deg"]) |
425 | 426 | np.testing.assert_array_almost_equal(data_el_az["az_sv_deg"], |
426 | 427 | navdata["az_sv_deg"]) |
| 428 | + |
| 429 | + |
| 430 | +def test_wrap_0_to_2pi(): |
| 431 | + """Test wrapping. |
| 432 | +
|
| 433 | + """ |
| 434 | + # nothing should change |
| 435 | + angles_in = np.linspace(0,7*np.pi/4.,8) |
| 436 | + angles_out = np.linspace(0,7*np.pi/4.,8) |
| 437 | + np.testing.assert_array_equal(wrap_0_to_2pi(angles_in),angles_out) |
| 438 | + |
| 439 | + # test greater than loop |
| 440 | + angles_in = np.linspace(0,7*np.pi/4.,8) + 16*np.pi |
| 441 | + angles_out = np.linspace(0,7*np.pi/4.,8) |
| 442 | + np.testing.assert_array_almost_equal(wrap_0_to_2pi(angles_in),angles_out) |
| 443 | + |
| 444 | + # test greater than loop |
| 445 | + angles_in = np.linspace(0,7*np.pi/4.,8) - 12*np.pi |
| 446 | + angles_out = np.linspace(0,7*np.pi/4.,8) |
| 447 | + np.testing.assert_array_almost_equal(wrap_0_to_2pi(angles_in),angles_out) |
| 448 | + |
| 449 | + # test positive offset loop |
| 450 | + angles_in = np.linspace(0,7*np.pi/4.,8) + 7*np.pi |
| 451 | + angles_out = np.concatenate((np.linspace(np.pi,7*np.pi/4.,4), |
| 452 | + np.linspace(0,3*np.pi/4.,4))) |
| 453 | + np.testing.assert_array_almost_equal(wrap_0_to_2pi(angles_in),angles_out) |
| 454 | + |
| 455 | + # test positive offset loop |
| 456 | + angles_in = np.linspace(0,7*np.pi/4.,8) - 11*np.pi |
| 457 | + angles_out = np.concatenate((np.linspace(np.pi,7*np.pi/4.,4), |
| 458 | + np.linspace(0,3*np.pi/4.,4))) |
| 459 | + np.testing.assert_array_almost_equal(wrap_0_to_2pi(angles_in),angles_out) |
0 commit comments