This tutorial shows how to use the NavData
class, including how to initialize instances and perform basic operations.
[1]:
import gnss_lib_py as glp
[2]:
# Get data path of example file
glp.make_dir("../data")
!wget https://raw.githubusercontent.com/Stanford-NavLab/gnss_lib_py/main/notebooks/tutorials/data/myreceiver.csv --quiet -nc -O "../data/myreceiver.csv"
data_path = "../data/myreceiver.csv"
NavData Operations
Create a NavData class from a csv file
[3]:
navdata = glp.NavData(csv_path=data_path)
print(navdata)
myTimestamp mySatId myPseudorange
0 10 10 270000001
1 10 14 270000007
2 10 7 270000004
3 10 3 270000005
4 11 10 270000002
5 11 14 270000008
6 11 7 270000003
7 11 3 270000004
Looping across a Time Row
You can use the NavData.loop_time()
method to loop over groups of data that belong to same time stamp.
[4]:
for timestamp, delta_t, navdata_subset in glp.loop_time(navdata,'myTimestamp'):
print('Current timestamp: ', timestamp)
print('Difference between current and future time step', delta_t)
print('Current group of data')
print(navdata_subset)
Current timestamp: 10
Difference between current and future time step 0
Current group of data
myTimestamp mySatId myPseudorange
0 10 10 270000001
1 10 14 270000007
2 10 7 270000004
3 10 3 270000005
Current timestamp: 11
Difference between current and future time step 1
Current group of data
myTimestamp mySatId myPseudorange
0 11 10 270000002
1 11 14 270000008
2 11 7 270000003
3 11 3 270000004
Concatenating NavData Instances
Use the glp.concat()
method to concatenate two or more NavData
instances. Each type of data is included in a row, so adding new rows with axis=0
, means adding new types of data. Concat requires that the new NavData matches the length of the existing NavData. Row concatenation assumes the same ordering within rows across both NavData instances (e.g. sorted by timestamp) and does not perform any matching/sorting itself. If the concatenating navdatas share a column name with axis=0
then concat will add a suffix to create a unique row name.
[5]:
double_navdata = glp.concat(navdata, navdata, axis=0)
double_navdata
[5]:
myTimestamp mySatId myPseudorange myTimestamp_0 mySatId_0 \
0 10 10 270000001 10 10
1 10 14 270000007 10 14
2 10 7 270000004 10 7
3 10 3 270000005 10 3
4 11 10 270000002 11 10
5 11 14 270000008 11 14
6 11 7 270000003 11 7
7 11 3 270000004 11 3
myPseudorange_0
0 270000001
1 270000007
2 270000004
3 270000005
4 270000002
5 270000008
6 270000003
7 270000004
You can also concatenate new data to existing rows with axis=1
. If the row names of the new NavData instance don’t match the row names ofthe existing NavData instance, the mismatched values will be filled with np.nan.
[6]:
glp.concat(double_navdata, navdata, axis=1)
[6]:
myTimestamp mySatId myPseudorange myTimestamp_0 mySatId_0 \
0 10 10 270000001 10.0 10.0
1 10 14 270000007 10.0 14.0
2 10 7 270000004 10.0 7.0
3 10 3 270000005 10.0 3.0
4 11 10 270000002 11.0 10.0
5 11 14 270000008 11.0 14.0
6 11 7 270000003 11.0 7.0
7 11 3 270000004 11.0 3.0
8 10 10 270000001 NaN NaN
9 10 14 270000007 NaN NaN
10 10 7 270000004 NaN NaN
11 10 3 270000005 NaN NaN
12 11 10 270000002 NaN NaN
13 11 14 270000008 NaN NaN
14 11 7 270000003 NaN NaN
15 11 3 270000004 NaN NaN
myPseudorange_0
0 270000001.0
1 270000007.0
2 270000004.0
3 270000005.0
4 270000002.0
5 270000008.0
6 270000003.0
7 270000004.0
8 NaN
9 NaN
10 NaN
11 NaN
12 NaN
13 NaN
14 NaN
15 NaN