Skip to content

Commit 852b0c1

Browse files
committed
handle multiple inputs in clk and sp3
1 parent e01a607 commit 852b0c1

4 files changed

Lines changed: 98 additions & 99 deletions

File tree

gnss_lib_py/parsers/clk.py

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,7 @@
1717
from gnss_lib_py.utils.time_conversions import gps_datetime_to_gps_millis
1818

1919
class Clk(NavData):
20-
"""Clk specific loading and preprocessing for any GNSS constellation
21-
22-
Parameters
23-
----------
24-
input_paths : string or path-like or list of paths
25-
Path to measurement clk file(s).
26-
27-
Returns
28-
-------
29-
clkdata : dict
30-
Populated gnss_lib_py.parsers.clk.Clk objects
31-
with key of `gnss_sv_id` for each satellite.
20+
"""Clk specific loading and preprocessing for any GNSS constellation.
3221
3322
Notes
3423
-----
@@ -44,59 +33,63 @@ class Clk(NavData):
4433
Accessed as of August 24, 2022
4534
4635
"""
47-
def __init__(self, input_path):
36+
def __init__(self, input_paths):
4837
"""Clk loading and preprocessing.
4938
5039
Parameters
5140
----------
52-
input_path : string or path-like
53-
Path to clk file
41+
input_paths : string or path-like or list of paths
42+
Path to measurement clk file(s).
5443
5544
"""
5645
super().__init__()
5746

47+
if isinstance(input_paths, (str, os.PathLike)):
48+
input_paths = [input_paths]
49+
5850
gps_millis = []
5951
unix_millis = []
6052
gnss_sv_ids = []
6153
gnss_id = []
6254
sv_id = []
6355
b_sv_m = []
6456

65-
# Initial checks for loading sp3_path
66-
if not isinstance(input_path, (str, os.PathLike)):
67-
raise TypeError("input_path must be string or path-like")
68-
if not os.path.exists(input_path):
69-
raise FileNotFoundError("file not found")
70-
71-
# Read Clock file
72-
with open(input_path, 'r', encoding="utf-8") as infile:
73-
clk = infile.readlines()
74-
75-
for clk_val in clk:
76-
77-
timelist_val = clk_val.split()
78-
79-
if len(timelist_val) == 0 or timelist_val[0] != 'AS':
80-
continue
81-
82-
gnss_sv_id = timelist_val[1]
83-
84-
curr_time = datetime(year = int(timelist_val[2]), \
85-
month = int(timelist_val[3]), \
86-
day = int(timelist_val[4]), \
87-
hour = int(timelist_val[5]), \
88-
minute = int(timelist_val[6]), \
89-
second = int(float(timelist_val[7])), \
90-
tzinfo=timezone.utc)
91-
gps_millis_timestep = gps_datetime_to_gps_millis(curr_time)
92-
unix_millis_timestep = gps_to_unix_millis(gps_millis_timestep)
93-
gnss_sv_ids.append(gnss_sv_id)
94-
gnss_id.append(CONSTELLATION_CHARS[gnss_sv_id[0]])
95-
sv_id.append(int(gnss_sv_id[1:]))
96-
gps_millis.append(gps_millis_timestep)
97-
unix_millis.append(unix_millis_timestep)
98-
# clock bias is given in seconds, convert to meters
99-
b_sv_m.append(float(timelist_val[9]) * C)
57+
for input_path in input_paths:
58+
# Initial checks for loading sp3_path
59+
if not isinstance(input_path, (str, os.PathLike)):
60+
raise TypeError("input_path must be string or path-like")
61+
if not os.path.exists(input_path):
62+
raise FileNotFoundError("file not found")
63+
64+
# Read Clock file
65+
with open(input_path, 'r', encoding="utf-8") as infile:
66+
clk = infile.readlines()
67+
68+
for clk_val in clk:
69+
70+
timelist_val = clk_val.split()
71+
72+
if len(timelist_val) == 0 or timelist_val[0] != 'AS':
73+
continue
74+
75+
gnss_sv_id = timelist_val[1]
76+
77+
curr_time = datetime(year = int(timelist_val[2]), \
78+
month = int(timelist_val[3]), \
79+
day = int(timelist_val[4]), \
80+
hour = int(timelist_val[5]), \
81+
minute = int(timelist_val[6]), \
82+
second = int(float(timelist_val[7])), \
83+
tzinfo=timezone.utc)
84+
gps_millis_timestep = gps_datetime_to_gps_millis(curr_time)
85+
unix_millis_timestep = gps_to_unix_millis(gps_millis_timestep)
86+
gnss_sv_ids.append(gnss_sv_id)
87+
gnss_id.append(CONSTELLATION_CHARS[gnss_sv_id[0]])
88+
sv_id.append(int(gnss_sv_id[1:]))
89+
gps_millis.append(gps_millis_timestep)
90+
unix_millis.append(unix_millis_timestep)
91+
# clock bias is given in seconds, convert to meters
92+
b_sv_m.append(float(timelist_val[9]) * C)
10093

10194
self["gps_millis"] = gps_millis
10295
self["unix_millis"] = unix_millis

gnss_lib_py/parsers/sp3.py

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
class Sp3(NavData):
2121
"""sp3 specific loading and preprocessing for any GNSS constellation.
2222
23-
Parameters
24-
----------
25-
input_path : string or path-like
26-
Path to sp3 file.
27-
2823
Notes
2924
-----
3025
The format for .sp3 files can be viewed in [1]_.
@@ -38,10 +33,20 @@ class Sp3(NavData):
3833
.. [1] https://files.igs.org/pub/data/format/sp3d.pdf
3934
Accessed as of August 20, 2022
4035
"""
41-
def __init__(self, input_path):
36+
def __init__(self, input_paths):
37+
"""Sp3 loading and preprocessing.
4238
39+
Parameters
40+
----------
41+
input_paths : string or path-like or list of paths
42+
Path to measurement sp3 file(s).
43+
44+
"""
4345
super().__init__()
4446

47+
if isinstance(input_paths, (str, os.PathLike)):
48+
input_paths = [input_paths]
49+
4550
gps_millis = []
4651
unix_millis = []
4752
gnss_sv_ids = []
@@ -51,47 +56,48 @@ def __init__(self, input_path):
5156
y_sv_m = []
5257
z_sv_m = []
5358

54-
# Initial checks for loading sp3_path
55-
if not isinstance(input_path, (str, os.PathLike)):
56-
raise TypeError("input_path must be string or path-like")
57-
if not os.path.exists(input_path):
58-
raise FileNotFoundError("file not found")
59-
60-
# Load in the file
61-
with open(input_path, 'r', encoding="utf-8") as infile:
62-
data = [line.strip() for line in infile]
63-
64-
# Loop through each line
65-
for dval in data:
66-
if len(dval) == 0:
67-
# No data
68-
continue
69-
70-
if dval[0] == '*':
71-
# A new record
72-
# Get the date
73-
temp = dval.split()
74-
curr_time = datetime( int(temp[1]), int(temp[2]), \
75-
int(temp[3]), int(temp[4]), \
76-
int(temp[5]),int(float(temp[6])),\
77-
tzinfo=timezone.utc )
78-
gps_millis_timestep = gps_datetime_to_gps_millis(curr_time)
79-
unix_millis_timestep = gps_to_unix_millis(gps_millis_timestep)
80-
81-
if 'P' in dval[0]:
82-
# A satellite record. Get the satellite number, and coordinate (X,Y,Z) info
83-
temp = dval.split()
84-
85-
gnss_sv_id = temp[0][1:]
86-
87-
gps_millis.append(gps_millis_timestep)
88-
unix_millis.append(unix_millis_timestep)
89-
gnss_sv_ids.append(gnss_sv_id)
90-
gnss_id.append(CONSTELLATION_CHARS[gnss_sv_id[0]])
91-
sv_id.append(int(gnss_sv_id[1:]))
92-
x_sv_m.append(float(temp[1])*1e3)
93-
y_sv_m.append(float(temp[2])*1e3)
94-
z_sv_m.append(float(temp[3])*1e3)
59+
for input_path in input_paths:
60+
# Initial checks for loading sp3_path
61+
if not isinstance(input_path, (str, os.PathLike)):
62+
raise TypeError("input_path must be string or path-like")
63+
if not os.path.exists(input_path):
64+
raise FileNotFoundError("file not found")
65+
66+
# Load in the file
67+
with open(input_path, 'r', encoding="utf-8") as infile:
68+
data = [line.strip() for line in infile]
69+
70+
# Loop through each line
71+
for dval in data:
72+
if len(dval) == 0:
73+
# No data
74+
continue
75+
76+
if dval[0] == '*':
77+
# A new record
78+
# Get the date
79+
temp = dval.split()
80+
curr_time = datetime( int(temp[1]), int(temp[2]), \
81+
int(temp[3]), int(temp[4]), \
82+
int(temp[5]),int(float(temp[6])),\
83+
tzinfo=timezone.utc )
84+
gps_millis_timestep = gps_datetime_to_gps_millis(curr_time)
85+
unix_millis_timestep = gps_to_unix_millis(gps_millis_timestep)
86+
87+
if 'P' in dval[0]:
88+
# A satellite record. Get the satellite number, and coordinate (X,Y,Z) info
89+
temp = dval.split()
90+
91+
gnss_sv_id = temp[0][1:]
92+
93+
gps_millis.append(gps_millis_timestep)
94+
unix_millis.append(unix_millis_timestep)
95+
gnss_sv_ids.append(gnss_sv_id)
96+
gnss_id.append(CONSTELLATION_CHARS[gnss_sv_id[0]])
97+
sv_id.append(int(gnss_sv_id[1:]))
98+
x_sv_m.append(float(temp[1])*1e3)
99+
y_sv_m.append(float(temp[2])*1e3)
100+
z_sv_m.append(float(temp[3])*1e3)
95101

96102
self["gps_millis"] = gps_millis
97103
self["unix_millis"] = unix_millis

tests/parsers/test_clk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_load_clkdata_missing(clk_path_missing):
119119

120120
# raises exception if input not string or path-like
121121
with pytest.raises(TypeError):
122-
Clk([])
122+
Clk([1])
123123

124124
@pytest.fixture(name="clk_path_nodata")
125125
def fixture_clk_path_nodata(root_path):

tests/parsers/test_sp3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_load_sp3data_missing(sp3_path_missing):
116116

117117
# raises exception if input not string or path-like
118118
with pytest.raises(TypeError):
119-
Sp3([])
119+
Sp3([1])
120120

121121
@pytest.fixture(name="sp3_path_nodata")
122122
def fixture_sp3_path_nodata(root_path):

0 commit comments

Comments
 (0)