Skip to content

Commit

Permalink
Now deriving decimal degree format from lat/lon values; fixed warning…
Browse files Browse the repository at this point in the history
… in newer versions of Python; updated requirements.txt
  • Loading branch information
nabelekt committed Jan 7, 2021
1 parent 92dcae4 commit 087f547
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
40 changes: 38 additions & 2 deletions nmea_data_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections import namedtuple
import re
import numpy as np
# import LatLon23
import functools
print = functools.partial(print, flush=True) # Prevent print statements from buffering till end of execution

Expand Down Expand Up @@ -260,6 +261,41 @@ def backfill_datetimes(sentence_dfs, verbose=False):
df['datetime_is_interpolated'][sen_idx] = True


# Derive custom data from NMEA data
def derive_data(sentence_dfs):

for df in sentence_dfs:

if df['sentence_type'][0] == 'RMC':

# Derive decimal degree lat/lon format from NMEA DDMM.MMMMM/DDDMM.MMMMM formats
df['latitude'] = df.apply(lambda row : get_coordinate(row['lat'], row['lat_dir'], 'lat'), axis = 1)
df['longitude'] = df.apply(lambda row : get_coordinate(row['lon'], row['lon_dir'], 'lon'), axis = 1)


def get_coordinate(coord, coord_dir, coord_type):

# 'lat' is in DDMM.MMMMM format, number of decimal places is variable
# 'lon' is in DDDMM.MMMMM format, number of decimal places is variable

if coord != coord: # If is NaN
return coord

if coord_type == 'lat':
degree = float(coord[:2])
minute = float(coord[2:])
if coord_type == 'lon':
degree = float(coord[:3])
minute = float(coord[3:])

coord = degree + minute/60

if coord_dir == 'S' or coord_dir == 'W':
coord = -coord

return coord


def sentences_to_dataframes(sentence_sets):

dfs = []
Expand Down Expand Up @@ -358,7 +394,7 @@ def dfs_to_csv(sentence_dfs, input_file_path, verbose=False):
df.to_csv(filename, index=False) # Save to cwd

if verbose:
if df_idx is 0: # If this is the first df
if df_idx == 0: # If this is the first df
print(f"data from logfile '{input_file_path}' written to:")
print(" " + filename)

Expand Down Expand Up @@ -478,7 +514,7 @@ def main():
sentence_dfs = process_data_common(sentences, cycle_start='GNRMC') # Cycle starts with 'RMC' sentence
if args.backfill_datetimes:
backfill_datetimes(sentence_dfs, verbose=True)
# derive_data(sentence_dfs)
derive_data(sentence_dfs)
print("done.")

if (args.output_method == 'csv' or args.output_method == 'both'):
Expand Down
18 changes: 13 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Automatically generated by https://github.com/damnever/pigar.

# nmea_parser/data_to_db.py: 5
# nmea_data_convert/column_casting.py: 1
# nmea_data_convert/db_data_import.py: 6
# nmea_data_convert/db_utils.py: 4
SQLAlchemy == 1.3.22

# nmea_parser/nmea_parser.py: 6
# nmea_data_convert/nmea_data_convert.py: 9
numpy == 1.19.5

# nmea_data_convert/nmea_data_convert.py: 6
pandas == 1.2.0

# nmea_parser/nmea_parser.py: 1
pynmea2 == 1.15.0
# nmea_data_convert/db_data_import.py: 7
# nmea_data_convert/db_utils.py: 2,3
psycopg2_binary == 2.8.6

psycopg2-binary >= 2.8.6
# nmea_data_convert/nmea_data_convert.py: 1
pynmea2 == 1.15.0

0 comments on commit 087f547

Please sign in to comment.