Skip to content

Commit 76d1c99

Browse files
committed
android docstrings, testing, remove_timing_outliers
1 parent d169ac5 commit 76d1c99

7 files changed

Lines changed: 132 additions & 139 deletions

File tree

gnss_lib_py/parsers/android.py

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
"""
44

5-
__authors__ = "Shubh Gupta, Adam Dai, Ashwin Kanhere"
5+
__authors__ = "Ashwin Kanhere, Shubh Gupta, Adam Dai"
66
__date__ = "02 Nov 2021"
77

88

@@ -22,23 +22,22 @@ class AndroidDerived2021(NavData):
2222
2323
Inherits from NavData().
2424
"""
25-
def __init__(self, input_path, remove_bad_measures=True):
25+
def __init__(self, input_path, remove_timing_outliers=True):
2626
"""Android specific loading and preprocessing
2727
2828
Parameters
2929
----------
3030
input_path : string
3131
Path to measurement csv file
32-
33-
remove_bad_measures : bool
32+
remove_timing_outliers : bool
3433
Flag for whether to remove measures that are too close or
3534
too far away in time. Code from the competition hosts used
36-
to implement changes
35+
to implement changes. See note.
3736
3837
Notes
3938
-----
4039
Removes duplicate rows using correction 5 from competition hosts
41-
implemented from https://www.kaggle.com/c/google-smartphone-decimeter-challenge/data
40+
implemented from https://www.kaggle.com/code/gymf123/tips-notes-from-the-competition-hosts/notebook
4241
retrieved on 10 August, 2022
4342
4443
"""
@@ -52,7 +51,7 @@ def __init__(self, input_path, remove_bad_measures=True):
5251

5352

5453
# Correction 5 implemented verbatim from competition tips
55-
if remove_bad_measures:
54+
if remove_timing_outliers:
5655
delta_millis = pd_df['millisSinceGpsEpoch'] - pd_df['receivedSvTimeInGpsNanos'] / 1e6
5756
where_good_signals = (delta_millis > 0) & (delta_millis < 300)
5857
pd_df = pd_df[where_good_signals].copy()
@@ -68,11 +67,11 @@ def postprocess(self):
6867
implemented from https://www.kaggle.com/c/google-smartphone-decimeter-challenge/data
6968
retrieved on 10 August, 2022
7069
"""
71-
pr_corrected = self['raw_pr_m', :] \
72-
+ self['b_sv_m', :] \
73-
- self['intersignal_bias_m', :] \
74-
- self['tropo_delay_m', :] \
75-
- self['iono_delay_m', :]
70+
pr_corrected = self['raw_pr_m'] \
71+
+ self['b_sv_m'] \
72+
- self['intersignal_bias_m'] \
73+
- self['tropo_delay_m'] \
74+
- self['iono_delay_m']
7675
self['corr_pr_m'] = pr_corrected
7776

7877
@staticmethod
@@ -134,11 +133,11 @@ def postprocess(self):
134133
implemented from https://www.kaggle.com/c/google-smartphone-decimeter-challenge/data
135134
retrieved on 10 August, 2022
136135
"""
137-
pr_corrected = self['raw_pr_m', :] \
138-
+ self['b_sv_m', :] \
139-
- self['intersignal_bias_m', :] \
140-
- self['tropo_delay_m', :] \
141-
- self['iono_delay_m', :]
136+
pr_corrected = self['raw_pr_m'] \
137+
+ self['b_sv_m'] \
138+
- self['intersignal_bias_m'] \
139+
- self['tropo_delay_m'] \
140+
- self['iono_delay_m']
142141
self['corr_pr_m'] = pr_corrected
143142

