Skip to content

Commit af07e68

Browse files
committed
functionalize added el and az to navdata
1 parent 943ce19 commit af07e68

3 files changed

Lines changed: 52 additions & 34 deletions

File tree

gnss_lib_py/utils/coordinates.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,51 @@ def ecef_to_el_az(rx_pos, sv_pos):
467467
el_az[:,1][el_az[:,1] < 0] += 360
468468

469469
return el_az
470+
471+
def add_el_az(navdata, receiver_state):
472+
"""Adds elevation and azimuth to NavData object.
473+
474+
Parameters
475+
----------
476+
navdata : gnss_lib_py.parsers.navdata.NavData
477+
Instance of the NavData class. Must include ``gps_millis`` as
478+
well as satellite ECEF positions as ``x_sv_m``, ``y_sv_m``,
479+
``z_sv_m``, ``gnss_id`` and ``sv_id``.
480+
receiver_state : gnss_lib_py.parsers.navdata.NavData
481+
Either estimated or ground truth receiver position in ECEF frame
482+
in meters as an instance of the NavData class with the
483+
following rows: ``x_*_m``, ``y_*_m``, ``z_*_m``, ``gps_millis``.
484+
485+
"""
486+
487+
# check for missing rows
488+
navdata.in_rows(["gps_millis","x_sv_m","y_sv_m","z_sv_m",
489+
"gnss_id","sv_id"])
490+
receiver_state.in_rows(["gps_millis"])
491+
492+
# check for receiver_state indexes
493+
rx_idxs = receiver_state.find_wildcard_indexes(["x_*_m","y_*_m",
494+
"z_*_m"],max_allow=1)
495+
496+
sv_el_az = None
497+
for timestamp, _, navdata_subset in navdata.loop_time("gps_millis"):
498+
499+
pos_sv_m = navdata_subset[["x_sv_m","y_sv_m","z_sv_m"]].T
500+
501+
# find time index for receiver_state NavData instance
502+
rx_t_idx = np.argmin(np.abs(receiver_state["gps_millis"] - timestamp))
503+
504+
pos_rx_m = receiver_state[[rx_idxs["x_*_m"][0],
505+
rx_idxs["y_*_m"][0],
506+
rx_idxs["z_*_m"][0]],
507+
rx_t_idx].reshape(1,-1)
508+
509+
timestep_el_az = ecef_to_el_az(pos_rx_m, pos_sv_m)
510+
511+
if sv_el_az is None:
512+
sv_el_az = timestep_el_az.T
513+
else:
514+
sv_el_az = np.hstack((sv_el_az,timestep_el_az.T))
515+
516+
navdata["el_sv_deg"] = sv_el_az[0,:]
517+
navdata["az_sv_deg"] = sv_el_az[1,:]

gnss_lib_py/utils/visualizations.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import gnss_lib_py.utils.file_operations as fo
2323
from gnss_lib_py.parsers.navdata import NavData
24-
from gnss_lib_py.utils.coordinates import ecef_to_el_az
24+
from gnss_lib_py.utils.coordinates import add_el_az
2525

2626
STANFORD_COLORS = [
2727
"#8C1515", # cardinal red
@@ -274,39 +274,9 @@ def plot_skyplot(navdata, receiver_state, save=False, prefix="",
274274

275275
if not isinstance(prefix, str):
276276
raise TypeError("Prefix must be a string.")
277-
# check for missing rows
278-
navdata.in_rows(["gps_millis","x_sv_m","y_sv_m","z_sv_m",
279-
"gnss_id","sv_id"])
280-
receiver_state.in_rows(["gps_millis"])
281-
282-
# check for receiver_state indexes
283-
rx_idxs = receiver_state.find_wildcard_indexes(["x_*_m","y_*_m",
284-
"z_*_m"],max_allow=1)
285277

286278
if "el_sv_deg" not in navdata.rows or "az_sv_deg" not in navdata.rows:
287-
sv_el_az = None
288-
289-
for timestamp, _, navdata_subset in navdata.loop_time("gps_millis"):
290-
291-
pos_sv_m = navdata_subset[["x_sv_m","y_sv_m","z_sv_m"]].T
292-
293-
# find time index for receiver_state NavData instance
294-
rx_t_idx = np.argmin(np.abs(receiver_state["gps_millis"] - timestamp))
295-
296-
pos_rx_m = receiver_state[[rx_idxs["x_*_m"][0],
297-
rx_idxs["y_*_m"][0],
298-
rx_idxs["z_*_m"][0]],
299-
rx_t_idx].reshape(1,-1)
300-
301-
timestep_el_az = ecef_to_el_az(pos_rx_m, pos_sv_m)
302-
303-
if sv_el_az is None:
304-
sv_el_az = timestep_el_az.T
305-
else:
306-
sv_el_az = np.hstack((sv_el_az,timestep_el_az.T))
307-
308-
navdata["el_sv_deg"] = sv_el_az[0,:]
309-
navdata["az_sv_deg"] = sv_el_az[1,:]
279+
add_el_az(navdata, receiver_state)
310280

311281
# create new figure
312282
fig = plt.figure(figsize=(6,4.5))

tests/utils/test_visualizations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,11 @@ def test_plot_skyplot(navdata, state_estimate):
369369
navdata["x_sv_m",col_idx] = np.nan
370370

371371
# don't save figures
372-
fig = viz.plot_skyplot(navdata, state_estimate, save=True)
372+
fig = viz.plot_skyplot(navdata.copy(), state_estimate, save=False)
373373
viz.close_figures(fig)
374374

375375
with pytest.raises(TypeError) as excinfo:
376-
viz.plot_skyplot(navdata, state_estimate, save=True, prefix=1)
376+
viz.plot_skyplot(navdata.copy(), state_estimate, save=True, prefix=1)
377377
assert "Prefix" in str(excinfo.value)
378378

379379
for row in ["x_sv_m","y_sv_m","z_sv_m","gps_millis"]:

0 commit comments

Comments
 (0)