script_gps.py 2.1 KB
import pandas as pd
import sys
import folium
import matplotlib.pyplot as plt
from matplotlib.dates import DayLocator, HourLocator, DateFormatter, drange 
import numpy as np
from rdp import rdp


def plot_path(df,out):
	df2	= pd.DataFrame({\
			'GPS_LATITUDE'	:list(df['GPS_LATITUDE']),\
			'GPS_LONGITUDE'	:list(df['GPS_LONGITUDE']),\
			'TIME_STAMP'	:list(df['TIME_STAMP'])\
			})

	index_with_nan = df2.index[df2.isnull().any(axis=1)]
	df2.drop(index_with_nan,0, inplace=True)
	df2.reset_index(drop = True, inplace = True)

	coordinates=np.array([np.array(df2['GPS_LATITUDE']),np.array(df2['GPS_LONGITUDE'])]).transpose()
	#coordinates=rdp(coordinates,epsilon=0.00002)
	print(coordinates.shape[0])
	_map = folium.Map(location=[coordinates[0,0],coordinates[0,1]], zoom_start=20)

	for i in range(len(coordinates)):
		folium.Marker([coordinates[i,0],coordinates[i,1]],\
		popup=str(i),\
		icon=folium.Icon(color='green')).add_to(_map)

	folium.Marker([coordinates[0,0],coordinates[0,1]],\
		popup="A",\
		icon=folium.Icon(color='green')).add_to(_map)

	folium.Marker([coordinates[coordinates.shape[0]-1,0],coordinates[coordinates.shape[0]-1,1]],\
		popup="B",\
		icon=folium.Icon(color='red')).add_to(_map)

	_map.save(out)


def plot_magnitude(df,label,unit,x=None):
	df2	= pd.DataFrame({\
			label	:list(df[label]),\
			'TIME_STAMP'	:list(df['TIME_STAMP'])\
			})
	index_with_nan = df2.index[df2.isnull().any(axis=1)]
	df2.drop(index_with_nan,0, inplace=True)
	
	df2.reset_index(drop = True, inplace = True)
	if x!=None:
		index_with_x =df2.index[df2[label]>x]
		df2.drop(index_with_x,0, inplace=True)
		df2.reset_index(drop = True, inplace = True)

	fig, ax = plt.subplots() 
	ax.plot(df2['TIME_STAMP'],df2[label]) 
	plt.xticks(np.linspace(0,df2.shape[0]-1,5,endpoint=True),fontsize=6)
	plt.ylabel(unit)
	fig.autofmt_xdate() 
	plt.title(label) 
	plt.savefig('{}.png'.format(label), format='png')
	plt.close(fig) 

input_file 	= sys.argv[1]
output_file	= sys.argv[2]

df 	= pd.read_csv(input_file)
plot_path(df,output_file)
plot_magnitude(df,"GPS_ALTITUDE","in m")
plot_magnitude(df,"GPS_SPEED","in Km/h")
plot_magnitude(df,"PID_SPEED","in km/h")