Skip to content

Commit b4a9c7b

Browse files
committed
handle empty measurements in solve_wls
1 parent 204a7a2 commit b4a9c7b

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

gnss_lib_py/algorithms/snapshot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def solve_wls(measurements, weight_type = None, only_bias = False,
3535
Parameters
3636
----------
3737
measurements : gnss_lib_py.parsers.navdata.NavData
38-
Instance of the NavData class
38+
Instance of the NavData class which must include at least
39+
``gps_millis``, ``x_sv_m``, ``y_sv_m``, and ``z_sv_m``
3940
weight_type : string
4041
Must either be None or the name of a row in measurements
4142
only_bias : bool
@@ -132,7 +133,7 @@ def solve_wls(measurements, weight_type = None, only_bias = False,
132133
states.append([timestamp, np.nan, np.nan, np.nan, np.nan])
133134

134135
if len(states) == 0:
135-
states = [[np.nan]*5]
136+
states = np.empty((0,5))
136137
states = np.array(states)
137138

138139
state_estimate = NavData()

tests/algorithms/test_snapshot.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,3 +646,23 @@ def test_rotation_of_earth_fix(derived_2022):
646646
error_rotn = np.mean(np.abs(google_wls[idx, :] - glp_wls[idx, :]))
647647
error_no_rotn = np.mean(np.abs(google_wls[idx, :] - glp_wls_no_rotn[idx, :]))
648648
assert error_rotn < error_no_rotn
649+
650+
def test_solve_wls_empty():
651+
"""Test scenario where an empty measurement class is passed in.
652+
653+
"""
654+
655+
measurements = NavData()
656+
measurements["gps_millis"] = []
657+
measurements["x_sv_m"] = []
658+
measurements["y_sv_m"] = []
659+
measurements["z_sv_m"] = []
660+
with pytest.warns(RuntimeWarning) as warns:
661+
state_estimate = solve_wls(measurements)
662+
663+
# should have the following contents
664+
assert "gps_millis" in state_estimate.rows
665+
assert "x_rx_wls_m" in state_estimate.rows
666+
assert "y_rx_wls_m" in state_estimate.rows
667+
assert "z_rx_wls_m" in state_estimate.rows
668+
assert "b_rx_wls_m" in state_estimate.rows

0 commit comments

Comments
 (0)