-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_trace_ascoRun.Rmd
372 lines (314 loc) · 10.8 KB
/
example_trace_ascoRun.Rmd
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
370
371
372
---
title: "Example_run"
author: "Vignette author"
date: "`r Sys.Date()`"
output: html_document
---
```{r load_libraries, message=FALSE}
library(ascotraceR)
library(lubridate)
library(data.table)
library(future)
library(readxl)
library(dplyr)
library(ggplot2)
library(patchwork)
```
## Aims
To validate the ascotraceR spatial model with field data.
## Experimental design
We refer to a paddock as being a spatial unit made up of 1 meter x 1 meter spatial sub-units.
A paddock measures a length of 20 meters and width of 20 meters.
There are four replicate paddocks at each site.
A quadrant refers to a 1 meter x 1 meter spatial unit inside a paddock.
The experiment was conducted at two locations, Billa Billa and Tosari, Queensland, AU.
## Billa Billa
Import Billa Billa's weather data.
```{r import_Billa_Billa_weather}
Billa_Billa <-
fread("data/2020_Billa_Billa_weather_data_ozforecast.csv")
Billa_Billa[, local_time := dmy_hm(local_time)]
```
The Billa Billa weather data needs formatting
```{r}
# specify the station coordinates of the Billa Billa weather station
Billa_Billa[, c("lat", "lon") := .(-28.1011505, 150.3307084)]
Billa_Billa <- format_weather(
x = Billa_Billa,
POSIXct_time = "local_time",
temp = "mean_daily_temp",
ws = "ws",
wd_sd = "wd_sd",
rain = "rain_mm",
wd = "wd",
station = "location",
time_zone = "Australia/Brisbane",
lon = "lon",
lat = "lat"
)
```
First we run the model based on what we discussed.
Because the model is stochastic, we'll run it 20 times and compare the average outputs.
```{r trace_asco-Billa_Billa}
billa_list <- vector(mode = "list", length = 20)
time_run_vec <-
vector(mode = "numeric", length = length(billa_list))
plan(multisession)
for (i in seq_len(20)) {
T1 <- proc.time()[[3]]
billa_list[[i]] <-
trace_asco(
weather = Billa_Billa,
paddock_length = 20,
paddock_width = 20,
initial_infection = as.POSIXct("2020-07-16"),
sowing_date = as.POSIXct("2020-06-04"),
harvest_date = as.POSIXct("2020-10-27"),
time_zone = "Australia/Brisbane",
seeding_rate = 40,
gp_rr = 0.0065,
spores_per_gp_per_wet_hour = 0.6,
#min = 0.15 - max = 0.6 (step 0.05)
latent_period_cdd = 150,
primary_inoculum_intensity = 200,
primary_infection_foci = "centre"
)
T2 <- proc.time()[[3]]
time_run_vec[i] <- sum(T2, -T1)
}
```
Average model runtime was `r mean(time_run_vec)` for `r length(billa_list)` simulations.
Inspect the severity of the paddock sub-quadrats.
```{r billa-heatmap, fig.cap="Heatmap of average infected growing points for 20 model runs for Billa Billa.", message=FALSE}
# create a single data.table object of the list output from `trace_asco()`
billa <- rbindlist(lapply(billa_list, tidy_trace), idcol = TRUE)
# create a new object of xy values scaled to match field observations with 0, 0
# at the middle rather than lower-left and add to `billa` object
xy_scaled <- CJ(-9:10, -9:10)
colnames(xy_scaled) <- c("x_scaled", "y_scaled")
xy_scaled <-
xy_scaled %>%
mutate(
quadrat = case_when(
x_scaled == 0 & y_scaled == 0 ~ "F",
x_scaled == 0 & y_scaled == 9 ~ "N9",
x_scaled == 9 & y_scaled == 9 ~ "NE9",
x_scaled == 9 & y_scaled == 0 ~ "E9",
x_scaled == 9 & y_scaled == -9 ~ "SE9",
x_scaled == 0 & y_scaled == -9 ~ "S9",
x_scaled == -9 & y_scaled == -9 ~ "SW9",
x_scaled == -9 & y_scaled == 0 ~ "W9",
x_scaled == 0 & y_scaled == 0 ~ "F",
x_scaled == 0 & y_scaled == 6 ~ "N6",
x_scaled == 6 & y_scaled == 6 ~ "NE6",
x_scaled == 6 & y_scaled == 0 ~ "E6",
x_scaled == 6 & y_scaled == -6 ~ "SE6",
x_scaled == 0 & y_scaled == -6 ~ "S6",
x_scaled == -6 & y_scaled == -6 ~ "SW6",
x_scaled == -6 & y_scaled == 0 ~ "W6",
x_scaled == 0 & y_scaled == 0 ~ "F",
x_scaled == 0 & y_scaled == 3 ~ "N3",
x_scaled == 3 & y_scaled == 3 ~ "NE3",
x_scaled == 3 & y_scaled == 0 ~ "E3",
x_scaled == 3 & y_scaled == -3 ~ "SE3",
x_scaled == 0 & y_scaled == -3 ~ "S3",
x_scaled == -3 & y_scaled == -3 ~ "SW3",
x_scaled == -3 & y_scaled == 0 ~ "W3",
TRUE ~ "other"
)
)
billa <- cbind(billa, xy_scaled)
billa_summary <-
billa %>%
filter(i_day == 145) %>%
group_by(i_date, x_scaled, y_scaled) %>%
summarise(infectious_gp = mean(infectious_gp)) %>%
ungroup()
ggplot(data = billa_summary,
aes(x = x_scaled, y = y_scaled, fill = infectious_gp)) +
geom_tile() +
scale_fill_viridis_c(option = "E",
"Infectious growing points",
direction = -1) +
labs(x = "x (m)",
y = "y (m)") +
theme_classic() +
theme(legend.position = "top") +
guides(fill = guide_colorbar(
title.position = "top",
title.hjust = 0.5,
barwidth = unit(20, "lines"),
barheight = unit(0.5, "lines")
)) +
coord_equal()
```
Plot the increase in disease over time as the proportion of infected plots.
Taking the model predictions data frame, filter only the quadrats that were surveyed, mutate it to create a column that indicates whether a quadrat is infected or not, then group by `.id` and `i_date` and calculate the percent infection as the number of infected quadrats per paddock on `i_date` as `infected / number of rows`.
```{r filter-billa-quadrats}
billa <-
billa %>%
filter(quadrat != "other") %>%
mutate(infected = if_else(infectious_gp > 0, TRUE, FALSE, NA)) %>%
group_by(i_date) %>%
summarise(p_inf = sum(infected) / n())
```
Import field observations for including in graph.
```{r import-billa-obs}
obs_dat <-
setDT(read_xlsx("data/field_experiment_data.xlsx"))
```
Create a line graph of the observed disease over time with the model prediction over layed.
The plot will display the proportion of infected quadrats on day "x".
```{r billa-proportions}
obs_billa <-
obs_dat[location == "Billa Billa", sum(infected_plants > 0) /
.N, by = .(distance, location, assessment_date, plot_number, quadrat)]
obs_billa <-
obs_billa %>%
mutate(assessment_date = as.Date(assessment_date)) %>%
group_by(assessment_date) %>%
mutate(i_perc = mean(V1))
billa_proportions <-
ggplot(obs_billa, aes(x = assessment_date, y = i_perc)) +
geom_line(aes(linetype = "Observed")) +
geom_line(
data = billa,
aes(
x = i_date,
y = p_inf,
linetype = "Model"
),
) +
labs(x = "Assessment Date", y = "Proportion of Infected Quadrats") +
theme_classic() +
theme(
legend.title = element_blank(),
legend.spacing.y = unit(0, "mm"),
panel.border = element_rect(colour = "black", fill = NA),
aspect.ratio = 1,
axis.text = element_text(colour = 1, size = 12),
legend.background = element_blank(),
legend.box.background = element_rect(colour = "black"),
legend.position = c(0.25, 0.84)
)
```
## Tosari
Import Tosari's weather data and format the time as a date object.
```{r tosari-weather-import}
Tosari <- fread("data/2020_Tosari_weather_data_ozforecast.csv")
Tosari[, local_time := dmy_hm(local_time)]
```
Pass the data through `format_weather() function from _ascotraceR_.
```{r tosari-weather-format}
# specify the station coordinates of the Billa Billa weather station
Tosari[, c("lat", "lon") := .(-27.856248, 151.447391)]
Tosari <- format_weather(
x = Tosari,
POSIXct_time = "local_time",
temp = "mean_daily_temp",
ws = "ws",
wd_sd = "wd_sd",
rain = "rain_mm",
wd = "wd",
station = "location",
time_zone = "Australia/Brisbane",
lon = "lon",
lat = "lat"
)
```
Run the model.
```{r tosari-trace-asco}
tosari_list <- vector(mode = "list", length = 20)
time_run_vec <-
vector(mode = "numeric", length = length(tosari_list))
for (i in seq_len(length(tosari_list))) {
T1 <- Sys.time()
tosari_list[[i]] <-
trace_asco(
weather = Tosari,
paddock_length = 20,
paddock_width = 20,
initial_infection = as.POSIXct("2020-07-30"),
sowing_date = as.POSIXct("2020-06-27"),
harvest_date = as.POSIXct("2020-11-05"),
time_zone = "Australia/Brisbane",
seeding_rate = 40,
gp_rr = 0.0065,
spores_per_gp_per_wet_hour = 0.6,
#min = 0.15 - max = 0.6 (step 0.05)
latent_period_cdd = 150,
primary_inoculum_intensity = 200,
primary_infection_foci = "centre"
)
T2 <- Sys.time()
time_run_vec[i] <- T2 - T1
}
```
Average model runtime was `r mean(time_run_vec)` for `r length(tosari_list)` simulations.
```{r tosari-heatmap, fig.cap="Heatmap of average infected growing points for 20 model runs for Tosari.", message=FALSE}
tosari <-
rbindlist(lapply(tosari_list, tidy_trace), idcol = TRUE)
tosari <- cbind(tosari, xy_scaled)
tosari_summary <-
tosari %>%
filter(i_day == 131) %>%
group_by(i_date, x_scaled, y_scaled) %>%
summarise(infectious_gp = mean(infectious_gp)) %>%
ungroup()
ggplot(data = tosari_summary,
aes(x = x_scaled, y = y_scaled, fill = infectious_gp)) +
geom_tile() +
scale_fill_viridis_c(option = "E",
"Infectious growing points",
direction = -1) +
labs(x = "x (m)",
y = "y (m)") +
theme_classic() +
theme(legend.position = "top") +
guides(fill = guide_colorbar(
title.position = "top",
title.hjust = 0.5,
barwidth = unit(20, "lines"),
barheight = unit(0.5, "lines")
)) +
coord_equal()
```
Import field observations data for Tosari
```{r import-tosari-obs}
obs_tosari <-
obs_dat[location == "Tosari", sum(infected_plants > 0) /
.N, by = .(distance, location, assessment_date, plot_number)]
```
Plot the increase in disease over time as the proportion of infected plots for Tosari
```{r tosari-proportions}
tosari <-
tosari %>%
filter(quadrat != "other") %>%
mutate(infected = if_else(infectious_gp > 0, TRUE, FALSE, NA)) %>%
group_by(i_date) %>%
summarise(p_inf = sum(infected, na.rm = TRUE) / n())
obs_tosari <-
obs_tosari %>%
mutate(assessment_date = as.Date(assessment_date)) %>%
group_by(assessment_date) %>%
summarise(i_perc = mean(V1))
tosari_proportions <-
ggplot(tosari, aes(x = i_date, y = p_inf)) +
geom_line(aes(linetype = "Model")) +
geom_line(data = obs_tosari,
aes(x = assessment_date, y = i_perc, linetype = "Observed")) +
labs(x = "Assessment Date", y = "Proportion of Infected Quadrats") +
theme_classic() +
theme(
legend.position = "none",
panel.border = element_rect(colour = "black", fill = NA),
aspect.ratio = 1,
axis.text = element_text(colour = 1, size = 12)
)
```
## Combind the plots of proportion over time
```{r combined-plots, fig.cap = "Observed proportion of diseased sites versus model predictions over time for, A) Billa Billa, Qld and B) Tosari, Qld. Observed data are shown with the dotted line. The model is shown with a solid line. The model line is the mean of 20 stochastic model runs."}
billa_proportions +
tosari_proportions +
plot_annotation(tag_levels = 'A')
```