Skip to content

Commit 986e313

Browse files
committed
tests
1 parent 2924787 commit 986e313

6 files changed

Lines changed: 47 additions & 6 deletions

File tree

src/smsfusion/_ins/_common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _dhda_head(q: NDArray[np.float64]) -> NDArray[np.float64]:
4444
return dhda # type: ignore[no-any-return]
4545

4646

47-
@njit
47+
@njit # type: ignore[misc]
4848
def _h_head(q: NDArray[np.float64]) -> float:
4949
"""
5050
Compute yaw angle from unit quaternion.
@@ -73,7 +73,7 @@ def _h_head(q: NDArray[np.float64]) -> float:
7373
return np.arctan2(u_y, u_x) # type: ignore[no-any-return]
7474

7575

76-
@njit
76+
@njit # type: ignore[misc]
7777
def _signed_smallest_angle(angle: float, degrees: bool = True) -> float:
7878
"""
7979
Convert the given angle to the smallest angle between [-180., 180) degrees.
@@ -324,6 +324,7 @@ def _project_covariance_ahead(
324324
return P
325325

326326

327+
@njit # type: ignore[misc]
327328
def _nz2vg(nav_frame: str) -> float:
328329
"""
329330
Gravity direction along the navigation frame's z-axis. Transforms the z-axis

src/smsfusion/_ins/_vru.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
)
2727

2828

29+
@njit # type: ignore[misc]
2930
def _state_transition_matrix_init(
3031
dt: float,
3132
dtheta: NDArray[np.float64],
@@ -82,6 +83,7 @@ def _state_transition_matrix_update(
8283
return phi
8384

8485

86+
@njit # type: ignore[misc]
8587
def _process_noise_covariance_matrix(
8688
dt: float, arw: float, gbs: float, gbc: float
8789
) -> NDArray[np.float64]:
@@ -110,6 +112,7 @@ def _process_noise_covariance_matrix(
110112
return Q
111113

112114

115+
@njit # type: ignore[misc]
113116
def _measurement_matrix_init() -> NDArray[np.float64]:
114117
"""
115118
Measurement matrix.

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import os
2+
os.environ["NUMBA_DISABLE_JIT"] = "1"

tests/test_ins_/test_common.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,28 @@ def test__update_quaternion_with_gibbs2(quaternion, da, quaternion_update_expect
194194
np.testing.assert_allclose(
195195
quaternion_update, quaternion_update_expected, atol=1e-10
196196
)
197+
198+
199+
@pytest.mark.parametrize(
200+
"q_nb,nav_frame_factor",
201+
[
202+
(np.array([1.0, 0.0, 0.0, 0.0]), 1.0),
203+
(np.array([1.0, 0.0, 0.0, 0.0]), -1.0),
204+
(np.array([np.cos(0.1/2), np.sin(0.1/2), 0.0, 0.0]), -1.0),
205+
(np.array([np.cos(0.1/2), np.sin(0.1/2), 0.0, 0.0]), 1.0),
206+
(np.array([np.cos(0.1/2), 0.0, np.sin(0.1/2), 0.0]), -1.0),
207+
(np.array([np.cos(0.1/2), 0.0, np.sin(0.1/2), 0.0]), 1.0),
208+
(np.array([np.cos(0.1/2), 0.0, 0.0, np.sin(0.1/2)]), -1.0),
209+
(np.array([np.cos(0.1/2), 0.0, 0.0, np.sin(0.1/2)]), 1.0)
210+
]
211+
)
212+
def test__nz_b_from_quat(q_nb, nav_frame_factor):
213+
out = _common._nz_b_from_quat(q_nb, nav_frame_factor=nav_frame_factor)
214+
215+
expect = Rotation.from_quat(q_nb, scalar_first=True).apply(nav_frame_factor * np.array([0.0, 0.0, 1.0]), inverse=True)
216+
np.testing.assert_allclose(out, expect)
217+
218+
219+
def test__nz2vg():
220+
assert _common._nz2vg("NED") == 1.0
221+
assert _common._nz2vg("ENU") == -1.0

tests/test_ins_/test_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def test_euler_from_acc(euler):
3939
euler_enu = _utils.euler_from_acc(acc_enu, nav_frame="ENU", yaw=euler[2], degrees=True)
4040
np.testing.assert_allclose(euler_enu, euler_degrees)
4141

42+
def test_euler_from_acc_invalid_frame():
43+
44+
acc_ned = np.array([0.0, 0.0, 1])
45+
with pytest.raises(ValueError):
46+
_utils.euler_from_acc(acc_ned, nav_frame="STAR")
47+
4248

4349
@pytest.mark.parametrize(
4450
"mu, g_expect",

tests/test_ins_/test_vru.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ def test_vru_methods():
122122

123123

124124
@pytest.mark.parametrize(
125-
"benchmark_gen",
126-
[benchmark_pure_attitude_beat_202311A, benchmark_pure_attitude_chirp_202311A],
125+
"benchmark_gen, degrees",
126+
[(benchmark_pure_attitude_beat_202311A, False), (benchmark_pure_attitude_chirp_202311A, True)],
127127
)
128-
def test_vru_benchmark(benchmark_gen):
128+
def test_vru_benchmark(benchmark_gen, degrees):
129129
fs_imu = 100.0
130130
warmup = int(fs_imu * 600.0) # truncate 600 seconds from the beginning
131131

@@ -143,6 +143,9 @@ def test_vru_benchmark(benchmark_gen):
143143
acc_noise = acc_ref + imu_noise[:, :3]
144144
gyro_noise = gyro_ref + imu_noise[:, 3:] + bg
145145

146+
if degrees:
147+
gyro_noise = np.degrees(gyro_noise)
148+
146149
# MEKF
147150
q0 = sf.quaternion_from_euler(euler_ref[0], degrees=False)
148151
mekf = VRU(
@@ -158,13 +161,14 @@ def test_vru_benchmark(benchmark_gen):
158161
for i, (f_i, w_i) in enumerate(
159162
zip(acc_noise, gyro_noise)
160163
):
164+
161165
dvel = f_i / fs_imu
162166
dtheta = w_i / fs_imu
163167

164168
mekf.update(
165169
dvel,
166170
dtheta,
167-
degrees=False,
171+
degrees=degrees,
168172
gref=True
169173
)
170174

0 commit comments

Comments
 (0)