144143
@staticmethod
@@ -202,27 +201,29 @@ def postprocess(self):
202201
"""
203202
# Correcting reported altitude
204203
self['alt_gt_m'] = self['alt_gt_m'] - 61.
205-
gt_lla = np.transpose(np.vstack([self['lat_gt_deg'], self['long_gt_deg'], self['alt_gt_m']]))
204+
gt_lla = np.transpose(np.vstack([self['lat_gt_deg'],
205+
self['long_gt_deg'],
206+
self['alt_gt_m']]))
206207
gt_ecef = geodetic_to_ecef(gt_lla)
207208
self["x_gt_m"] = gt_ecef[:,0]
208209
self["y_gt_m"] = gt_ecef[:,1]
209210
self["z_gt_m"] = gt_ecef[:,2]
210211

211212
@staticmethod
212213
def _row_map():
213-
"""Map of row names from loaded ground truth to gnss_lib_py standard
214+
"""Map of row names from loaded ground truth to gnss_lib_py standard
214215
215-
Returns
216-
-------
217-
row_map : Dict
218-
Dictionary of the form {old_name : new_name}
219-
"""
220-
row_map = {'latDeg' : 'lat_gt_deg',
221-
'lngDeg' : 'long_gt_deg',
222-
'heightAboveWgs84EllipsoidM' : 'alt_gt_m',
223-
'millisSinceGpsEpoch' : 'gps_millis'
224-
}
225-
return row_map
216+
Returns
217+
-------
218+
row_map : Dict
219+
Dictionary of the form {old_name : new_name}
220+
"""
221+
row_map = {'latDeg' : 'lat_gt_deg',
222+
'lngDeg' : 'long_gt_deg',
223+
'heightAboveWgs84EllipsoidM' : 'alt_gt_m',
224+
'millisSinceGpsEpoch' : 'gps_millis'
225+
}
226+
return row_map
226227

227228

228229
class AndroidGroundTruth2022(AndroidGroundTruth2021):
@@ -240,7 +241,9 @@ def postprocess(self):
240241
if np.any(np.isnan(self['alt_gt_m'])):
241242
warnings.warn("Some altitude values were missing, using 0m ", RuntimeWarning)
242243
self['alt_gt_m'] = np.nan_to_num(self['alt_gt_m'])
243-
gt_lla = np.transpose(np.vstack([self['lat_gt_deg'], self['long_gt_deg'], self['alt_gt_m']]))
244+
gt_lla = np.transpose(np.vstack([self['lat_gt_deg'],
245+
self['long_gt_deg'],
246+
self['alt_gt_m']]))
244247
gt_ecef = geodetic_to_ecef(gt_lla)
245248
self["x_gt_m"] = gt_ecef[:,0]
246249
self["y_gt_m"] = gt_ecef[:,1]
@@ -249,19 +252,19 @@ def postprocess(self):
249252

250253
@staticmethod
251254
def _row_map():
252-
"""Map of row names from loaded ground truth to gnss_lib_py standard
253-
254-
Returns
255-
-------
256-
row_map : Dict
257-
Dictionary of the form {old_name : new_name}
258-
"""
259-
row_map = {'LatitudeDegrees' : 'lat_gt_deg',
260-
'LongitudeDegrees' : 'long_gt_deg',
261-
'AltitudeMeters' : 'alt_gt_m',
262-
'UnixTimeMillis' : 'unix_millis'
263-
}
264-
return row_map
255+
"""Map row names from loaded data to gnss_lib_py standard
256+
257+
Returns
258+
-------
259+
row_map : Dict
260+
Dictionary of the form {old_name : new_name}
261+
"""
262+
row_map = {'LatitudeDegrees' : 'lat_gt_deg',
263+
'LongitudeDegrees' : 'long_gt_deg',
264+
'AltitudeMeters' : 'alt_gt_m',
265+
'UnixTimeMillis' : 'unix_millis'
266+
}
267+
return row_map
265268

266269
class AndroidRawImu(NavData):
267270
"""Class handling IMU measurements from raw Android dataset.
@@ -304,11 +307,14 @@ def preprocess(self, input_path):
304307
elif row[0] == 'Gyro':
305308
gyro.append(row[1:])
306309

307-
accel = pd.DataFrame(accel[1:], columns = accel[0], dtype=np.float64)
308-
gyro = pd.DataFrame(gyro[1:], columns = gyro[0], dtype=np.float64)
310+
accel = pd.DataFrame(accel[1:], columns = accel[0],
311+
dtype=np.float64)
312+
gyro = pd.DataFrame(gyro[1:], columns = gyro[0],
313+
dtype=np.float64)
309314

