Commit e80231667ff8bde138c7f10009b34b32e4d40db2
1 parent
f45c121f
26-01-2021 adding script.py
Showing
1 changed file
with
97 additions
and
0 deletions
Show diff stats
1 | +import pandas as pd | ||
2 | +import sys | ||
3 | +import folium | ||
4 | +import matplotlib.pyplot as plt | ||
5 | +from matplotlib.dates import DayLocator, HourLocator, DateFormatter, drange | ||
6 | +import numpy as np | ||
7 | +from rdp import rdp | ||
8 | + | ||
9 | + | ||
10 | +def plot_path(df,out): | ||
11 | + df2 = pd.DataFrame({\ | ||
12 | + 'GPS_LATITUDE' :list(df['GPS_LATITUDE']),\ | ||
13 | + 'GPS_LONGITUDE' :list(df['GPS_LONGITUDE']),\ | ||
14 | + 'TIME_STAMP' :list(df['TIME_STAMP'])\ | ||
15 | + }) | ||
16 | + | ||
17 | + index_with_nan = df2.index[df2.isnull().any(axis=1)] | ||
18 | + df2.drop(index_with_nan,0, inplace=True) | ||
19 | + df2.reset_index(drop = True, inplace = True) | ||
20 | + | ||
21 | + coordinates=np.array([np.array(df2['GPS_LATITUDE']),np.array(df2['GPS_LONGITUDE'])]).transpose() | ||
22 | + #coordinates=rdp(coordinates,epsilon=0.000005) | ||
23 | + print(coordinates.shape[0]) | ||
24 | + _map = folium.Map(location=[coordinates[0,0],coordinates[0,1]], zoom_start=20) | ||
25 | + | ||
26 | + for i in range(len(coordinates)): | ||
27 | + folium.Marker([coordinates[i,0],coordinates[i,1]],\ | ||
28 | + popup=str(i),\ | ||
29 | + icon=folium.Icon(color='green')).add_to(_map) | ||
30 | + | ||
31 | + folium.Marker([coordinates[0,0],coordinates[0,1]],\ | ||
32 | + popup="A",\ | ||
33 | + icon=folium.Icon(color='green')).add_to(_map) | ||
34 | + | ||
35 | + folium.Marker([coordinates[coordinates.shape[0]-1,0],coordinates[coordinates.shape[0]-1,1]],\ | ||
36 | + popup="B",\ | ||
37 | + icon=folium.Icon(color='red')).add_to(_map) | ||
38 | + | ||
39 | + """ | ||
40 | + _map = folium.Map(location=[df2['GPS_LATITUDE'][0],df2['GPS_LONGITUDE'][0]], zoom_start=20) | ||
41 | + | ||
42 | + for i in range(len(df2['GPS_LATITUDE'])): | ||
43 | + folium.Marker([df2['GPS_LATITUDE'][i],df2['GPS_LONGITUDE'][i]],\ | ||
44 | + popup=str(i),\ | ||
45 | + icon=folium.Icon(color='green')).add_to(_map) | ||
46 | + | ||
47 | + folium.Marker([df2['GPS_LATITUDE'][0],df2['GPS_LONGITUDE'][0]],\ | ||
48 | + popup="A",\ | ||
49 | + icon=folium.Icon(color='green')).add_to(_map) | ||
50 | + | ||
51 | + folium.Marker([df2['GPS_LATITUDE'][df2.shape[0]-1],df2['GPS_LONGITUDE'][df2.shape[0]-1]],\ | ||
52 | + popup="B",\ | ||
53 | + icon=folium.Icon(color='red')).add_to(_map) | ||
54 | + | ||
55 | + print("nbr_points = "+str(df2.shape[0])) | ||
56 | + """ | ||
57 | + """ | ||
58 | + L=[] | ||
59 | + for i in range(df2.shape[0]): | ||
60 | + L+=[[df2['GPS_LATITUDE'][i],df2['GPS_LONGITUDE'][i]]] | ||
61 | + folium.PolyLine(L, tooltip="Journey", color='red').add_to(_map) | ||
62 | + """ | ||
63 | + _map.save(out) | ||
64 | + | ||
65 | + | ||
66 | +def plot_magnitude(df,label,unit,x=None): | ||
67 | + df2 = pd.DataFrame({\ | ||
68 | + label :list(df[label]),\ | ||
69 | + 'TIME_STAMP' :list(df['TIME_STAMP'])\ | ||
70 | + }) | ||
71 | + index_with_nan = df2.index[df2.isnull().any(axis=1)] | ||
72 | + df2.drop(index_with_nan,0, inplace=True) | ||
73 | + | ||
74 | + df2.reset_index(drop = True, inplace = True) | ||
75 | + if x!=None: | ||
76 | + index_with_x =df2.index[df2[label]>x] | ||
77 | + df2.drop(index_with_x,0, inplace=True) | ||
78 | + df2.reset_index(drop = True, inplace = True) | ||
79 | + | ||
80 | + fig, ax = plt.subplots() | ||
81 | + ax.plot(df2['TIME_STAMP'],df2[label]) | ||
82 | + plt.xticks(np.linspace(0,df2.shape[0]-1,5,endpoint=True),fontsize=6) | ||
83 | + plt.ylabel(unit) | ||
84 | + fig.autofmt_xdate() | ||
85 | + plt.title(label) | ||
86 | + plt.savefig('{}.png'.format(label), format='png') | ||
87 | + plt.close(fig) | ||
88 | + | ||
89 | +input_file = sys.argv[1] | ||
90 | +output_file = sys.argv[2] | ||
91 | + | ||
92 | +df = pd.read_csv(input_file) | ||
93 | +plot_path(df,output_file) | ||
94 | +plot_magnitude(df,"GPS_ALTITUDE","in m") | ||
95 | +plot_magnitude(df,"GPS_SPEED","in m/s",100) | ||
96 | +plot_magnitude(df,"PID_SPEED","in km/h") | ||
97 | + |