-
Notifications
You must be signed in to change notification settings - Fork 1
/
kolmogorov.R
275 lines (205 loc) · 9.46 KB
/
kolmogorov.R
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#Define:
x_test <-matrix(nrow=length(filename_dati_tot), ncol=4)
y_test <-matrix(nrow=length(filename_dati_tot), ncol=4)
z_test <-matrix(nrow=length(filename_dati_tot), ncol=4)
h_test <-matrix(nrow=length(filename_dati_tot), ncol=4)
n<-0
f_cut_up <- sonic_fqc/2
f_cut_down <- 0.002014610 #outdoor 0.01048
#Here the cycle starts: it reads all the files.Inside this cycle, there is
#another for cycle that works C
for(fl in 1:length(filename_dati_tot))
{
if (fl==1) {
# Extracted data from csv using the script convert_cvs.awk.
# header=TRUE --> Essential! High performance decay for header=FALSE
data <- read.csv(filename_dati_tot[fl], header=TRUE)
dati <- read.title.time(filename_dati[fl])
mem<-dati[1]
}
if (fl!=1){
data <- read.csv(filename_dati_tot[fl], header=TRUE)
dati <- read.title.time(filename_dati[fl])
if (dati[1]!=mem) {
for(counter in (n+1):(fl-1)) {
print(counter)
data <- read.csv(filename_dati_tot[counter], header=TRUE)
info <- read.title.time(filename_dati[counter])
# Converted data (of class data.frame) into an object of class turbulence
turb <- as.turbulence(data)
turb <- set_hvel(turb) # setting horizontal velocity
turb <- set_direction(turb) # setting direction
cat(name_dir[counter],"\n")
path_output <- paste('grafici_output/', line, '/',info[1], '/con_filtro/', sep = '')
create_directory(path_output)
path_output_new<-paste(path_output, "block/", sep ='')
create_directory(path_output_new)
##Performing Kolmogorov-Smirnoff test.
##firth column: date; second : hour
##third column: d ; fourth column: p-value
#u
x_vel <- get_uvel(turb)
x <- x_vel[,1]
#Filtering
hamming <- hamming.window(length(x))
hamming <- hamming/sum(hamming)*length(x)
x <- x*hamming
fft_x<- dofft(x,sonic_fqc)
down_smooth<-LowPassfilter.data(fft_x$freq,fft_x$fft_vel,f_cut_up)
tot_smooth<-HiPassfilter.data(down_smooth$freq,down_smooth$fft_vel,f_cut_down)
x <- Re(tot_smooth$vel)/hamming
#test
x_test[counter,]<-kolm.test(x, info)
#v
y_vel <- get_vvel(turb)
y <- y_vel[,1]
#Filtering
down_smooth<-NULL
tot_smooth<-NULL
hamming <- hamming.window(length(y))
hamming <- hamming/sum(hamming)*length(y)
y <- y*hamming
fft_y<- dofft(y,sonic_fqc)
down_smooth<-LowPassfilter.data(fft_y$freq,fft_y$fft_vel,f_cut_up)
tot_smooth<-HiPassfilter.data(down_smooth$freq,down_smooth$fft_vel,f_cut_down)
y <- Re(tot_smooth$vel)/hamming
y_test[counter,]<-kolm.test(y, info)
#w
z_vel <- get_zvel(turb)
z <- z_vel[,1]
#Filtering
down_smooth<-NULL
tot_smooth<-NULL
hamming <- hamming.window(length(z))
hamming <- hamming/sum(hamming)*length(z)
z <- z*hamming
fft_z<- dofft(z,sonic_fqc)
down_smooth<-LowPassfilter.data(fft_z$freq,fft_z$fft_vel,f_cut_up)
tot_smooth<-HiPassfilter.data(down_smooth$freq,down_smooth$fft_vel,f_cut_down)
z <- Re(tot_smooth$vel)/hamming
z_test[counter,]<-kolm.test(z, info)
#h
h_vel <- get_hvel(turb)
h <- h_vel[,1]
h_test[counter,]<-kolm.test(h, info)
# Extracting blocks of 5 minutes from original dataset
dim_bl <- 300
time_stamp <- seq(from=0, to=length(z)-1)*(1/sonic_fqc)
numb <- length(z)%/%(dim_bl*sonic_fqc) # number of blocks: watch out, blocks are in
# seconds, not in 0.1s...
cat("* Number of blocks: ",numb,"\n")
#Creating matrices with 4 columns:
m.x_test <- matrix(ncol = 4 ,nrow = numb)
m.y_test <- matrix(ncol = 4 ,nrow = numb)
m.z_test <- matrix(ncol = 4 ,nrow = numb)
m.h_test <- matrix(ncol = 4 ,nrow = numb)
tempo<-info
for(block in 1:numb){
tempo[2]<-info[2] + (block-1)*0.05
m.x_test[block,] <-kolm.test.blocks(time_stamp, x, block, dim_bl, tempo)
m.y_test[block,] <-kolm.test.blocks(time_stamp, y, block, dim_bl, tempo)
m.z_test[block,] <-kolm.test.blocks(time_stamp, z, block, dim_bl, tempo)
m.h_test[block,] <-kolm.test.blocks(time_stamp, h, block, dim_bl, tempo)
}
kolm.test_plot(m.x_gauss, paste(path_output_new, info[2], "_", sep = '') ,"x")
kolm.test_plot(m.y_gauss, paste(path_output_new, info[2], "_", sep = '') ,"y")
kolm.test_plot(m.z_gauss, paste(path_output_new, info[2], "_", sep = '') ,"z")
kolm.test_plot(m.h_gauss, paste(path_output_new, info[2], "_", sep = '') ,"h")
}
kolm.test_plot(x_test[(n+1):counter, ], path_output ,"x")
kolm.test_plot(y_test[(n+1):counter, ], path_output ,"y")
kolm.test_plot(z_test[(n+1):counter, ], path_output ,"z")
kolm.test_plot(h_test[(n+1):counter, ], path_output ,"h")
n <- counter
}
if (fl==length(filename_dati_tot)) {
for(counter in (n+1):fl) {
data <- read.csv(filename_dati_tot[counter], header=TRUE)
info <- read.title.time(filename_dati[counter])
turb <- as.turbulence(data)
turb <- set_hvel(turb) # setting horizontal velocity
turb <- set_direction(turb) # setting direction
cat(name_dir[counter],"\n")
path_output <- paste('grafici_output/', line, '/',info[1], '/con_filtro/', sep = '')
create_directory(path_output)
path_output_new<-paste(path_output, "block/", sep ='')
create_directory(path_output_new)
##Performing Kolmogorov-Smirnoff test.
##firth column: date; second : hour
##third column: d ; fourth column: p-value
#u
x_vel <- get_uvel(turb)
x <- x_vel[,1]
hamming <- hamming.window(length(x))
hamming <- hamming/sum(hamming)*length(x)
x <- x*hamming
fft_x<- dofft(x,sonic_fqc)
down_smooth<-LowPassfilter.data(fft_x$freq,fft_x$fft_vel,f_cut_up)
tot_smooth<-HiPassfilter.data(down_smooth$freq,down_smooth$fft_vel,f_cut_down)
x <- Re(tot_smooth$vel)/hamming
x_test[counter,]<-kolm.test(x, info)
#v
y_vel <- get_vvel(turb)
y <- y_vel[,1]
down_smooth<-NULL
tot_smooth<-NULL
hamming <- hamming.window(length(y))
hamming <- hamming/sum(hamming)*length(y)
y <- y*hamming
fft_y<- dofft(y,sonic_fqc)
down_smooth<-LowPassfilter.data(fft_y$freq,fft_y$fft_vel,f_cut_up)
tot_smooth<-HiPassfilter.data(down_smooth$freq,down_smooth$fft_vel,f_cut_down)
y <- Re(tot_smooth$vel)/hamming
y_test[counter,]<-kolm.test(y, info)
#w
z_vel <- get_zvel(turb)
z <- z_vel[,1]
down_smooth<-NULL
tot_smooth<-NULL
hamming <- hamming.window(length(z))
hamming <- hamming/sum(hamming)*length(z)
z <- z*hamming
fft_z<- dofft(z,sonic_fqc)
down_smooth<-LowPassfilter.data(fft_z$freq,fft_z$fft_vel,f_cut_up)
tot_smooth<-HiPassfilter.data(down_smooth$freq,down_smooth$fft_vel,f_cut_down)
z <- Re(tot_smooth$vel)/hamming
z_test[counter,]<-kolm.test(z, info)
#h
h_vel <- get_hvel(turb)
h <- h_vel[,1]
h_test[counter,]<-kolm.test(h, info)
#Here there is the programme that studies the skewness and kurtosis coefficient of our data
# Extracting blocks of 5 minutes from original dataset
dim_bl <- 300
time_stamp <- seq(from=0, to=length(z)-1)*(1/sonic_fqc)
numb <- length(z)%/%(dim_bl*sonic_fqc) # number of blocks: watch out, blocks are in
# seconds, not in 0.1s...
cat("* Number of blocks: ",numb,"\n")
m.x_test <- matrix(ncol = 4 ,nrow = numb)
m.y_test <- matrix(ncol = 4 ,nrow = numb)
m.z_test <- matrix(ncol = 4 ,nrow = numb)
m.h_test <- matrix(ncol = 4 ,nrow = numb)
tempo<-info
for(block in 1:numb){
tempo[2]<-info[2] + (block-1)*0.05
m.x_test[block,] <-kolm.test.blocks(time_stamp, x, block, dim_bl, tempo)
m.y_test[block,] <-kolm.test.blocks(time_stamp, y, block, dim_bl, tempo)
m.z_test[block,] <-kolm.test.blocks(time_stamp, z, block, dim_bl, tempo)
m.h_test[block,] <-kolm.test.blocks(time_stamp, h, block, dim_bl, tempo)
}
#plot per blocchetto
kolm.test_plot(m.x_test, paste(path_output_new, info[2], "_", sep = '') ,"x")
kolm.test_plot(m.y_test, paste(path_output_new, info[2], "_", sep = '') ,"y")
kolm.test_plot(m.z_test, paste(path_output_new, info[2], "_", sep = '') ,"z")
kolm.test_plot(m.h_test, paste(path_output_new, info[2], "_", sep = '') ,"h")
}
#plot orari
kolm.test_plot(x_test[(n+1):counter, ], path_output ,"x")
kolm.test_plot(y_test[(n+1):counter, ], path_output ,"y")
kolm.test_plot(z_test[(n+1):counter, ], path_output ,"z")
kolm.test_plot(h_test[(n+1):counter, ], path_output ,"h")
n <- counter
}
mem<-dati[1]
}
}