Load gnss_lib_py
into the Python workspace
[1]:
import gnss_lib_py as glp
NMEA File Parsing
NMEA is a file standard for storing and transferring position data and GPS measurements. gnss_lib_py
has functionality for reading NMEA files and loading the data into a NavData
, which we demonstrate next.
Each NMEA sentence has a header eg. $GPGGA
which describes whether the message is propreitary or general purpose and the type of message. In this case, the message is GGA
. gnss_lib_py
currently supports GGA
and RMC
message types.
Each NMEA sentence also comes with a checksum, which may appear after the ’*’ in each sentence. In case the checksums are to be checked, pass the parameter check=True
to the Nmea
initialization.
[2]:
# download NMEA data and load it into NavData instance
glp.make_dir("../data")
!wget https://raw.githubusercontent.com/Stanford-NavLab/gnss_lib_py/main/data/unit_test/nmea/nmea_w_correct_checksum.nmea --quiet -nc -O "../data/nmea_w_correct_checksum.nmea"
# Load the NMEA file into a NavData structure
nmea_navdata = glp.Nmea('../data/nmea_w_correct_checksum.nmea')
print('Loaded NMEA data\n', nmea_navdata)
Loaded NMEA data
lat_rx_deg lon_rx_deg gps_qual num_sats horizontal_dil alt_rx_m \
0 37.423617 -122.094167 1 14 1.0 2.7
1 37.423617 -122.094167 1 14 1.0 2.7
altitude_units geo_sep geo_sep_units age_gps_data ref_station_id status \
0 M -32.64 M NaN NaN A
1 M -32.64 M NaN NaN A
vx_rx_mps heading_raw_rx_deg gps_millis heading_rx_rad
0 0.0 192.8 1.273529e+12 3.364995
1 0.0 192.8 1.273529e+12 3.364995
If the checksum is not to be checked, pass the parameter check=False
to the initialization.
[3]:
glp.make_dir("../data")
!wget https://raw.githubusercontent.com/Stanford-NavLab/gnss_lib_py/main/data/unit_test/nmea/nmea_no_checksum.nmea --quiet -nc -O "../data/nmea_w_no_checksum.nmea"
# Load the NMEA file into a NavData structure
nmea_navdata = glp.Nmea('../data/nmea_w_no_checksum.nmea', check=False)
print('Loaded NMEA data\n', nmea_navdata)
Loaded NMEA data
lat_rx_deg lon_rx_deg gps_qual num_sats horizontal_dil alt_rx_m \
0 37.423617 -122.094167 1 14 1.0 2.7
1 37.423617 -122.094167 1 14 1.0 2.7
altitude_units geo_sep geo_sep_units age_gps_data ref_station_id status \
0 M -32.64 M NaN \n A
1 M -32.64 M NaN \n A
vx_rx_mps heading_raw_rx_deg gps_millis heading_rx_rad
0 0.0 192.8 1.273529e+12 3.364995
1 0.0 192.8 1.273529e+12 3.364995
NMEA GGA and RMC sentences store latitude and longitude coordinates in a ddmm.mmmmmmm
format along with a cardinal direction like N
or W
.
By default, these coordinates are transformed into decimal degrees but the original data format can be retained in the final loaded NavData
. Also, the LLH coordinates can be transformed to ECEF coordinates.
[4]:
nmea_navdata = glp.Nmea('../data/nmea_w_correct_checksum.nmea', keep_raw=True, include_ecef=True)
print('Loaded NMEA data with raw data and ECEF coordinates\n', nmea_navdata)
Loaded NMEA data with raw data and ECEF coordinates
lat_rx_deg lon_rx_deg lat lat_dir lon lon_dir gps_qual \
0 37.423617 -122.094167 3725.417 N 12205.650 W 1
1 37.423617 -122.094167 3725.417 N 12205.650 W 1
num_sats horizontal_dil alt_rx_m ... age_gps_data ref_station_id \
0 14 1.0 2.7 ... NaN NaN
1 14 1.0 2.7 ... NaN NaN
status vx_rx_mps heading_raw_rx_deg gps_millis heading_rx_rad \
0 A 0.0 192.8 1.273529e+12 3.364995
1 A 0.0 192.8 1.273529e+12 3.364995
x_rx_m y_rx_m z_rx_m
0 -2.694584e+06 -4.296507e+06 3.854837e+06
1 -2.694584e+06 -4.296507e+06 3.854837e+06
[23 rows x 2 columns]