310315
#Drop common columns from gyro and keep values from accel
311-
gyro.drop(columns=['utcTimeMillis', 'elapsedRealtimeNanos'], inplace=True)
316+
gyro.drop(columns=['utcTimeMillis', 'elapsedRealtimeNanos'],
317+
inplace=True)
312318
measurements = pd.concat([accel, gyro], axis=1)
313319
#NOTE: Assuming pandas index corresponds to measurements order
314320
#NOTE: Override times of gyro measurements with corresponding
@@ -413,4 +419,4 @@ def make_csv(input_path, output_directory, field, show_path=False):
413419
if show_path: #pragma: no cover
414420
print(output_path)
415421

416-
return output_path
422+
return output_path

gnss_lib_py/parsers/navdata.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ def __setitem__(self, key_idx, newvalue):
311311
newvalue : np.ndarray/list/int
312312
Values to be added to self.array attribute
313313
"""
314-
#TODO: Fix error when assigning strings with 2D arrays
315314
if isinstance(key_idx, int) and len(self.map)<=key_idx:
316315
raise KeyError('Row indices must be strings when assigning new values')
317316
if isinstance(key_idx, slice) and len(self.map)==0:
@@ -454,7 +453,7 @@ def add(self, csv_path=None, pandas_df=None, numpy_array=None):
454453
if old_len == 0:
455454
self.from_pandas_df(pandas_df)
456455
else:
457-
#TODO: Case handling for when column name in dataframe is different?
456+
458457
self.array = np.hstack((self.array, np.empty(pandas_df.shape).T))
459458
for col in pandas_df.columns:
460459
self[col, new_data_cols] = np.asarray(pandas_df[col].values)

gnss_lib_py/utils/time_conversions.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@
1717

1818
# Manually need to add leapSeconds when needed for future ones
1919
LEAPSECONDS_TABLE = [datetime(2017, 1, 1, 0, 0, tzinfo=timezone.utc),
20-
datetime(2015, 7, 1, 0, 0, tzinfo=timezone.utc),
21-
datetime(2012, 7, 1, 0, 0, tzinfo=timezone.utc),
22-
datetime(2009, 1, 1, 0, 0, tzinfo=timezone.utc),
23-
datetime(2006, 1, 1, 0, 0, tzinfo=timezone.utc),
24-
datetime(1999, 1, 1, 0, 0, tzinfo=timezone.utc),
25-
datetime(1997, 7, 1, 0, 0, tzinfo=timezone.utc),
26-
datetime(1996, 1, 1, 0, 0, tzinfo=timezone.utc),
27-
datetime(1994, 7, 1, 0, 0, tzinfo=timezone.utc),
28-
datetime(1993, 7, 1, 0, 0, tzinfo=timezone.utc),
29-
datetime(1992, 7, 1, 0, 0, tzinfo=timezone.utc),
30-
datetime(1991, 1, 1, 0, 0, tzinfo=timezone.utc),
31-
datetime(1990, 1, 1, 0, 0, tzinfo=timezone.utc),
32-
datetime(1988, 1, 1, 0, 0, tzinfo=timezone.utc),
33-
datetime(1985, 7, 1, 0, 0, tzinfo=timezone.utc),
34-
datetime(1983, 7, 1, 0, 0, tzinfo=timezone.utc),
35-
datetime(1982, 7, 1, 0, 0, tzinfo=timezone.utc),
36-
datetime(1981, 7, 1, 0, 0, tzinfo=timezone.utc),
37-
GPS_EPOCH_0]
20+
datetime(2015, 7, 1, 0, 0, tzinfo=timezone.utc),
21+
datetime(2012, 7, 1, 0, 0, tzinfo=timezone.utc),
22+
datetime(2009, 1, 1, 0, 0, tzinfo=timezone.utc),
23+
datetime(2006, 1, 1, 0, 0, tzinfo=timezone.utc),
24+
datetime(1999, 1, 1, 0, 0, tzinfo=timezone.utc),
25+
datetime(1997, 7, 1, 0, 0, tzinfo=timezone.utc),
26+
datetime(1996, 1, 1, 0, 0, tzinfo=timezone.utc),
27+
datetime(1994, 7, 1, 0, 0, tzinfo=timezone.utc),
28+
datetime(1993, 7, 1, 0, 0, tzinfo=timezone.utc),
29+
datetime(1992, 7, 1, 0, 0, tzinfo=timezone.utc),
30+
datetime(1991, 1, 1, 0, 0, tzinfo=timezone.utc),
31+
datetime(1990, 1, 1, 0, 0, tzinfo=timezone.utc),
32+
datetime(1988, 1, 1, 0, 0, tzinfo=timezone.utc),
33+
datetime(1985, 7, 1, 0, 0, tzinfo=timezone.utc),
34+
datetime(1983, 7, 1, 0, 0, tzinfo=timezone.utc),
35+
datetime(1982, 7, 1, 0, 0, tzinfo=timezone.utc),
36+
datetime(1981, 7, 1, 0, 0, tzinfo=timezone.utc),
37+
GPS_EPOCH_0]
3838

3939
def get_leap_seconds(gps_time):
4040
"""Compute leap seconds to be added in time conversions.

