-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.Rhistory
More file actions
369 lines (369 loc) · 12.2 KB
/
Copy path.Rhistory
File metadata and controls
369 lines (369 loc) · 12.2 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
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
h1 <- hist(Metrics$CH)
options(rstudio.help.showDataPreview = FALSE) # Prevent bug
rm(list=ls()) # clean workspace
# setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) # Set working directory to the current file
# PLANT PARAM PATH
path_wheat <- "Wheat.xml"
# SET HERE YOUR PYTHON3 PATH
# path_python3 <- "/home/mdago/anaconda3/envs/CPB/bin/python3"
path_python3 <- "/home/mdago/anaconda3/envs/CPB2/bin/python3"
# PYTHON SCRIPTS PATH
path_CPB <- "python_files/"
# R SCRIPTS PATH
path_R_functions <- "R Functions/"
#==========================================================================
libs <- c("fmsb", "SciViews", "pander", "visreg", "readxl", "EnvStats", "FactoMineR", "factoextra", "knitr", "data.table", "reticulate", "xml2", "tidyverse", "dplyr", "plyr", "viridis", "Hmisc", "ggplot2", "gridExtra", "ggpubr","cowplot", "stats", "emmeans")
# "riot"
#==========================================================================
for(pk in libs) {
if (!requireNamespace(pk, quietly = TRUE)) {
# If not installed, install the package
install.packages(pk)
}
library(pk, character.only = T)
}
#==========================================================================
fct <- list.files(path_R_functions, pattern = ".R")
for(i in fct){
# print(paste0("R Functions/", i))
source(paste0(path_R_functions, i))
}
#==========================================================================
# source("My_Neural_Network_functions.R")
files <- list.files(path = "data/LiDAR_Metrics/", pattern = ".csv")
LiDAR_metrics <- data.frame()
for(i in files){
print(i)
date_i <- as.Date(strsplit(i, split = "_")[[1]][1], format="%Y%m%d")
file_i <- read.csv(paste0("data/LiDAR_Metrics/", i))
file_i$date <- date_i
LiDAR_metrics <- rbind(LiDAR_metrics, file_i)
}
BBCH <- data.frame(date = unique(LiDAR_metrics$date),
BBCH = c(28, 33, 36, 61, 76, 87, 90))
Days <- data.frame(date = unique(LiDAR_metrics$date),
day = as.numeric(as.Date(unique(LiDAR_metrics$date)) - as.Date("2020-11-16")))
LiDAR_metrics <- inner_join(LiDAR_metrics, BBCH, by = "date")
# Read tables
BBCH2 <- read_excel(path = "data/myCKA.xlsx", sheet = "BBCH")
Biomass <- read_excel(path = "data/myCKA.xlsx", sheet = "biomass")
BBCH_scale <- read.csv("data/BBCH_scale.csv")
coords = read.csv("test/Test.csv") # Load the csv
#==============================================================================
result_map <- ggplot(data = coords) +
geom_point(aes(x = X, y = Y, color = Z), size = 0.01) +
coord_fixed() +
scale_color_viridis() +
theme_test()
#==============================================================================
result_map
source("R Functions/Extract_Metrics.R")
Metrics <- Extract_Metrics(coords, gridsize = 20, method = "max") # Extract CH and GF
source("R Functions/Extract_Metrics.R")
Metrics <- Extract_Metrics(coords, gridsize = 20, method = "max") # Extract CH and GF
h1 <- hist(Metrics$CH)
h1
plot(h1)
h1
h1 <- hist(Metrics$CH)
ggplot(data = Metrics) +
geom_histogram(mapping = CH)
ggplot(data = Metrics) +
geom_histogram(mapping = Metrics$CH)
ggplot(data = Metrics) +
geom_histogram(aes(mapping = Metrics$CH))
ggplot(data = Metrics) +
geom_histogram(aes(x = Metrics$CH))
ggplot(data = Metrics) +
geom_histogram(aes(x = Metrics$CH)) +
theme_bw()
ggplot(data = Metrics) +
geom_histogram(aes(x = Metrics$CH)) +
xlab("Crop Height") +
ylab("Count") +
theme_bw()
ggplot(data = Metrics) +
geom_histogram(aes(x = Metrics$CH)) +
xlab("Crop Height") +
ylab("Count") +
ggtitle("Crop Height DIstribution") +
theme_bw()
h1 <- ggplot(data = Metrics) +
geom_histogram(aes(x = Metrics$CH)) +
xlab("Crop Height") +
ylab("Count") +
ggtitle("Crop Height Distribution") +
theme_bw()
h1 <- ggplot(data = Metrics) +
geom_histogram(aes(x = Metrics$GF)) +
xlab("Gap Fraction") +
ylab("Count") +
ggtitle("Gap Fraction Distribution") +
theme_bw()
plot_grid(h1, h2, h3)
h1 <- ggplot(data = Metrics) +
geom_histogram(aes(x = Metrics$CH)) +
xlab("Crop Height") +
ylab("Count") +
ggtitle("Crop Height Distribution") +
theme_bw()
h2 <- ggplot(data = Metrics) +
geom_histogram(aes(x = Metrics$GF)) +
xlab("Gap Fraction") +
ylab("Count") +
ggtitle("Gap Fraction Distribution") +
theme_bw()
h3 <- ggplot(data = Metrics) +
geom_histogram(aes(x = Metrics$GF)) +
xlab("Density") +
ylab("Count") +
ggtitle("Denstity Distribution") +
theme_bw()
plot_grid(h1, h2, h3)
h1 <- ggplot(data = Metrics) +
geom_histogram(aes(x = CH), bins = 20) +
xlab("Crop Height") +
ylab("Count") +
ggtitle("Crop Height Distribution") +
theme_bw()
h1
h1 <- ggplot(data = Metrics) +
geom_histogram(aes(x = CH), bins = 20) +
xlab("Crop Height") +
ylab("Count") +
ggtitle("Crop Height Distribution") +
theme_bw()
h2 <- ggplot(data = Metrics) +
geom_histogram(aes(x = GF), bins = 20) +
xlab("Gap Fraction") +
ylab("Count") +
ggtitle("Gap Fraction Distribution") +
theme_bw()
h3 <- ggplot(data = Metrics) +
geom_histogram(aes(x = GF), bins = 20) +
xlab("Density") +
ylab("Count") +
ggtitle("Denstity Distribution") +
theme_bw()
plot_grid(h1, h2, h3)
Grid_density <- ggplot(data = Metrics) +
geom_tile(aes(x = X, y = Y, fill = Density)) +
scale_color_viridis() +
scale_fill_viridis() +
coord_fixed() +
theme_test()
plot_grid(Grid_density, Grid_GF, Grid_CH)
Grid_GF <- ggplot(data = Metrics) +
geom_tile(aes(x = X, y = Y, fill = GF)) +
scale_color_viridis() +
scale_fill_viridis() +
coord_fixed() +
theme_test()
Grid_CH <- ggplot(data = Metrics) +
geom_tile(aes(x = X, y = Y, fill = CH)) +
scale_color_viridis() +
scale_fill_viridis() +
coord_fixed() +
theme_test()
plot_grid(Grid_density, Grid_GF, Grid_CH)
ggplot(data = GF_Layers) +
geom_tile(aes(x = X, y = Y, fill = GF)) +
scale_color_viridis() +
scale_fill_viridis() +
facet_wrap(~layer) +
coord_fixed() +
theme_test()
biom <- ggplot(data = Biomass) +
geom_line(aes(x = Date, y = Value, color = Organ)) +
# geom_smooth(aes(x = Date, y = Value, color = Organ)) +
facet_wrap(~Type) +
theme_test()
plot_grid(biom, bbch)
options(rstudio.help.showDataPreview = FALSE) # Prevent bug
rm(list=ls()) # clean workspace
# setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) # Set working directory to the current file
# PLANT PARAM PATH
path_wheat <- "Wheat.xml"
# SET HERE YOUR PYTHON3 PATH
# path_python3 <- "/home/mdago/anaconda3/envs/CPB/bin/python3"
path_python3 <- "/home/mdago/anaconda3/envs/CPB2/bin/python3"
# PYTHON SCRIPTS PATH
path_CPB <- "python_files/"
# R SCRIPTS PATH
path_R_functions <- "R Functions/"
#==========================================================================
libs <- c("fmsb", "SciViews", "pander", "visreg", "readxl", "EnvStats", "FactoMineR", "factoextra", "knitr", "data.table", "reticulate", "xml2", "tidyverse", "dplyr", "plyr", "viridis", "Hmisc", "ggplot2", "gridExtra", "ggpubr","cowplot", "stats", "emmeans")
# "riot"
#==========================================================================
for(pk in libs) {
if (!requireNamespace(pk, quietly = TRUE)) {
# If not installed, install the package
install.packages(pk)
}
library(pk, character.only = T)
}
#==========================================================================
fct <- list.files(path_R_functions, pattern = ".R")
for(i in fct){
# print(paste0("R Functions/", i))
source(paste0(path_R_functions, i))
}
#==========================================================================
# source("My_Neural_Network_functions.R")
files <- list.files(path = "data/LiDAR_Metrics/", pattern = ".csv")
LiDAR_metrics <- data.frame()
for(i in files){
print(i)
date_i <- as.Date(strsplit(i, split = "_")[[1]][1], format="%Y%m%d")
file_i <- read.csv(paste0("data/LiDAR_Metrics/", i))
file_i$date <- date_i
LiDAR_metrics <- rbind(LiDAR_metrics, file_i)
}
BBCH <- data.frame(date = unique(LiDAR_metrics$date),
BBCH = c(28, 33, 36, 61, 76, 87, 90))
Days <- data.frame(date = unique(LiDAR_metrics$date),
day = as.numeric(as.Date(unique(LiDAR_metrics$date)) - as.Date("2020-11-16")))
LiDAR_metrics <- inner_join(LiDAR_metrics, BBCH, by = "date")
# Read tables
BBCH2 <- read_excel(path = "data/myCKA.xlsx", sheet = "BBCH")
Biomass <- read_excel(path = "data/myCKA.xlsx", sheet = "biomass")
BBCH_scale <- read.csv("data/BBCH_scale.csv")
biom <- ggplot(data = Biomass) +
geom_line(aes(x = Date, y = Value, color = Organ)) +
# geom_smooth(aes(x = Date, y = Value, color = Organ)) +
facet_wrap(~Type) +
theme_test()
bbch <- ggplot(data = BBCH2) +
geom_line(aes(x = Date, y = BBCH)) +
theme_test()
plot_grid(biom, bbch)
plot_grid(biom, bbch, align = "v")
plot_grid(biom, bbch, align = "h")
plot_grid(biom, bbch, ncol = 1)
#==========================================================================
libs <- c("fmsb", "SciViews", "pander", "visreg", "readxl", "EnvStats", "FactoMineR", "factoextra", "knitr", "data.table", "reticulate", "xml2", "tidyverse", "dplyr", "plyr", "viridis", "Hmisc", "ggplot2", "gridExtra", "ggpubr","cowplot", "stats", "emmeans")
# "riot"
#==========================================================================
for(pk in libs) {
if (!requireNamespace(pk, quietly = TRUE)) {
# If not installed, install the package
install.packages(pk)
}
library(pk, character.only = T)
}
#==========================================================================
fct <- list.files(path_R_functions, pattern = ".R")
for(i in fct){
# print(paste0("R Functions/", i))
source(paste0(path_R_functions, i))
}
#==========================================================================
# source("My_Neural_Network_functions.R")
files <- list.files(path = "data/LiDAR_Metrics/", pattern = ".csv")
LiDAR_metrics <- data.frame()
for(i in files){
print(i)
date_i <- as.Date(strsplit(i, split = "_")[[1]][1], format="%Y%m%d")
file_i <- read.csv(paste0("data/LiDAR_Metrics/", i))
file_i$date <- date_i
LiDAR_metrics <- rbind(LiDAR_metrics, file_i)
}
BBCH <- data.frame(date = unique(LiDAR_metrics$date),
BBCH = c(28, 33, 36, 61, 76, 87, 90))
Days <- data.frame(date = unique(LiDAR_metrics$date),
day = as.numeric(as.Date(unique(LiDAR_metrics$date)) - as.Date("2020-11-16")))
LiDAR_metrics <- inner_join(LiDAR_metrics, BBCH, by = "date")
# Read tables
BBCH2 <- read_excel(path = "data/myCKA.xlsx", sheet = "BBCH")
Biomass <- read_excel(path = "data/myCKA.xlsx", sheet = "biomass")
BBCH_scale <- read.csv("data/BBCH_scale.csv")
biom <- ggplot(data = Biomass) +
geom_line(aes(x = Date, y = Value, color = Organ)) +
# geom_smooth(aes(x = Date, y = Value, color = Organ)) +
facet_wrap(~Type) +
ggtitle("Biomass per organ") +
theme_test()
bbch <- ggplot(data = BBCH2) +
geom_line(aes(x = Date, y = BBCH)) +
ggtitle("Devlopment Stages") +
theme_test()
plot_grid(biom, bbch, ncol = 1)
GF_grid <- ggplot(data = LiDAR_metrics,
aes(x = x-min(x), y = y-min(y), color = GF, fill = GF)) +
#geom_point(size = , shape = 15) +
geom_tile() +
coord_fixed() +
theme_test() +
scale_color_viridis() +
scale_fill_viridis() +
xlab("x") +
ylab("y") +
ggtitle("Gap Fraction") +
facet_wrap(~date)
CH_grid <- ggplot(data = LiDAR_metrics,
aes(x = x-min(x), y = y-min(y), color = Height, fill = Height)) +
# geom_point(size = 1, shape = 15) +
geom_tile() +
coord_fixed() +
theme_test() +
scale_color_viridis() +
scale_fill_viridis() +
xlab("x") +
ylab("y") +
ggtitle("Crop Height") +
facet_wrap(~date)
I_grid <- ggplot(data = LiDAR_metrics,
aes(x = x-min(x), y = y-min(y), color = Intensity, fill = Intensity)) +
# geom_point(size = 1, shape = 15) +
geom_tile() +
coord_fixed() +
theme_test() +
scale_color_viridis() +
scale_fill_viridis() +
xlab("x") +
ylab("y") +
ggtitle("Intensity") +
facet_wrap(~date)
plot_grid(GF_grid, CH_grid, I_grid)
plot_grid(GF_grid, CH_grid, I_grid, ncol =1)
grid.arrange(GF_grid, CH_grid, I_grid, ncol =1)
GF_grid <- ggplot(data = LiDAR_metrics,
aes(x = x-min(x), y = y-min(y), color = GF, fill = GF)) +
#geom_point(size = , shape = 15) +
geom_tile() +
coord_fixed() +
theme_test() +
scale_color_viridis() +
scale_fill_viridis() +
xlab("x") +
ylab("y") +
ggtitle("Gap Fraction") +
facet_wrap(~date)
CH_grid <- ggplot(data = LiDAR_metrics,
aes(x = x-min(x), y = y-min(y), color = Height, fill = Height)) +
# geom_point(size = 1, shape = 15) +
geom_tile() +
coord_fixed() +
theme_test() +
scale_color_viridis() +
scale_fill_viridis() +
xlab("x") +
ylab("y") +
ggtitle("Crop Height") +
facet_wrap(~date)
I_grid <- ggplot(data = LiDAR_metrics,
aes(x = x-min(x), y = y-min(y), color = Intensity, fill = Intensity)) +
# geom_point(size = 1, shape = 15) +
geom_tile() +
coord_fixed() +
theme_test() +
scale_color_viridis() +
scale_fill_viridis() +
xlab("x") +
ylab("y") +
ggtitle("Intensity") +
facet_wrap(~date)
# grid.arrange(GF_grid, CH_grid, I_grid, ncol =1)
GF_grid
CH_grid
I_grid