Skip to content

Commit d7b4fe1

Browse files
committed
residuals working for single sat case, better test, residuals to residuals_m
1 parent ef83fbe commit d7b4fe1

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

gnss_lib_py/algorithms/residuals.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def solve_residuals(measurements, receiver_state, inplace=True):
2323
following rows: x_*_m, y_*_m, z_*_m, b_*_m.
2424
inplace : bool
2525
If False, will return new NavData instance with gps_millis and
26-
reisuals. If True, will add a "residuals" rows in the
26+
reisuals. If True, will add a "residuals_m" rows in the
2727
current NavData instance.
2828
2929
Returns
@@ -63,6 +63,7 @@ def solve_residuals(measurements, receiver_state, inplace=True):
6363
for timestamp, _, measurement_subset in measurements.loop_time("gps_millis"):
6464

6565
pos_sv_m = measurement_subset[["x_sv_m","y_sv_m","z_sv_m"]].T
66+
pos_sv_m = np.atleast_2d(pos_sv_m)
6667

6768
num_svs = pos_sv_m.shape[0]
6869

@@ -74,26 +75,25 @@ def solve_residuals(measurements, receiver_state, inplace=True):
7475
rx_pos = receiver_state[[rx_idxs["x_*_m"],
7576
rx_idxs["y_*_m"],
7677
rx_idxs["z_*_m"]],
77-
rx_t_idx].reshape(-1,1)
78-
pos_rx_m = np.tile(rx_pos.T, (num_svs, 1))
78+
rx_t_idx].reshape(1,-1)
79+
pos_rx_m = np.tile(rx_pos, (num_svs, 1))
7980

8081
gt_pr_m = np.linalg.norm(pos_rx_m - pos_sv_m, axis = 1,
8182
keepdims = True) \
8283
+ receiver_state[rx_idxs["b_*_m"],rx_t_idx]
8384

8485
# calculate residual
8586
residuals_epoch = corr_pr_m - gt_pr_m
86-
87-
residuals += np.squeeze(residuals_epoch).tolist()
87+
residuals += residuals_epoch.reshape(-1).tolist()
8888

8989
if inplace:
9090
# add measurements to measurement class
91-
measurements["residuals"] = residuals
91+
measurements["residuals_m"] = residuals
9292
return None
9393

9494
# if not inplace, create new NavData instance to return
9595
residual_navdata = NavData()
96-
residual_navdata["residuals"] = residuals
96+
residual_navdata["residuals_m"] = residuals
9797
residual_navdata["gps_millis"]= measurements["gps_millis"]
9898
for row in ["gnss_id","sv_id","signal_type"]:
9999
if row in measurements.rows:

notebooks/tutorials/algorithms.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
18-
"from gnss_lib_py.algorithms.snapshot import solve_wls\n",
1918
"from gnss_lib_py.parsers.android import AndroidDerived2021\n",
20-
"from gnss_lib_py.utils.visualizations import plot_metric"
19+
"from gnss_lib_py.algorithms.snapshot import solve_wls\n",
20+
"from gnss_lib_py.utils.visualizations import plot_map"
2121
]
2222
},
2323
{
@@ -65,7 +65,7 @@
6565
"metadata": {},
6666
"outputs": [],
6767
"source": [
68-
"fig = plot_metric(state, \"x_rx_m\", \"y_rx_m\", save=False)"
68+
"plot_map(state)"
6969
]
7070
},
7171
{
@@ -93,7 +93,7 @@
9393
"id": "a4ff4bdc",
9494
"metadata": {},
9595
"source": [
96-
"Solve for residuals using the estimated state. A new \"residuals\" row is added to derived_data"
96+
"Solve for residuals using the estimated state. A new \"residuals_m\" row is added to derived_data"
9797
]
9898
},
9999
{
@@ -121,13 +121,13 @@
121121
"metadata": {},
122122
"outputs": [],
123123
"source": [
124-
"figs = plot_metric_by_constellation(galileo_data, \"gps_millis\", \"residuals\", save=False)"
124+
"figs = plot_metric_by_constellation(galileo_data, \"gps_millis\", \"residuals_m\")"
125125
]
126126
}
127127
],
128128
"metadata": {
129129
"kernelspec": {
130-
"display_name": "Python 3 (ipykernel)",
130+
"display_name": "Python 3",
131131
"language": "python",
132132
"name": "python3"
133133
},

tests/algorithms/test_residuals.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,13 @@ def test_residuals_inplace(derived):
101101
assert len(derived) == len(derived_original)
102102

103103
# derived should include new residuals rows but not its copy
104-
assert "residuals" in derived.rows
105-
assert "residuals" not in derived_original.rows
104+
assert "residuals_m" in derived.rows
105+
assert "residuals_m" not in derived_original.rows
106106

107-
assert not np.any(np.isinf(derived["residuals"]))
107+
assert not np.any(np.isinf(derived["residuals_m"]))
108+
109+
# max is 47.814594604074955
110+
assert max(derived["residuals_m"]) < 50.
108111

109112
def test_residuals(derived):
110113
"""Test that solving for residuals doesn't fail
@@ -124,14 +127,17 @@ def test_residuals(derived):
124127
assert isinstance(residuals,type(NavData()))
125128

126129
# derived should have one more row but same number of cols
127-
for row in ["residuals","gps_millis","gnss_id","sv_id","signal_type"]:
130+
for row in ["residuals_m","gps_millis","gnss_id","sv_id","signal_type"]:
128131
assert row in residuals.rows
129132
assert len(residuals) == len(derived)
130133

131134
# derived should not include new residuals row
132-
assert "residuals" not in derived.rows
135+
assert "residuals_m" not in derived.rows
136+
137+
assert not np.any(np.isinf(residuals["residuals_m"]))
133138

134-
assert not np.any(np.isinf(residuals["residuals"]))
139+
# max is 47.814594604074955
140+
assert max(residuals["residuals_m"]) < 50.
135141

136142
def test_residuals_fails(derived):
137143
"""Test that solving for residuals fails when it should

0 commit comments

Comments
 (0)