Skip to content

Commit

Permalink
Edit name of spore_rate paramenter and parse it as a editable parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Melloy committed Mar 8, 2021
1 parent 95aabc1 commit e73445b
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 25 deletions.
9 changes: 6 additions & 3 deletions R/one_day.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#'
#' @param daily_vals `list` of model variables which have been calculated for days prior to the `i_date`
#' @param weather_dat `data.table` of weather observations which includes the query date `i_date`
#' @param spores_per_gp_per_wet_hour
#'
#' @return a `data.table` of values generated for the day `i_date`
#'
Expand All @@ -17,7 +18,8 @@ one_day <- function(i_date,
gp_rr,
max_gp,
max_new_gp,
spore_interception_parameter) {
spore_interception_parameter,
spores_per_gp_per_wet_hour) {

# expand time to be hourly
i_time <- rep(i_date, 24) + lubridate::dhours(0:23)
Expand All @@ -28,7 +30,7 @@ one_day <- function(i_date,

# obtain summary weather for i_day
i_mean_air_temp <- mean(weather_day[, temp])
i_wet_hours <- weather_day[1, wet_hours]
i_wet_hours <- weather_day[2, wet_hours]
i_rainfall <- sum(weather_day[, rain], na.rm = TRUE)

# Start building a list of values for 'i'
Expand Down Expand Up @@ -61,7 +63,8 @@ if(any(is.na(daily_vals[["paddock"]][,sporulating_gp]))){
weather_hourly = weather_day[rain >= 0.2, ],
paddock = daily_vals[["paddock"]],
max_interception_probability = max_interception_probability,
spore_interception_parameter = spore_interception_parameter
spore_interception_parameter = spore_interception_parameter,
spores_per_gp_per_wet_hour = spores_per_gp_per_wet_hour
)
)
newly_infected_dt[, cdd_at_infection := daily_vals[["cdd"]]]
Expand Down
8 changes: 4 additions & 4 deletions R/potentially_effective_spores.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Estimate the potentially effective spore
#'
#' @param infected_source_address vector of length two giving the paddock coordinates with ascochyta infection
#' @param sporesPerInfectiveGPPerWetHour estimated number of spores produced in one hour from a single chickpea growing point
#' @param spores_per_gp_per_wet_hour estimated number of spores produced in one hour from a single chickpea growing point
#' @param max_interception_probability maximum interception probability
#' @param paddock_infected_gp integer value giving paddockInfectiveGrowingPoints at paddock coordinates
#'
#' @return a double providing the potentially infective spores at the paddock_infected_gp coordinates
#'
#' @examples
potentially_effective_spores <- function(sporesPerInfectiveGPPerWetHour,
potentially_effective_spores <- function(spores_per_gp_per_wet_hour,
max_interception_probability,
paddock_infected_gp) {

Expand All @@ -17,13 +17,13 @@ potentially_effective_spores <- function(sporesPerInfectiveGPPerWetHour,
return(0)
} else{
expected_effective_spores <-
sporesPerInfectiveGPPerWetHour *
spores_per_gp_per_wet_hour *
max_interception_probability *
paddock_infected_gp

if(expected_effective_spores < 0) {
stop("Function 'potentially_effective_spores() returning negative values\n
Check parameters sporesPerInfectiveGPPerWetHour and max_interception_probability")
Check parameters spores_per_gp_per_wet_hour and max_interception_probability")
}else{

p_e_s <-
Expand Down
6 changes: 5 additions & 1 deletion R/spores_each_wet_hour.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @param paddock data.table of paddock coordinates detailing the growing points and infections at each location
#' @param max_interception_probability double with length of one
#' @param spore_interception_parameter double with length of one
#' @param spores_per_gp_per_wet_hour Number of spores produced per sporulating growing point each wet hour.
#' Also known as the 'spore_rate'. Value is dependent on the susceptibility of the host genotype.
#' @keywords internal
#' @noRd

Expand All @@ -16,7 +18,8 @@ spores_each_wet_hour <- function(h,
weather_hourly,
paddock,
max_interception_probability,
spore_interception_parameter) {
spore_interception_parameter,
spores_per_gp_per_wet_hour) {

# obtain weather data for hour_i

Expand Down Expand Up @@ -50,6 +53,7 @@ spores_each_wet_hour <- function(h,

newly_infected_dt <-
apply(paddock_infective, 1, spores_from_1_element,
spores_per_gp_per_wet_hour = spores_per_gp_per_wet_hour,
max_interception_probability = max_interception_probability,
wind_direction_in_hour = wind_direction_in_hour,
average_wind_speed_in_hour = average_wind_speed_in_hour,
Expand Down
4 changes: 2 additions & 2 deletions R/spores_from_1_element.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' @noRd
spores_from_1_element <-
function(paddock_source,
sporesPerInfectiveGPPerWetHour = 0.15,
spores_per_gp_per_wet_hour = 0.15,
max_interception_probability,
wind_direction_in_hour,
average_wind_speed_in_hour,
Expand All @@ -37,7 +37,7 @@ spores_from_1_element <-

# this might be able to be calculated at the spread_spores level, and If statement should come first
# given that it is if == 0
spore_packets <- potentially_effective_spores(sporesPerInfectiveGPPerWetHour = sporesPerInfectiveGPPerWetHour,
spore_packets <- potentially_effective_spores(spores_per_gp_per_wet_hour = spores_per_gp_per_wet_hour,
max_interception_probability = max_interception_probability,
paddock_source["sporulating_gp"])

Expand Down
10 changes: 6 additions & 4 deletions R/trace_asco.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
#' @param initial_infection refers to initial or primary infection on seedlings,
#' resulting in the production of infected growing points
#' @param time_zone refers to time in Coordinated Universal Time (UTC)
#'
#' @param spores_per_gp_per_wet_hour Number of spores produced per sporulating growing point each wet hour.
#' Also known as the 'spore_rate'. Value is dependent on the susceptibility of the host genotype.
#'
#' @return a x y `data.frame` simulating the spread of Ascochyta blight in a
#' chickpea paddock
Expand All @@ -61,8 +62,8 @@ trace_asco <- function(weather,
time_zone = "UTC",
primary_infection_foci = "random",
primary_infection_intensity = 1,
n_foci = 1
){
n_foci = 1,
spores_per_gp_per_wet_hour = 0.5){


# check date inputs for validity -----------------------------------------
Expand Down Expand Up @@ -256,7 +257,8 @@ trace_asco <- function(weather,
gp_rr = gp_rr,
max_gp = max_gp,
max_new_gp = max_new_gp,
spore_interception_parameter = spore_interception_parameter)
spore_interception_parameter = spore_interception_parameter,
spores_per_gp_per_wet_hour = spores_per_gp_per_wet_hour)

# temporary line of code to test building of daily_vals in loop
#daily_vals_list <- day_out
Expand Down
4 changes: 2 additions & 2 deletions man/potentially_effective_spores.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tests/testthat/test-potentially_effective_spores.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ context("Estimate the potentially effective spores")

test1 <-
potentially_effective_spores(
sporesPerInfectiveGPPerWetHour = 0.15,
spores_per_gp_per_wet_hour = 0.15,
# default parameter of the model
max_interception_probability = 1,
# calculated in spread_spores and almost always 1
Expand All @@ -17,7 +17,7 @@ test_that("test1 returns zero", {

test2 <-
potentially_effective_spores(
sporesPerInfectiveGPPerWetHour = 0.15,
spores_per_gp_per_wet_hour = 0.15,
# default parameter of the model
max_interception_probability = 1,
# calculated in spread_spores and almost always 1
Expand All @@ -33,7 +33,7 @@ test_that("test2 returns in range of 0 -2", {

test3 <- sapply(rep(1, 1e5), function(x) {
potentially_effective_spores(
sporesPerInfectiveGPPerWetHour = 0.15,
spores_per_gp_per_wet_hour = 0.15,
max_interception_probability = 1,
paddock_infected_gp = x
)
Expand All @@ -50,7 +50,7 @@ test_that("test3 returns in range of 100000 iterations", {

test4 <- sapply(rep(40, 1e5), function(x) {
potentially_effective_spores(
sporesPerInfectiveGPPerWetHour = 0.15,
spores_per_gp_per_wet_hour = 0.15,
max_interception_probability = 1,
paddock_infected_gp = x
)
Expand All @@ -67,7 +67,7 @@ test_that("test3 returns in range of 100000 iterations", {
test_that("test5 returns an error", {
expect_error(
potentially_effective_spores(
sporesPerInfectiveGPPerWetHour = 0.15,
spores_per_gp_per_wet_hour = 0.15,
max_interception_probability = -1,
paddock_infected_gp = 1
)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-spores_from_1_element.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test1 <- apply(
X = paddock_infected,
MARGIN = 1,
FUN = spores_from_1_element,
sporesPerInfectiveGPPerWetHour = 0.15, # default parameter for the function
spores_per_gp_per_wet_hour = 0.15, # default parameter for the function
max_interception_probability = 1, # parameter in potentially_effective_spores defined in spread_spores
wind_direction_in_hour = w_dat[1, wd],
average_wind_speed_in_hour = w_dat[1, ws],
Expand All @@ -55,7 +55,7 @@ test2 <- apply(
X = paddock_infected,
MARGIN = 1,
FUN = spores_from_1_element,
sporesPerInfectiveGPPerWetHour = 0.15, # default parameter for the function
spores_per_gp_per_wet_hour = 0.15, # default parameter for the function
max_interception_probability = 1, # parameter in potentially_effective_spores defined in spread_spores
wind_direction_in_hour = w_dat[1, wd],
average_wind_speed_in_hour = w_dat[1, ws],
Expand All @@ -82,7 +82,7 @@ test3 <- apply(
X = paddock_infected,
MARGIN = 1,
FUN = spores_from_1_element,
sporesPerInfectiveGPPerWetHour = 0.15, # default parameter for the function
spores_per_gp_per_wet_hour = 0.15, # default parameter for the function
max_interception_probability = 1, # parameter in potentially_effective_spores defined in spread_spores
wind_direction_in_hour = w_dat[1, wd],
average_wind_speed_in_hour = w_dat[1, ws],
Expand Down Expand Up @@ -119,7 +119,7 @@ test4 <- apply(
X = paddock_infected,
MARGIN = 1,
FUN = spores_from_1_element,
sporesPerInfectiveGPPerWetHour = 0.15, # default parameter for the function
spores_per_gp_per_wet_hour = 0.15, # default parameter for the function
max_interception_probability = 1, # parameter in potentially_effective_spores defined in spread_spores
wind_direction_in_hour = w_dat[1, wd],
average_wind_speed_in_hour = w_dat[1, ws],
Expand Down

0 comments on commit e73445b

Please sign in to comment.