Skip to content

Commit 9ea7986

Browse files
committed
Initial framework for add_sv_states wrapper
1 parent 21f63c0 commit 9ea7986

2 files changed

Lines changed: 65 additions & 26 deletions

File tree

gnss_lib_py/utils/sv_models.py

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,46 @@
2121
from gnss_lib_py.parsers.sp3 import Sp3
2222
from gnss_lib_py.parsers.clk import Clk
2323

24-
def svs_from_el_az(elaz_deg):
25-
"""Generate NED satellite positions for given elevation and azimuth.
2624

27-
Given elevation and azimuth angles, with respect to the receiver,
28-
generate satellites in the NED frame of reference with the receiver
29-
position as the origin. Satellites are assumed to have a nominal
30-
distance of 20,200 km from the receiver (height of GNSS satellite orbit)
25+
def add_sv_states(measurements, source = 'precise', file_paths = None,
26+
download_directory = DEFAULT_EPHEM_PATH,
27+
constellations = None, delta_t_dec = -2,
28+
verbose = True):
29+
"""Add SV states to measurements using SP3 and CLK or Rinex files.
30+
"""
31+
if source == 'precise':
32+
measurements_w_sv_states = add_sv_states_precise(measurements,
33+
sp3_clk_paths = file_paths,
34+
download_directory = download_directory,
35+
constellations = constellations,
36+
delta_t_dec = delta_t_dec,
37+
verbose = verbose)
38+
else:
39+
raise RuntimeError('Only Precise SV state estimation supported')
40+
return measurements_w_sv_states
41+
42+
43+
44+
def add_sv_states_precise(measurements, sp3_clk_paths = None,
45+
download_directory = DEFAULT_EPHEM_PATH,
46+
constellations=None, delta_t_dec=-2,
47+
verbose=True):
48+
"""Add SV states to measurements using SP3 and CLK files.
49+
50+
Given received measurements, add SV states for measurements corresponding
51+
to received time and SV ID using SP3 and CLK files. If receiver
52+
position is given, that position is used to calculate the difference
53+
between signal transmission and reception to find the SV states
54+
corresponding to the time at which the signal was transmitted.
3155
3256
Parameters
3357
----------
34-
elaz_deg : np.ndarray
35-
Nx2 array of elevation and azimuth angles [degrees]
36-
37-
Returns
38-
-------
39-
svs_ned : np.ndarray
40-
Nx3 satellite NED positions, simulated at a distance of 20,200 km
4158
"""
42-
assert np.shape(elaz_deg)[0] == 2, "elaz_deg should be a 2xN array"
43-
el_deg = np.deg2rad(elaz_deg[0, :])
44-
az_deg = np.deg2rad(elaz_deg[1, :])
45-
unit_vect = np.zeros([3, np.shape(elaz_deg)[1]])
46-
unit_vect[0, :] = np.sin(az_deg)*np.cos(el_deg)
47-
unit_vect[1, :] = np.cos(az_deg)*np.cos(el_deg)
48-
unit_vect[2, :] = np.sin(el_deg)
49-
svs_ned = 20200000*unit_vect
50-
return svs_ned
59+
return measurements
60+
5161

5262

53-
def add_sv_states(measurements, ephemeris_path= DEFAULT_EPHEM_PATH,
63+
def add_sv_states_rinex(measurements, ephemeris_path= DEFAULT_EPHEM_PATH,
5464
constellations=['gps'], delta_t_dec = -2):
5565
"""
5666
Add SV states (ECEF position and velocities) to measurements.
@@ -121,6 +131,7 @@ def add_sv_states(measurements, ephemeris_path= DEFAULT_EPHEM_PATH,
121131
sv_states_all_time.concat(measure_frame, inplace=True)
122132
return sv_states_all_time
123133

134+
124135
def add_visible_svs_for_trajectory(rx_states,
125136
ephemeris_path=DEFAULT_EPHEM_PATH,
126137
constellations=['gps'], el_mask = 5.):
@@ -198,6 +209,34 @@ def add_visible_svs_for_trajectory(rx_states,
198209

199210
return sv_posvel_trajectory
200211

212+
def svs_from_el_az(elaz_deg):
213+
"""Generate NED satellite positions for given elevation and azimuth.
214+
215+
Given elevation and azimuth angles, with respect to the receiver,
216+
generate satellites in the NED frame of reference with the receiver
217+
position as the origin. Satellites are assumed to have a nominal
218+
distance of 20,200 km from the receiver (height of GNSS satellite orbit)
219+
220+
Parameters
221+
----------
222+
elaz_deg : np.ndarray
223+
Nx2 array of elevation and azimuth angles [degrees]
224+
225+
Returns
226+
-------
227+
svs_ned : np.ndarray
228+
Nx3 satellite NED positions, simulated at a distance of 20,200 km
229+
"""
230+
assert np.shape(elaz_deg)[0] == 2, "elaz_deg should be a 2xN array"
231+
el_deg = np.deg2rad(elaz_deg[0, :])
232+
az_deg = np.deg2rad(elaz_deg[1, :])
233+
unit_vect = np.zeros([3, np.shape(elaz_deg)[1]])
234+
unit_vect[0, :] = np.sin(az_deg)*np.cos(el_deg)
235+
unit_vect[1, :] = np.cos(az_deg)*np.cos(el_deg)
236+
unit_vect[2, :] = np.sin(el_deg)
237+
svs_ned = 20200000*unit_vect
238+
return svs_ned
239+
201240

202241
def find_sv_states(gps_millis, ephem):
203242
"""Compute position and velocities for all satellites in ephemeris file

tests/utils/test_sv_models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def test_add_sv_state_wrapper(android_measurements, ephemeris_path, error_tol_de
350350
for row in true_rows:
351351
comparison_states[row] = android_measurements[row]
352352
android_measurements.remove(true_rows, inplace=True)
353-
android_gps_states = sv_models.add_sv_states(android_measurements, ephemeris_path)
353+
android_gps_states = sv_models.add_sv_states_rinex(android_measurements, ephemeris_path)
354354
for row in true_rows:
355355
if 'mps' in row:
356356
np.testing.assert_almost_equal(android_gps_states[row],
@@ -363,11 +363,11 @@ def test_add_sv_state_wrapper(android_measurements, ephemeris_path, error_tol_de
363363
# Test position estimation when desired constellations are not in
364364
# received measurements
365365
with pytest.warns(RuntimeWarning):
366-
android_gps_states = sv_models.add_sv_states(android_measurements, ephemeris_path,
366+
android_gps_states = sv_models.add_sv_states_rinex(android_measurements, ephemeris_path,
367367
constellations=['gps', 'glonass'])
368368
# Testing position estimation without receiver position
369369
android_measurements.remove(rows=['x_rx_m', 'y_rx_m', 'z_rx_m'], inplace=True)
370-
android_gps_states = sv_models.add_sv_states(android_measurements, ephemeris_path)
370+
android_gps_states = sv_models.add_sv_states_rinex(android_measurements, ephemeris_path)
371371
for row in true_rows:
372372
if 'mps' in row:
373373
np.testing.assert_almost_equal(android_gps_states[row],

0 commit comments

Comments
 (0)