Skip to content

Commit 0173b9d

Browse files
committed
resolutions to review of #84
1 parent af07e68 commit 0173b9d

3 files changed

Lines changed: 74 additions & 6 deletions

File tree

gnss_lib_py/utils/coordinates.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import numpy as np
3434

3535
import gnss_lib_py.utils.constants as consts
36+
from gnss_lib_py.parsers.navdata import NavData
3637

3738
EPSILON = 1e-7
3839

@@ -468,7 +469,7 @@ def ecef_to_el_az(rx_pos, sv_pos):
468469

469470
return el_az
470471

471-
def add_el_az(navdata, receiver_state):
472+
def add_el_az(navdata, receiver_state, inplace=False):
472473
"""Adds elevation and azimuth to NavData object.
473474
474475
Parameters
@@ -481,6 +482,19 @@ def add_el_az(navdata, receiver_state):
481482
Either estimated or ground truth receiver position in ECEF frame
482483
in meters as an instance of the NavData class with the
483484
following rows: ``x_*_m``, ``y_*_m``, ``z_*_m``, ``gps_millis``.
485+
inplace : bool
486+
If false (default) will add elevation and azimuth to a new
487+
NavData instance. If true, will add elevation and azimuth to the
488+
existing NavData instance.
489+
490+
Returns
491+
-------
492+
data_el_az : None or gnss_lib_py.parsers.navdata.NavData
493+
If inplace is True, adds ``el_sv_deg`` and ``az_sv_deg`` to
494+
the input navdata. If inplace is False, returns ``el_sv_deg``
495+
and ``az_sv_deg`` in a new NavData instance along with
496+
``gps_millis`` and the corresponding satellite and receiver
497+
rows.
484498
485499
"""
486500

@@ -513,5 +527,22 @@ def add_el_az(navdata, receiver_state):
513527
else:
514528
sv_el_az = np.hstack((sv_el_az,timestep_el_az.T))
515529

516-
navdata["el_sv_deg"] = sv_el_az[0,:]
517-
navdata["az_sv_deg"] = sv_el_az[1,:]
530+
if inplace:
531+
navdata["el_sv_deg"] = sv_el_az[0,:]
532+
navdata["az_sv_deg"] = sv_el_az[1,:]
533+
return None
534+
535+
data_el_az = NavData()
536+
data_el_az["gps_millis"] = navdata["gps_millis"]
537+
data_el_az["gnss_id"] = navdata["gnss_id"]
538+
data_el_az["sv_id"] = navdata["sv_id"]
539+
data_el_az["x_sv_m"] = navdata["x_sv_m"]
540+
data_el_az["y_sv_m"] = navdata["y_sv_m"]
541+
data_el_az["z_sv_m"] = navdata["z_sv_m"]
542+
data_el_az[rx_idxs["x_*_m"][0]] = receiver_state[rx_idxs["x_*_m"][0]]
543+
data_el_az[rx_idxs["y_*_m"][0]] = receiver_state[rx_idxs["y_*_m"][0]]
544+
data_el_az[rx_idxs["z_*_m"][0]] = receiver_state[rx_idxs["z_*_m"][0]]
545+
data_el_az["el_sv_deg"] = sv_el_az[0,:]
546+
data_el_az["az_sv_deg"] = sv_el_az[1,:]
547+
548+
return data_el_az

gnss_lib_py/utils/visualizations.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def plot_skyplot(navdata, receiver_state, save=False, prefix="",
276276
raise TypeError("Prefix must be a string.")
277277

278278
if "el_sv_deg" not in navdata.rows or "az_sv_deg" not in navdata.rows:
279-
add_el_az(navdata, receiver_state)
279+
add_el_az(navdata, receiver_state, inplace=True)
280280

281281
# create new figure
282282
fig = plt.figure(figsize=(6,4.5))
@@ -553,10 +553,17 @@ def _get_label(inputs):
553553
units = {"m","km",
554554
"deg","rad",
555555
"sec","s","hr","min",
556-
"mps",
556+
"mps","kmph","mph",
557+
"dgps","radps",
558+
"mps2",
557559
}
558560
unit_replacements = {
559561
"mps" : "m/s",
562+
"kmph" : "km/hr",
563+
"mph" : "miles/hr",
564+
"degps" : "deg/s",
565+
"radps" : "rad/s",
566+
"mps2" : "m/s^2",
560567
}
561568

562569
label = ""

tests/utils/test_coordinates.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import gnss_lib_py.utils.constants as consts
1515
from gnss_lib_py.parsers.android import AndroidDerived2022
16-
from gnss_lib_py.utils.coordinates import ecef_to_el_az
16+
from gnss_lib_py.utils.coordinates import ecef_to_el_az, add_el_az
1717
from gnss_lib_py.utils.coordinates import geodetic_to_ecef
1818
from gnss_lib_py.utils.coordinates import ecef_to_geodetic, LocalCoord
1919

@@ -409,3 +409,33 @@ def test_ecef_to_el_az_fails(set_sv_pos, set_rx_pos):
409409
with pytest.raises(RuntimeError) as excinfo:
410410
ecef_to_el_az(set_rx_pos,set_sv_pos.T)
411411
assert "Nx3" in str(excinfo.value)
412+
413+
414+
@pytest.mark.parametrize('navdata',[
415+
lazy_fixture('derived_2022'),
416+
])
417+
def test_add_el_az(navdata):
418+
"""Test for plotting skyplot.
419+
420+
Parameters
421+
----------
422+
navdata : AndroidDerived
423+
Instance of AndroidDerived for testing.
424+
425+
"""
426+
427+
receiver_state = navdata.copy(rows=["gps_millis",
428+
"WlsPositionXEcefMeters",
429+
"WlsPositionYEcefMeters",
430+
"WlsPositionZEcefMeters"])
431+
row_map = {
432+
"WlsPositionXEcefMeters" : "x_rx_m",
433+
"WlsPositionYEcefMeters" : "y_rx_m",
434+
"WlsPositionZEcefMeters" : "z_rx_m",
435+
}
436+
receiver_state.rename(row_map,inplace=True)
437+
data_el_az = add_el_az(navdata, receiver_state)
438+
np.testing.assert_array_almost_equal(data_el_az["el_sv_deg"],
439+
navdata["el_sv_deg"])
440+
np.testing.assert_array_almost_equal(data_el_az["az_sv_deg"],
441+
navdata["az_sv_deg"])

0 commit comments

Comments
 (0)