Getting-started
Getting-started.Rmd
The cercospoRa
package estimates the proportional
progress towards a Cercospora beticola epidemic on sugarbeet.
This requires formated hourly weather data that the model recognises.
The R package epiphytoolR
contains functions which
automatically checks the weather data and returns it in the required
hourly format.
We will need to install epiphytoolR
# install stationaRy package if it is not installed
if("epiphytoolR" %in% installed.packages()[,1] == FALSE){
remotes::install_github("PaulMelloy/epiphytoolR", dependencies = TRUE)
}
library(epiphytoolR)
Next lets download some weather data using the R package
nasapower
.
# install stationaRy package if it is not installed
if("nasapower" %in% installed.packages()[,1] == FALSE){
install.packages("nasapower")
}
library(nasapower)
np <- get_power(
community = "ag",
pars = c(
"RH2M", # Relative humidity at 2 meters
"T2M", # Air temperature at 2 meters
"WS2M", # wind speed at 2 meters,
"WD2M",# wind direction at 2 meters,
"PRECTOTCORR",
"ALLSKY_SFC_SW_DWN", # short wave downward solar radiation at the earth surface
"ALLSKY_SFC_LW_DWN", # long wave downward solar radiation at the earth surface
"PS", # surface pressure
"ALLSKY_SRF_ALB" # Surface albedo
),
temporal_api = "hourly",
lonlat = c(9.916,51.41866),
dates = c("2018-02-01", "2022-12-08"),
time_standard = "UTC"
)
# set as a data.table
setDT(np)
# give the weather data a station name
np$station <- "Belgium"
# provide a wind direction standard deviation
np$WDSD <- 20
# format weather
w_beau <-
format_weather(np,
time_zone = "UTC",
temp = "T2M",
rain = "PRECTOTCORR",
YYYY = "YEAR",
MM = "MO",
DD = "DY",
hh = "HR",
rh = "RH2M",
ws = "WS2M",
wd = "WD2M",
wd_sd = "WDSD",
station = "station",
lon = "LON",
lat = "LAT"
)
calc_epidemic_onset(start = as.POSIXct("2022-04-25",tz = "UTC"),
end = as.POSIXct("2022-09-30",tz = "UTC"),
c_closure = as.POSIXct("2022-07-01",tz = "UTC"),
weather = w_beau)
Format weather station data
This is data recorded by a weather station and contributed by Facundo Ramón Ispizua Yamati and is from a sugarbeet field trial.
We will format the data so the model functions can recognise the data and won’t return errors due to inconsistencies and NAs which are common in weather data. This will require the user to think about how to replace the NAs or state default values to complete the dataset.
# format to data.table
wthr <- data.table(weathr)
# Use POSIXct formatted time.
wthr[,Time := as.POSIXct(paste0(Datum, " ",Stunde,":00"),tz = "UTC")]
# Nominate Latitude and Longitude location of the weather station.
# While not needed in cercospoRa some plant disease models will use location to
# decide the closest weather station to pull weather from
wthr[, c("lon","lat") := list(9.916,51.41866)]
# weather is hourly and will error if we don't specify a standard deviation of
# weather direction. This is intentional to force the user to decide how variable
# the wind direction data could be.
wthr[, wd_std := 20]
# remove all data after September as it contains missing data
wthr <- wthr[Datum < as.POSIXct("2022-10-01")]
# set NA wind speed values to zero
wthr[is.na(WG200),WG200 := 0]
# set NA wind direction values to 20 degrees. Wind is not important for this model
wthr[is.na(WR200),WR200 := 20]
#> Warning in `[.data.table`(wthr, is.na(WR200), `:=`(WR200, 20)): 20.000000 (type
#> 'double') at RHS position 1 taken as TRUE when assigning to type 'logical'
#> (column 10 named 'WR200')
wthr <- format_weather(wthr,
POSIXct_time = "Time",
time_zone = "UTC",
temp = "T200",
rain = "N100",
rh = "F200",
wd = "WR200",
ws = "WG200",
station = "Station",
lon = "lon",
lat = "lat",
wd_sd = "wd_std",
data_check = FALSE # this stops the function from checking for faults
)
# As the data is formatted closely enough for what is expected for the model.
# We can elect to turn the data_check off so
We can find the epidemic start date by calling the
calc_epidemic_onset()
function. This function is a wrapper
for the calc_DIV()
function which calculates the daily
infection values for both, Wolf and Racca methods.
This date is determined by the negative prognosis models to be the last day for which a epidemic is likely not to start.
cercospoRa::calc_epidemic_onset(start = as.POSIXct("2022-04-25",tz = "UTC"),
end = as.POSIXct("2022-09-30",tz = "UTC"),
c_closure = as.POSIXct("2022-07-01",tz = "UTC"),
weather = wthr)
#> [1] "2022-08-14 UTC"
calc_DIV()
will do this for all the days in the weather
data frame provided, starting at the first day, integrating over the
hourly data.
divalues <- calc_DIV(dat = wthr[times > as.POSIXct("2022-07-01")])
# we take the cumulative sum of the daily infection values to monitor the increasing
# risk of infection from cercospora
divalues[, DIV_sum := cumsum(DIV)]
divalues
#> Year Month Day DIV DIV_sum
#> <int> <int> <int> <num> <num>
#> 1: 2022 7 1 0.165500280 0.1655003
#> 2: 2022 7 2 0.063727905 0.2292282
#> 3: 2022 7 3 0.016898351 0.2461265
#> 4: 2022 7 4 0.027797511 0.2739240
#> 5: 2022 7 5 0.047537502 0.3214615
#> 6: 2022 7 6 0.060521455 0.3819830
#> 7: 2022 7 7 0.257954209 0.6399372
#> 8: 2022 7 8 0.030218730 0.6701559
#> 9: 2022 7 9 0.267514611 0.9376706
#> 10: 2022 7 10 0.078461287 1.0161318
#> 11: 2022 7 11 0.288331098 1.3044629
#> 12: 2022 7 12 0.190241937 1.4947049
#> 13: 2022 7 13 0.000000000 1.4947049
#> 14: 2022 7 14 0.000000000 1.4947049
#> 15: 2022 7 15 0.011209887 1.5059148
#> 16: 2022 7 16 0.025857077 1.5317718
#> 17: 2022 7 17 0.008908782 1.5406806
#> 18: 2022 7 18 0.009226384 1.5499070
#> 19: 2022 7 19 0.021267705 1.5711747
#> 20: 2022 7 20 0.000000000 1.5711747
#> 21: 2022 7 21 0.234356051 1.8055308
#> 22: 2022 7 22 0.170079229 1.9756100
#> 23: 2022 7 23 0.228783155 2.2043931
#> 24: 2022 7 24 0.079615278 2.2840084
#> 25: 2022 7 25 0.183973467 2.4679819
#> 26: 2022 7 26 0.121867469 2.5898494
#> 27: 2022 7 27 0.006757847 2.5966072
#> 28: 2022 7 28 0.044689818 2.6412970
#> 29: 2022 7 29 0.041666667 2.6829637
#> 30: 2022 7 30 0.462612250 3.1455759
#> 31: 2022 7 31 0.302201078 3.4477770
#> 32: 2022 8 1 0.424414009 3.8721910
#> 33: 2022 8 2 0.173996949 4.0461880
#> 34: 2022 8 3 0.117259276 4.1634473
#> 35: 2022 8 4 0.129816581 4.2932638
#> 36: 2022 8 5 0.322271402 4.6155352
#> 37: 2022 8 6 0.079180314 4.6947156
#> 38: 2022 8 7 0.027401031 4.7221166
#> 39: 2022 8 8 0.033111762 4.7552283
#> 40: 2022 8 9 0.030192336 4.7854207
#> 41: 2022 8 10 0.042301396 4.8277221
#> 42: 2022 8 11 0.024614564 4.8523366
#> 43: 2022 8 12 0.008054118 4.8603908
#> 44: 2022 8 13 0.020336547 4.8807273
#> 45: 2022 8 14 0.219406616 5.1001339
#> 46: 2022 8 15 0.188091523 5.2882254
#> 47: 2022 8 16 0.100004132 5.3882296
#> 48: 2022 8 17 0.088723334 5.4769529
#> 49: 2022 8 18 0.222953154 5.6999061
#> 50: 2022 8 19 0.000000000 5.6999061
#> 51: 2022 8 20 0.212824463 5.9127305
#> 52: 2022 8 21 0.152592502 6.0653230
#> 53: 2022 8 22 0.039150504 6.1044735
#> 54: 2022 8 23 0.000000000 6.1044735
#> 55: 2022 8 24 0.027788531 6.1322621
#> 56: 2022 8 25 0.042535976 6.1747980
#> 57: 2022 8 26 0.031571048 6.2063691
#> 58: 2022 8 27 0.307960507 6.5143296
#> 59: 2022 8 28 0.000000000 6.5143296
#> 60: 2022 8 29 0.027454171 6.5417838
#> 61: 2022 8 30 0.053477913 6.5952617
#> 62: 2022 8 31 0.062036251 6.6572979
#> 63: 2022 9 1 0.008539707 6.6658376
#> 64: 2022 9 2 0.002708646 6.6685463
#> 65: 2022 9 3 0.002535854 6.6710821
#> 66: 2022 9 4 0.010285475 6.6813676
#> 67: 2022 9 5 0.014062267 6.6954299
#> 68: 2022 9 6 0.000000000 6.6954299
#> 69: 2022 9 7 0.035162167 6.7305921
#> 70: 2022 9 8 0.464297685 7.1948897
#> 71: 2022 9 9 0.161786631 7.3566764
#> 72: 2022 9 10 0.258781180 7.6154575
#> 73: 2022 9 11 0.311252144 7.9267097
#> 74: 2022 9 12 0.107940332 8.0346500
#> 75: 2022 9 13 0.234799231 8.2694493
#> 76: 2022 9 14 0.492716973 8.7621662
#> 77: 2022 9 15 0.185762169 8.9479284
#> 78: 2022 9 16 0.039530829 8.9874592
#> 79: 2022 9 17 0.142460498 9.1299197
#> 80: 2022 9 18 0.098757913 9.2286776
#> 81: 2022 9 19 0.135678947 9.3643566
#> 82: 2022 9 20 0.150351404 9.5147080
#> 83: 2022 9 21 0.067211235 9.5819192
#> 84: 2022 9 22 0.035073466 9.6169927
#> 85: 2022 9 23 0.035956151 9.6529488
#> 86: 2022 9 24 0.127146411 9.7800952
#> 87: 2022 9 25 0.141123070 9.9212183
#> 88: 2022 9 26 0.045373086 9.9665914
#> 89: 2022 9 27 0.123789674 10.0903811
#> 90: 2022 9 28 0.067217948 10.1575990
#> 91: 2022 9 29 0.053824152 10.2114232
#> 92: 2022 9 30 0.048315601 10.2597388
#> Year Month Day DIV DIV_sum