-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanalysis.py
More file actions
132 lines (128 loc) · 5.42 KB
/
Copy pathanalysis.py
File metadata and controls
132 lines (128 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import os
def draw_time_series(df, directory = None, save = False):
"""Generate the time-series using seaborn tsplot
Args:
df (dataframe) : dataframe of stats generated by simulation
directory (str) : used to create a folder to save images when save = True
save (bool) : When True save the images
"""
# select relevant columns
df_time = df[df.keys()[df.keys().str.contains('hourly') & \
df.keys().str.contains('waiting') & \
~df.keys().str.contains('Depot')& \
~df.keys().str.contains('Bus')& \
~df.keys().str.contains('Wegmans-West')& \
~df.keys().str.contains('Commons-Eastbound-Wegmans-West')& \
~df.keys().str.contains('Commons-Eastbound-Commons-Westbound ')]]
# read the string of array and convert the format
df_time.fillna(0)
lengh = 0
for k in df_time.keys():
data = []
for i in df_time[k].values:
try:
length = len(np.fromstring(i, dtype=np.float, sep=' '))
data.append(np.fromstring(i, dtype=np.float, sep=' '))
except:
data.append([0]*length)
df_time[k] = data
# add model for grouping
df_time['model'] = df['model']
df_time = df_time.sort_values(by = 'model')
df_data = []
# creat a dataframe to use seaborn
for i, data in df_time.iterrows():
dict_point = {}
for k in data.keys():
if k != 'model':
for hour,obs in enumerate(data[k]):
df_data.append({'stats':k, '.5 hour':hour, 'observation': obs, 'simulation' : i, 'model' : data['model']})
tf = pd.DataFrame(df_data)
# for each column, create a time-series
for k in list(set(tf['stats'])):
tmp = tf[tf['stats'] == k]
plt.title(k)
ax = sns.tsplot(time=".5 hour", value="observation", unit = 'simulation', condition="model",data=tmp, ci=[68, 95])
if save:
if not os.path.exists(directory):
os.makedirs(directory)
plt.savefig(directory + '/' + k + '.png')
plt.show()
def draw_time_series_bus(df, directory = None, save = False):
"""Generate the time-series using seaborn tsplot
Args:
df (dataframe) : dataframe of stats generated by simulation
directory (str) : used to create a folder to save images when save = True
save (bool) : When True save the images
"""
# select relevant columns
df_time = df[df.keys()[df.keys().str.contains('hourly') & \
~df.keys().str.contains('waiting') & \
~df.keys().str.contains('Depot')& \
~df.keys().str.contains('Bus')& \
~df.keys().str.contains('Commons-Eastbound-Wegmans-West')&\
~df.keys().str.contains('Commons-Eastbound-Commons-Westbound')&\
~df.keys().str.contains('Commons-Westbound-Commons-Eastbound')
]]
# read the string of array and convert the format
df_time.fillna(0)
lengh = 0
for k in df_time.keys():
data = []
for i in df_time[k].values:
try:
length = len(np.fromstring(i, dtype=np.float, sep=' '))
data.append(np.fromstring(i, dtype=np.float, sep=' '))
except:
data.append([0]*length)
df_time[k] = data
# add model for grouping
df_time['model'] = df['model']
df_time = df_time.sort_values(by = 'model')
df_data = []
# creat a dataframe to use seaborn
for i, data in df_time.iterrows():
dict_point = {}
for k in data.keys():
if k != 'model':
for hour,obs in enumerate(data[k]):
df_data.append({'stats':k, '.5 hour':hour, 'observation': obs, 'simulation' : i, 'model' : data['model']})
tf = pd.DataFrame(df_data)
# for each column, create a time-series
for k in list(set(tf['stats'])):
tmp = tf[tf['stats'] == k]
plt.title(k)
ax = sns.tsplot(time=".5 hour", value="observation", unit = 'simulation', condition="model",data=tmp, ci=[68, 95])
if save:
if not os.path.exists(directory):
os.makedirs(directory)
plt.savefig(directory + '/' + k + '.png')
plt.show()
def draw_smore(df, directory = None, save = False):
"""Generate the smore plot using seaborn boxplot
Args:
df (dataframe) : dataframe of stats generated by simulation
directory (str) : used to create a folder to save images when save = True
save (bool) : When True save the images
"""
# select relevant columns
df_smore = df[df.keys()[~df.keys().str.contains('distance') & \
~df.keys().str.contains('hourly') & \
~df.keys().str.contains('Depot') & \
~df.keys().str.contains('iteration')&\
~df.keys().str.contains('Bus')]]
# generate boxplot for each column
df_smore = df_smore.sort_values(by = 'model')
for k in df_smore.keys():
if k != 'model':
plt.title(k)
ax = sns.boxplot(x="model", y=k, data=df_smore)
if save:
if not os.path.exists(directory):
os.makedirs(directory)
plt.savefig(directory + '/' + k + '.png')
plt.show()