notebooks/tutorials/algorithms.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"source": [
3333
"# load Android Google Challenge data\n",
3434
"!wget https://raw.githubusercontent.com/Stanford-NavLab/gnss_lib_py/main/data/unit_test/Pixel4XL_derived.csv --quiet -O \"Pixel4XL_derived.csv\"\n",
35-
"derived_data = AndroidDerived2021(\"Pixel4XL_derived.csv\", remove_bad_measures=False)"
35+
"derived_data = AndroidDerived2021(\"Pixel4XL_derived.csv\", remove_timing_outliers=False)"
3636
]
3737
},
3838
{

notebooks/tutorials/parsers.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"\n",
5555
"In this case, the data is filtered to be seconds apart, in the regular\n",
5656
"setting, such measurements would be removed. To prevent this from happening,\n",
57-
"we use the remove_bad_measures flag here. For the full dataset, set this flag to True"
57+
"we use the remove_timing_outliers flag here. For the full dataset, set this flag to True"
5858
]
5959
},
6060
{
@@ -67,7 +67,7 @@
6767
"# download Android data file\n",
6868
"!wget https://raw.githubusercontent.com/Stanford-NavLab/gnss_lib_py/main/data/unit_test/Pixel4XL_derived.csv --quiet -O \"Pixel4XL_derived.csv\"\n",
6969
"# load Android Google Challenge data\n",
70-
"derived_data = AndroidDerived2021(\"Pixel4XL_derived.csv\", remove_bad_measures=False)"
70+
"derived_data = AndroidDerived2021(\"Pixel4XL_derived.csv\", remove_timing_outliers=False)"
7171
]
7272
},
7373
{

notebooks/tutorials/utilities.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"metadata": {},
2424
"outputs": [],
2525
"source": [
26-
"from datetime import datetime\n",
26+
"from datetime import datetime, timezone\n",
2727
"from gnss_lib_py.utils.time_conversions import datetime_to_tow"
2828
]
2929
},
@@ -42,7 +42,7 @@
4242
"metadata": {},
4343
"outputs": [],
4444
"source": [
45-
"time_now = datetime.now()\n",
45+
"time_now = datetime.now(tz=timezone.utc)\n",
4646
"time_now"
4747
]
4848
},
@@ -96,7 +96,7 @@
9696
"\n",
9797
"# load Android Google Challenge data\n",
9898
"!wget https://raw.githubusercontent.com/Stanford-NavLab/gnss_lib_py/main/data/unit_test/Pixel4XL_derived.csv --quiet -O \"Pixel4XL_derived.csv\"\n",
99-
"derived_data = AndroidDerived2021(\"Pixel4XL_derived.csv\", remove_bad_measures=False)"
99+
"derived_data = AndroidDerived2021(\"Pixel4XL_derived.csv\", remove_timing_outliers=False)"
100100
]
101101
},
102102
{

0 commit comments

Comments
 (0)