-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
103 lines (77 loc) · 2.95 KB
/
run.py
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
from DAAQS import CAMSData, OpenAQData, temporal_average, Model, StationsMap, generate_day_list
from tqdm import tqdm
import time
# Just to time the script
strt_time = time.time()
# Define variables
day = "2019-01-04"
span = 3
parameter = "pm25"
comp_with_cams = "cams"
comp_with_openaq = "openaq"
n_steps = 52
# Genrate the list of days
day_list= generate_day_list(day, step_size=2*span+1, n_steps=n_steps)
# Initialise empty list
t_A_KNN = []
t_B_KNN = []
t_C_KNN = []
t_A_PCA = []
t_B_PCA = []
t_C_PCA = []
t_A_COPOD = []
t_B_COPOD = []
t_C_COPOD = []
for day in day_list:
# Read CAMS and OPENAQ Data
c_data = CAMSData(day, span, parameter).data
o_data = OpenAQData(day, span, parameter).data
## We know that lat ranges from 0, 240 and lon ranges from 0, 479
s_A_KNN = []
s_B_KNN = []
s_C_KNN = []
s_A_PCA = []
s_B_PCA = []
s_C_PCA = []
s_A_COPOD = []
s_B_COPOD = []
s_C_COPOD = []
# Loop through all lat and lon
for index_lat in tqdm(range(1,240)):
for index_lon in range(1,479):
c_dict, o_dict = temporal_average(c_data,o_data, index_lat, index_lon )
# Initialise the model
model = Model(c_dict, o_dict)
# USE KNN
A_loc_KNN, B_loc_KNN, C_loc_KNN = model.pred_KNN(comp_with = comp_with_cams)
s_A_KNN.extend(A_loc_KNN)
s_B_KNN.extend(B_loc_KNN)
s_C_KNN.extend(C_loc_KNN)
# USE PCA
A_loc_PCA, B_loc_PCA, C_loc_PCA = model.pred_PCA(comp_with = comp_with_cams)
s_A_PCA.extend(A_loc_PCA)
s_B_PCA.extend(B_loc_PCA)
s_C_PCA.extend(C_loc_PCA)
# USE COPOD
A_loc_COPOD, B_loc_COPOD, C_loc_COPOD = model.pred_COPOD(comp_with = comp_with_cams)
s_A_COPOD.extend(A_loc_COPOD)
s_B_COPOD.extend(B_loc_COPOD)
s_C_COPOD.extend(C_loc_COPOD)
t_A_KNN.append(s_A_KNN)
t_B_KNN.append(s_B_KNN)
t_C_KNN.append(s_C_KNN)
t_A_PCA.append(s_A_PCA)
t_B_PCA.append(s_B_PCA)
t_C_PCA.append(s_C_PCA)
t_A_COPOD.append(s_A_COPOD)
t_B_COPOD.append(s_B_COPOD)
t_C_COPOD.append(s_C_COPOD)
# Generate over all plot for each methods
outlier_maps = StationsMap(t_A_KNN,t_B_KNN, t_C_KNN)
outlier_maps.generate_overall_plot("plots/overall_KNN_"+parameter+"_"+comp_with_cams+".png", "outputs/overall_KNN_"+parameter+"_"+comp_with_cams+".csv")
outlier_maps = StationsMap(t_A_PCA,t_B_PCA, t_C_PCA)
outlier_maps.generate_overall_plot("plots/overall_PCA_"+parameter+"_"+comp_with_cams+".png", "outputs/overall_PCA_"+parameter+"_"+comp_with_cams+".csv")
outlier_maps = StationsMap(t_A_COPOD,t_B_COPOD, t_C_COPOD)
outlier_maps.generate_overall_plot("plots/overall_COPOD_"+parameter+"_"+comp_with_cams+".png", "outputs/overall_COPOD_"+parameter+"_"+comp_with_cams+".csv")
# Print the total time
print(f"The total time taken by the script is {time.time()-strt_time:.3f}")