From 24c17de152ab47980f91cd7b289d5b2e4d22738d Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 30 Sep 2023 06:44:16 -0400 Subject: [PATCH] Add soils (#178) * add tests for multiple random seeds. * add tests for random seeds * fix error when creating random_seeds that somehow overwrote random_seed in config list. * add tests to use quarantine_directions. * fix error in create_random_seeds function where every anthropogenic dispersal was identical. * remove unused packages from imports * add tests for temp and precip sd. * add combination of temp and precip sd correctly * Add in boolean for using data for initial pests/pathogens in soil. * add soil activation * lint and add documentation for random_seeds to pops_model function * fix notes * return correct soil_reservoirs from cpp. * add checks for weather size within r and remove check from cpp --- .Rbuildignore | 1 + DESCRIPTION | 12 +- NAMESPACE | 1 + R/RcppExports.R | 4 +- R/calibrate.R | 16 +- R/checks.R | 4 +- R/configuration.R | 73 +- R/error_messages.R | 14 + R/helpers.R | 8 +- R/pops.r | 322 ++-- R/pops_model.R | 12 +- R/pops_multirun.R | 15 +- R/validate.R | 16 +- inst/extdata/simple2x2/coefficient_sd.tif | Bin 0 -> 12550 bytes inst/include/PoPS_RcppExports.h | 8 +- man/calibrate.Rd | 313 ++-- man/pops.Rd | 322 ++-- man/pops_model.Rd | 169 +- man/pops_multirun.Rd | 322 ++-- man/validate.Rd | 313 ++-- src/RcppExports.cpp | 15 +- src/pops.cpp | 35 +- tests/testthat/test-pops.r | 1725 +++++++++++---------- 23 files changed, 1898 insertions(+), 1822 deletions(-) create mode 100644 inst/extdata/simple2x2/coefficient_sd.tif diff --git a/.Rbuildignore b/.Rbuildignore index ce0f3e27..bf477251 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -21,6 +21,7 @@ ^CHANGELOG\.md$ ^CODE_OF_CONDUCT\.md$ ^CONTRIBUTING\.md$ +^.lintr ^inst/cpp/pops-core/contributing\.md$ ^inst/cpp/pops-core/LICENSE$ diff --git a/DESCRIPTION b/DESCRIPTION index eac5327a..5ec95e1f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,21 +19,20 @@ Authors@R: comment = c(ORCID = "0000-0002-5120-5538"))) Depends: R (>= 4.0.0) Imports: - raster (>= 3.5-15), - terra (>= 1.5-17), - Rcpp (>= 0.12.19), + terra, + Rcpp, stats, foreach, parallel, doParallel, landscapemetrics, lubridate, - sp, utils, MASS, - methods, aws.s3, - Metrics + Metrics, + raster, + methods License: GPL-3 | file LICENSE BugReports: https://github.com/ncsu-landscape-dynamics/rpops/issues URL: http://www.github.com/ncsu-landscape-dynamics/rpops @@ -44,6 +43,7 @@ SystemRequirements: Suggests: testthat, rgdal, + sp, rlist, knitr, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index fd55b9a4..9b722b0d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -62,5 +62,6 @@ importFrom(terra,vect) importFrom(terra,xres) importFrom(terra,yres) importFrom(utils,read.csv) +importFrom(utils,read.table) importFrom(utils,write.csv) useDynLib(PoPS, .registration = TRUE) diff --git a/R/RcppExports.R b/R/RcppExports.R index 98a7be91..8d188761 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -1,8 +1,8 @@ # Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 -pops_model_cpp <- function(random_seed, multiple_random_seeds, random_seeds, lethal_temperature, lethal_temperature_month, infected, total_exposed, exposed, susceptible, total_populations, total_hosts, mortality_tracker, mortality, quarantine_areas, quarantine_directions, treatment_maps, treatment_dates, pesticide_duration, resistant, movements, movements_dates, temperature, survival_rates, weather_coefficient, weather_coefficient_sd, bbox, res, rows_cols, reproductive_rate, spatial_indices, season_month_start_end, frequency_config, bool_config, mortality_rate = 0.0, mortality_time_lag = 2L, start_date = "2018-01-01", end_date = "2018-12-31", treatment_method = "ratio", natural_kernel_type = "cauchy", anthropogenic_kernel_type = "cauchy", percent_natural_dispersal = 0.0, natural_distance_scale = 21, anthropogenic_distance_scale = 0.0, natural_dir = "NONE", natural_kappa = 0, anthropogenic_dir = "NONE", anthropogenic_kappa = 0, frequencies_n_config = NULL, model_type_ = "SI", latency_period = 0L, establishment_probability = 0, dispersal_percentage = 0.99, survival_rate_month = 0L, survival_rate_day = 0L, overpopulation_config = NULL, network_config = NULL, network_data_config = NULL, weather_size = 0L, weather_type = "deterministic", dispersers_to_soils_percentage = 0) { - .Call(`_PoPS_pops_model_cpp`, random_seed, multiple_random_seeds, random_seeds, lethal_temperature, lethal_temperature_month, infected, total_exposed, exposed, susceptible, total_populations, total_hosts, mortality_tracker, mortality, quarantine_areas, quarantine_directions, treatment_maps, treatment_dates, pesticide_duration, resistant, movements, movements_dates, temperature, survival_rates, weather_coefficient, weather_coefficient_sd, bbox, res, rows_cols, reproductive_rate, spatial_indices, season_month_start_end, frequency_config, bool_config, mortality_rate, mortality_time_lag, start_date, end_date, treatment_method, natural_kernel_type, anthropogenic_kernel_type, percent_natural_dispersal, natural_distance_scale, anthropogenic_distance_scale, natural_dir, natural_kappa, anthropogenic_dir, anthropogenic_kappa, frequencies_n_config, model_type_, latency_period, establishment_probability, dispersal_percentage, survival_rate_month, survival_rate_day, overpopulation_config, network_config, network_data_config, weather_size, weather_type, dispersers_to_soils_percentage) +pops_model_cpp <- function(random_seed, multiple_random_seeds, random_seeds, lethal_temperature, lethal_temperature_month, infected, total_exposed, exposed, susceptible, total_populations, total_hosts, mortality_tracker, mortality, quarantine_areas, quarantine_directions, treatment_maps, treatment_dates, pesticide_duration, resistant, movements, movements_dates, temperature, survival_rates, weather_coefficient, weather_coefficient_sd, bbox, res, rows_cols, soil_reservoirs, reproductive_rate, spatial_indices, season_month_start_end, frequency_config, bool_config, mortality_rate = 0.0, mortality_time_lag = 2L, start_date = "2018-01-01", end_date = "2018-12-31", treatment_method = "ratio", natural_kernel_type = "cauchy", anthropogenic_kernel_type = "cauchy", percent_natural_dispersal = 0.0, natural_distance_scale = 21, anthropogenic_distance_scale = 0.0, natural_dir = "NONE", natural_kappa = 0, anthropogenic_dir = "NONE", anthropogenic_kappa = 0, frequencies_n_config = NULL, model_type_ = "SI", latency_period = 0L, establishment_probability = 0, dispersal_percentage = 0.99, survival_rate_month = 0L, survival_rate_day = 0L, overpopulation_config = NULL, network_config = NULL, network_data_config = NULL, weather_size = 0L, weather_type = "deterministic", dispersers_to_soils_percentage = 0) { + .Call(`_PoPS_pops_model_cpp`, random_seed, multiple_random_seeds, random_seeds, lethal_temperature, lethal_temperature_month, infected, total_exposed, exposed, susceptible, total_populations, total_hosts, mortality_tracker, mortality, quarantine_areas, quarantine_directions, treatment_maps, treatment_dates, pesticide_duration, resistant, movements, movements_dates, temperature, survival_rates, weather_coefficient, weather_coefficient_sd, bbox, res, rows_cols, soil_reservoirs, reproductive_rate, spatial_indices, season_month_start_end, frequency_config, bool_config, mortality_rate, mortality_time_lag, start_date, end_date, treatment_method, natural_kernel_type, anthropogenic_kernel_type, percent_natural_dispersal, natural_distance_scale, anthropogenic_distance_scale, natural_dir, natural_kappa, anthropogenic_dir, anthropogenic_kappa, frequencies_n_config, model_type_, latency_period, establishment_probability, dispersal_percentage, survival_rate_month, survival_rate_day, overpopulation_config, network_config, network_data_config, weather_size, weather_type, dispersers_to_soils_percentage) } # Register entry points for exported C++ functions diff --git a/R/calibrate.R b/R/calibrate.R index 96399ea4..8526aa97 100644 --- a/R/calibrate.R +++ b/R/calibrate.R @@ -107,7 +107,8 @@ #' @importFrom lubridate interval time_length mdy %within% #' @importFrom MASS mvrnorm #' @importFrom Metrics rmse -#' @importFrom utils write.csv +#' @importFrom utils write.csv read.table read.csv +#' @importFrom methods is #' #' @return a dataframe of the variables saved and their success metrics for #' each run @@ -197,9 +198,10 @@ calibrate <- function(infected_years_file, dispersers_to_soils_percentage = 0, quarantine_directions = "", multiple_random_seeds = FALSE, - random_seeds = NULL, + file_random_seeds = NULL, use_soils = FALSE, - soil_starting_pest_file = "") { + soil_starting_pest_file = "", + start_with_soil_populations = FALSE) { # add all data to config list config <- c() @@ -290,9 +292,10 @@ calibrate <- function(infected_years_file, config$precipitation_coefficient_sd_file <- precipitation_coefficient_sd_file config$dispersers_to_soils_percentage <- dispersers_to_soils_percentage config$multiple_random_seeds <- multiple_random_seeds - config$random_seeds <- random_seeds + config$file_random_seeds <- file_random_seeds config$use_soils <- use_soils config$soil_starting_pest_file <- soil_starting_pest_file + config$start_with_soil_populations <- start_with_soil_populations # call configuration function to perform data checks and transform data into # format used in pops c++ @@ -394,6 +397,7 @@ calibrate <- function(infected_years_file, reproductive_rate = reproductive_rate, spatial_indices = config$spatial_indices, season_month_start_end = config$season_month_start_end, + soil_reservoirs = config$soil_reservoirs, mortality_rate = config$mortality_rate, mortality_time_lag = config$mortality_time_lag, start_date = config$start_date, @@ -438,8 +442,8 @@ calibrate <- function(infected_years_file, network_movement = config$network_movement, weather_size = config$weather_size, weather_type = config$weather_type, - dispersers_to_soils_percentage = config$dispersers_to_soils_percentage - ) + dispersers_to_soils_percentage = config$dispersers_to_soils_percentage, + use_soils = config$use_soils) return(data) } diff --git a/R/checks.R b/R/checks.R index 67d1507e..94e4cefe 100644 --- a/R/checks.R +++ b/R/checks.R @@ -599,8 +599,8 @@ random_seeds_file_checks <- function(x, number_of_iterations = 1) { } if (checks_passed) { - random_seeds <- read.csv(x) - if (NCOL(random_seeds) != 9 && NROW(random_seeds != number_of_iterations)) { + random_seeds <- read.table(x, sep = ",", header = TRUE) + if (base::ncol(random_seeds) != 9 || base::nrow(random_seeds) <= number_of_iterations) { checks_passed <- FALSE failed_check <- random_seeds_dimensions_error } diff --git a/R/configuration.R b/R/configuration.R index 9f4c8dc6..7763b316 100644 --- a/R/configuration.R +++ b/R/configuration.R @@ -31,12 +31,14 @@ configuration <- function(config) { } if (config$multiple_random_seeds) { - if (!is.null(config$random_seeds)) { + if (!is.null(config$file_random_seeds)) { ## check random seed file - random_seeds_file_check <- random_seeds_file_checks(config$random_seeds) + random_seeds_file_check <- random_seeds_file_checks(config$file_random_seeds) if (!random_seeds_file_check$checks_passed) { config$failure <- random_seeds_file_check$failed_check return(config) + } else { + config$random_seeds <- random_seeds_file_check$random_seeds } } else { config$random_seeds <- create_random_seeds(config$number_of_iterations) @@ -148,9 +150,9 @@ configuration <- function(config) { return(config) } - zero_matrix <- infected[[1]] - terra::values(zero_matrix) <- 0 - zero_matrix <- terra::as.matrix(zero_matrix, wide = TRUE) + zero_rast <- infected[[1]] + terra::values(zero_rast) <- 0 + zero_matrix <- terra::as.matrix(zero_rast, wide = TRUE) one_matrix <- infected[[1]] terra::values(one_matrix) <- 0 @@ -192,25 +194,33 @@ configuration <- function(config) { # check that soils raster has the same crs, resolutin, and extent. if (config$use_soils) { - if (config$function_name %in% aws_bucket_list) { - soils_check <- - secondary_raster_checks( - config$soil_starting_pest_file, infected, config$use_s3, config$bucket) - } else { - soils_check <- secondary_raster_checks(config$soil_starting_pest_file, infected) + config$soil_survival_steps <- ceiling(1 / config$dispersers_to_soils_percentage) + soil_reservoirs <- list(zero_matrix) + for (sr in 2:(config$soil_survival_steps)) { + soil_reservoirs[[sr]] <- zero_matrix } - if (soils_check$checks_passed) { - soil_pests <- soils_check$raster - config$soil_pests <- terra::as.matrix(soil_pests, wide = TRUE) - } else { - config$failure <- soils_check$failed_check - if (config$failure == file_exists_error) { - config$failure <- detailed_file_exists_error(config$soil_starting_pest_file) + if (config$start_with_soil_populations) { + if (config$function_name %in% aws_bucket_list) { + soils_check <- + secondary_raster_checks( + config$soil_starting_pest_file, infected, config$use_s3, config$bucket) + } else { + soils_check <- secondary_raster_checks(config$soil_starting_pest_file, infected) + } + if (soils_check$checks_passed) { + soil_pests <- soils_check$raster + soil_reservoirs[[config$soil_survival_steps]] <- terra::as.matrix(soil_pests, wide = TRUE) + } else { + config$failure <- soils_check$failed_check + if (config$failure == file_exists_error) { + config$failure <- detailed_file_exists_error(config$soil_starting_pest_file) + } + return(config) } - return(config) } + config$soil_reservoirs <- soil_reservoirs } else { - config$soil_pests <- zero_matrix + config$soil_reservoirs <- list(zero_matrix) } # check that survival_rates raster has the same crs, resolution, and extent @@ -365,7 +375,10 @@ configuration <- function(config) { weather_coefficient_stack <- weather_coefficient_stack * precipitation_coefficient if (config$weather_type == "probabilistic") { - weather_coefficient_sd_stack <- weather_coefficient_sd_stack * precipitation_coefficient_sd + # compute sd from combined sd of the two rasters hard coded 10 years as our current + weather_coefficient_sd_stack <- + combined_sd(temperature_coefficient_sd, precipitation_coefficient_sd, + temperature_coefficient, precipitation_coefficient, 10, 10) } } } else if (config$precip == TRUE) { @@ -419,11 +432,29 @@ configuration <- function(config) { if (config$weather == TRUE) { config$weather_size <- terra::nlyr(weather_coefficient_stack) + if (config$weather_type == "deterministic") { + if (config$number_of_time_steps > config$weather_size) { + config$failure <- weather_size_deterministic_error + return(config) + } + } + weather_coefficient <- list(terra::as.matrix(weather_coefficient_stack[[1]], wide = TRUE)) for (i in 2:terra::nlyr(weather_coefficient_stack)) { weather_coefficient[[i]] <- terra::as.matrix(weather_coefficient_stack[[i]], wide = TRUE) } + if (config$weather_type == "probabilistic") { + if (config$number_of_time_steps > config$weather_size) { + config$failure <- weather_size_probabilitic_error + return(config) + } + + if (config$weather_size != terra::nlyr(weather_coefficient_sd_stack)) { + config$failure <- weather_sd_layer_error + return(config) + } + weather_coefficient_sd <- list(terra::as.matrix(weather_coefficient_sd_stack[[1]], wide = TRUE)) for (i in 2:terra::nlyr(weather_coefficient_sd_stack)) { diff --git a/R/error_messages.R b/R/error_messages.R index 7f1e4cf0..71ad3074 100644 --- a/R/error_messages.R +++ b/R/error_messages.R @@ -146,6 +146,8 @@ infection_years_length_error <- function(num_layers_infected_years, number_of_ti success_metric_error <- "success_metric is not one of the listed options." + + initial_cond_uncert_error <- "use_initial_condition_uncertainty is TRUE but the number of layers in the infected file is not 2. This should be a raster file with 2 layers the first being the mean value and the second the @@ -160,3 +162,15 @@ random_seeds_dimensions_error <- set in the model or the number of columns does not equal the number of unique random seeds" weather_type_error <- "Weather type is not one of 'probabilistic', 'deterministic', or 'none'" + +weather_size_deterministic_error <- + "Weather coeeficient number of layers with deterministic is not equal to the total number of time + steps." + +weather_size_probabilitic_error <- + "Weather coefficient number of layers with probablisitc is not equal to the total number of time + steps annual." + +weather_sd_layer_error <- + "weather coefficient sd file number of layers not equal to number of layers in weather coefficient + file" diff --git a/R/helpers.R b/R/helpers.R index 5d56a318..b5059f1c 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -231,7 +231,7 @@ create_random_seeds <- function(n) { random_seeds <- data.frame(disperser_generation = sample(1:999999999, n, replace = FALSE), natural_dispersal = sample(1:999999999, n, replace = FALSE), - anthropogenic_dispersal = sample(1:999999999999, 1, replace = FALSE), + anthropogenic_dispersal = sample(1:999999999999, n, replace = FALSE), establishment = sample(1:999999999, n, replace = FALSE), weather = sample(1:999999999, n, replace = FALSE), movement = sample(1:999999999, n, replace = FALSE), @@ -264,3 +264,9 @@ output_from_raster_mean_and_sd <- function(x) { x2 <- suppressWarnings(terra::app(x, fun)) return(x2) } + +# Combine two standard deviation spatRasters +combined_sd <- function(v1, v2, m1, m2, n1, n2) { + (((n1 - 1) * v1 + (n2 - 1) * v2) / (n1 + n2 - 1)) + + (((n1 * n2) * (m1 - m2)^2) / ((n1 + n2) * (n1 + n2 - 1))) +} diff --git a/R/pops.r b/R/pops.r index 2e81abe0..e6d71aaf 100644 --- a/R/pops.r +++ b/R/pops.r @@ -8,198 +8,170 @@ #' a single stochastic realization of the model and is predominantly used for #' automated tests of model features. #' -#' @param infected_file Raster file with initial infections. Units for -#' infections are based on data availability and the way the units used for your -#' host file is created (e.g. percent area, # of hosts per cell, etc.). -#' @param host_file path to raster files with number of hosts and standard -#' deviation on those estimates can be based in 3 formats (a single file with -#' number of hosts, a single file with 2 layers number of hosts and standard -#' deviation, or two files 1 with number of hosts and the other with standard -#' deviation of those estimates). The units for this can be of many formats the -#' two most common that we use are either percent area (0 to 100) or # of hosts -#' in the cell. Usually depends on data available and estimation methods. -#' @param total_populations_file path to raster file with number of total -#' populations of all hosts and non-hosts. This depends on how your host data is -#' set up. If host is percent area then this should be a raster with values -#' that are 100 anywhere with host. If host file is # of hosts in a cell then -#' this should be a raster with values that are the max of the host raster any -#' where the # of hosts is greater than 0. -#' @param temp boolean that allows the use of temperature coefficients to -#' modify spread (TRUE or FALSE) -#' @param temperature_coefficient_file path to raster file with temperature -#' coefficient data for the timestep and and time period specified (e.g. if timestep -#' = week and start_date = 2017_01_01 and end_date = 2019_12_31 this file would -#' have 52 * 3 bands = 156 bands with data being weekly precipitation -#' coefficients). We convert raw precipitation values to coefficients that -#' affect the reproduction and survival of the pest all values in the raster are -#' between 0 and 1. -#' @param precip boolean that allows the use of precipitation coefficients to -#' modify spread (TRUE or FALSE) -#' @param precipitation_coefficient_file Raster file with precipitation -#' coefficient data for the timestep and time period specified (e.g. if timestep -#' = week and start_date = 2017_01_01 and end_date = 2019_12_31 this file would -#' have 52 * 3 bands = 156 bands with data being weekly precipitation -#' coefficients). We convert raw precipitation values to coefficients that -#' affect the reproduction and survival of the pest all values in the raster are -#' between 0 and 1. -#' @param time_step how often should spread occur options: ('day', 'week', 'month'). -#' @param season_month_start when does spread first start occurring in the year -#' for your pest or pathogen (integer value between 1 and 12) -#' @param season_month_end when does spread end during the year for your pest -#' or pathogen (integer value between 1 and 12) -#' @param start_date date to start the simulation with format ('YYYY_MM_DD') -#' @param end_date date to end the simulation with format ('YYYY_MM_DD') -#' @param use_lethal_temperature a boolean to answer the question: does your -#' pest or pathogen have a temperature at which it cannot survive? +#' @param infected_file Raster file with initial infections. Units for infections are based on data +#' availability and the way the units used for your host file is created (e.g. percent area, # of +#' hosts per cell, etc.). +#' @param host_file path to raster files with number of hosts and standard deviation on those +#' estimates can be based in 3 formats (a single file with number of hosts, a single file with 2 +#' layers number of hosts and standard deviation, or two files 1 with number of hosts and the other +#' with standard deviation of those estimates). The units for this can be of many formats the two +#' most common that we use are either percent area (0 to 100) or # of hosts in the cell. Usually +#' depends on data available and estimation methods. +#' @param total_populations_file path to raster file with number of total populations of all hosts +#' and non-hosts. This depends on how your host data is set up. If host is percent area then this +#' should be a raster with values that are 100 anywhere with host. If host file is # of hosts in a +#' cell then this should be a raster with values that are the max of the host raster any where the +#' # of hosts is greater than 0. +#' @param temp boolean that allows the use of temperature coefficients to modify spread #' (TRUE or FALSE) -#' @param temperature_file path to raster file with temperature data for -#' minimum temperature -#' @param lethal_temperature the temperature in degrees C at which lethal -#' temperature related mortality occurs for your pest or pathogen (-50 to 60) -#' @param lethal_temperature_month the month in which lethal temperature -#' related mortality occurs for your pest or pathogen integer value between 1 -#' and 12 -#' @param mortality_on boolean to turn host mortality on and off +#' @param temperature_coefficient_file path to raster file with temperature coefficient data for the +#' timestep and and time period specified (e.g. if timestep = week and start_date = 2017_01_01 and +#' end_date = 2019_12_31 this file would have 52 * 3 bands = 156 bands with data being weekly +#' precipitation coefficients). We convert raw precipitation values to coefficients that affect the +#' reproduction and survival of the pest all values in the raster are between 0 and 1. +#' @param precip boolean that allows the use of precipitation coefficients to modify spread #' (TRUE or FALSE) -#' @param mortality_rate rate at which mortality occurs value between 0 and 1 -#' @param mortality_time_lag time lag from infection until mortality can occur -#' in time steps integer >= 1 -#' @param mortality_frequency sets the frequency of mortality calculations occur -#' either ('year', 'month', week', 'day', 'time step', or 'every_n_steps') -#' @param mortality_frequency_n sets number of units from mortality_frequency in -#' which to run the mortality calculation if mortality_frequency is -#' 'every_n_steps'. Must be an integer >= 1. -#' @param management boolean to allow use of management (TRUE or FALSE) -#' @param treatment_dates dates in which to apply treatment list with format -#' ('YYYY_MM_DD') (needs to be the same length as treatment_file and -#' pesticide_duration) -#' @param treatments_file path to raster files with treatment data by dates. -#' Needs to be a list of files the same length as treatment_dates and -#' pesticide_duration. -#' @param treatment_method what method to use when applying treatment one of -#' ("ratio" or "all infected"). ratio removes a portion of all infected and -#' susceptibles, all infected removes all infected a portion of susceptibles. -#' @param natural_kernel_type what type of dispersal kernel should be used for -#' natural dispersal. Current dispersal kernel options are -#' ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', -#' 'hyperbolic secant', 'gamma', 'weibull', -#' 'logistic') -#' @param anthropogenic_kernel_type what type of dispersal kernel should be -#' used for anthropogenic dispersal. Current dispersal kernel options are -#' ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', -#' 'hyperbolic secant', 'gamma', 'weibull', 'logistic', 'network') -#' @param natural_dir sets the predominate direction of natural dispersal -#' usually due to wind values ('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', -#' 'NONE') -#' @param anthropogenic_dir sets the predominate direction of anthropogenic -#' dispersal usually due to human movement typically over long distances (e.g. -#' nursery trade, movement of firewood, etc..) ('N', 'NW', 'W', 'SW', 'S', -#' 'SE', 'E', 'NE', 'NONE') -#' @param pesticide_duration how long does the pestcide (herbicide, vaccine, -#' etc..) last before the host is susceptible again. If value is 0 treatment -#' is a culling (i.e. host removal) not a pesticide treatment. (needs to be the -#' same length as treatment_dates and treatment_file) -#' @param pesticide_efficacy how effictive is the pesticide at preventing the -#' disease or killing the pest (if this is 0.70 then when applied it -#' successfully treats 70 percent of the plants or animals) -#' @param random_seed sets the random seed for the simulation used for reproducibility -#' @param output_frequency sets when outputs occur either ('year', 'month', -#' 'week', 'day', 'time step', or 'every_n_steps') -#' @param output_frequency_n sets number of units from output_frequency in which -#' to export model results if mortality_frequency is 'every_n_steps'. -#' Must be an integer >= 1. -#' @param movements_file this is a csv file with columns lon_from, lat_from, -#' lon_to, lat_to, number of animals, and date. -#' @param use_movements this is a boolean to turn on use of the movement module. -#' @param latency_period How many times steps does it take to for exposed -#' populations become infected/infested. This is an integer value and must be -#' greater than 0 if model type is SEI. -#' @param model_type What type of model most represents your system. Options -#' are "SEI" (Susceptible - Exposed - Infected/Infested) or "SI" -#' (Susceptible - Infected/Infested). Default value is "SI". -#' @param parameter_means A vector of the means of the model parameters -#' (reproductive_rate, natural_dispersal_distance, percent_natural_dispersal, -#' anthropogenic_dispersal_distance, natural kappa, anthropogenic kappa, -#' network_min_distance, and network_max_distance). 1x8 vector. -#' @param parameter_cov_matrix A covariance matrix from the previous years -#' posterior parameter estimation ordered from (reproductive_rate, -#' natural_dispersal_distance, percent_natural_dispersal, -#' anthropogenic_dispersal_distance, natural kappa, anthropogenic kappa, +#' @param precipitation_coefficient_file Raster file with precipitation coefficient data for the +#' timestep and time period specified (e.g. if timestep = week and start_date = 2017_01_01 and +#' end_date = 2019_12_31 this file would have 52 * 3 bands = 156 bands with data being weekly +#' precipitation coefficients). We convert raw precipitation values to coefficients that affect the +#' reproduction and survival of the pest all values in the raster are between 0 and 1. +#' @param time_step How often should spread occur options: ('day', 'week', 'month'). +#' @param season_month_start When does spread first start occurring in the year for your pest or +#' pathogen (integer value between 1 and 12) +#' @param season_month_end When does spread end during the year for your pest +#' or pathogen (integer value between 1 and 12) +#' @param start_date Date to start the simulation with format ('YYYY_MM_DD') +#' @param end_date Date to end the simulation with format ('YYYY_MM_DD') +#' @param use_lethal_temperature A boolean to answer the question: does your pest or pathogen have +#' a temperature at which it cannot survive? (TRUE or FALSE) +#' @param temperature_file Path to raster file with temperature data for minimum temperature +#' @param lethal_temperature The temperature in degrees C at which lethal temperature related +#' mortality occurs for your pest or pathogen (-50 to 60) +#' @param lethal_temperature_month The month in which lethal temperature related mortality occurs +#' for your pest or pathogen integer value between 1 and 12 +#' @param mortality_on Boolean to turn host mortality on and off (TRUE or FALSE) +#' @param mortality_rate Rate at which mortality occurs value between 0 and 1 +#' @param mortality_time_lag Time lag from infection until mortality can occur in time steps +#' integer >= 1 +#' @param mortality_frequency Sets the frequency of mortality calculations occur either ('year', +#' 'month', week', 'day', 'time step', or 'every_n_steps') +#' @param mortality_frequency_n Sets number of units from mortality_frequency in which to run the +#' mortality calculation if mortality_frequency is 'every_n_steps'. Must be an integer >= 1. +#' @param management Boolean to allow use of management (TRUE or FALSE) +#' @param treatment_dates Dates in which to apply treatment list with format ('YYYY_MM_DD') +#' (needs to be the same length as treatment_file and pesticide_duration) +#' @param treatments_file Path to raster files with treatment data by dates. Needs to be a list of +#' files the same length as treatment_dates and pesticide_duration. +#' @param treatment_method What method to use when applying treatment one of ("ratio" or "all +#' infected"). ratio removes a portion of all infected and susceptibles, all infected removes all +#' infected a portion of susceptibles. +#' @param natural_kernel_type What type of dispersal kernel should be used for natural dispersal. +#' Current dispersal kernel options are ('Cauchy', 'exponential', 'uniform', +#' 'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic') +#' @param anthropogenic_kernel_type What type of dispersal kernel should be used for anthropogenic +#' dispersal. Current dispersal kernel options are ('cauchy', 'exponential', 'uniform', +#' 'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic', +#' 'network') +#' @param natural_dir Sets the predominate direction of natural dispersal usually due to wind values +#' ('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE') +#' @param anthropogenic_dir Sets the predominate direction of anthropogenic dispersal usually due +#' to human movement typically over long distances (e.g. nursery trade, movement of firewood, etc..) +#' ('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE') +#' @param pesticide_duration How long does the pesticide (herbicide, vaccine, etc..) last before the +#' host is susceptible again. If value is 0 treatment is a culling (i.e. host removal) not a +#' pesticide treatment. (needs to be the same length as treatment_dates and treatment_file) +#' @param pesticide_efficacy How effective is the pesticide at preventing the disease or killing the +#' pest (if this is 0.70 then when applied it successfully treats 70 percent of the plants or +#' animals). +#' @param random_seed Sets the random seed for the simulation used for reproducibility +#' @param output_frequency Sets when outputs occur either ('year', 'month', week', 'day', +#' 'time step', or 'every_n_steps') +#' @param output_frequency_n Sets number of units from output_frequency in which to export model +#' results if mortality_frequency is 'every_n_steps'. Must be an integer >= 1. +#' @param movements_file This is a csv file with columns lon_from, lat_from, lon_to, lat_to, number +#' of animals, and date. +#' @param use_movements This is a boolean to turn on use of the movement module. +#' @param latency_period How many times steps does it take to for exposed populations become +#' infected/infested. This is an integer value and must be greater than 0 if model type is SEI. +#' @param model_type What type of model most represents your system. Options are "SEI" +#' (Susceptible - Exposed - Infected/Infested) or "SI" (Susceptible - Infected/Infested). Default +#' value is "SI". +#' @param parameter_means A vector of the means of the model parameters (reproductive_rate, +#' natural_dispersal_distance, percent_natural_dispersal, anthropogenic_dispersal_distance, natural +#' kappa, anthropogenic kappa, network_min_distance, and network_max_distance). 1x8 vector. +#' @param parameter_cov_matrix A covariance matrix from the previous years posterior parameter +#' estimation ordered from (reproductive_rate, natural_dispersal_distance, +#' percent_natural_dispersal, anthropogenic_dispersal_distance, natural kappa, anthropogenic kappa, #' network_min_distance, and network_max_distance) Should be 8x8 matrix. -#' @param start_exposed Do your initial conditions start as exposed or infected -#' (only used if model_type is "SEI"). Default False. If this is TRUE need to -#' have both an infected_file (this can be a raster of all 0's) and exposed_file -#' @param generate_stochasticity Boolean to indicate whether to use -#' stochasticity in reproductive functions default is TRUE -#' @param establishment_stochasticity Boolean to indicate whether to use -#' stochasticity in establishment functions default is TRUE -#' @param movement_stochasticity Boolean to indicate whether to use -#' stochasticity in movement functions default is TRUE +#' @param start_exposed Do your initial conditions start as exposed or infected (only used if +#' model_type is "SEI"). Default False. If this is TRUE need to have both an infected_file (this +#' can be a raster of all 0's) and exposed_file +#' @param generate_stochasticity Boolean to indicate whether to use stochasticity in reproductive +#' functions default is TRUE +#' @param establishment_stochasticity Boolean to indicate whether to use stochasticity in +#' establishment functions default is TRUE +#' @param movement_stochasticity Boolean to indicate whether to use stochasticity in movement +#' functions default is TRUE #' @param dispersal_stochasticity Boolean to indicate whether to use a stochasticity in the #' dispersal kernel default is TRUE #' @param establishment_probability Threshold to determine establishment if #' establishment_stochasticity is FALSE (range 0 to 1, default = 0.5) -#' @param dispersal_percentage Percentage of dispersal used to calculate the -#' bounding box for deterministic dispersal -#' @param quarantine_areas_file path to raster file with quarantine boundaries -#' used in calculating likelihood of quarantine escape if use_quarantine is -#' TRUE -#' @param use_quarantine boolean to indicate whether or not there is a -#' quarantine area if TRUE must pass in a raster file indicating the -#' quarantine areas (default = FALSE) -#' @param quarantine_directions string with comma separated directions to include -#' in the quarantine direction analysis, e.g., 'N,E'. By default all directions -#' (N, S, E, W) are considered -#' @param use_spreadrates boolean to indicate whether or not to calculate -#' spread rates -#' @param use_overpopulation_movements boolean to indicate whether to use -#' the overpopulation pest movement module (driven by the natural kernel with -#' its scale parameter modified by a coefficient) -#' @param overpopulation_percentage percentage of occupied hosts when the cell -#' is considered to be overpopulated -#' @param leaving_percentage percentage of pests leaving an overpopulated cell -#' @param leaving_scale_coefficient coefficient to multiply scale parameter of -#' the natural kernel (if applicable) -#' @param exposed_file a file with the exposed for the current -#' @param mask Raster file used to provide a mask to remove 0's that are not -#' true negatives from comparisons (e.g. mask out lakes and oceans from statics -#' if modeling terrestrial species). This can also be used to mask out areas -#' that can't be managed in the auto_manage function. -#' @param network_filename entire file path for the network file. Used if +#' @param dispersal_percentage Percentage of dispersal used to calculate the bounding box for +#' deterministic dispersal +#' @param quarantine_areas_file Path to raster file with quarantine boundaries used in calculating +#' likelihood of quarantine escape if use_quarantine is TRUE +#' @param use_quarantine Boolean to indicate whether or not there is a quarantine area if TRUE must +#' pass in a raster file indicating the quarantine areas (default = FALSE) +#' @param quarantine_directions String with comma separated directions to include in the quarantine +#' direction analysis, e.g., 'N,E'. By default all directions (N, S, E, W) are considered +#' @param use_spreadrates Boolean to indicate whether or not to calculate spread rates +#' @param use_overpopulation_movements Boolean to indicate whether to use the overpopulation pest +#' movement module (driven by the natural kernel with its scale parameter modified by a coefficient) +#' @param overpopulation_percentage Percentage of occupied hosts when the cell is considered to be +#' overpopulated +#' @param leaving_percentage Percentage of pests leaving an overpopulated cell +#' @param leaving_scale_coefficient Coefficient to multiply scale parameter of the natural kernel +#' (if applicable) +#' @param exposed_file A file with the exposed for the current +#' @param mask Raster file used to provide a mask to remove 0's that are not true negatives from +#' comparisons (e.g. mask out lakes and oceans from statics if modeling terrestrial species). This +#' can also be used to mask out areas that can't be managed in the auto_manage function. +#' @param network_filename The entire file path for the network file. Used if #' anthropogenic_kernel_type = 'network'. -#' @param use_survival_rates boolean to indicate if the model will use survival rates to limit the +#' @param use_survival_rates Boolean to indicate if the model will use survival rates to limit the #' survival or emergence of overwintering generations. #' @param survival_rate_month What month do over wintering generations emerge. We suggest using the #' month before for this parameter as it is when the survival rates raster will be applied. -#' @param survival_rate_day what day should the survival rates be applied +#' @param survival_rate_day What day should the survival rates be applied #' @param survival_rates_file Raster file with survival rates from 0 to 1 representing the #' percentage of emergence for a cell. #' @param network_movement What movement type do you want to use in the network kernel either #' "walk", "jump", or "teleport". "walk" allows dispersing units to leave the network at any cell #' along the edge. "jump" automatically moves to the nearest node when moving through the network. #' "teleport" moves from node to node most likely used for airport and seaport networks. -#' @param use_initial_condition_uncertainty boolean to indicate whether or not to propagate and +#' @param use_initial_condition_uncertainty Boolean to indicate whether or not to propagate and #' partition uncertainty from initial conditions. If TRUE the infected_file needs to have 2 layers #' one with the mean value and one with the standard deviation. If an SEI model is used the #' exposed_file needs to have 2 layers one with the mean value and one with the standard #' deviation -#' @param use_host_uncertainty boolean to indicate whether or not to propagate and partition +#' @param use_host_uncertainty Boolean to indicate whether or not to propagate and partition #' uncertainty from host data. If TRUE the host_file needs to have 2 layers one with the mean value #' and one with the standard deviation. -#' @param weather_type string indicating how the weather data is passed in either -#' as a mean and standard deviation to represent uncertainty ("probabilistic") or as a time -#' series ("deterministic") -#' @param dispersers_to_soils_percentage range from 0 to 1 representing the percentage -#' of dispersers that fall to the soil and survive. -#' @param soil_starting_pest_file path to the raster file with the starting -#' amount of pest or pathogen. -#' @param use_soils boolean to indicate if pests establish in the soil and spread out from there. +#' @param weather_type string indicating how the weather data is passed in either as a mean and +#' standard deviation to represent uncertainty ("probabilistic") or as a time series +#' ("deterministic") +#' @param dispersers_to_soils_percentage Range from 0 to 1 representing the percentage of dispersers +#' that fall to the soil and survive. +#' @param soil_starting_pest_file path to the raster file with the starting amount of pest or +#' pathogen. +#' @param use_soils Boolean to indicate if pests establish in the soil and spread out from there. #' Typically used for soil borne pathogens. -#' @param multiple_random_seeds boolean to indicate if the model should use multiple random seeds +#' @param multiple_random_seeds Boolean to indicate if the model should use multiple random seeds #' (allows for performing uncertainty partitioning) or a single random seed (backwards #' compatibility option). Default is FALSE. -#' @param random_seeds A file path to the file with the .csv file containing random_seeds table. -#' Use a file if you are trying to recreate an exact analysis otherwise we suggest leaving the +#' @param file_random_seeds A file path to the file with the .csv file containing random_seeds +#' table. Use if you are trying to recreate an exact analysis otherwise we suggest leaving the #' default. Default is Null which draws the seed numbers for each. #' @param temperature_coefficient_sd_file Raster file with temperature coefficient standard #' deviation data for the timestep and time period specified (e.g. if timestep = week this file @@ -211,6 +183,8 @@ #' would have 52 bands with data being weekly precipitation coefficient standard deviations). We #' convert raw precipitation values to coefficients that affect the reproduction and survival of #' the pest all values in the raster are between 0 and 1. +#' @param start_with_soil_populations Boolean to indicate whether to use a starting soil pest or +#' pathogen population if TRUE then soil_starting_pest_file is required. #' #' @useDynLib PoPS, .registration = TRUE #' @importFrom terra app rast xres yres classify extract ext as.points ncol nrow project @@ -218,8 +192,8 @@ #' @importFrom Rcpp sourceCpp evalCpp #' @importFrom stats runif #' @importFrom lubridate interval time_length mdy %within% -#' @importFrom utils read.csv -#' @importFrom methods is +#' @importFrom utils read.csv read.table +#' @importFrom methods is #' @return list of infected and susceptible per year #' @export #' @@ -294,9 +268,10 @@ pops <- function(infected_file, dispersers_to_soils_percentage = 0, quarantine_directions = "", multiple_random_seeds = FALSE, - random_seeds = NULL, + file_random_seeds = NULL, use_soils = FALSE, - soil_starting_pest_file = "") { + soil_starting_pest_file = "", + start_with_soil_populations = FALSE) { config <- c() config$random_seed <- random_seed @@ -380,9 +355,10 @@ pops <- function(infected_file, config$precipitation_coefficient_sd_file <- precipitation_coefficient_sd_file config$dispersers_to_soils_percentage <- dispersers_to_soils_percentage config$multiple_random_seeds <- multiple_random_seeds - config$random_seeds <- random_seeds + config$file_random_seeds <- file_random_seeds config$use_soils <- use_soils config$soil_starting_pest_file <- soil_starting_pest_file + config$start_with_soil_populations <- start_with_soil_populations config <- configuration(config) @@ -463,6 +439,7 @@ pops <- function(infected_file, reproductive_rate = config$reproductive_rate[1], spatial_indices = config$spatial_indices, season_month_start_end = config$season_month_start_end, + soil_reservoirs = config$soil_reservoirs, mortality_rate = config$mortality_rate, mortality_time_lag = config$mortality_time_lag, start_date = config$start_date, @@ -507,7 +484,8 @@ pops <- function(infected_file, network_movement = config$network_movement, weather_size = config$weather_size, weather_type = config$weather_type, - dispersers_to_soils_percentage = config$dispersers_to_soils_percentage) + dispersers_to_soils_percentage = config$dispersers_to_soils_percentage, + use_soils = config$use_soils) return(data) } diff --git a/R/pops_model.R b/R/pops_model.R index 8b77cd15..547ca876 100644 --- a/R/pops_model.R +++ b/R/pops_model.R @@ -75,10 +75,14 @@ #' overwinter population that emerges #' @param weather_size the number of matrices in a list or layers in a raster object #' @param weather_type string indicating how the weather data is passed in either -#' as a mean and standard deviation to represent uncertainty ("probablisticc") or as a time +#' as a mean and standard deviation to represent uncertainty ("probabilistic") or as a time #' series ("deterministic") #' @param dispersers_to_soils_percentage range from 0 to 1 representing the percentage #' of dispersers that fall to the soil and survive. +#' @param soil_reservoirs list of matrices with soil pests created from soil_pest_file. +#' @param random_seeds vector of random seeds in the order of "disperser_generation", +#' "natural_dispersal", "anthropogenic_dispersal", "establishment", "weather", "movement", +#' "overpopulation", "survival_rate", "soil" #' #' @return list of vector matrices of infected and susceptible hosts per #' simulated year and associated statistics (e.g. spread rate) @@ -124,6 +128,7 @@ pops_model <- reproductive_rate, spatial_indices, season_month_start_end, + soil_reservoirs, mortality_rate = 0.0, mortality_time_lag = 2, start_date = "2018-01-01", @@ -168,7 +173,8 @@ pops_model <- network_movement = "walk", weather_size = 0, weather_type = "deterministic", - dispersers_to_soils_percentage = 0) { + dispersers_to_soils_percentage = 0, + use_soils = FALSE) { # List of overpopulation parameters of type double overpopulation_config <- c() @@ -220,6 +226,7 @@ pops_model <- bool_config$dispersal_stochasticity <- dispersal_stochasticity bool_config$use_overpopulation_movements <- use_overpopulation_movements bool_config$use_survival_rate <- use_survival_rates + bool_config$use_soils <- use_soils data <- @@ -251,6 +258,7 @@ pops_model <- bbox = bbox, res = res, rows_cols = rows_cols, + soil_reservoirs = soil_reservoirs, reproductive_rate = reproductive_rate, spatial_indices = spatial_indices, season_month_start_end = season_month_start_end, diff --git a/R/pops_multirun.R b/R/pops_multirun.R index be876c10..03c90c3f 100644 --- a/R/pops_multirun.R +++ b/R/pops_multirun.R @@ -27,7 +27,8 @@ #' @importFrom foreach registerDoSEQ %dopar% %do% #' @importFrom parallel makeCluster stopCluster detectCores #' @importFrom lubridate interval time_length mdy %within% -#' @importFrom utils write.csv +#' @importFrom utils write.csv read.table read.csv +#' @importFrom methods is #' #' @return list of infected and susceptible per year #' @export @@ -106,9 +107,10 @@ pops_multirun <- function(infected_file, dispersers_to_soils_percentage = 0, quarantine_directions = "", multiple_random_seeds = FALSE, - random_seeds = NULL, + file_random_seeds = NULL, use_soils = FALSE, - soil_starting_pest_file = "") { + soil_starting_pest_file = "", + start_with_soil_populations = FALSE) { config <- c() config$random_seed <- random_seed config$infected_file <- infected_file @@ -189,9 +191,10 @@ pops_multirun <- function(infected_file, config$precipitation_coefficient_sd_file <- precipitation_coefficient_sd_file config$dispersers_to_soils_percentage <- dispersers_to_soils_percentage config$multiple_random_seeds <- multiple_random_seeds - config$random_seeds <- random_seeds + config$file_random_seeds <- file_random_seeds config$use_soils <- use_soils config$soil_starting_pest_file <- soil_starting_pest_file + config$start_with_soil_populations <- start_with_soil_populations config <- configuration(config) @@ -286,6 +289,7 @@ pops_multirun <- function(infected_file, reproductive_rate = config$reproductive_rate, spatial_indices = config$spatial_indices, season_month_start_end = config$season_month_start_end, + soil_reservoirs = config$soil_reservoirs, mortality_rate = config$mortality_rate, mortality_time_lag = config$mortality_time_lag, start_date = config$start_date, @@ -330,7 +334,8 @@ pops_multirun <- function(infected_file, network_movement = config$network_movement, weather_size = config$weather_size, weather_type = config$weather_type, - dispersers_to_soils_percentage = config$dispersers_to_soils_percentage) + dispersers_to_soils_percentage = config$dispersers_to_soils_percentage, + use_soils = config$use_soils) run <- c() run$single_run <- data$infected diff --git a/R/validate.R b/R/validate.R index c95aa2ae..4d79789d 100644 --- a/R/validate.R +++ b/R/validate.R @@ -40,7 +40,8 @@ #' @importFrom lubridate interval time_length mdy %within% #' @importFrom MASS mvrnorm #' @importFrom Metrics rmse -#' @importFrom utils write.csv +#' @importFrom utils write.csv read.table read.csv +#' @importFrom methods is #' #' @return a data frame of statistical measures of model performance. #' @export @@ -122,9 +123,10 @@ validate <- function(infected_years_file, dispersers_to_soils_percentage = 0, quarantine_directions = "", multiple_random_seeds = FALSE, - random_seeds = NULL, + file_random_seeds = NULL, use_soils = FALSE, - soil_starting_pest_file = "") { + soil_starting_pest_file = "", + start_with_soil_populations = FALSE) { config <- c() config$infected_years_file <- infected_years_file config$infected_file <- infected_file @@ -208,9 +210,10 @@ validate <- function(infected_years_file, config$precipitation_coefficient_sd_file <- precipitation_coefficient_sd_file config$dispersers_to_soils_percentage <- dispersers_to_soils_percentage config$multiple_random_seeds <- multiple_random_seeds - config$random_seeds <- random_seeds + config$file_random_seeds <- file_random_seeds config$use_soils <- use_soils config$soil_starting_pest_file <- soil_starting_pest_file + config$start_with_soil_populations <- start_with_soil_populations config <- configuration(config) @@ -304,6 +307,7 @@ validate <- function(infected_years_file, reproductive_rate = config$reproductive_rate, spatial_indices = config$spatial_indices, season_month_start_end = config$season_month_start_end, + soil_reservoirs = config$soil_reservoirs, mortality_rate = config$mortality_rate, mortality_time_lag = config$mortality_time_lag, start_date = config$start_date, @@ -348,8 +352,8 @@ validate <- function(infected_years_file, network_movement = config$network_movement, weather_size = config$weather_size, weather_type = config$weather_type, - dispersers_to_soils_percentage = config$dispersers_to_soils_percentage - ) + dispersers_to_soils_percentage = config$dispersers_to_soils_percentage, + use_soils = config$use_soils) all_disagreement <- diff --git a/inst/extdata/simple2x2/coefficient_sd.tif b/inst/extdata/simple2x2/coefficient_sd.tif new file mode 100644 index 0000000000000000000000000000000000000000..e74e18f05aca9430b522bb430e830275931fb372 GIT binary patch literal 12550 zcmb`OQD|FL7{^bNuA8M!hFBRmi0PQP(KhFtBuz#e3~e13O)X7Uov@9pjbmuj*+$&P zgl-O^0~LG_8T4gT91fNGGz$)e4Tp;Cq2iMd6BN|?;)BnAC-+v`?wos??|i)^_v7B2 z|M%rb67COfJ#RnT!5Dj(u}F+Xpo+pHvaXIoy%&!C1CLm6d>hp5L9N#8inKM?zMf?4 zk>I#m(-qVz^U>fn??L_8y0wGr>T#&M;ru}eEkUg^=AqvCW+#h5{bL_v7cX_PcBp@c z`twGN#i8zkzDtcLdmQQssOJ}>Y+Em5cVO)WsN3Lptx|($2Ct{tnqkgQF?e4T+rXjW z!n4I{y)sp)SMnY4_<&chPRDDN>FQvjR4$agQrR0S9WNGM@QR0viTGS)`t&PsE}6(D zdz0B*^Do0iI+M!|^r^*RDI8s%y^u=DBoQ_QNBk zp>c1l>^-+(;`r>0diPV+xyjj6r|YL?YKc6&=i}Vk{yu`-oghRY3Hr?)35K`V666UJ zLD4!v;Z6`DkOckajs(NoYY7S?LD@P%=}r(LkOckajs(NoYY9pt!Bp!6Q|<&I0!h$s z?np4ay_R6gNYMT>eBbY2+MOUoAPM@-9SMfF*Ah${31(XV3})O3LIjea-`tU4czZ3u zjFDh}>jeAV2|@&tpx@k)V0e2i!G0sbEnLZMz8=iF6NCsPLBF{p!SME4f>|TMEnL)Y zCYW<42oXqvesf2H;qA2qb4G$Z+4|R*6IhALKtc@KJ5sa^pv4GlOxM*Mqb3w?5^e|U z-Ey?a%{D4f7hR0j6*Na84#0rVWrmckL5!U;S@Wnejyn2KcpJx8;v zaD=RI0$WiTSdJvVVi`cs(QGUnp)8!hSyTp=BZ;+G2GDafdkaU13nwram4W3*;x3i} z^c>Ch!V&ty3H(K6U^$W)jAZ~lN3+9lgv4+Hi%}U^jwBvq89>j`Y%(07GMvC=R0ftK ziOpCB&~r5Vj6nE|An+NLf#evpck~&{09uZ)#^f^s;WL83XH*83BZ<#g2GDaf`;0*N zj3DqCm4W3*;xm>3^c>ATBM?3#2z*9mU^$ZbjAZ~lN3+iegwF^9pHUfDjwC)~89>j` z>@x!4GlIZpR0ftKiO*OD&~r5Vj6nE|An+NLf#pczGnN7L9L+u>5I!Rad`4wpIg z5k4acd`4wpIg>Ht{wcp&+pitB?MH)kaQ{DSjBRJ?#(7o4t^3V=v~8)e8_q;_ zEH$>X-K-t{bs)mt?Pi^7zw4p4=Kjg<=MR1$)MsYT`zOw` z`RJ8D`D(`l?H9kkmpoHW?0N95p~TpY#rzXpmv2q-Gb<+s_q=oPy8{m0#Z&T#!dDee-w6+fQG;`$y{B;lx7mT4{fI`J?>D z6Q8WSoIdx{iLZ`+T4;Q5VDHXvU;5(O>c7{EpZzj@I?-y?V_3HAm+RxW-FGv3a DVxXb@ literal 0 HcmV?d00001 diff --git a/inst/include/PoPS_RcppExports.h b/inst/include/PoPS_RcppExports.h index 08eeb477..df011e15 100644 --- a/inst/include/PoPS_RcppExports.h +++ b/inst/include/PoPS_RcppExports.h @@ -24,17 +24,17 @@ namespace PoPS { } } - inline List pops_model_cpp(int random_seed, bool multiple_random_seeds, std::vector random_seeds, double lethal_temperature, int lethal_temperature_month, IntegerMatrix infected, IntegerMatrix total_exposed, std::vector exposed, IntegerMatrix susceptible, IntegerMatrix total_populations, IntegerMatrix total_hosts, std::vector mortality_tracker, IntegerMatrix mortality, IntegerMatrix quarantine_areas, std::string quarantine_directions, std::vector treatment_maps, std::vector treatment_dates, std::vector pesticide_duration, IntegerMatrix resistant, std::vector> movements, std::vector movements_dates, std::vector temperature, std::vector survival_rates, std::vector weather_coefficient, std::vector weather_coefficient_sd, List bbox, List res, List rows_cols, double reproductive_rate, std::vector> spatial_indices, List season_month_start_end, List frequency_config, List bool_config, double mortality_rate = 0.0, int mortality_time_lag = 2, std::string start_date = "2018-01-01", std::string end_date = "2018-12-31", std::string treatment_method = "ratio", std::string natural_kernel_type = "cauchy", std::string anthropogenic_kernel_type = "cauchy", double percent_natural_dispersal = 0.0, double natural_distance_scale = 21, double anthropogenic_distance_scale = 0.0, std::string natural_dir = "NONE", double natural_kappa = 0, std::string anthropogenic_dir = "NONE", double anthropogenic_kappa = 0, Nullable frequencies_n_config = R_NilValue, std::string model_type_ = "SI", int latency_period = 0, double establishment_probability = 0, double dispersal_percentage = 0.99, int survival_rate_month = 0, int survival_rate_day = 0, Nullable overpopulation_config = R_NilValue, Nullable network_config = R_NilValue, Nullable network_data_config = R_NilValue, int weather_size = 0, std::string weather_type = "deterministic", double dispersers_to_soils_percentage = 0) { - typedef SEXP(*Ptr_pops_model_cpp)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); + inline List pops_model_cpp(int random_seed, bool multiple_random_seeds, std::vector random_seeds, double lethal_temperature, int lethal_temperature_month, IntegerMatrix infected, IntegerMatrix total_exposed, std::vector exposed, IntegerMatrix susceptible, IntegerMatrix total_populations, IntegerMatrix total_hosts, std::vector mortality_tracker, IntegerMatrix mortality, IntegerMatrix quarantine_areas, std::string quarantine_directions, std::vector treatment_maps, std::vector treatment_dates, std::vector pesticide_duration, IntegerMatrix resistant, std::vector> movements, std::vector movements_dates, std::vector temperature, std::vector survival_rates, std::vector weather_coefficient, std::vector weather_coefficient_sd, List bbox, List res, List rows_cols, std::vector soil_reservoirs, double reproductive_rate, std::vector> spatial_indices, List season_month_start_end, List frequency_config, List bool_config, double mortality_rate = 0.0, int mortality_time_lag = 2, std::string start_date = "2018-01-01", std::string end_date = "2018-12-31", std::string treatment_method = "ratio", std::string natural_kernel_type = "cauchy", std::string anthropogenic_kernel_type = "cauchy", double percent_natural_dispersal = 0.0, double natural_distance_scale = 21, double anthropogenic_distance_scale = 0.0, std::string natural_dir = "NONE", double natural_kappa = 0, std::string anthropogenic_dir = "NONE", double anthropogenic_kappa = 0, Nullable frequencies_n_config = R_NilValue, std::string model_type_ = "SI", int latency_period = 0, double establishment_probability = 0, double dispersal_percentage = 0.99, int survival_rate_month = 0, int survival_rate_day = 0, Nullable overpopulation_config = R_NilValue, Nullable network_config = R_NilValue, Nullable network_data_config = R_NilValue, int weather_size = 0, std::string weather_type = "deterministic", double dispersers_to_soils_percentage = 0) { + typedef SEXP(*Ptr_pops_model_cpp)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP); static Ptr_pops_model_cpp p_pops_model_cpp = NULL; if (p_pops_model_cpp == NULL) { - validateSignature("List(*pops_model_cpp)(int,bool,std::vector,double,int,IntegerMatrix,IntegerMatrix,std::vector,IntegerMatrix,IntegerMatrix,IntegerMatrix,std::vector,IntegerMatrix,IntegerMatrix,std::string,std::vector,std::vector,std::vector,IntegerMatrix,std::vector>,std::vector,std::vector,std::vector,std::vector,std::vector,List,List,List,double,std::vector>,List,List,List,double,int,std::string,std::string,std::string,std::string,std::string,double,double,double,std::string,double,std::string,double,Nullable,std::string,int,double,double,int,int,Nullable,Nullable,Nullable,int,std::string,double)"); + validateSignature("List(*pops_model_cpp)(int,bool,std::vector,double,int,IntegerMatrix,IntegerMatrix,std::vector,IntegerMatrix,IntegerMatrix,IntegerMatrix,std::vector,IntegerMatrix,IntegerMatrix,std::string,std::vector,std::vector,std::vector,IntegerMatrix,std::vector>,std::vector,std::vector,std::vector,std::vector,std::vector,List,List,List,std::vector,double,std::vector>,List,List,List,double,int,std::string,std::string,std::string,std::string,std::string,double,double,double,std::string,double,std::string,double,Nullable,std::string,int,double,double,int,int,Nullable,Nullable,Nullable,int,std::string,double)"); p_pops_model_cpp = (Ptr_pops_model_cpp)R_GetCCallable("PoPS", "_PoPS_pops_model_cpp"); } RObject rcpp_result_gen; { RNGScope RCPP_rngScope_gen; - rcpp_result_gen = p_pops_model_cpp(Shield(Rcpp::wrap(random_seed)), Shield(Rcpp::wrap(multiple_random_seeds)), Shield(Rcpp::wrap(random_seeds)), Shield(Rcpp::wrap(lethal_temperature)), Shield(Rcpp::wrap(lethal_temperature_month)), Shield(Rcpp::wrap(infected)), Shield(Rcpp::wrap(total_exposed)), Shield(Rcpp::wrap(exposed)), Shield(Rcpp::wrap(susceptible)), Shield(Rcpp::wrap(total_populations)), Shield(Rcpp::wrap(total_hosts)), Shield(Rcpp::wrap(mortality_tracker)), Shield(Rcpp::wrap(mortality)), Shield(Rcpp::wrap(quarantine_areas)), Shield(Rcpp::wrap(quarantine_directions)), Shield(Rcpp::wrap(treatment_maps)), Shield(Rcpp::wrap(treatment_dates)), Shield(Rcpp::wrap(pesticide_duration)), Shield(Rcpp::wrap(resistant)), Shield(Rcpp::wrap(movements)), Shield(Rcpp::wrap(movements_dates)), Shield(Rcpp::wrap(temperature)), Shield(Rcpp::wrap(survival_rates)), Shield(Rcpp::wrap(weather_coefficient)), Shield(Rcpp::wrap(weather_coefficient_sd)), Shield(Rcpp::wrap(bbox)), Shield(Rcpp::wrap(res)), Shield(Rcpp::wrap(rows_cols)), Shield(Rcpp::wrap(reproductive_rate)), Shield(Rcpp::wrap(spatial_indices)), Shield(Rcpp::wrap(season_month_start_end)), Shield(Rcpp::wrap(frequency_config)), Shield(Rcpp::wrap(bool_config)), Shield(Rcpp::wrap(mortality_rate)), Shield(Rcpp::wrap(mortality_time_lag)), Shield(Rcpp::wrap(start_date)), Shield(Rcpp::wrap(end_date)), Shield(Rcpp::wrap(treatment_method)), Shield(Rcpp::wrap(natural_kernel_type)), Shield(Rcpp::wrap(anthropogenic_kernel_type)), Shield(Rcpp::wrap(percent_natural_dispersal)), Shield(Rcpp::wrap(natural_distance_scale)), Shield(Rcpp::wrap(anthropogenic_distance_scale)), Shield(Rcpp::wrap(natural_dir)), Shield(Rcpp::wrap(natural_kappa)), Shield(Rcpp::wrap(anthropogenic_dir)), Shield(Rcpp::wrap(anthropogenic_kappa)), Shield(Rcpp::wrap(frequencies_n_config)), Shield(Rcpp::wrap(model_type_)), Shield(Rcpp::wrap(latency_period)), Shield(Rcpp::wrap(establishment_probability)), Shield(Rcpp::wrap(dispersal_percentage)), Shield(Rcpp::wrap(survival_rate_month)), Shield(Rcpp::wrap(survival_rate_day)), Shield(Rcpp::wrap(overpopulation_config)), Shield(Rcpp::wrap(network_config)), Shield(Rcpp::wrap(network_data_config)), Shield(Rcpp::wrap(weather_size)), Shield(Rcpp::wrap(weather_type)), Shield(Rcpp::wrap(dispersers_to_soils_percentage))); + rcpp_result_gen = p_pops_model_cpp(Shield(Rcpp::wrap(random_seed)), Shield(Rcpp::wrap(multiple_random_seeds)), Shield(Rcpp::wrap(random_seeds)), Shield(Rcpp::wrap(lethal_temperature)), Shield(Rcpp::wrap(lethal_temperature_month)), Shield(Rcpp::wrap(infected)), Shield(Rcpp::wrap(total_exposed)), Shield(Rcpp::wrap(exposed)), Shield(Rcpp::wrap(susceptible)), Shield(Rcpp::wrap(total_populations)), Shield(Rcpp::wrap(total_hosts)), Shield(Rcpp::wrap(mortality_tracker)), Shield(Rcpp::wrap(mortality)), Shield(Rcpp::wrap(quarantine_areas)), Shield(Rcpp::wrap(quarantine_directions)), Shield(Rcpp::wrap(treatment_maps)), Shield(Rcpp::wrap(treatment_dates)), Shield(Rcpp::wrap(pesticide_duration)), Shield(Rcpp::wrap(resistant)), Shield(Rcpp::wrap(movements)), Shield(Rcpp::wrap(movements_dates)), Shield(Rcpp::wrap(temperature)), Shield(Rcpp::wrap(survival_rates)), Shield(Rcpp::wrap(weather_coefficient)), Shield(Rcpp::wrap(weather_coefficient_sd)), Shield(Rcpp::wrap(bbox)), Shield(Rcpp::wrap(res)), Shield(Rcpp::wrap(rows_cols)), Shield(Rcpp::wrap(soil_reservoirs)), Shield(Rcpp::wrap(reproductive_rate)), Shield(Rcpp::wrap(spatial_indices)), Shield(Rcpp::wrap(season_month_start_end)), Shield(Rcpp::wrap(frequency_config)), Shield(Rcpp::wrap(bool_config)), Shield(Rcpp::wrap(mortality_rate)), Shield(Rcpp::wrap(mortality_time_lag)), Shield(Rcpp::wrap(start_date)), Shield(Rcpp::wrap(end_date)), Shield(Rcpp::wrap(treatment_method)), Shield(Rcpp::wrap(natural_kernel_type)), Shield(Rcpp::wrap(anthropogenic_kernel_type)), Shield(Rcpp::wrap(percent_natural_dispersal)), Shield(Rcpp::wrap(natural_distance_scale)), Shield(Rcpp::wrap(anthropogenic_distance_scale)), Shield(Rcpp::wrap(natural_dir)), Shield(Rcpp::wrap(natural_kappa)), Shield(Rcpp::wrap(anthropogenic_dir)), Shield(Rcpp::wrap(anthropogenic_kappa)), Shield(Rcpp::wrap(frequencies_n_config)), Shield(Rcpp::wrap(model_type_)), Shield(Rcpp::wrap(latency_period)), Shield(Rcpp::wrap(establishment_probability)), Shield(Rcpp::wrap(dispersal_percentage)), Shield(Rcpp::wrap(survival_rate_month)), Shield(Rcpp::wrap(survival_rate_day)), Shield(Rcpp::wrap(overpopulation_config)), Shield(Rcpp::wrap(network_config)), Shield(Rcpp::wrap(network_data_config)), Shield(Rcpp::wrap(weather_size)), Shield(Rcpp::wrap(weather_type)), Shield(Rcpp::wrap(dispersers_to_soils_percentage))); } if (rcpp_result_gen.inherits("interrupted-error")) throw Rcpp::internal::InterruptedException(); diff --git a/man/calibrate.Rd b/man/calibrate.Rd index 6824ec48..16d1df22 100644 --- a/man/calibrate.Rd +++ b/man/calibrate.Rd @@ -88,9 +88,10 @@ calibrate( dispersers_to_soils_percentage = 0, quarantine_directions = "", multiple_random_seeds = FALSE, - random_seeds = NULL, + file_random_seeds = NULL, use_soils = FALSE, - soil_starting_pest_file = "" + soil_starting_pest_file = "", + start_with_soil_populations = FALSE ) } \arguments{ @@ -152,155 +153,136 @@ until 1,000 model runs are less than the threshold value. We recommend running at least 1,000 but the greater this number the more accurate the model parameters selected will be.} -\item{infected_file}{Raster file with initial infections. Units for -infections are based on data availability and the way the units used for your -host file is created (e.g. percent area, # of hosts per cell, etc.).} - -\item{host_file}{path to raster files with number of hosts and standard -deviation on those estimates can be based in 3 formats (a single file with -number of hosts, a single file with 2 layers number of hosts and standard -deviation, or two files 1 with number of hosts and the other with standard -deviation of those estimates). The units for this can be of many formats the -two most common that we use are either percent area (0 to 100) or # of hosts -in the cell. Usually depends on data available and estimation methods.} - -\item{total_populations_file}{path to raster file with number of total -populations of all hosts and non-hosts. This depends on how your host data is -set up. If host is percent area then this should be a raster with values -that are 100 anywhere with host. If host file is # of hosts in a cell then -this should be a raster with values that are the max of the host raster any -where the # of hosts is greater than 0.} - -\item{temp}{boolean that allows the use of temperature coefficients to -modify spread (TRUE or FALSE)} - -\item{temperature_coefficient_file}{path to raster file with temperature -coefficient data for the timestep and and time period specified (e.g. if timestep -= week and start_date = 2017_01_01 and end_date = 2019_12_31 this file would -have 52 * 3 bands = 156 bands with data being weekly precipitation -coefficients). We convert raw precipitation values to coefficients that -affect the reproduction and survival of the pest all values in the raster are -between 0 and 1.} - -\item{precip}{boolean that allows the use of precipitation coefficients to -modify spread (TRUE or FALSE)} - -\item{precipitation_coefficient_file}{Raster file with precipitation -coefficient data for the timestep and time period specified (e.g. if timestep -= week and start_date = 2017_01_01 and end_date = 2019_12_31 this file would -have 52 * 3 bands = 156 bands with data being weekly precipitation -coefficients). We convert raw precipitation values to coefficients that -affect the reproduction and survival of the pest all values in the raster are -between 0 and 1.} - -\item{model_type}{What type of model most represents your system. Options -are "SEI" (Susceptible - Exposed - Infected/Infested) or "SI" -(Susceptible - Infected/Infested). Default value is "SI".} - -\item{latency_period}{How many times steps does it take to for exposed -populations become infected/infested. This is an integer value and must be -greater than 0 if model type is SEI.} - -\item{time_step}{how often should spread occur options: ('day', 'week', 'month').} - -\item{season_month_start}{when does spread first start occurring in the year -for your pest or pathogen (integer value between 1 and 12)} - -\item{season_month_end}{when does spread end during the year for your pest +\item{infected_file}{Raster file with initial infections. Units for infections are based on data +availability and the way the units used for your host file is created (e.g. percent area, # of +hosts per cell, etc.).} + +\item{host_file}{path to raster files with number of hosts and standard deviation on those +estimates can be based in 3 formats (a single file with number of hosts, a single file with 2 +layers number of hosts and standard deviation, or two files 1 with number of hosts and the other +with standard deviation of those estimates). The units for this can be of many formats the two +most common that we use are either percent area (0 to 100) or # of hosts in the cell. Usually +depends on data available and estimation methods.} + +\item{total_populations_file}{path to raster file with number of total populations of all hosts +and non-hosts. This depends on how your host data is set up. If host is percent area then this +should be a raster with values that are 100 anywhere with host. If host file is # of hosts in a +cell then this should be a raster with values that are the max of the host raster any where the +# of hosts is greater than 0.} + +\item{temp}{boolean that allows the use of temperature coefficients to modify spread +(TRUE or FALSE)} + +\item{temperature_coefficient_file}{path to raster file with temperature coefficient data for the +timestep and and time period specified (e.g. if timestep = week and start_date = 2017_01_01 and +end_date = 2019_12_31 this file would have 52 * 3 bands = 156 bands with data being weekly +precipitation coefficients). We convert raw precipitation values to coefficients that affect the +reproduction and survival of the pest all values in the raster are between 0 and 1.} + +\item{precip}{boolean that allows the use of precipitation coefficients to modify spread +(TRUE or FALSE)} + +\item{precipitation_coefficient_file}{Raster file with precipitation coefficient data for the +timestep and time period specified (e.g. if timestep = week and start_date = 2017_01_01 and +end_date = 2019_12_31 this file would have 52 * 3 bands = 156 bands with data being weekly +precipitation coefficients). We convert raw precipitation values to coefficients that affect the +reproduction and survival of the pest all values in the raster are between 0 and 1.} + +\item{model_type}{What type of model most represents your system. Options are "SEI" +(Susceptible - Exposed - Infected/Infested) or "SI" (Susceptible - Infected/Infested). Default +value is "SI".} + +\item{latency_period}{How many times steps does it take to for exposed populations become +infected/infested. This is an integer value and must be greater than 0 if model type is SEI.} + +\item{time_step}{How often should spread occur options: ('day', 'week', 'month').} + +\item{season_month_start}{When does spread first start occurring in the year for your pest or +pathogen (integer value between 1 and 12)} + +\item{season_month_end}{When does spread end during the year for your pest or pathogen (integer value between 1 and 12)} -\item{start_date}{date to start the simulation with format ('YYYY_MM_DD')} +\item{start_date}{Date to start the simulation with format ('YYYY_MM_DD')} -\item{end_date}{date to end the simulation with format ('YYYY_MM_DD')} +\item{end_date}{Date to end the simulation with format ('YYYY_MM_DD')} -\item{use_survival_rates}{boolean to indicate if the model will use survival rates to limit the +\item{use_survival_rates}{Boolean to indicate if the model will use survival rates to limit the survival or emergence of overwintering generations.} \item{survival_rate_month}{What month do over wintering generations emerge. We suggest using the month before for this parameter as it is when the survival rates raster will be applied.} -\item{survival_rate_day}{what day should the survival rates be applied} +\item{survival_rate_day}{What day should the survival rates be applied} \item{survival_rates_file}{Raster file with survival rates from 0 to 1 representing the percentage of emergence for a cell.} -\item{use_lethal_temperature}{a boolean to answer the question: does your -pest or pathogen have a temperature at which it cannot survive? -(TRUE or FALSE)} +\item{use_lethal_temperature}{A boolean to answer the question: does your pest or pathogen have +a temperature at which it cannot survive? (TRUE or FALSE)} -\item{temperature_file}{path to raster file with temperature data for -minimum temperature} +\item{temperature_file}{Path to raster file with temperature data for minimum temperature} -\item{lethal_temperature}{the temperature in degrees C at which lethal -temperature related mortality occurs for your pest or pathogen (-50 to 60)} +\item{lethal_temperature}{The temperature in degrees C at which lethal temperature related +mortality occurs for your pest or pathogen (-50 to 60)} -\item{lethal_temperature_month}{the month in which lethal temperature -related mortality occurs for your pest or pathogen integer value between 1 -and 12} +\item{lethal_temperature_month}{The month in which lethal temperature related mortality occurs +for your pest or pathogen integer value between 1 and 12} -\item{mortality_on}{boolean to turn host mortality on and off -(TRUE or FALSE)} +\item{mortality_on}{Boolean to turn host mortality on and off (TRUE or FALSE)} -\item{mortality_rate}{rate at which mortality occurs value between 0 and 1} +\item{mortality_rate}{Rate at which mortality occurs value between 0 and 1} -\item{mortality_time_lag}{time lag from infection until mortality can occur -in time steps integer >= 1} +\item{mortality_time_lag}{Time lag from infection until mortality can occur in time steps +integer >= 1} -\item{mortality_frequency}{sets the frequency of mortality calculations occur -either ('year', 'month', week', 'day', 'time step', or 'every_n_steps')} +\item{mortality_frequency}{Sets the frequency of mortality calculations occur either ('year', +'month', week', 'day', 'time step', or 'every_n_steps')} -\item{mortality_frequency_n}{sets number of units from mortality_frequency in -which to run the mortality calculation if mortality_frequency is -'every_n_steps'. Must be an integer >= 1.} +\item{mortality_frequency_n}{Sets number of units from mortality_frequency in which to run the +mortality calculation if mortality_frequency is 'every_n_steps'. Must be an integer >= 1.} -\item{management}{boolean to allow use of management (TRUE or FALSE)} +\item{management}{Boolean to allow use of management (TRUE or FALSE)} -\item{treatment_dates}{dates in which to apply treatment list with format -('YYYY_MM_DD') (needs to be the same length as treatment_file and -pesticide_duration)} +\item{treatment_dates}{Dates in which to apply treatment list with format ('YYYY_MM_DD') +(needs to be the same length as treatment_file and pesticide_duration)} -\item{treatments_file}{path to raster files with treatment data by dates. -Needs to be a list of files the same length as treatment_dates and -pesticide_duration.} +\item{treatments_file}{Path to raster files with treatment data by dates. Needs to be a list of +files the same length as treatment_dates and pesticide_duration.} -\item{treatment_method}{what method to use when applying treatment one of -("ratio" or "all infected"). ratio removes a portion of all infected and -susceptibles, all infected removes all infected a portion of susceptibles.} +\item{treatment_method}{What method to use when applying treatment one of ("ratio" or "all +infected"). ratio removes a portion of all infected and susceptibles, all infected removes all +infected a portion of susceptibles.} -\item{natural_kernel_type}{what type of dispersal kernel should be used for -natural dispersal. Current dispersal kernel options are - ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', - 'hyperbolic secant', 'gamma', 'weibull', - 'logistic')} +\item{natural_kernel_type}{What type of dispersal kernel should be used for natural dispersal. +Current dispersal kernel options are ('Cauchy', 'exponential', 'uniform', +'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic')} -\item{anthropogenic_kernel_type}{what type of dispersal kernel should be -used for anthropogenic dispersal. Current dispersal kernel options are - ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', - 'hyperbolic secant', 'gamma', 'weibull', 'logistic', 'network')} +\item{anthropogenic_kernel_type}{What type of dispersal kernel should be used for anthropogenic +dispersal. Current dispersal kernel options are ('cauchy', 'exponential', 'uniform', +'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic', +'network')} -\item{natural_dir}{sets the predominate direction of natural dispersal -usually due to wind values ('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', -'NONE')} +\item{natural_dir}{Sets the predominate direction of natural dispersal usually due to wind values +('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE')} \item{natural_kappa}{sets the strength of the natural direction in the von-mises distribution numeric value between 0.01 and 12} -\item{anthropogenic_dir}{sets the predominate direction of anthropogenic -dispersal usually due to human movement typically over long distances (e.g. -nursery trade, movement of firewood, etc..) ('N', 'NW', 'W', 'SW', 'S', -'SE', 'E', 'NE', 'NONE')} +\item{anthropogenic_dir}{Sets the predominate direction of anthropogenic dispersal usually due +to human movement typically over long distances (e.g. nursery trade, movement of firewood, etc..) +('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE')} \item{anthropogenic_kappa}{sets the strength of the anthropogenic direction in the von-mises distribution numeric value between 0.01 and 12} -\item{pesticide_duration}{how long does the pestcide (herbicide, vaccine, -etc..) last before the host is susceptible again. If value is 0 treatment -is a culling (i.e. host removal) not a pesticide treatment. (needs to be the - same length as treatment_dates and treatment_file)} +\item{pesticide_duration}{How long does the pesticide (herbicide, vaccine, etc..) last before the +host is susceptible again. If value is 0 treatment is a culling (i.e. host removal) not a +pesticide treatment. (needs to be the same length as treatment_dates and treatment_file)} -\item{pesticide_efficacy}{how effictive is the pesticide at preventing the -disease or killing the pest (if this is 0.70 then when applied it -successfully treats 70 percent of the plants or animals)} +\item{pesticide_efficacy}{How effective is the pesticide at preventing the disease or killing the +pest (if this is 0.70 then when applied it successfully treats 70 percent of the plants or +animals).} \item{mask}{Raster file used to provide a mask to remove 0's that are not true negatives from comparisons (e.g. mask out lakes and oceans from statics @@ -308,30 +290,29 @@ if modeling terrestrial species). A numerical value represents the area you want to calculate statistics on and an NA value represents the area to remove from the statistics.} -\item{output_frequency}{sets when outputs occur either ('year', 'month', -'week', 'day', 'time step', or 'every_n_steps')} +\item{output_frequency}{Sets when outputs occur either ('year', 'month', week', 'day', +'time step', or 'every_n_steps')} -\item{output_frequency_n}{sets number of units from output_frequency in which -to export model results if mortality_frequency is 'every_n_steps'. -Must be an integer >= 1.} +\item{output_frequency_n}{Sets number of units from output_frequency in which to export model +results if mortality_frequency is 'every_n_steps'. Must be an integer >= 1.} -\item{movements_file}{this is a csv file with columns lon_from, lat_from, -lon_to, lat_to, number of animals, and date.} +\item{movements_file}{This is a csv file with columns lon_from, lat_from, lon_to, lat_to, number +of animals, and date.} -\item{use_movements}{this is a boolean to turn on use of the movement module.} +\item{use_movements}{This is a boolean to turn on use of the movement module.} -\item{start_exposed}{Do your initial conditions start as exposed or infected -(only used if model_type is "SEI"). Default False. If this is TRUE need to -have both an infected_file (this can be a raster of all 0's) and exposed_file} +\item{start_exposed}{Do your initial conditions start as exposed or infected (only used if +model_type is "SEI"). Default False. If this is TRUE need to have both an infected_file (this +can be a raster of all 0's) and exposed_file} -\item{generate_stochasticity}{Boolean to indicate whether to use -stochasticity in reproductive functions default is TRUE} +\item{generate_stochasticity}{Boolean to indicate whether to use stochasticity in reproductive +functions default is TRUE} -\item{establishment_stochasticity}{Boolean to indicate whether to use -stochasticity in establishment functions default is TRUE} +\item{establishment_stochasticity}{Boolean to indicate whether to use stochasticity in +establishment functions default is TRUE} -\item{movement_stochasticity}{Boolean to indicate whether to use -stochasticity in movement functions default is TRUE} +\item{movement_stochasticity}{Boolean to indicate whether to use stochasticity in movement +functions default is TRUE} \item{dispersal_stochasticity}{Boolean to indicate whether to use a stochasticity in the dispersal kernel default is TRUE} @@ -339,31 +320,27 @@ dispersal kernel default is TRUE} \item{establishment_probability}{Threshold to determine establishment if establishment_stochasticity is FALSE (range 0 to 1, default = 0.5)} -\item{dispersal_percentage}{Percentage of dispersal used to calculate the -bounding box for deterministic dispersal} +\item{dispersal_percentage}{Percentage of dispersal used to calculate the bounding box for +deterministic dispersal} -\item{quarantine_areas_file}{path to raster file with quarantine boundaries -used in calculating likelihood of quarantine escape if use_quarantine is -TRUE} +\item{quarantine_areas_file}{Path to raster file with quarantine boundaries used in calculating +likelihood of quarantine escape if use_quarantine is TRUE} -\item{use_quarantine}{boolean to indicate whether or not there is a -quarantine area if TRUE must pass in a raster file indicating the -quarantine areas (default = FALSE)} +\item{use_quarantine}{Boolean to indicate whether or not there is a quarantine area if TRUE must +pass in a raster file indicating the quarantine areas (default = FALSE)} -\item{use_spreadrates}{boolean to indicate whether or not to calculate -spread rates} +\item{use_spreadrates}{Boolean to indicate whether or not to calculate spread rates} -\item{use_overpopulation_movements}{boolean to indicate whether to use -the overpopulation pest movement module (driven by the natural kernel with -its scale parameter modified by a coefficient)} +\item{use_overpopulation_movements}{Boolean to indicate whether to use the overpopulation pest +movement module (driven by the natural kernel with its scale parameter modified by a coefficient)} -\item{overpopulation_percentage}{percentage of occupied hosts when the cell -is considered to be overpopulated} +\item{overpopulation_percentage}{Percentage of occupied hosts when the cell is considered to be +overpopulated} -\item{leaving_percentage}{percentage of pests leaving an overpopulated cell} +\item{leaving_percentage}{Percentage of pests leaving an overpopulated cell} -\item{leaving_scale_coefficient}{coefficient to multiply scale parameter of -the natural kernel (if applicable)} +\item{leaving_scale_coefficient}{Coefficient to multiply scale parameter of the natural kernel +(if applicable)} \item{calibration_method}{choose which method of calibration to use either 'ABC' (Approximate Bayesian Computation) or 'MCMC' (Markov Chain Monte Carlo @@ -373,7 +350,7 @@ Approximation)} the calibration to converge (recommend a minimum of at least 100,000 but preferably 1 million).} -\item{exposed_file}{a file with the exposed for the current} +\item{exposed_file}{A file with the exposed for the current} \item{verbose}{Boolean with true printing current status of calibration, (e.g. the current generation, current particle, and the acceptance rate). @@ -385,7 +362,7 @@ Defaults if FALSE.} \item{output_folder_path}{this is the full path with either / or \\ (e.g., "C:/user_name/desktop/pops_sod_2020_2023/outputs/")} -\item{network_filename}{entire file path for the network file. Used if +\item{network_filename}{The entire file path for the network file. Used if anthropogenic_kernel_type = 'network'.} \item{network_movement}{What movement type do you want to use in the network kernel either @@ -405,19 +382,19 @@ comparing simulations vs. observations. Must be one of "quantity", "allocation", "mcc and distance", "rmse and distance", "mcc and configuration", "mcc and RMSE", "mcc, quantity, and configuration"). Default is "mcc"} -\item{use_initial_condition_uncertainty}{boolean to indicate whether or not to propagate and +\item{use_initial_condition_uncertainty}{Boolean to indicate whether or not to propagate and partition uncertainty from initial conditions. If TRUE the infected_file needs to have 2 layers one with the mean value and one with the standard deviation. If an SEI model is used the exposed_file needs to have 2 layers one with the mean value and one with the standard deviation} -\item{use_host_uncertainty}{boolean to indicate whether or not to propagate and partition +\item{use_host_uncertainty}{Boolean to indicate whether or not to propagate and partition uncertainty from host data. If TRUE the host_file needs to have 2 layers one with the mean value and one with the standard deviation.} -\item{weather_type}{string indicating how the weather data is passed in either -as a mean and standard deviation to represent uncertainty ("probabilistic") or as a time -series ("deterministic")} +\item{weather_type}{string indicating how the weather data is passed in either as a mean and +standard deviation to represent uncertainty ("probabilistic") or as a time series +("deterministic")} \item{temperature_coefficient_sd_file}{Raster file with temperature coefficient standard deviation data for the timestep and time period specified (e.g. if timestep = week this file @@ -431,26 +408,28 @@ would have 52 bands with data being weekly precipitation coefficient standard de convert raw precipitation values to coefficients that affect the reproduction and survival of the pest all values in the raster are between 0 and 1.} -\item{dispersers_to_soils_percentage}{range from 0 to 1 representing the percentage -of dispersers that fall to the soil and survive.} +\item{dispersers_to_soils_percentage}{Range from 0 to 1 representing the percentage of dispersers +that fall to the soil and survive.} -\item{quarantine_directions}{string with comma separated directions to include -in the quarantine direction analysis, e.g., 'N,E'. By default all directions -(N, S, E, W) are considered} +\item{quarantine_directions}{String with comma separated directions to include in the quarantine +direction analysis, e.g., 'N,E'. By default all directions (N, S, E, W) are considered} -\item{multiple_random_seeds}{boolean to indicate if the model should use multiple random seeds +\item{multiple_random_seeds}{Boolean to indicate if the model should use multiple random seeds (allows for performing uncertainty partitioning) or a single random seed (backwards compatibility option). Default is FALSE.} -\item{random_seeds}{A file path to the file with the .csv file containing random_seeds table. -Use a file if you are trying to recreate an exact analysis otherwise we suggest leaving the +\item{file_random_seeds}{A file path to the file with the .csv file containing random_seeds +table. Use if you are trying to recreate an exact analysis otherwise we suggest leaving the default. Default is Null which draws the seed numbers for each.} -\item{use_soils}{boolean to indicate if pests establish in the soil and spread out from there. +\item{use_soils}{Boolean to indicate if pests establish in the soil and spread out from there. Typically used for soil borne pathogens.} -\item{soil_starting_pest_file}{path to the raster file with the starting -amount of pest or pathogen.} +\item{soil_starting_pest_file}{path to the raster file with the starting amount of pest or +pathogen.} + +\item{start_with_soil_populations}{Boolean to indicate whether to use a starting soil pest or +pathogen population if TRUE then soil_starting_pest_file is required.} } \value{ a dataframe of the variables saved and their success metrics for diff --git a/man/pops.Rd b/man/pops.Rd index e6eec7ab..c6a825e6 100644 --- a/man/pops.Rd +++ b/man/pops.Rd @@ -75,193 +75,172 @@ pops( dispersers_to_soils_percentage = 0, quarantine_directions = "", multiple_random_seeds = FALSE, - random_seeds = NULL, + file_random_seeds = NULL, use_soils = FALSE, - soil_starting_pest_file = "" + soil_starting_pest_file = "", + start_with_soil_populations = FALSE ) } \arguments{ -\item{infected_file}{Raster file with initial infections. Units for -infections are based on data availability and the way the units used for your -host file is created (e.g. percent area, # of hosts per cell, etc.).} - -\item{host_file}{path to raster files with number of hosts and standard -deviation on those estimates can be based in 3 formats (a single file with -number of hosts, a single file with 2 layers number of hosts and standard -deviation, or two files 1 with number of hosts and the other with standard -deviation of those estimates). The units for this can be of many formats the -two most common that we use are either percent area (0 to 100) or # of hosts -in the cell. Usually depends on data available and estimation methods.} - -\item{total_populations_file}{path to raster file with number of total -populations of all hosts and non-hosts. This depends on how your host data is -set up. If host is percent area then this should be a raster with values -that are 100 anywhere with host. If host file is # of hosts in a cell then -this should be a raster with values that are the max of the host raster any -where the # of hosts is greater than 0.} - -\item{parameter_means}{A vector of the means of the model parameters -(reproductive_rate, natural_dispersal_distance, percent_natural_dispersal, -anthropogenic_dispersal_distance, natural kappa, anthropogenic kappa, -network_min_distance, and network_max_distance). 1x8 vector.} - -\item{parameter_cov_matrix}{A covariance matrix from the previous years -posterior parameter estimation ordered from (reproductive_rate, -natural_dispersal_distance, percent_natural_dispersal, -anthropogenic_dispersal_distance, natural kappa, anthropogenic kappa, +\item{infected_file}{Raster file with initial infections. Units for infections are based on data +availability and the way the units used for your host file is created (e.g. percent area, # of +hosts per cell, etc.).} + +\item{host_file}{path to raster files with number of hosts and standard deviation on those +estimates can be based in 3 formats (a single file with number of hosts, a single file with 2 +layers number of hosts and standard deviation, or two files 1 with number of hosts and the other +with standard deviation of those estimates). The units for this can be of many formats the two +most common that we use are either percent area (0 to 100) or # of hosts in the cell. Usually +depends on data available and estimation methods.} + +\item{total_populations_file}{path to raster file with number of total populations of all hosts +and non-hosts. This depends on how your host data is set up. If host is percent area then this +should be a raster with values that are 100 anywhere with host. If host file is # of hosts in a +cell then this should be a raster with values that are the max of the host raster any where the +# of hosts is greater than 0.} + +\item{parameter_means}{A vector of the means of the model parameters (reproductive_rate, +natural_dispersal_distance, percent_natural_dispersal, anthropogenic_dispersal_distance, natural +kappa, anthropogenic kappa, network_min_distance, and network_max_distance). 1x8 vector.} + +\item{parameter_cov_matrix}{A covariance matrix from the previous years posterior parameter +estimation ordered from (reproductive_rate, natural_dispersal_distance, +percent_natural_dispersal, anthropogenic_dispersal_distance, natural kappa, anthropogenic kappa, network_min_distance, and network_max_distance) Should be 8x8 matrix.} -\item{temp}{boolean that allows the use of temperature coefficients to -modify spread (TRUE or FALSE)} +\item{temp}{boolean that allows the use of temperature coefficients to modify spread +(TRUE or FALSE)} -\item{temperature_coefficient_file}{path to raster file with temperature -coefficient data for the timestep and and time period specified (e.g. if timestep -= week and start_date = 2017_01_01 and end_date = 2019_12_31 this file would -have 52 * 3 bands = 156 bands with data being weekly precipitation -coefficients). We convert raw precipitation values to coefficients that -affect the reproduction and survival of the pest all values in the raster are -between 0 and 1.} +\item{temperature_coefficient_file}{path to raster file with temperature coefficient data for the +timestep and and time period specified (e.g. if timestep = week and start_date = 2017_01_01 and +end_date = 2019_12_31 this file would have 52 * 3 bands = 156 bands with data being weekly +precipitation coefficients). We convert raw precipitation values to coefficients that affect the +reproduction and survival of the pest all values in the raster are between 0 and 1.} -\item{precip}{boolean that allows the use of precipitation coefficients to -modify spread (TRUE or FALSE)} +\item{precip}{boolean that allows the use of precipitation coefficients to modify spread +(TRUE or FALSE)} -\item{precipitation_coefficient_file}{Raster file with precipitation -coefficient data for the timestep and time period specified (e.g. if timestep -= week and start_date = 2017_01_01 and end_date = 2019_12_31 this file would -have 52 * 3 bands = 156 bands with data being weekly precipitation -coefficients). We convert raw precipitation values to coefficients that -affect the reproduction and survival of the pest all values in the raster are -between 0 and 1.} +\item{precipitation_coefficient_file}{Raster file with precipitation coefficient data for the +timestep and time period specified (e.g. if timestep = week and start_date = 2017_01_01 and +end_date = 2019_12_31 this file would have 52 * 3 bands = 156 bands with data being weekly +precipitation coefficients). We convert raw precipitation values to coefficients that affect the +reproduction and survival of the pest all values in the raster are between 0 and 1.} -\item{model_type}{What type of model most represents your system. Options -are "SEI" (Susceptible - Exposed - Infected/Infested) or "SI" -(Susceptible - Infected/Infested). Default value is "SI".} +\item{model_type}{What type of model most represents your system. Options are "SEI" +(Susceptible - Exposed - Infected/Infested) or "SI" (Susceptible - Infected/Infested). Default +value is "SI".} -\item{latency_period}{How many times steps does it take to for exposed -populations become infected/infested. This is an integer value and must be -greater than 0 if model type is SEI.} +\item{latency_period}{How many times steps does it take to for exposed populations become +infected/infested. This is an integer value and must be greater than 0 if model type is SEI.} -\item{time_step}{how often should spread occur options: ('day', 'week', 'month').} +\item{time_step}{How often should spread occur options: ('day', 'week', 'month').} -\item{season_month_start}{when does spread first start occurring in the year -for your pest or pathogen (integer value between 1 and 12)} +\item{season_month_start}{When does spread first start occurring in the year for your pest or +pathogen (integer value between 1 and 12)} -\item{season_month_end}{when does spread end during the year for your pest +\item{season_month_end}{When does spread end during the year for your pest or pathogen (integer value between 1 and 12)} -\item{start_date}{date to start the simulation with format ('YYYY_MM_DD')} +\item{start_date}{Date to start the simulation with format ('YYYY_MM_DD')} -\item{end_date}{date to end the simulation with format ('YYYY_MM_DD')} +\item{end_date}{Date to end the simulation with format ('YYYY_MM_DD')} -\item{use_survival_rates}{boolean to indicate if the model will use survival rates to limit the +\item{use_survival_rates}{Boolean to indicate if the model will use survival rates to limit the survival or emergence of overwintering generations.} \item{survival_rate_month}{What month do over wintering generations emerge. We suggest using the month before for this parameter as it is when the survival rates raster will be applied.} -\item{survival_rate_day}{what day should the survival rates be applied} +\item{survival_rate_day}{What day should the survival rates be applied} \item{survival_rates_file}{Raster file with survival rates from 0 to 1 representing the percentage of emergence for a cell.} -\item{use_lethal_temperature}{a boolean to answer the question: does your -pest or pathogen have a temperature at which it cannot survive? -(TRUE or FALSE)} +\item{use_lethal_temperature}{A boolean to answer the question: does your pest or pathogen have +a temperature at which it cannot survive? (TRUE or FALSE)} -\item{temperature_file}{path to raster file with temperature data for -minimum temperature} +\item{temperature_file}{Path to raster file with temperature data for minimum temperature} -\item{lethal_temperature}{the temperature in degrees C at which lethal -temperature related mortality occurs for your pest or pathogen (-50 to 60)} +\item{lethal_temperature}{The temperature in degrees C at which lethal temperature related +mortality occurs for your pest or pathogen (-50 to 60)} -\item{lethal_temperature_month}{the month in which lethal temperature -related mortality occurs for your pest or pathogen integer value between 1 -and 12} +\item{lethal_temperature_month}{The month in which lethal temperature related mortality occurs +for your pest or pathogen integer value between 1 and 12} -\item{mortality_on}{boolean to turn host mortality on and off -(TRUE or FALSE)} +\item{mortality_on}{Boolean to turn host mortality on and off (TRUE or FALSE)} -\item{mortality_rate}{rate at which mortality occurs value between 0 and 1} +\item{mortality_rate}{Rate at which mortality occurs value between 0 and 1} -\item{mortality_time_lag}{time lag from infection until mortality can occur -in time steps integer >= 1} +\item{mortality_time_lag}{Time lag from infection until mortality can occur in time steps +integer >= 1} -\item{mortality_frequency}{sets the frequency of mortality calculations occur -either ('year', 'month', week', 'day', 'time step', or 'every_n_steps')} +\item{mortality_frequency}{Sets the frequency of mortality calculations occur either ('year', +'month', week', 'day', 'time step', or 'every_n_steps')} -\item{mortality_frequency_n}{sets number of units from mortality_frequency in -which to run the mortality calculation if mortality_frequency is -'every_n_steps'. Must be an integer >= 1.} +\item{mortality_frequency_n}{Sets number of units from mortality_frequency in which to run the +mortality calculation if mortality_frequency is 'every_n_steps'. Must be an integer >= 1.} -\item{management}{boolean to allow use of management (TRUE or FALSE)} +\item{management}{Boolean to allow use of management (TRUE or FALSE)} -\item{treatment_dates}{dates in which to apply treatment list with format -('YYYY_MM_DD') (needs to be the same length as treatment_file and -pesticide_duration)} +\item{treatment_dates}{Dates in which to apply treatment list with format ('YYYY_MM_DD') +(needs to be the same length as treatment_file and pesticide_duration)} -\item{treatments_file}{path to raster files with treatment data by dates. -Needs to be a list of files the same length as treatment_dates and -pesticide_duration.} +\item{treatments_file}{Path to raster files with treatment data by dates. Needs to be a list of +files the same length as treatment_dates and pesticide_duration.} -\item{treatment_method}{what method to use when applying treatment one of -("ratio" or "all infected"). ratio removes a portion of all infected and -susceptibles, all infected removes all infected a portion of susceptibles.} +\item{treatment_method}{What method to use when applying treatment one of ("ratio" or "all +infected"). ratio removes a portion of all infected and susceptibles, all infected removes all +infected a portion of susceptibles.} -\item{natural_kernel_type}{what type of dispersal kernel should be used for -natural dispersal. Current dispersal kernel options are - ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', - 'hyperbolic secant', 'gamma', 'weibull', - 'logistic')} +\item{natural_kernel_type}{What type of dispersal kernel should be used for natural dispersal. +Current dispersal kernel options are ('Cauchy', 'exponential', 'uniform', +'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic')} -\item{anthropogenic_kernel_type}{what type of dispersal kernel should be -used for anthropogenic dispersal. Current dispersal kernel options are - ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', - 'hyperbolic secant', 'gamma', 'weibull', 'logistic', 'network')} +\item{anthropogenic_kernel_type}{What type of dispersal kernel should be used for anthropogenic +dispersal. Current dispersal kernel options are ('cauchy', 'exponential', 'uniform', +'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic', +'network')} -\item{natural_dir}{sets the predominate direction of natural dispersal -usually due to wind values ('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', -'NONE')} +\item{natural_dir}{Sets the predominate direction of natural dispersal usually due to wind values +('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE')} -\item{anthropogenic_dir}{sets the predominate direction of anthropogenic -dispersal usually due to human movement typically over long distances (e.g. -nursery trade, movement of firewood, etc..) ('N', 'NW', 'W', 'SW', 'S', -'SE', 'E', 'NE', 'NONE')} +\item{anthropogenic_dir}{Sets the predominate direction of anthropogenic dispersal usually due +to human movement typically over long distances (e.g. nursery trade, movement of firewood, etc..) +('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE')} -\item{pesticide_duration}{how long does the pestcide (herbicide, vaccine, -etc..) last before the host is susceptible again. If value is 0 treatment -is a culling (i.e. host removal) not a pesticide treatment. (needs to be the - same length as treatment_dates and treatment_file)} +\item{pesticide_duration}{How long does the pesticide (herbicide, vaccine, etc..) last before the +host is susceptible again. If value is 0 treatment is a culling (i.e. host removal) not a +pesticide treatment. (needs to be the same length as treatment_dates and treatment_file)} -\item{pesticide_efficacy}{how effictive is the pesticide at preventing the -disease or killing the pest (if this is 0.70 then when applied it -successfully treats 70 percent of the plants or animals)} +\item{pesticide_efficacy}{How effective is the pesticide at preventing the disease or killing the +pest (if this is 0.70 then when applied it successfully treats 70 percent of the plants or +animals).} -\item{random_seed}{sets the random seed for the simulation used for reproducibility} +\item{random_seed}{Sets the random seed for the simulation used for reproducibility} -\item{output_frequency}{sets when outputs occur either ('year', 'month', -'week', 'day', 'time step', or 'every_n_steps')} +\item{output_frequency}{Sets when outputs occur either ('year', 'month', week', 'day', +'time step', or 'every_n_steps')} -\item{output_frequency_n}{sets number of units from output_frequency in which -to export model results if mortality_frequency is 'every_n_steps'. -Must be an integer >= 1.} +\item{output_frequency_n}{Sets number of units from output_frequency in which to export model +results if mortality_frequency is 'every_n_steps'. Must be an integer >= 1.} -\item{movements_file}{this is a csv file with columns lon_from, lat_from, -lon_to, lat_to, number of animals, and date.} +\item{movements_file}{This is a csv file with columns lon_from, lat_from, lon_to, lat_to, number +of animals, and date.} -\item{use_movements}{this is a boolean to turn on use of the movement module.} +\item{use_movements}{This is a boolean to turn on use of the movement module.} -\item{start_exposed}{Do your initial conditions start as exposed or infected -(only used if model_type is "SEI"). Default False. If this is TRUE need to -have both an infected_file (this can be a raster of all 0's) and exposed_file} +\item{start_exposed}{Do your initial conditions start as exposed or infected (only used if +model_type is "SEI"). Default False. If this is TRUE need to have both an infected_file (this +can be a raster of all 0's) and exposed_file} -\item{generate_stochasticity}{Boolean to indicate whether to use -stochasticity in reproductive functions default is TRUE} +\item{generate_stochasticity}{Boolean to indicate whether to use stochasticity in reproductive +functions default is TRUE} -\item{establishment_stochasticity}{Boolean to indicate whether to use -stochasticity in establishment functions default is TRUE} +\item{establishment_stochasticity}{Boolean to indicate whether to use stochasticity in +establishment functions default is TRUE} -\item{movement_stochasticity}{Boolean to indicate whether to use -stochasticity in movement functions default is TRUE} +\item{movement_stochasticity}{Boolean to indicate whether to use stochasticity in movement +functions default is TRUE} \item{dispersal_stochasticity}{Boolean to indicate whether to use a stochasticity in the dispersal kernel default is TRUE} @@ -269,40 +248,35 @@ dispersal kernel default is TRUE} \item{establishment_probability}{Threshold to determine establishment if establishment_stochasticity is FALSE (range 0 to 1, default = 0.5)} -\item{dispersal_percentage}{Percentage of dispersal used to calculate the -bounding box for deterministic dispersal} +\item{dispersal_percentage}{Percentage of dispersal used to calculate the bounding box for +deterministic dispersal} -\item{quarantine_areas_file}{path to raster file with quarantine boundaries -used in calculating likelihood of quarantine escape if use_quarantine is -TRUE} +\item{quarantine_areas_file}{Path to raster file with quarantine boundaries used in calculating +likelihood of quarantine escape if use_quarantine is TRUE} -\item{use_quarantine}{boolean to indicate whether or not there is a -quarantine area if TRUE must pass in a raster file indicating the -quarantine areas (default = FALSE)} +\item{use_quarantine}{Boolean to indicate whether or not there is a quarantine area if TRUE must +pass in a raster file indicating the quarantine areas (default = FALSE)} -\item{use_spreadrates}{boolean to indicate whether or not to calculate -spread rates} +\item{use_spreadrates}{Boolean to indicate whether or not to calculate spread rates} -\item{use_overpopulation_movements}{boolean to indicate whether to use -the overpopulation pest movement module (driven by the natural kernel with -its scale parameter modified by a coefficient)} +\item{use_overpopulation_movements}{Boolean to indicate whether to use the overpopulation pest +movement module (driven by the natural kernel with its scale parameter modified by a coefficient)} -\item{overpopulation_percentage}{percentage of occupied hosts when the cell -is considered to be overpopulated} +\item{overpopulation_percentage}{Percentage of occupied hosts when the cell is considered to be +overpopulated} -\item{leaving_percentage}{percentage of pests leaving an overpopulated cell} +\item{leaving_percentage}{Percentage of pests leaving an overpopulated cell} -\item{leaving_scale_coefficient}{coefficient to multiply scale parameter of -the natural kernel (if applicable)} +\item{leaving_scale_coefficient}{Coefficient to multiply scale parameter of the natural kernel +(if applicable)} -\item{exposed_file}{a file with the exposed for the current} +\item{exposed_file}{A file with the exposed for the current} -\item{mask}{Raster file used to provide a mask to remove 0's that are not -true negatives from comparisons (e.g. mask out lakes and oceans from statics -if modeling terrestrial species). This can also be used to mask out areas -that can't be managed in the auto_manage function.} +\item{mask}{Raster file used to provide a mask to remove 0's that are not true negatives from +comparisons (e.g. mask out lakes and oceans from statics if modeling terrestrial species). This +can also be used to mask out areas that can't be managed in the auto_manage function.} -\item{network_filename}{entire file path for the network file. Used if +\item{network_filename}{The entire file path for the network file. Used if anthropogenic_kernel_type = 'network'.} \item{network_movement}{What movement type do you want to use in the network kernel either @@ -310,19 +284,19 @@ anthropogenic_kernel_type = 'network'.} along the edge. "jump" automatically moves to the nearest node when moving through the network. "teleport" moves from node to node most likely used for airport and seaport networks.} -\item{use_initial_condition_uncertainty}{boolean to indicate whether or not to propagate and +\item{use_initial_condition_uncertainty}{Boolean to indicate whether or not to propagate and partition uncertainty from initial conditions. If TRUE the infected_file needs to have 2 layers one with the mean value and one with the standard deviation. If an SEI model is used the exposed_file needs to have 2 layers one with the mean value and one with the standard deviation} -\item{use_host_uncertainty}{boolean to indicate whether or not to propagate and partition +\item{use_host_uncertainty}{Boolean to indicate whether or not to propagate and partition uncertainty from host data. If TRUE the host_file needs to have 2 layers one with the mean value and one with the standard deviation.} -\item{weather_type}{string indicating how the weather data is passed in either -as a mean and standard deviation to represent uncertainty ("probabilistic") or as a time -series ("deterministic")} +\item{weather_type}{string indicating how the weather data is passed in either as a mean and +standard deviation to represent uncertainty ("probabilistic") or as a time series +("deterministic")} \item{temperature_coefficient_sd_file}{Raster file with temperature coefficient standard deviation data for the timestep and time period specified (e.g. if timestep = week this file @@ -336,26 +310,28 @@ would have 52 bands with data being weekly precipitation coefficient standard de convert raw precipitation values to coefficients that affect the reproduction and survival of the pest all values in the raster are between 0 and 1.} -\item{dispersers_to_soils_percentage}{range from 0 to 1 representing the percentage -of dispersers that fall to the soil and survive.} +\item{dispersers_to_soils_percentage}{Range from 0 to 1 representing the percentage of dispersers +that fall to the soil and survive.} -\item{quarantine_directions}{string with comma separated directions to include -in the quarantine direction analysis, e.g., 'N,E'. By default all directions -(N, S, E, W) are considered} +\item{quarantine_directions}{String with comma separated directions to include in the quarantine +direction analysis, e.g., 'N,E'. By default all directions (N, S, E, W) are considered} -\item{multiple_random_seeds}{boolean to indicate if the model should use multiple random seeds +\item{multiple_random_seeds}{Boolean to indicate if the model should use multiple random seeds (allows for performing uncertainty partitioning) or a single random seed (backwards compatibility option). Default is FALSE.} -\item{random_seeds}{A file path to the file with the .csv file containing random_seeds table. -Use a file if you are trying to recreate an exact analysis otherwise we suggest leaving the +\item{file_random_seeds}{A file path to the file with the .csv file containing random_seeds +table. Use if you are trying to recreate an exact analysis otherwise we suggest leaving the default. Default is Null which draws the seed numbers for each.} -\item{use_soils}{boolean to indicate if pests establish in the soil and spread out from there. +\item{use_soils}{Boolean to indicate if pests establish in the soil and spread out from there. Typically used for soil borne pathogens.} -\item{soil_starting_pest_file}{path to the raster file with the starting -amount of pest or pathogen.} +\item{soil_starting_pest_file}{path to the raster file with the starting amount of pest or +pathogen.} + +\item{start_with_soil_populations}{Boolean to indicate whether to use a starting soil pest or +pathogen population if TRUE then soil_starting_pest_file is required.} } \value{ list of infected and susceptible per year diff --git a/man/pops_model.Rd b/man/pops_model.Rd index 1d9271d6..85c159a3 100644 --- a/man/pops_model.Rd +++ b/man/pops_model.Rd @@ -43,6 +43,7 @@ pops_model( reproductive_rate, spatial_indices, season_month_start_end, + soil_reservoirs, mortality_rate = 0, mortality_time_lag = 2, start_date = "2018-01-01", @@ -87,38 +88,37 @@ pops_model( network_movement = "walk", weather_size = 0, weather_type = "deterministic", - dispersers_to_soils_percentage = 0 + dispersers_to_soils_percentage = 0, + use_soils = FALSE ) } \arguments{ -\item{random_seed}{sets the random seed for the simulation used for reproducibility} +\item{random_seed}{Sets the random seed for the simulation used for reproducibility} -\item{multiple_random_seeds}{boolean to indicate if the model should use multiple random seeds +\item{multiple_random_seeds}{Boolean to indicate if the model should use multiple random seeds (allows for performing uncertainty partitioning) or a single random seed (backwards compatibility option). Default is FALSE.} -\item{random_seeds}{A file path to the file with the .csv file containing random_seeds table. -Use a file if you are trying to recreate an exact analysis otherwise we suggest leaving the -default. Default is Null which draws the seed numbers for each.} +\item{random_seeds}{vector of random seeds in the order of "disperser_generation", +"natural_dispersal", "anthropogenic_dispersal", "establishment", "weather", "movement", +"overpopulation", "survival_rate", "soil"} -\item{use_lethal_temperature}{a boolean to answer the question: does your -pest or pathogen have a temperature at which it cannot survive? -(TRUE or FALSE)} +\item{use_lethal_temperature}{A boolean to answer the question: does your pest or pathogen have +a temperature at which it cannot survive? (TRUE or FALSE)} -\item{lethal_temperature}{the temperature in degrees C at which lethal -temperature related mortality occurs for your pest or pathogen (-50 to 60)} +\item{lethal_temperature}{The temperature in degrees C at which lethal temperature related +mortality occurs for your pest or pathogen (-50 to 60)} -\item{lethal_temperature_month}{the month in which lethal temperature -related mortality occurs for your pest or pathogen integer value between 1 -and 12} +\item{lethal_temperature_month}{The month in which lethal temperature related mortality occurs +for your pest or pathogen integer value between 1 and 12} -\item{use_survival_rates}{boolean to indicate if the model will use survival rates to limit the +\item{use_survival_rates}{Boolean to indicate if the model will use survival rates to limit the survival or emergence of overwintering generations.} \item{survival_rate_month}{What month do over wintering generations emerge. We suggest using the month before for this parameter as it is when the survival rates raster will be applied.} -\item{survival_rate_day}{what day should the survival rates be applied} +\item{survival_rate_day}{What day should the survival rates be applied} \item{infected}{matrix of infected hosts} @@ -134,8 +134,7 @@ model type} \item{total_hosts}{matrix of all hosts} -\item{mortality_on}{boolean to turn host mortality on and off -(TRUE or FALSE)} +\item{mortality_on}{Boolean to turn host mortality on and off (TRUE or FALSE)} \item{mortality_tracker}{matrix of 0's to track mortality per year} @@ -144,21 +143,18 @@ model type} \item{quarantine_areas}{areas that are set as quarantined for computing escape from quarantine statistics.} -\item{quarantine_directions}{string with comma separated directions to include -in the quarantine direction analysis, e.g., 'N,E'. By default all directions -(N, S, E, W) are considered} +\item{quarantine_directions}{String with comma separated directions to include in the quarantine +direction analysis, e.g., 'N,E'. By default all directions (N, S, E, W) are considered} \item{treatment_maps}{list of matrices where treatment or management has occurred in a given year} -\item{treatment_dates}{dates in which to apply treatment list with format -('YYYY_MM_DD') (needs to be the same length as treatment_file and -pesticide_duration)} +\item{treatment_dates}{Dates in which to apply treatment list with format ('YYYY_MM_DD') +(needs to be the same length as treatment_file and pesticide_duration)} -\item{pesticide_duration}{how long does the pestcide (herbicide, vaccine, -etc..) last before the host is susceptible again. If value is 0 treatment -is a culling (i.e. host removal) not a pesticide treatment. (needs to be the - same length as treatment_dates and treatment_file)} +\item{pesticide_duration}{How long does the pesticide (herbicide, vaccine, etc..) last before the +host is susceptible again. If value is 0 treatment is a culling (i.e. host removal) not a +pesticide treatment. (needs to be the same length as treatment_dates and treatment_file)} \item{resistant}{matrix to track resistant population over time} @@ -186,7 +182,7 @@ overwinter population that emerges} \item{rows_cols}{vector of number of rows and columns in the raster files} -\item{time_step}{how often should spread occur options: ('day', 'week', 'month').} +\item{time_step}{How often should spread occur options: ('day', 'week', 'month').} \item{reproductive_rate}{number of spores or pest units produced by a single host under optimal weather conditions} @@ -195,29 +191,29 @@ host under optimal weather conditions} \item{season_month_start_end}{vector of months when spread starts and stops} -\item{mortality_rate}{rate at which mortality occurs value between 0 and 1} +\item{soil_reservoirs}{list of matrices with soil pests created from soil_pest_file.} -\item{mortality_time_lag}{time lag from infection until mortality can occur -in time steps integer >= 1} +\item{mortality_rate}{Rate at which mortality occurs value between 0 and 1} -\item{start_date}{date to start the simulation with format ('YYYY_MM_DD')} +\item{mortality_time_lag}{Time lag from infection until mortality can occur in time steps +integer >= 1} -\item{end_date}{date to end the simulation with format ('YYYY_MM_DD')} +\item{start_date}{Date to start the simulation with format ('YYYY_MM_DD')} -\item{treatment_method}{what method to use when applying treatment one of -("ratio" or "all infected"). ratio removes a portion of all infected and -susceptibles, all infected removes all infected a portion of susceptibles.} +\item{end_date}{Date to end the simulation with format ('YYYY_MM_DD')} -\item{natural_kernel_type}{what type of dispersal kernel should be used for -natural dispersal. Current dispersal kernel options are - ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', - 'hyperbolic secant', 'gamma', 'weibull', - 'logistic')} +\item{treatment_method}{What method to use when applying treatment one of ("ratio" or "all +infected"). ratio removes a portion of all infected and susceptibles, all infected removes all +infected a portion of susceptibles.} -\item{anthropogenic_kernel_type}{what type of dispersal kernel should be -used for anthropogenic dispersal. Current dispersal kernel options are - ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', - 'hyperbolic secant', 'gamma', 'weibull', 'logistic', 'network')} +\item{natural_kernel_type}{What type of dispersal kernel should be used for natural dispersal. +Current dispersal kernel options are ('Cauchy', 'exponential', 'uniform', +'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic')} + +\item{anthropogenic_kernel_type}{What type of dispersal kernel should be used for anthropogenic +dispersal. Current dispersal kernel options are ('cauchy', 'exponential', 'uniform', +'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic', +'network')} \item{use_anthropogenic_kernel}{A boolean that turns on the use of the anthropogenic or long distance dispersal portion of the 2 scale dispersal @@ -232,27 +228,24 @@ dispersal kernel numeric value > 0} \item{anthropogenic_distance_scale}{distance scale parameter for anthropogenic range dispersal kernel numeric value > 0} -\item{natural_dir}{sets the predominate direction of natural dispersal -usually due to wind values ('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', -'NONE')} +\item{natural_dir}{Sets the predominate direction of natural dispersal usually due to wind values +('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE')} \item{natural_kappa}{sets the strength of the natural direction in the von-mises distribution numeric value between 0.01 and 12} -\item{anthropogenic_dir}{sets the predominate direction of anthropogenic -dispersal usually due to human movement typically over long distances (e.g. -nursery trade, movement of firewood, etc..) ('N', 'NW', 'W', 'SW', 'S', -'SE', 'E', 'NE', 'NONE')} +\item{anthropogenic_dir}{Sets the predominate direction of anthropogenic dispersal usually due +to human movement typically over long distances (e.g. nursery trade, movement of firewood, etc..) +('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE')} \item{anthropogenic_kappa}{sets the strength of the anthropogenic direction in the von-mises distribution numeric value between 0.01 and 12} -\item{output_frequency}{sets when outputs occur either ('year', 'month', -'week', 'day', 'time step', or 'every_n_steps')} +\item{output_frequency}{Sets when outputs occur either ('year', 'month', week', 'day', +'time step', or 'every_n_steps')} -\item{output_frequency_n}{sets number of units from output_frequency in which -to export model results if mortality_frequency is 'every_n_steps'. -Must be an integer >= 1.} +\item{output_frequency_n}{Sets number of units from output_frequency in which to export model +results if mortality_frequency is 'every_n_steps'. Must be an integer >= 1.} \item{quarantine_frequency}{sets how often the quarantine statistics are calculated either ('year', 'month', 'week', 'day' or 'time step') @@ -261,9 +254,8 @@ calculated either ('year', 'month', 'week', 'day' or 'time step') \item{quarantine_frequency_n}{sets number units ('year', 'month', 'week', 'day' or 'time step') in which to calculate and export quarantine statistics.} -\item{use_quarantine}{boolean to indicate whether or not there is a -quarantine area if TRUE must pass in a raster file indicating the -quarantine areas (default = FALSE)} +\item{use_quarantine}{Boolean to indicate whether or not there is a quarantine area if TRUE must +pass in a raster file indicating the quarantine areas (default = FALSE)} \item{spreadrate_frequency}{sets how often the spread rate statistics are calculated either ('year', 'month', 'week', 'day' or 'time step') @@ -273,32 +265,29 @@ calculated either ('year', 'month', 'week', 'day' or 'time step') 'day' or 'time step') in which to calculate and export spread rate statistics.} -\item{mortality_frequency}{sets the frequency of mortality calculations occur -either ('year', 'month', week', 'day', 'time step', or 'every_n_steps')} +\item{mortality_frequency}{Sets the frequency of mortality calculations occur either ('year', +'month', week', 'day', 'time step', or 'every_n_steps')} -\item{mortality_frequency_n}{sets number of units from mortality_frequency in -which to run the mortality calculation if mortality_frequency is -'every_n_steps'. Must be an integer >= 1.} +\item{mortality_frequency_n}{Sets number of units from mortality_frequency in which to run the +mortality calculation if mortality_frequency is 'every_n_steps'. Must be an integer >= 1.} -\item{use_spreadrates}{boolean to indicate whether or not to calculate -spread rates} +\item{use_spreadrates}{Boolean to indicate whether or not to calculate spread rates} \item{model_type_}{What type of model most represents your system. Options are "SEI" (Susceptible - Exposed - Infected/Infested) or "SI" (Susceptible - Infected/Infested). Default value is "SI".} -\item{latency_period}{How many times steps does it take to for exposed -populations become infected/infested. This is an integer value and must be -greater than 0 if model type is SEI.} +\item{latency_period}{How many times steps does it take to for exposed populations become +infected/infested. This is an integer value and must be greater than 0 if model type is SEI.} -\item{generate_stochasticity}{Boolean to indicate whether to use -stochasticity in reproductive functions default is TRUE} +\item{generate_stochasticity}{Boolean to indicate whether to use stochasticity in reproductive +functions default is TRUE} -\item{establishment_stochasticity}{Boolean to indicate whether to use -stochasticity in establishment functions default is TRUE} +\item{establishment_stochasticity}{Boolean to indicate whether to use stochasticity in +establishment functions default is TRUE} -\item{movement_stochasticity}{Boolean to indicate whether to use -stochasticity in movement functions default is TRUE} +\item{movement_stochasticity}{Boolean to indicate whether to use stochasticity in movement +functions default is TRUE} \item{dispersal_stochasticity}{Boolean to indicate whether to use a stochasticity in the dispersal kernel default is TRUE} @@ -306,20 +295,19 @@ dispersal kernel default is TRUE} \item{establishment_probability}{Threshold to determine establishment if establishment_stochasticity is FALSE (range 0 to 1, default = 0.5)} -\item{dispersal_percentage}{Percentage of dispersal used to calculate the -bounding box for deterministic dispersal} +\item{dispersal_percentage}{Percentage of dispersal used to calculate the bounding box for +deterministic dispersal} -\item{use_overpopulation_movements}{boolean to indicate whether to use -the overpopulation pest movement module (driven by the natural kernel with -its scale parameter modified by a coefficient)} +\item{use_overpopulation_movements}{Boolean to indicate whether to use the overpopulation pest +movement module (driven by the natural kernel with its scale parameter modified by a coefficient)} -\item{overpopulation_percentage}{percentage of occupied hosts when the cell -is considered to be overpopulated} +\item{overpopulation_percentage}{Percentage of occupied hosts when the cell is considered to be +overpopulated} -\item{leaving_percentage}{percentage of pests leaving an overpopulated cell} +\item{leaving_percentage}{Percentage of pests leaving an overpopulated cell} -\item{leaving_scale_coefficient}{coefficient to multiply scale parameter of -the natural kernel (if applicable)} +\item{leaving_scale_coefficient}{Coefficient to multiply scale parameter of the natural kernel +(if applicable)} \item{bbox}{bounding box for network kernel} @@ -329,7 +317,7 @@ anthropogenic_kernel_type = 'network'.} \item{network_max_distance}{maximum time a propagule rides on the network. Used if anthropogenic_kernel_type = 'network'.} -\item{network_filename}{entire file path for the network file. Used if +\item{network_filename}{The entire file path for the network file. Used if anthropogenic_kernel_type = 'network'.} \item{network_movement}{What movement type do you want to use in the network kernel either @@ -340,11 +328,14 @@ along the edge. "jump" automatically moves to the nearest node when moving throu \item{weather_size}{the number of matrices in a list or layers in a raster object} \item{weather_type}{string indicating how the weather data is passed in either -as a mean and standard deviation to represent uncertainty ("probablisticc") or as a time +as a mean and standard deviation to represent uncertainty ("probabilistic") or as a time series ("deterministic")} \item{dispersers_to_soils_percentage}{range from 0 to 1 representing the percentage of dispersers that fall to the soil and survive.} + +\item{use_soils}{Boolean to indicate if pests establish in the soil and spread out from there. +Typically used for soil borne pathogens.} } \value{ list of vector matrices of infected and susceptible hosts per diff --git a/man/pops_multirun.Rd b/man/pops_multirun.Rd index a82cebd7..9c999d55 100644 --- a/man/pops_multirun.Rd +++ b/man/pops_multirun.Rd @@ -79,157 +79,138 @@ pops_multirun( dispersers_to_soils_percentage = 0, quarantine_directions = "", multiple_random_seeds = FALSE, - random_seeds = NULL, + file_random_seeds = NULL, use_soils = FALSE, - soil_starting_pest_file = "" + soil_starting_pest_file = "", + start_with_soil_populations = FALSE ) } \arguments{ -\item{infected_file}{Raster file with initial infections. Units for -infections are based on data availability and the way the units used for your -host file is created (e.g. percent area, # of hosts per cell, etc.).} - -\item{host_file}{path to raster files with number of hosts and standard -deviation on those estimates can be based in 3 formats (a single file with -number of hosts, a single file with 2 layers number of hosts and standard -deviation, or two files 1 with number of hosts and the other with standard -deviation of those estimates). The units for this can be of many formats the -two most common that we use are either percent area (0 to 100) or # of hosts -in the cell. Usually depends on data available and estimation methods.} - -\item{total_populations_file}{path to raster file with number of total -populations of all hosts and non-hosts. This depends on how your host data is -set up. If host is percent area then this should be a raster with values -that are 100 anywhere with host. If host file is # of hosts in a cell then -this should be a raster with values that are the max of the host raster any -where the # of hosts is greater than 0.} - -\item{parameter_means}{A vector of the means of the model parameters -(reproductive_rate, natural_dispersal_distance, percent_natural_dispersal, -anthropogenic_dispersal_distance, natural kappa, anthropogenic kappa, -network_min_distance, and network_max_distance). 1x8 vector.} - -\item{parameter_cov_matrix}{A covariance matrix from the previous years -posterior parameter estimation ordered from (reproductive_rate, -natural_dispersal_distance, percent_natural_dispersal, -anthropogenic_dispersal_distance, natural kappa, anthropogenic kappa, +\item{infected_file}{Raster file with initial infections. Units for infections are based on data +availability and the way the units used for your host file is created (e.g. percent area, # of +hosts per cell, etc.).} + +\item{host_file}{path to raster files with number of hosts and standard deviation on those +estimates can be based in 3 formats (a single file with number of hosts, a single file with 2 +layers number of hosts and standard deviation, or two files 1 with number of hosts and the other +with standard deviation of those estimates). The units for this can be of many formats the two +most common that we use are either percent area (0 to 100) or # of hosts in the cell. Usually +depends on data available and estimation methods.} + +\item{total_populations_file}{path to raster file with number of total populations of all hosts +and non-hosts. This depends on how your host data is set up. If host is percent area then this +should be a raster with values that are 100 anywhere with host. If host file is # of hosts in a +cell then this should be a raster with values that are the max of the host raster any where the +# of hosts is greater than 0.} + +\item{parameter_means}{A vector of the means of the model parameters (reproductive_rate, +natural_dispersal_distance, percent_natural_dispersal, anthropogenic_dispersal_distance, natural +kappa, anthropogenic kappa, network_min_distance, and network_max_distance). 1x8 vector.} + +\item{parameter_cov_matrix}{A covariance matrix from the previous years posterior parameter +estimation ordered from (reproductive_rate, natural_dispersal_distance, +percent_natural_dispersal, anthropogenic_dispersal_distance, natural kappa, anthropogenic kappa, network_min_distance, and network_max_distance) Should be 8x8 matrix.} -\item{temp}{boolean that allows the use of temperature coefficients to -modify spread (TRUE or FALSE)} +\item{temp}{boolean that allows the use of temperature coefficients to modify spread +(TRUE or FALSE)} -\item{temperature_coefficient_file}{path to raster file with temperature -coefficient data for the timestep and and time period specified (e.g. if timestep -= week and start_date = 2017_01_01 and end_date = 2019_12_31 this file would -have 52 * 3 bands = 156 bands with data being weekly precipitation -coefficients). We convert raw precipitation values to coefficients that -affect the reproduction and survival of the pest all values in the raster are -between 0 and 1.} +\item{temperature_coefficient_file}{path to raster file with temperature coefficient data for the +timestep and and time period specified (e.g. if timestep = week and start_date = 2017_01_01 and +end_date = 2019_12_31 this file would have 52 * 3 bands = 156 bands with data being weekly +precipitation coefficients). We convert raw precipitation values to coefficients that affect the +reproduction and survival of the pest all values in the raster are between 0 and 1.} -\item{precip}{boolean that allows the use of precipitation coefficients to -modify spread (TRUE or FALSE)} +\item{precip}{boolean that allows the use of precipitation coefficients to modify spread +(TRUE or FALSE)} -\item{precipitation_coefficient_file}{Raster file with precipitation -coefficient data for the timestep and time period specified (e.g. if timestep -= week and start_date = 2017_01_01 and end_date = 2019_12_31 this file would -have 52 * 3 bands = 156 bands with data being weekly precipitation -coefficients). We convert raw precipitation values to coefficients that -affect the reproduction and survival of the pest all values in the raster are -between 0 and 1.} +\item{precipitation_coefficient_file}{Raster file with precipitation coefficient data for the +timestep and time period specified (e.g. if timestep = week and start_date = 2017_01_01 and +end_date = 2019_12_31 this file would have 52 * 3 bands = 156 bands with data being weekly +precipitation coefficients). We convert raw precipitation values to coefficients that affect the +reproduction and survival of the pest all values in the raster are between 0 and 1.} -\item{model_type}{What type of model most represents your system. Options -are "SEI" (Susceptible - Exposed - Infected/Infested) or "SI" -(Susceptible - Infected/Infested). Default value is "SI".} +\item{model_type}{What type of model most represents your system. Options are "SEI" +(Susceptible - Exposed - Infected/Infested) or "SI" (Susceptible - Infected/Infested). Default +value is "SI".} -\item{latency_period}{How many times steps does it take to for exposed -populations become infected/infested. This is an integer value and must be -greater than 0 if model type is SEI.} +\item{latency_period}{How many times steps does it take to for exposed populations become +infected/infested. This is an integer value and must be greater than 0 if model type is SEI.} -\item{time_step}{how often should spread occur options: ('day', 'week', 'month').} +\item{time_step}{How often should spread occur options: ('day', 'week', 'month').} -\item{season_month_start}{when does spread first start occurring in the year -for your pest or pathogen (integer value between 1 and 12)} +\item{season_month_start}{When does spread first start occurring in the year for your pest or +pathogen (integer value between 1 and 12)} -\item{season_month_end}{when does spread end during the year for your pest +\item{season_month_end}{When does spread end during the year for your pest or pathogen (integer value between 1 and 12)} -\item{start_date}{date to start the simulation with format ('YYYY_MM_DD')} +\item{start_date}{Date to start the simulation with format ('YYYY_MM_DD')} -\item{end_date}{date to end the simulation with format ('YYYY_MM_DD')} +\item{end_date}{Date to end the simulation with format ('YYYY_MM_DD')} -\item{use_survival_rates}{boolean to indicate if the model will use survival rates to limit the +\item{use_survival_rates}{Boolean to indicate if the model will use survival rates to limit the survival or emergence of overwintering generations.} \item{survival_rate_month}{What month do over wintering generations emerge. We suggest using the month before for this parameter as it is when the survival rates raster will be applied.} -\item{survival_rate_day}{what day should the survival rates be applied} +\item{survival_rate_day}{What day should the survival rates be applied} \item{survival_rates_file}{Raster file with survival rates from 0 to 1 representing the percentage of emergence for a cell.} -\item{use_lethal_temperature}{a boolean to answer the question: does your -pest or pathogen have a temperature at which it cannot survive? -(TRUE or FALSE)} +\item{use_lethal_temperature}{A boolean to answer the question: does your pest or pathogen have +a temperature at which it cannot survive? (TRUE or FALSE)} -\item{temperature_file}{path to raster file with temperature data for -minimum temperature} +\item{temperature_file}{Path to raster file with temperature data for minimum temperature} -\item{lethal_temperature}{the temperature in degrees C at which lethal -temperature related mortality occurs for your pest or pathogen (-50 to 60)} +\item{lethal_temperature}{The temperature in degrees C at which lethal temperature related +mortality occurs for your pest or pathogen (-50 to 60)} -\item{lethal_temperature_month}{the month in which lethal temperature -related mortality occurs for your pest or pathogen integer value between 1 -and 12} +\item{lethal_temperature_month}{The month in which lethal temperature related mortality occurs +for your pest or pathogen integer value between 1 and 12} -\item{mortality_on}{boolean to turn host mortality on and off -(TRUE or FALSE)} +\item{mortality_on}{Boolean to turn host mortality on and off (TRUE or FALSE)} -\item{mortality_rate}{rate at which mortality occurs value between 0 and 1} +\item{mortality_rate}{Rate at which mortality occurs value between 0 and 1} -\item{mortality_time_lag}{time lag from infection until mortality can occur -in time steps integer >= 1} +\item{mortality_time_lag}{Time lag from infection until mortality can occur in time steps +integer >= 1} -\item{mortality_frequency}{sets the frequency of mortality calculations occur -either ('year', 'month', week', 'day', 'time step', or 'every_n_steps')} +\item{mortality_frequency}{Sets the frequency of mortality calculations occur either ('year', +'month', week', 'day', 'time step', or 'every_n_steps')} -\item{mortality_frequency_n}{sets number of units from mortality_frequency in -which to run the mortality calculation if mortality_frequency is -'every_n_steps'. Must be an integer >= 1.} +\item{mortality_frequency_n}{Sets number of units from mortality_frequency in which to run the +mortality calculation if mortality_frequency is 'every_n_steps'. Must be an integer >= 1.} -\item{management}{boolean to allow use of management (TRUE or FALSE)} +\item{management}{Boolean to allow use of management (TRUE or FALSE)} -\item{treatment_dates}{dates in which to apply treatment list with format -('YYYY_MM_DD') (needs to be the same length as treatment_file and -pesticide_duration)} +\item{treatment_dates}{Dates in which to apply treatment list with format ('YYYY_MM_DD') +(needs to be the same length as treatment_file and pesticide_duration)} -\item{treatments_file}{path to raster files with treatment data by dates. -Needs to be a list of files the same length as treatment_dates and -pesticide_duration.} +\item{treatments_file}{Path to raster files with treatment data by dates. Needs to be a list of +files the same length as treatment_dates and pesticide_duration.} -\item{treatment_method}{what method to use when applying treatment one of -("ratio" or "all infected"). ratio removes a portion of all infected and -susceptibles, all infected removes all infected a portion of susceptibles.} +\item{treatment_method}{What method to use when applying treatment one of ("ratio" or "all +infected"). ratio removes a portion of all infected and susceptibles, all infected removes all +infected a portion of susceptibles.} -\item{natural_kernel_type}{what type of dispersal kernel should be used for -natural dispersal. Current dispersal kernel options are - ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', - 'hyperbolic secant', 'gamma', 'weibull', - 'logistic')} +\item{natural_kernel_type}{What type of dispersal kernel should be used for natural dispersal. +Current dispersal kernel options are ('Cauchy', 'exponential', 'uniform', +'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic')} -\item{anthropogenic_kernel_type}{what type of dispersal kernel should be -used for anthropogenic dispersal. Current dispersal kernel options are - ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', - 'hyperbolic secant', 'gamma', 'weibull', 'logistic', 'network')} +\item{anthropogenic_kernel_type}{What type of dispersal kernel should be used for anthropogenic +dispersal. Current dispersal kernel options are ('cauchy', 'exponential', 'uniform', +'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic', +'network')} -\item{natural_dir}{sets the predominate direction of natural dispersal -usually due to wind values ('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', -'NONE')} +\item{natural_dir}{Sets the predominate direction of natural dispersal usually due to wind values +('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE')} -\item{anthropogenic_dir}{sets the predominate direction of anthropogenic -dispersal usually due to human movement typically over long distances (e.g. -nursery trade, movement of firewood, etc..) ('N', 'NW', 'W', 'SW', 'S', -'SE', 'E', 'NE', 'NONE')} +\item{anthropogenic_dir}{Sets the predominate direction of anthropogenic dispersal usually due +to human movement typically over long distances (e.g. nursery trade, movement of firewood, etc..) +('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE')} \item{number_of_iterations}{how many iterations do you want to run to allow the calibration to converge at least 10} @@ -237,41 +218,39 @@ the calibration to converge at least 10} \item{number_of_cores}{enter how many cores you want to use (default = NA). If not set uses the # of CPU cores - 1. must be an integer >= 1} -\item{pesticide_duration}{how long does the pestcide (herbicide, vaccine, -etc..) last before the host is susceptible again. If value is 0 treatment -is a culling (i.e. host removal) not a pesticide treatment. (needs to be the - same length as treatment_dates and treatment_file)} +\item{pesticide_duration}{How long does the pesticide (herbicide, vaccine, etc..) last before the +host is susceptible again. If value is 0 treatment is a culling (i.e. host removal) not a +pesticide treatment. (needs to be the same length as treatment_dates and treatment_file)} -\item{pesticide_efficacy}{how effictive is the pesticide at preventing the -disease or killing the pest (if this is 0.70 then when applied it -successfully treats 70 percent of the plants or animals)} +\item{pesticide_efficacy}{How effective is the pesticide at preventing the disease or killing the +pest (if this is 0.70 then when applied it successfully treats 70 percent of the plants or +animals).} -\item{random_seed}{sets the random seed for the simulation used for reproducibility} +\item{random_seed}{Sets the random seed for the simulation used for reproducibility} -\item{output_frequency}{sets when outputs occur either ('year', 'month', -'week', 'day', 'time step', or 'every_n_steps')} +\item{output_frequency}{Sets when outputs occur either ('year', 'month', week', 'day', +'time step', or 'every_n_steps')} -\item{output_frequency_n}{sets number of units from output_frequency in which -to export model results if mortality_frequency is 'every_n_steps'. -Must be an integer >= 1.} +\item{output_frequency_n}{Sets number of units from output_frequency in which to export model +results if mortality_frequency is 'every_n_steps'. Must be an integer >= 1.} -\item{movements_file}{this is a csv file with columns lon_from, lat_from, -lon_to, lat_to, number of animals, and date.} +\item{movements_file}{This is a csv file with columns lon_from, lat_from, lon_to, lat_to, number +of animals, and date.} -\item{use_movements}{this is a boolean to turn on use of the movement module.} +\item{use_movements}{This is a boolean to turn on use of the movement module.} -\item{start_exposed}{Do your initial conditions start as exposed or infected -(only used if model_type is "SEI"). Default False. If this is TRUE need to -have both an infected_file (this can be a raster of all 0's) and exposed_file} +\item{start_exposed}{Do your initial conditions start as exposed or infected (only used if +model_type is "SEI"). Default False. If this is TRUE need to have both an infected_file (this +can be a raster of all 0's) and exposed_file} -\item{generate_stochasticity}{Boolean to indicate whether to use -stochasticity in reproductive functions default is TRUE} +\item{generate_stochasticity}{Boolean to indicate whether to use stochasticity in reproductive +functions default is TRUE} -\item{establishment_stochasticity}{Boolean to indicate whether to use -stochasticity in establishment functions default is TRUE} +\item{establishment_stochasticity}{Boolean to indicate whether to use stochasticity in +establishment functions default is TRUE} -\item{movement_stochasticity}{Boolean to indicate whether to use -stochasticity in movement functions default is TRUE} +\item{movement_stochasticity}{Boolean to indicate whether to use stochasticity in movement +functions default is TRUE} \item{dispersal_stochasticity}{Boolean to indicate whether to use a stochasticity in the dispersal kernel default is TRUE} @@ -279,38 +258,33 @@ dispersal kernel default is TRUE} \item{establishment_probability}{Threshold to determine establishment if establishment_stochasticity is FALSE (range 0 to 1, default = 0.5)} -\item{dispersal_percentage}{Percentage of dispersal used to calculate the -bounding box for deterministic dispersal} +\item{dispersal_percentage}{Percentage of dispersal used to calculate the bounding box for +deterministic dispersal} -\item{quarantine_areas_file}{path to raster file with quarantine boundaries -used in calculating likelihood of quarantine escape if use_quarantine is -TRUE} +\item{quarantine_areas_file}{Path to raster file with quarantine boundaries used in calculating +likelihood of quarantine escape if use_quarantine is TRUE} -\item{use_quarantine}{boolean to indicate whether or not there is a -quarantine area if TRUE must pass in a raster file indicating the -quarantine areas (default = FALSE)} +\item{use_quarantine}{Boolean to indicate whether or not there is a quarantine area if TRUE must +pass in a raster file indicating the quarantine areas (default = FALSE)} -\item{use_spreadrates}{boolean to indicate whether or not to calculate -spread rates} +\item{use_spreadrates}{Boolean to indicate whether or not to calculate spread rates} -\item{use_overpopulation_movements}{boolean to indicate whether to use -the overpopulation pest movement module (driven by the natural kernel with -its scale parameter modified by a coefficient)} +\item{use_overpopulation_movements}{Boolean to indicate whether to use the overpopulation pest +movement module (driven by the natural kernel with its scale parameter modified by a coefficient)} -\item{overpopulation_percentage}{percentage of occupied hosts when the cell -is considered to be overpopulated} +\item{overpopulation_percentage}{Percentage of occupied hosts when the cell is considered to be +overpopulated} -\item{leaving_percentage}{percentage of pests leaving an overpopulated cell} +\item{leaving_percentage}{Percentage of pests leaving an overpopulated cell} -\item{leaving_scale_coefficient}{coefficient to multiply scale parameter of -the natural kernel (if applicable)} +\item{leaving_scale_coefficient}{Coefficient to multiply scale parameter of the natural kernel +(if applicable)} -\item{exposed_file}{a file with the exposed for the current} +\item{exposed_file}{A file with the exposed for the current} -\item{mask}{Raster file used to provide a mask to remove 0's that are not -true negatives from comparisons (e.g. mask out lakes and oceans from statics -if modeling terrestrial species). This can also be used to mask out areas -that can't be managed in the auto_manage function.} +\item{mask}{Raster file used to provide a mask to remove 0's that are not true negatives from +comparisons (e.g. mask out lakes and oceans from statics if modeling terrestrial species). This +can also be used to mask out areas that can't be managed in the auto_manage function.} \item{write_outputs}{Either c("summary_outputs", or "None"). If not "None" output folder path must be provided.} @@ -318,7 +292,7 @@ that can't be managed in the auto_manage function.} \item{output_folder_path}{this is the full path with either / or \\ (e.g., "C:/user_name/desktop/pops_sod_2020_2023/outputs/")} -\item{network_filename}{entire file path for the network file. Used if +\item{network_filename}{The entire file path for the network file. Used if anthropogenic_kernel_type = 'network'.} \item{network_movement}{What movement type do you want to use in the network kernel either @@ -326,19 +300,19 @@ anthropogenic_kernel_type = 'network'.} along the edge. "jump" automatically moves to the nearest node when moving through the network. "teleport" moves from node to node most likely used for airport and seaport networks.} -\item{use_initial_condition_uncertainty}{boolean to indicate whether or not to propagate and +\item{use_initial_condition_uncertainty}{Boolean to indicate whether or not to propagate and partition uncertainty from initial conditions. If TRUE the infected_file needs to have 2 layers one with the mean value and one with the standard deviation. If an SEI model is used the exposed_file needs to have 2 layers one with the mean value and one with the standard deviation} -\item{use_host_uncertainty}{boolean to indicate whether or not to propagate and partition +\item{use_host_uncertainty}{Boolean to indicate whether or not to propagate and partition uncertainty from host data. If TRUE the host_file needs to have 2 layers one with the mean value and one with the standard deviation.} -\item{weather_type}{string indicating how the weather data is passed in either -as a mean and standard deviation to represent uncertainty ("probabilistic") or as a time -series ("deterministic")} +\item{weather_type}{string indicating how the weather data is passed in either as a mean and +standard deviation to represent uncertainty ("probabilistic") or as a time series +("deterministic")} \item{temperature_coefficient_sd_file}{Raster file with temperature coefficient standard deviation data for the timestep and time period specified (e.g. if timestep = week this file @@ -352,26 +326,28 @@ would have 52 bands with data being weekly precipitation coefficient standard de convert raw precipitation values to coefficients that affect the reproduction and survival of the pest all values in the raster are between 0 and 1.} -\item{dispersers_to_soils_percentage}{range from 0 to 1 representing the percentage -of dispersers that fall to the soil and survive.} +\item{dispersers_to_soils_percentage}{Range from 0 to 1 representing the percentage of dispersers +that fall to the soil and survive.} -\item{quarantine_directions}{string with comma separated directions to include -in the quarantine direction analysis, e.g., 'N,E'. By default all directions -(N, S, E, W) are considered} +\item{quarantine_directions}{String with comma separated directions to include in the quarantine +direction analysis, e.g., 'N,E'. By default all directions (N, S, E, W) are considered} -\item{multiple_random_seeds}{boolean to indicate if the model should use multiple random seeds +\item{multiple_random_seeds}{Boolean to indicate if the model should use multiple random seeds (allows for performing uncertainty partitioning) or a single random seed (backwards compatibility option). Default is FALSE.} -\item{random_seeds}{A file path to the file with the .csv file containing random_seeds table. -Use a file if you are trying to recreate an exact analysis otherwise we suggest leaving the +\item{file_random_seeds}{A file path to the file with the .csv file containing random_seeds +table. Use if you are trying to recreate an exact analysis otherwise we suggest leaving the default. Default is Null which draws the seed numbers for each.} -\item{use_soils}{boolean to indicate if pests establish in the soil and spread out from there. +\item{use_soils}{Boolean to indicate if pests establish in the soil and spread out from there. Typically used for soil borne pathogens.} -\item{soil_starting_pest_file}{path to the raster file with the starting -amount of pest or pathogen.} +\item{soil_starting_pest_file}{path to the raster file with the starting amount of pest or +pathogen.} + +\item{start_with_soil_populations}{Boolean to indicate whether to use a starting soil pest or +pathogen population if TRUE then soil_starting_pest_file is required.} } \value{ list of infected and susceptible per year diff --git a/man/validate.Rd b/man/validate.Rd index ef75e57a..766d07af 100644 --- a/man/validate.Rd +++ b/man/validate.Rd @@ -83,9 +83,10 @@ validate( dispersers_to_soils_percentage = 0, quarantine_directions = "", multiple_random_seeds = FALSE, - random_seeds = NULL, + file_random_seeds = NULL, use_soils = FALSE, - soil_starting_pest_file = "" + soil_starting_pest_file = "", + start_with_soil_populations = FALSE ) } \arguments{ @@ -104,178 +105,158 @@ If not set uses the # of CPU cores - 1. must be an integer >= 1} \item{parameter_cov_matrix}{the parameter covariance matrix from the ABC calibration function (posterior covariance matrix)} -\item{infected_file}{Raster file with initial infections. Units for -infections are based on data availability and the way the units used for your -host file is created (e.g. percent area, # of hosts per cell, etc.).} - -\item{host_file}{path to raster files with number of hosts and standard -deviation on those estimates can be based in 3 formats (a single file with -number of hosts, a single file with 2 layers number of hosts and standard -deviation, or two files 1 with number of hosts and the other with standard -deviation of those estimates). The units for this can be of many formats the -two most common that we use are either percent area (0 to 100) or # of hosts -in the cell. Usually depends on data available and estimation methods.} - -\item{total_populations_file}{path to raster file with number of total -populations of all hosts and non-hosts. This depends on how your host data is -set up. If host is percent area then this should be a raster with values -that are 100 anywhere with host. If host file is # of hosts in a cell then -this should be a raster with values that are the max of the host raster any -where the # of hosts is greater than 0.} - -\item{temp}{boolean that allows the use of temperature coefficients to -modify spread (TRUE or FALSE)} - -\item{temperature_coefficient_file}{path to raster file with temperature -coefficient data for the timestep and and time period specified (e.g. if timestep -= week and start_date = 2017_01_01 and end_date = 2019_12_31 this file would -have 52 * 3 bands = 156 bands with data being weekly precipitation -coefficients). We convert raw precipitation values to coefficients that -affect the reproduction and survival of the pest all values in the raster are -between 0 and 1.} - -\item{precip}{boolean that allows the use of precipitation coefficients to -modify spread (TRUE or FALSE)} - -\item{precipitation_coefficient_file}{Raster file with precipitation -coefficient data for the timestep and time period specified (e.g. if timestep -= week and start_date = 2017_01_01 and end_date = 2019_12_31 this file would -have 52 * 3 bands = 156 bands with data being weekly precipitation -coefficients). We convert raw precipitation values to coefficients that -affect the reproduction and survival of the pest all values in the raster are -between 0 and 1.} - -\item{model_type}{What type of model most represents your system. Options -are "SEI" (Susceptible - Exposed - Infected/Infested) or "SI" -(Susceptible - Infected/Infested). Default value is "SI".} - -\item{latency_period}{How many times steps does it take to for exposed -populations become infected/infested. This is an integer value and must be -greater than 0 if model type is SEI.} - -\item{time_step}{how often should spread occur options: ('day', 'week', 'month').} - -\item{season_month_start}{when does spread first start occurring in the year -for your pest or pathogen (integer value between 1 and 12)} - -\item{season_month_end}{when does spread end during the year for your pest +\item{infected_file}{Raster file with initial infections. Units for infections are based on data +availability and the way the units used for your host file is created (e.g. percent area, # of +hosts per cell, etc.).} + +\item{host_file}{path to raster files with number of hosts and standard deviation on those +estimates can be based in 3 formats (a single file with number of hosts, a single file with 2 +layers number of hosts and standard deviation, or two files 1 with number of hosts and the other +with standard deviation of those estimates). The units for this can be of many formats the two +most common that we use are either percent area (0 to 100) or # of hosts in the cell. Usually +depends on data available and estimation methods.} + +\item{total_populations_file}{path to raster file with number of total populations of all hosts +and non-hosts. This depends on how your host data is set up. If host is percent area then this +should be a raster with values that are 100 anywhere with host. If host file is # of hosts in a +cell then this should be a raster with values that are the max of the host raster any where the +# of hosts is greater than 0.} + +\item{temp}{boolean that allows the use of temperature coefficients to modify spread +(TRUE or FALSE)} + +\item{temperature_coefficient_file}{path to raster file with temperature coefficient data for the +timestep and and time period specified (e.g. if timestep = week and start_date = 2017_01_01 and +end_date = 2019_12_31 this file would have 52 * 3 bands = 156 bands with data being weekly +precipitation coefficients). We convert raw precipitation values to coefficients that affect the +reproduction and survival of the pest all values in the raster are between 0 and 1.} + +\item{precip}{boolean that allows the use of precipitation coefficients to modify spread +(TRUE or FALSE)} + +\item{precipitation_coefficient_file}{Raster file with precipitation coefficient data for the +timestep and time period specified (e.g. if timestep = week and start_date = 2017_01_01 and +end_date = 2019_12_31 this file would have 52 * 3 bands = 156 bands with data being weekly +precipitation coefficients). We convert raw precipitation values to coefficients that affect the +reproduction and survival of the pest all values in the raster are between 0 and 1.} + +\item{model_type}{What type of model most represents your system. Options are "SEI" +(Susceptible - Exposed - Infected/Infested) or "SI" (Susceptible - Infected/Infested). Default +value is "SI".} + +\item{latency_period}{How many times steps does it take to for exposed populations become +infected/infested. This is an integer value and must be greater than 0 if model type is SEI.} + +\item{time_step}{How often should spread occur options: ('day', 'week', 'month').} + +\item{season_month_start}{When does spread first start occurring in the year for your pest or +pathogen (integer value between 1 and 12)} + +\item{season_month_end}{When does spread end during the year for your pest or pathogen (integer value between 1 and 12)} -\item{start_date}{date to start the simulation with format ('YYYY_MM_DD')} +\item{start_date}{Date to start the simulation with format ('YYYY_MM_DD')} -\item{end_date}{date to end the simulation with format ('YYYY_MM_DD')} +\item{end_date}{Date to end the simulation with format ('YYYY_MM_DD')} -\item{use_survival_rates}{boolean to indicate if the model will use survival rates to limit the +\item{use_survival_rates}{Boolean to indicate if the model will use survival rates to limit the survival or emergence of overwintering generations.} \item{survival_rate_month}{What month do over wintering generations emerge. We suggest using the month before for this parameter as it is when the survival rates raster will be applied.} -\item{survival_rate_day}{what day should the survival rates be applied} +\item{survival_rate_day}{What day should the survival rates be applied} \item{survival_rates_file}{Raster file with survival rates from 0 to 1 representing the percentage of emergence for a cell.} -\item{use_lethal_temperature}{a boolean to answer the question: does your -pest or pathogen have a temperature at which it cannot survive? -(TRUE or FALSE)} +\item{use_lethal_temperature}{A boolean to answer the question: does your pest or pathogen have +a temperature at which it cannot survive? (TRUE or FALSE)} -\item{temperature_file}{path to raster file with temperature data for -minimum temperature} +\item{temperature_file}{Path to raster file with temperature data for minimum temperature} -\item{lethal_temperature}{the temperature in degrees C at which lethal -temperature related mortality occurs for your pest or pathogen (-50 to 60)} +\item{lethal_temperature}{The temperature in degrees C at which lethal temperature related +mortality occurs for your pest or pathogen (-50 to 60)} -\item{lethal_temperature_month}{the month in which lethal temperature -related mortality occurs for your pest or pathogen integer value between 1 -and 12} +\item{lethal_temperature_month}{The month in which lethal temperature related mortality occurs +for your pest or pathogen integer value between 1 and 12} -\item{mortality_on}{boolean to turn host mortality on and off -(TRUE or FALSE)} +\item{mortality_on}{Boolean to turn host mortality on and off (TRUE or FALSE)} -\item{mortality_rate}{rate at which mortality occurs value between 0 and 1} +\item{mortality_rate}{Rate at which mortality occurs value between 0 and 1} -\item{mortality_time_lag}{time lag from infection until mortality can occur -in time steps integer >= 1} +\item{mortality_time_lag}{Time lag from infection until mortality can occur in time steps +integer >= 1} -\item{mortality_frequency}{sets the frequency of mortality calculations occur -either ('year', 'month', week', 'day', 'time step', or 'every_n_steps')} +\item{mortality_frequency}{Sets the frequency of mortality calculations occur either ('year', +'month', week', 'day', 'time step', or 'every_n_steps')} -\item{mortality_frequency_n}{sets number of units from mortality_frequency in -which to run the mortality calculation if mortality_frequency is -'every_n_steps'. Must be an integer >= 1.} +\item{mortality_frequency_n}{Sets number of units from mortality_frequency in which to run the +mortality calculation if mortality_frequency is 'every_n_steps'. Must be an integer >= 1.} -\item{management}{boolean to allow use of management (TRUE or FALSE)} +\item{management}{Boolean to allow use of management (TRUE or FALSE)} -\item{treatment_dates}{dates in which to apply treatment list with format -('YYYY_MM_DD') (needs to be the same length as treatment_file and -pesticide_duration)} +\item{treatment_dates}{Dates in which to apply treatment list with format ('YYYY_MM_DD') +(needs to be the same length as treatment_file and pesticide_duration)} -\item{treatments_file}{path to raster files with treatment data by dates. -Needs to be a list of files the same length as treatment_dates and -pesticide_duration.} +\item{treatments_file}{Path to raster files with treatment data by dates. Needs to be a list of +files the same length as treatment_dates and pesticide_duration.} -\item{treatment_method}{what method to use when applying treatment one of -("ratio" or "all infected"). ratio removes a portion of all infected and -susceptibles, all infected removes all infected a portion of susceptibles.} +\item{treatment_method}{What method to use when applying treatment one of ("ratio" or "all +infected"). ratio removes a portion of all infected and susceptibles, all infected removes all +infected a portion of susceptibles.} -\item{natural_kernel_type}{what type of dispersal kernel should be used for -natural dispersal. Current dispersal kernel options are - ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', - 'hyperbolic secant', 'gamma', 'weibull', - 'logistic')} +\item{natural_kernel_type}{What type of dispersal kernel should be used for natural dispersal. +Current dispersal kernel options are ('Cauchy', 'exponential', 'uniform', +'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic')} -\item{anthropogenic_kernel_type}{what type of dispersal kernel should be -used for anthropogenic dispersal. Current dispersal kernel options are - ('cauchy', 'exponential', 'uniform', 'deterministic neighbor','power law', - 'hyperbolic secant', 'gamma', 'weibull', 'logistic', 'network')} +\item{anthropogenic_kernel_type}{What type of dispersal kernel should be used for anthropogenic +dispersal. Current dispersal kernel options are ('cauchy', 'exponential', 'uniform', +'deterministic neighbor','power law', 'hyperbolic secant', 'gamma', 'weibull', 'logistic', +'network')} -\item{natural_dir}{sets the predominate direction of natural dispersal -usually due to wind values ('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', -'NONE')} +\item{natural_dir}{Sets the predominate direction of natural dispersal usually due to wind values +('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE')} -\item{anthropogenic_dir}{sets the predominate direction of anthropogenic -dispersal usually due to human movement typically over long distances (e.g. -nursery trade, movement of firewood, etc..) ('N', 'NW', 'W', 'SW', 'S', -'SE', 'E', 'NE', 'NONE')} +\item{anthropogenic_dir}{Sets the predominate direction of anthropogenic dispersal usually due +to human movement typically over long distances (e.g. nursery trade, movement of firewood, etc..) +('N', 'NW', 'W', 'SW', 'S', 'SE', 'E', 'NE', 'NONE')} -\item{pesticide_duration}{how long does the pestcide (herbicide, vaccine, -etc..) last before the host is susceptible again. If value is 0 treatment -is a culling (i.e. host removal) not a pesticide treatment. (needs to be the - same length as treatment_dates and treatment_file)} +\item{pesticide_duration}{How long does the pesticide (herbicide, vaccine, etc..) last before the +host is susceptible again. If value is 0 treatment is a culling (i.e. host removal) not a +pesticide treatment. (needs to be the same length as treatment_dates and treatment_file)} -\item{pesticide_efficacy}{how effictive is the pesticide at preventing the -disease or killing the pest (if this is 0.70 then when applied it -successfully treats 70 percent of the plants or animals)} +\item{pesticide_efficacy}{How effective is the pesticide at preventing the disease or killing the +pest (if this is 0.70 then when applied it successfully treats 70 percent of the plants or +animals).} \item{mask}{Raster file used to provide a mask to remove 0's that are not true negatives from comparisons (e.g. mask out lakes and oceans from statics if modeling terrestrial species).} -\item{output_frequency}{sets when outputs occur either ('year', 'month', -'week', 'day', 'time step', or 'every_n_steps')} +\item{output_frequency}{Sets when outputs occur either ('year', 'month', week', 'day', +'time step', or 'every_n_steps')} -\item{output_frequency_n}{sets number of units from output_frequency in which -to export model results if mortality_frequency is 'every_n_steps'. -Must be an integer >= 1.} +\item{output_frequency_n}{Sets number of units from output_frequency in which to export model +results if mortality_frequency is 'every_n_steps'. Must be an integer >= 1.} -\item{movements_file}{this is a csv file with columns lon_from, lat_from, -lon_to, lat_to, number of animals, and date.} +\item{movements_file}{This is a csv file with columns lon_from, lat_from, lon_to, lat_to, number +of animals, and date.} -\item{use_movements}{this is a boolean to turn on use of the movement module.} +\item{use_movements}{This is a boolean to turn on use of the movement module.} -\item{start_exposed}{Do your initial conditions start as exposed or infected -(only used if model_type is "SEI"). Default False. If this is TRUE need to -have both an infected_file (this can be a raster of all 0's) and exposed_file} +\item{start_exposed}{Do your initial conditions start as exposed or infected (only used if +model_type is "SEI"). Default False. If this is TRUE need to have both an infected_file (this +can be a raster of all 0's) and exposed_file} -\item{generate_stochasticity}{Boolean to indicate whether to use -stochasticity in reproductive functions default is TRUE} +\item{generate_stochasticity}{Boolean to indicate whether to use stochasticity in reproductive +functions default is TRUE} -\item{establishment_stochasticity}{Boolean to indicate whether to use -stochasticity in establishment functions default is TRUE} +\item{establishment_stochasticity}{Boolean to indicate whether to use stochasticity in +establishment functions default is TRUE} -\item{movement_stochasticity}{Boolean to indicate whether to use -stochasticity in movement functions default is TRUE} +\item{movement_stochasticity}{Boolean to indicate whether to use stochasticity in movement +functions default is TRUE} \item{dispersal_stochasticity}{Boolean to indicate whether to use a stochasticity in the dispersal kernel default is TRUE} @@ -283,33 +264,29 @@ dispersal kernel default is TRUE} \item{establishment_probability}{Threshold to determine establishment if establishment_stochasticity is FALSE (range 0 to 1, default = 0.5)} -\item{dispersal_percentage}{Percentage of dispersal used to calculate the -bounding box for deterministic dispersal} +\item{dispersal_percentage}{Percentage of dispersal used to calculate the bounding box for +deterministic dispersal} -\item{quarantine_areas_file}{path to raster file with quarantine boundaries -used in calculating likelihood of quarantine escape if use_quarantine is -TRUE} +\item{quarantine_areas_file}{Path to raster file with quarantine boundaries used in calculating +likelihood of quarantine escape if use_quarantine is TRUE} -\item{use_quarantine}{boolean to indicate whether or not there is a -quarantine area if TRUE must pass in a raster file indicating the -quarantine areas (default = FALSE)} +\item{use_quarantine}{Boolean to indicate whether or not there is a quarantine area if TRUE must +pass in a raster file indicating the quarantine areas (default = FALSE)} -\item{use_spreadrates}{boolean to indicate whether or not to calculate -spread rates} +\item{use_spreadrates}{Boolean to indicate whether or not to calculate spread rates} -\item{use_overpopulation_movements}{boolean to indicate whether to use -the overpopulation pest movement module (driven by the natural kernel with -its scale parameter modified by a coefficient)} +\item{use_overpopulation_movements}{Boolean to indicate whether to use the overpopulation pest +movement module (driven by the natural kernel with its scale parameter modified by a coefficient)} -\item{overpopulation_percentage}{percentage of occupied hosts when the cell -is considered to be overpopulated} +\item{overpopulation_percentage}{Percentage of occupied hosts when the cell is considered to be +overpopulated} -\item{leaving_percentage}{percentage of pests leaving an overpopulated cell} +\item{leaving_percentage}{Percentage of pests leaving an overpopulated cell} -\item{leaving_scale_coefficient}{coefficient to multiply scale parameter of -the natural kernel (if applicable)} +\item{leaving_scale_coefficient}{Coefficient to multiply scale parameter of the natural kernel +(if applicable)} -\item{exposed_file}{a file with the exposed for the current} +\item{exposed_file}{A file with the exposed for the current} \item{write_outputs}{Either c("summary_outputs", or "None"). If not "None" output folder path must be provided.} @@ -319,7 +296,7 @@ the natural kernel (if applicable)} \item{point_file}{file for point comparison if not provided skips calculations} -\item{network_filename}{entire file path for the network file. Used if +\item{network_filename}{The entire file path for the network file. Used if anthropogenic_kernel_type = 'network'.} \item{network_movement}{What movement type do you want to use in the network kernel either @@ -333,19 +310,19 @@ simulations and observations. Default is FALSE.} \item{use_configuration}{Boolean if you want to use configuration disagreement for comparing model runs. Default is FALSE.} -\item{use_initial_condition_uncertainty}{boolean to indicate whether or not to propagate and +\item{use_initial_condition_uncertainty}{Boolean to indicate whether or not to propagate and partition uncertainty from initial conditions. If TRUE the infected_file needs to have 2 layers one with the mean value and one with the standard deviation. If an SEI model is used the exposed_file needs to have 2 layers one with the mean value and one with the standard deviation} -\item{use_host_uncertainty}{boolean to indicate whether or not to propagate and partition +\item{use_host_uncertainty}{Boolean to indicate whether or not to propagate and partition uncertainty from host data. If TRUE the host_file needs to have 2 layers one with the mean value and one with the standard deviation.} -\item{weather_type}{string indicating how the weather data is passed in either -as a mean and standard deviation to represent uncertainty ("probabilistic") or as a time -series ("deterministic")} +\item{weather_type}{string indicating how the weather data is passed in either as a mean and +standard deviation to represent uncertainty ("probabilistic") or as a time series +("deterministic")} \item{temperature_coefficient_sd_file}{Raster file with temperature coefficient standard deviation data for the timestep and time period specified (e.g. if timestep = week this file @@ -359,26 +336,28 @@ would have 52 bands with data being weekly precipitation coefficient standard de convert raw precipitation values to coefficients that affect the reproduction and survival of the pest all values in the raster are between 0 and 1.} -\item{dispersers_to_soils_percentage}{range from 0 to 1 representing the percentage -of dispersers that fall to the soil and survive.} +\item{dispersers_to_soils_percentage}{Range from 0 to 1 representing the percentage of dispersers +that fall to the soil and survive.} -\item{quarantine_directions}{string with comma separated directions to include -in the quarantine direction analysis, e.g., 'N,E'. By default all directions -(N, S, E, W) are considered} +\item{quarantine_directions}{String with comma separated directions to include in the quarantine +direction analysis, e.g., 'N,E'. By default all directions (N, S, E, W) are considered} -\item{multiple_random_seeds}{boolean to indicate if the model should use multiple random seeds +\item{multiple_random_seeds}{Boolean to indicate if the model should use multiple random seeds (allows for performing uncertainty partitioning) or a single random seed (backwards compatibility option). Default is FALSE.} -\item{random_seeds}{A file path to the file with the .csv file containing random_seeds table. -Use a file if you are trying to recreate an exact analysis otherwise we suggest leaving the +\item{file_random_seeds}{A file path to the file with the .csv file containing random_seeds +table. Use if you are trying to recreate an exact analysis otherwise we suggest leaving the default. Default is Null which draws the seed numbers for each.} -\item{use_soils}{boolean to indicate if pests establish in the soil and spread out from there. +\item{use_soils}{Boolean to indicate if pests establish in the soil and spread out from there. Typically used for soil borne pathogens.} -\item{soil_starting_pest_file}{path to the raster file with the starting -amount of pest or pathogen.} +\item{soil_starting_pest_file}{path to the raster file with the starting amount of pest or +pathogen.} + +\item{start_with_soil_populations}{Boolean to indicate whether to use a starting soil pest or +pathogen population if TRUE then soil_starting_pest_file is required.} } \value{ a data frame of statistical measures of model performance. diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index dfc22ea9..8d147d66 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -14,8 +14,8 @@ Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif // pops_model_cpp -List pops_model_cpp(int random_seed, bool multiple_random_seeds, std::vector random_seeds, double lethal_temperature, int lethal_temperature_month, IntegerMatrix infected, IntegerMatrix total_exposed, std::vector exposed, IntegerMatrix susceptible, IntegerMatrix total_populations, IntegerMatrix total_hosts, std::vector mortality_tracker, IntegerMatrix mortality, IntegerMatrix quarantine_areas, std::string quarantine_directions, std::vector treatment_maps, std::vector treatment_dates, std::vector pesticide_duration, IntegerMatrix resistant, std::vector> movements, std::vector movements_dates, std::vector temperature, std::vector survival_rates, std::vector weather_coefficient, std::vector weather_coefficient_sd, List bbox, List res, List rows_cols, double reproductive_rate, std::vector> spatial_indices, List season_month_start_end, List frequency_config, List bool_config, double mortality_rate, int mortality_time_lag, std::string start_date, std::string end_date, std::string treatment_method, std::string natural_kernel_type, std::string anthropogenic_kernel_type, double percent_natural_dispersal, double natural_distance_scale, double anthropogenic_distance_scale, std::string natural_dir, double natural_kappa, std::string anthropogenic_dir, double anthropogenic_kappa, Nullable frequencies_n_config, std::string model_type_, int latency_period, double establishment_probability, double dispersal_percentage, int survival_rate_month, int survival_rate_day, Nullable overpopulation_config, Nullable network_config, Nullable network_data_config, int weather_size, std::string weather_type, double dispersers_to_soils_percentage); -static SEXP _PoPS_pops_model_cpp_try(SEXP random_seedSEXP, SEXP multiple_random_seedsSEXP, SEXP random_seedsSEXP, SEXP lethal_temperatureSEXP, SEXP lethal_temperature_monthSEXP, SEXP infectedSEXP, SEXP total_exposedSEXP, SEXP exposedSEXP, SEXP susceptibleSEXP, SEXP total_populationsSEXP, SEXP total_hostsSEXP, SEXP mortality_trackerSEXP, SEXP mortalitySEXP, SEXP quarantine_areasSEXP, SEXP quarantine_directionsSEXP, SEXP treatment_mapsSEXP, SEXP treatment_datesSEXP, SEXP pesticide_durationSEXP, SEXP resistantSEXP, SEXP movementsSEXP, SEXP movements_datesSEXP, SEXP temperatureSEXP, SEXP survival_ratesSEXP, SEXP weather_coefficientSEXP, SEXP weather_coefficient_sdSEXP, SEXP bboxSEXP, SEXP resSEXP, SEXP rows_colsSEXP, SEXP reproductive_rateSEXP, SEXP spatial_indicesSEXP, SEXP season_month_start_endSEXP, SEXP frequency_configSEXP, SEXP bool_configSEXP, SEXP mortality_rateSEXP, SEXP mortality_time_lagSEXP, SEXP start_dateSEXP, SEXP end_dateSEXP, SEXP treatment_methodSEXP, SEXP natural_kernel_typeSEXP, SEXP anthropogenic_kernel_typeSEXP, SEXP percent_natural_dispersalSEXP, SEXP natural_distance_scaleSEXP, SEXP anthropogenic_distance_scaleSEXP, SEXP natural_dirSEXP, SEXP natural_kappaSEXP, SEXP anthropogenic_dirSEXP, SEXP anthropogenic_kappaSEXP, SEXP frequencies_n_configSEXP, SEXP model_type_SEXP, SEXP latency_periodSEXP, SEXP establishment_probabilitySEXP, SEXP dispersal_percentageSEXP, SEXP survival_rate_monthSEXP, SEXP survival_rate_daySEXP, SEXP overpopulation_configSEXP, SEXP network_configSEXP, SEXP network_data_configSEXP, SEXP weather_sizeSEXP, SEXP weather_typeSEXP, SEXP dispersers_to_soils_percentageSEXP) { +List pops_model_cpp(int random_seed, bool multiple_random_seeds, std::vector random_seeds, double lethal_temperature, int lethal_temperature_month, IntegerMatrix infected, IntegerMatrix total_exposed, std::vector exposed, IntegerMatrix susceptible, IntegerMatrix total_populations, IntegerMatrix total_hosts, std::vector mortality_tracker, IntegerMatrix mortality, IntegerMatrix quarantine_areas, std::string quarantine_directions, std::vector treatment_maps, std::vector treatment_dates, std::vector pesticide_duration, IntegerMatrix resistant, std::vector> movements, std::vector movements_dates, std::vector temperature, std::vector survival_rates, std::vector weather_coefficient, std::vector weather_coefficient_sd, List bbox, List res, List rows_cols, std::vector soil_reservoirs, double reproductive_rate, std::vector> spatial_indices, List season_month_start_end, List frequency_config, List bool_config, double mortality_rate, int mortality_time_lag, std::string start_date, std::string end_date, std::string treatment_method, std::string natural_kernel_type, std::string anthropogenic_kernel_type, double percent_natural_dispersal, double natural_distance_scale, double anthropogenic_distance_scale, std::string natural_dir, double natural_kappa, std::string anthropogenic_dir, double anthropogenic_kappa, Nullable frequencies_n_config, std::string model_type_, int latency_period, double establishment_probability, double dispersal_percentage, int survival_rate_month, int survival_rate_day, Nullable overpopulation_config, Nullable network_config, Nullable network_data_config, int weather_size, std::string weather_type, double dispersers_to_soils_percentage); +static SEXP _PoPS_pops_model_cpp_try(SEXP random_seedSEXP, SEXP multiple_random_seedsSEXP, SEXP random_seedsSEXP, SEXP lethal_temperatureSEXP, SEXP lethal_temperature_monthSEXP, SEXP infectedSEXP, SEXP total_exposedSEXP, SEXP exposedSEXP, SEXP susceptibleSEXP, SEXP total_populationsSEXP, SEXP total_hostsSEXP, SEXP mortality_trackerSEXP, SEXP mortalitySEXP, SEXP quarantine_areasSEXP, SEXP quarantine_directionsSEXP, SEXP treatment_mapsSEXP, SEXP treatment_datesSEXP, SEXP pesticide_durationSEXP, SEXP resistantSEXP, SEXP movementsSEXP, SEXP movements_datesSEXP, SEXP temperatureSEXP, SEXP survival_ratesSEXP, SEXP weather_coefficientSEXP, SEXP weather_coefficient_sdSEXP, SEXP bboxSEXP, SEXP resSEXP, SEXP rows_colsSEXP, SEXP soil_reservoirsSEXP, SEXP reproductive_rateSEXP, SEXP spatial_indicesSEXP, SEXP season_month_start_endSEXP, SEXP frequency_configSEXP, SEXP bool_configSEXP, SEXP mortality_rateSEXP, SEXP mortality_time_lagSEXP, SEXP start_dateSEXP, SEXP end_dateSEXP, SEXP treatment_methodSEXP, SEXP natural_kernel_typeSEXP, SEXP anthropogenic_kernel_typeSEXP, SEXP percent_natural_dispersalSEXP, SEXP natural_distance_scaleSEXP, SEXP anthropogenic_distance_scaleSEXP, SEXP natural_dirSEXP, SEXP natural_kappaSEXP, SEXP anthropogenic_dirSEXP, SEXP anthropogenic_kappaSEXP, SEXP frequencies_n_configSEXP, SEXP model_type_SEXP, SEXP latency_periodSEXP, SEXP establishment_probabilitySEXP, SEXP dispersal_percentageSEXP, SEXP survival_rate_monthSEXP, SEXP survival_rate_daySEXP, SEXP overpopulation_configSEXP, SEXP network_configSEXP, SEXP network_data_configSEXP, SEXP weather_sizeSEXP, SEXP weather_typeSEXP, SEXP dispersers_to_soils_percentageSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::traits::input_parameter< int >::type random_seed(random_seedSEXP); @@ -46,6 +46,7 @@ BEGIN_RCPP Rcpp::traits::input_parameter< List >::type bbox(bboxSEXP); Rcpp::traits::input_parameter< List >::type res(resSEXP); Rcpp::traits::input_parameter< List >::type rows_cols(rows_colsSEXP); + Rcpp::traits::input_parameter< std::vector >::type soil_reservoirs(soil_reservoirsSEXP); Rcpp::traits::input_parameter< double >::type reproductive_rate(reproductive_rateSEXP); Rcpp::traits::input_parameter< std::vector> >::type spatial_indices(spatial_indicesSEXP); Rcpp::traits::input_parameter< List >::type season_month_start_end(season_month_start_endSEXP); @@ -78,15 +79,15 @@ BEGIN_RCPP Rcpp::traits::input_parameter< int >::type weather_size(weather_sizeSEXP); Rcpp::traits::input_parameter< std::string >::type weather_type(weather_typeSEXP); Rcpp::traits::input_parameter< double >::type dispersers_to_soils_percentage(dispersers_to_soils_percentageSEXP); - rcpp_result_gen = Rcpp::wrap(pops_model_cpp(random_seed, multiple_random_seeds, random_seeds, lethal_temperature, lethal_temperature_month, infected, total_exposed, exposed, susceptible, total_populations, total_hosts, mortality_tracker, mortality, quarantine_areas, quarantine_directions, treatment_maps, treatment_dates, pesticide_duration, resistant, movements, movements_dates, temperature, survival_rates, weather_coefficient, weather_coefficient_sd, bbox, res, rows_cols, reproductive_rate, spatial_indices, season_month_start_end, frequency_config, bool_config, mortality_rate, mortality_time_lag, start_date, end_date, treatment_method, natural_kernel_type, anthropogenic_kernel_type, percent_natural_dispersal, natural_distance_scale, anthropogenic_distance_scale, natural_dir, natural_kappa, anthropogenic_dir, anthropogenic_kappa, frequencies_n_config, model_type_, latency_period, establishment_probability, dispersal_percentage, survival_rate_month, survival_rate_day, overpopulation_config, network_config, network_data_config, weather_size, weather_type, dispersers_to_soils_percentage)); + rcpp_result_gen = Rcpp::wrap(pops_model_cpp(random_seed, multiple_random_seeds, random_seeds, lethal_temperature, lethal_temperature_month, infected, total_exposed, exposed, susceptible, total_populations, total_hosts, mortality_tracker, mortality, quarantine_areas, quarantine_directions, treatment_maps, treatment_dates, pesticide_duration, resistant, movements, movements_dates, temperature, survival_rates, weather_coefficient, weather_coefficient_sd, bbox, res, rows_cols, soil_reservoirs, reproductive_rate, spatial_indices, season_month_start_end, frequency_config, bool_config, mortality_rate, mortality_time_lag, start_date, end_date, treatment_method, natural_kernel_type, anthropogenic_kernel_type, percent_natural_dispersal, natural_distance_scale, anthropogenic_distance_scale, natural_dir, natural_kappa, anthropogenic_dir, anthropogenic_kappa, frequencies_n_config, model_type_, latency_period, establishment_probability, dispersal_percentage, survival_rate_month, survival_rate_day, overpopulation_config, network_config, network_data_config, weather_size, weather_type, dispersers_to_soils_percentage)); return rcpp_result_gen; END_RCPP_RETURN_ERROR } -RcppExport SEXP _PoPS_pops_model_cpp(SEXP random_seedSEXP, SEXP multiple_random_seedsSEXP, SEXP random_seedsSEXP, SEXP lethal_temperatureSEXP, SEXP lethal_temperature_monthSEXP, SEXP infectedSEXP, SEXP total_exposedSEXP, SEXP exposedSEXP, SEXP susceptibleSEXP, SEXP total_populationsSEXP, SEXP total_hostsSEXP, SEXP mortality_trackerSEXP, SEXP mortalitySEXP, SEXP quarantine_areasSEXP, SEXP quarantine_directionsSEXP, SEXP treatment_mapsSEXP, SEXP treatment_datesSEXP, SEXP pesticide_durationSEXP, SEXP resistantSEXP, SEXP movementsSEXP, SEXP movements_datesSEXP, SEXP temperatureSEXP, SEXP survival_ratesSEXP, SEXP weather_coefficientSEXP, SEXP weather_coefficient_sdSEXP, SEXP bboxSEXP, SEXP resSEXP, SEXP rows_colsSEXP, SEXP reproductive_rateSEXP, SEXP spatial_indicesSEXP, SEXP season_month_start_endSEXP, SEXP frequency_configSEXP, SEXP bool_configSEXP, SEXP mortality_rateSEXP, SEXP mortality_time_lagSEXP, SEXP start_dateSEXP, SEXP end_dateSEXP, SEXP treatment_methodSEXP, SEXP natural_kernel_typeSEXP, SEXP anthropogenic_kernel_typeSEXP, SEXP percent_natural_dispersalSEXP, SEXP natural_distance_scaleSEXP, SEXP anthropogenic_distance_scaleSEXP, SEXP natural_dirSEXP, SEXP natural_kappaSEXP, SEXP anthropogenic_dirSEXP, SEXP anthropogenic_kappaSEXP, SEXP frequencies_n_configSEXP, SEXP model_type_SEXP, SEXP latency_periodSEXP, SEXP establishment_probabilitySEXP, SEXP dispersal_percentageSEXP, SEXP survival_rate_monthSEXP, SEXP survival_rate_daySEXP, SEXP overpopulation_configSEXP, SEXP network_configSEXP, SEXP network_data_configSEXP, SEXP weather_sizeSEXP, SEXP weather_typeSEXP, SEXP dispersers_to_soils_percentageSEXP) { +RcppExport SEXP _PoPS_pops_model_cpp(SEXP random_seedSEXP, SEXP multiple_random_seedsSEXP, SEXP random_seedsSEXP, SEXP lethal_temperatureSEXP, SEXP lethal_temperature_monthSEXP, SEXP infectedSEXP, SEXP total_exposedSEXP, SEXP exposedSEXP, SEXP susceptibleSEXP, SEXP total_populationsSEXP, SEXP total_hostsSEXP, SEXP mortality_trackerSEXP, SEXP mortalitySEXP, SEXP quarantine_areasSEXP, SEXP quarantine_directionsSEXP, SEXP treatment_mapsSEXP, SEXP treatment_datesSEXP, SEXP pesticide_durationSEXP, SEXP resistantSEXP, SEXP movementsSEXP, SEXP movements_datesSEXP, SEXP temperatureSEXP, SEXP survival_ratesSEXP, SEXP weather_coefficientSEXP, SEXP weather_coefficient_sdSEXP, SEXP bboxSEXP, SEXP resSEXP, SEXP rows_colsSEXP, SEXP soil_reservoirsSEXP, SEXP reproductive_rateSEXP, SEXP spatial_indicesSEXP, SEXP season_month_start_endSEXP, SEXP frequency_configSEXP, SEXP bool_configSEXP, SEXP mortality_rateSEXP, SEXP mortality_time_lagSEXP, SEXP start_dateSEXP, SEXP end_dateSEXP, SEXP treatment_methodSEXP, SEXP natural_kernel_typeSEXP, SEXP anthropogenic_kernel_typeSEXP, SEXP percent_natural_dispersalSEXP, SEXP natural_distance_scaleSEXP, SEXP anthropogenic_distance_scaleSEXP, SEXP natural_dirSEXP, SEXP natural_kappaSEXP, SEXP anthropogenic_dirSEXP, SEXP anthropogenic_kappaSEXP, SEXP frequencies_n_configSEXP, SEXP model_type_SEXP, SEXP latency_periodSEXP, SEXP establishment_probabilitySEXP, SEXP dispersal_percentageSEXP, SEXP survival_rate_monthSEXP, SEXP survival_rate_daySEXP, SEXP overpopulation_configSEXP, SEXP network_configSEXP, SEXP network_data_configSEXP, SEXP weather_sizeSEXP, SEXP weather_typeSEXP, SEXP dispersers_to_soils_percentageSEXP) { SEXP rcpp_result_gen; { Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = PROTECT(_PoPS_pops_model_cpp_try(random_seedSEXP, multiple_random_seedsSEXP, random_seedsSEXP, lethal_temperatureSEXP, lethal_temperature_monthSEXP, infectedSEXP, total_exposedSEXP, exposedSEXP, susceptibleSEXP, total_populationsSEXP, total_hostsSEXP, mortality_trackerSEXP, mortalitySEXP, quarantine_areasSEXP, quarantine_directionsSEXP, treatment_mapsSEXP, treatment_datesSEXP, pesticide_durationSEXP, resistantSEXP, movementsSEXP, movements_datesSEXP, temperatureSEXP, survival_ratesSEXP, weather_coefficientSEXP, weather_coefficient_sdSEXP, bboxSEXP, resSEXP, rows_colsSEXP, reproductive_rateSEXP, spatial_indicesSEXP, season_month_start_endSEXP, frequency_configSEXP, bool_configSEXP, mortality_rateSEXP, mortality_time_lagSEXP, start_dateSEXP, end_dateSEXP, treatment_methodSEXP, natural_kernel_typeSEXP, anthropogenic_kernel_typeSEXP, percent_natural_dispersalSEXP, natural_distance_scaleSEXP, anthropogenic_distance_scaleSEXP, natural_dirSEXP, natural_kappaSEXP, anthropogenic_dirSEXP, anthropogenic_kappaSEXP, frequencies_n_configSEXP, model_type_SEXP, latency_periodSEXP, establishment_probabilitySEXP, dispersal_percentageSEXP, survival_rate_monthSEXP, survival_rate_daySEXP, overpopulation_configSEXP, network_configSEXP, network_data_configSEXP, weather_sizeSEXP, weather_typeSEXP, dispersers_to_soils_percentageSEXP)); + rcpp_result_gen = PROTECT(_PoPS_pops_model_cpp_try(random_seedSEXP, multiple_random_seedsSEXP, random_seedsSEXP, lethal_temperatureSEXP, lethal_temperature_monthSEXP, infectedSEXP, total_exposedSEXP, exposedSEXP, susceptibleSEXP, total_populationsSEXP, total_hostsSEXP, mortality_trackerSEXP, mortalitySEXP, quarantine_areasSEXP, quarantine_directionsSEXP, treatment_mapsSEXP, treatment_datesSEXP, pesticide_durationSEXP, resistantSEXP, movementsSEXP, movements_datesSEXP, temperatureSEXP, survival_ratesSEXP, weather_coefficientSEXP, weather_coefficient_sdSEXP, bboxSEXP, resSEXP, rows_colsSEXP, soil_reservoirsSEXP, reproductive_rateSEXP, spatial_indicesSEXP, season_month_start_endSEXP, frequency_configSEXP, bool_configSEXP, mortality_rateSEXP, mortality_time_lagSEXP, start_dateSEXP, end_dateSEXP, treatment_methodSEXP, natural_kernel_typeSEXP, anthropogenic_kernel_typeSEXP, percent_natural_dispersalSEXP, natural_distance_scaleSEXP, anthropogenic_distance_scaleSEXP, natural_dirSEXP, natural_kappaSEXP, anthropogenic_dirSEXP, anthropogenic_kappaSEXP, frequencies_n_configSEXP, model_type_SEXP, latency_periodSEXP, establishment_probabilitySEXP, dispersal_percentageSEXP, survival_rate_monthSEXP, survival_rate_daySEXP, overpopulation_configSEXP, network_configSEXP, network_data_configSEXP, weather_sizeSEXP, weather_typeSEXP, dispersers_to_soils_percentageSEXP)); } Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error"); if (rcpp_isInterrupt_gen) { @@ -111,7 +112,7 @@ RcppExport SEXP _PoPS_pops_model_cpp(SEXP random_seedSEXP, SEXP multiple_random_ static int _PoPS_RcppExport_validate(const char* sig) { static std::set signatures; if (signatures.empty()) { - signatures.insert("List(*pops_model_cpp)(int,bool,std::vector,double,int,IntegerMatrix,IntegerMatrix,std::vector,IntegerMatrix,IntegerMatrix,IntegerMatrix,std::vector,IntegerMatrix,IntegerMatrix,std::string,std::vector,std::vector,std::vector,IntegerMatrix,std::vector>,std::vector,std::vector,std::vector,std::vector,std::vector,List,List,List,double,std::vector>,List,List,List,double,int,std::string,std::string,std::string,std::string,std::string,double,double,double,std::string,double,std::string,double,Nullable,std::string,int,double,double,int,int,Nullable,Nullable,Nullable,int,std::string,double)"); + signatures.insert("List(*pops_model_cpp)(int,bool,std::vector,double,int,IntegerMatrix,IntegerMatrix,std::vector,IntegerMatrix,IntegerMatrix,IntegerMatrix,std::vector,IntegerMatrix,IntegerMatrix,std::string,std::vector,std::vector,std::vector,IntegerMatrix,std::vector>,std::vector,std::vector,std::vector,std::vector,std::vector,List,List,List,std::vector,double,std::vector>,List,List,List,double,int,std::string,std::string,std::string,std::string,std::string,double,double,double,std::string,double,std::string,double,Nullable,std::string,int,double,double,int,int,Nullable,Nullable,Nullable,int,std::string,double)"); } return signatures.find(sig) != signatures.end(); } @@ -124,7 +125,7 @@ RcppExport SEXP _PoPS_RcppExport_registerCCallable() { } static const R_CallMethodDef CallEntries[] = { - {"_PoPS_pops_model_cpp", (DL_FUNC) &_PoPS_pops_model_cpp, 60}, + {"_PoPS_pops_model_cpp", (DL_FUNC) &_PoPS_pops_model_cpp, 61}, {"_PoPS_RcppExport_registerCCallable", (DL_FUNC) &_PoPS_RcppExport_registerCCallable, 0}, {NULL, NULL, 0} }; diff --git a/src/pops.cpp b/src/pops.cpp index bf6f1cd5..b0768765 100644 --- a/src/pops.cpp +++ b/src/pops.cpp @@ -67,6 +67,7 @@ List pops_model_cpp( List bbox, List res, List rows_cols, + std::vector soil_reservoirs, double reproductive_rate, std::vector> spatial_indices, List season_month_start_end, @@ -189,6 +190,8 @@ List pops_model_cpp( int start_month = season_month_start_end["start_month"]; int end_month = season_month_start_end["end_month"]; config.set_season_start_end_month(start_month, end_month); + + bool use_soils = bool_config["use_soils"]; config.dispersers_to_soils_percentage = dispersers_to_soils_percentage; std::vector> spread_rates_vector; @@ -210,6 +213,8 @@ List pops_model_cpp( std::vector dispersers_vector; std::vector exposed_v; std::vector> exposed_vector; + std::vector> soil_reservoirs_vector; + std::vector soil_v; config.create_schedules(); @@ -229,11 +234,6 @@ List pops_model_cpp( } } - unsigned count_weather = get_number_of_scheduled_actions(config.spread_schedule()); - if (config.weather && count_weather > weather_coefficient.size()) { - Rcerr << "Not enough indices of weather coefficient data" << std::endl; - } - unsigned spread_rate_outputs; if (config.use_spreadrates) { spread_rate_outputs = config.rate_num_steps(); @@ -296,16 +296,20 @@ List pops_model_cpp( ModelType mt = model_type_from_string(config.model_type); WeatherType weather_typed = weather_type_from_string(config.weather_type); - + Simulation simulation( config.rows, config.cols, mt, config.latency_period_steps); Model model(config); + if (use_soils) { + model.activate_soils(soil_reservoirs); + } + for (unsigned current_index = 0; current_index < config.scheduler().get_num_steps(); ++current_index) { IntegerMatrix dispersers(config.rows, config.cols); - + auto weather_step = config.simulation_step_to_weather_step(current_index); if (weather_typed == WeatherType::Probabilistic) { model.environment().update_weather_from_distribution( @@ -315,7 +319,7 @@ List pops_model_cpp( else if (weather_typed == WeatherType::Deterministic) { model.environment().update_weather_coefficient(weather_coefficient[weather_step]); } - + model.run_step( current_index, infected, @@ -368,8 +372,18 @@ List pops_model_cpp( exposed_v = exposed; } - // exposed_v = exposed; + if (use_soils) { + soil_v.clear(); + for (unsigned s = 0; s < soil_reservoirs.size(); s++) { + soil_v.push_back(Rcpp::clone(soil_reservoirs[s])); + } + } + else{ + soil_v = soil_reservoirs; + } + exposed_vector.push_back(exposed_v); + soil_reservoirs_vector.push_back(soil_v); num_infected = sum_of_infected(infected, spatial_indices); number_infected.push_back(num_infected); @@ -416,5 +430,6 @@ List pops_model_cpp( _["quarantine_escape"] = quarantine_escapes, _["quarantine_escape_distance"] = escape_dists, _["quarantine_escape_directions"] = escape_directions, - _["spatial_indices"] = spatial_indices); + _["spatial_indices"] = spatial_indices, + _["soil_reservoirs"] = soil_reservoirs_vector); } diff --git a/tests/testthat/test-pops.r b/tests/testthat/test-pops.r index 9e55ba05..589ea3bb 100644 --- a/tests/testthat/test-pops.r +++ b/tests/testthat/test-pops.r @@ -20,7 +20,7 @@ test_that("Model stops if files don't exist or aren't the correct extension", { detailed_file_exists_error(infected_file)) infected_file <- system.file("extdata", "simple2x2", "infected.csv", package = "PoPS") - expect_error(pops( + expect_error(pops( infected_file = infected_file, host_file = host_file, total_populations_file = host_file, @@ -28,8 +28,8 @@ test_that("Model stops if files don't exist or aren't the correct extension", { parameter_cov_matrix = parameter_cov_matrix), raster_type_error, fixed = TRUE) - host_file <- "" - infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- "" + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") expect_error(pops(infected_file = infected_file, host_file = "", total_populations_file = host_file, @@ -182,10 +182,8 @@ test_that("Model stops if files don't exist or aren't the correct extension", { }) test_that("Model stops if treatments don't have correct dimenisions", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") start_date <- "2008-01-01" end_date <- "2010-12-31" parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) @@ -204,12 +202,9 @@ test_that("Model stops if treatments don't have correct dimenisions", { treatment_length_error, fixed = TRUE) }) -test_that("Model stops if time and date parameters are of the wrong type and/or - dimension", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") +test_that("Model stops if time and date parameters are of the wrong type and/or dimension", { + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") temperature_file <- @@ -232,68 +227,64 @@ test_that("Model stops if time and date parameters are of the wrong type and/or end_date = "two", parameter_means = parameter_means, parameter_cov_matrix = parameter_cov_matrix), - date_format_error, fixed = TRUE) + date_format_error, fixed = TRUE) expect_error(pops(infected_file = infected_file, host_file = host_file, total_populations_file = host_file, end_date = 156, parameter_means = parameter_means, parameter_cov_matrix = parameter_cov_matrix), - date_format_error, fixed = TRUE) + date_format_error, fixed = TRUE) expect_error(pops(infected_file = infected_file, host_file = host_file, total_populations_file = host_file, start_date = "five", parameter_means = parameter_means, parameter_cov_matrix = parameter_cov_matrix), - date_format_error, fixed = TRUE) + date_format_error, fixed = TRUE) expect_error(pops(infected_file = infected_file, host_file = host_file, total_populations_file = host_file, start_date = 19, parameter_means = parameter_means, parameter_cov_matrix = parameter_cov_matrix), - date_format_error, fixed = TRUE) + date_format_error, fixed = TRUE) }) test_that("Model stops if kernel is of the wrong type and/or dimension", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") - coefficient_file <- - system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") - temperature_file <- - system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", - package = "PoPS") - start_date <- "2008-01-01" - end_date <- "2010-12-31" - parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + coefficient_file <- + system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") + temperature_file <- system.file("extdata", "simple2x2", + "critical_temp_all_below_threshold.tif", + package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2010-12-31" + parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - expect_error( - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - natural_kernel_type = "none", - parameter_cov_matrix = parameter_cov_matrix), - natural_kernel_error, fixed = TRUE) - expect_error( - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - anthropogenic_kernel_type = "none", - parameter_cov_matrix = parameter_cov_matrix), - anthropogenic_kernel_error, fixed = TRUE) - }) + expect_error( + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + natural_kernel_type = "none", + parameter_cov_matrix = parameter_cov_matrix), + natural_kernel_error, fixed = TRUE) + expect_error( + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + anthropogenic_kernel_type = "none", + parameter_cov_matrix = parameter_cov_matrix), + anthropogenic_kernel_error, fixed = TRUE) +}) test_that("Input raster resolutions, extents, and crs all match", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") temperature_file <- @@ -693,13 +684,9 @@ test_that("Input raster resolutions, extents, and crs all match", { }) - -test_that( -"Infected results return initial infected if reproductive rate is set to 0", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") +test_that("Infected results return initial infected if reproductive rate is set to 0", { + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") temperature_file <- @@ -709,11 +696,11 @@ test_that( parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - expect_equal(suppressWarnings(pops(infected_file = infected_file, + expect_equal(pops(infected_file = infected_file, host_file = host_file, total_populations_file = host_file, parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix)$infected[[1]]), + parameter_cov_matrix = parameter_cov_matrix)$infected[[1]], terra::as.matrix(terra::rast(infected_file), wide = TRUE)) expect_equal(pops(infected_file = infected_file, host_file = host_file, @@ -896,68 +883,64 @@ test_that( test_that( "Infected results returns all 0's if minimum temp drops below lethal temperature", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") - coefficient_file <- - system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") - temperature_file <- - system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", package = "PoPS") - start_date <- "2008-01-01" - end_date <- "2010-12-31" - parameter_means <- c(1, 21, 1, 500, 0, 0, 0, 0) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + coefficient_file <- + system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") + temperature_file <- + system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2010-12-31" + parameter_means <- c(1, 21, 1, 500, 0, 0, 0, 0) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - expect_equal(pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - use_lethal_temperature = TRUE, - temperature_file = temperature_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix)$infected[[1]], - matrix(0, ncol = 2, nrow = 2)) - expect_equal(pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - use_lethal_temperature = TRUE, - temperature_file = temperature_file, - precip = TRUE, - precipitation_coefficient_file = coefficient_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix)$infected[[1]], - matrix(0, ncol = 2, nrow = 2)) - expect_equal(pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - use_lethal_temperature = TRUE, - temperature_file = temperature_file, - temp = TRUE, - temperature_coefficient_file = coefficient_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix)$infected[[1]], - matrix(0, ncol = 2, nrow = 2)) - expect_equal(pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - use_lethal_temperature = TRUE, - temperature_file = temperature_file, - temp = TRUE, - temperature_coefficient_file = coefficient_file, - precip = TRUE, - precipitation_coefficient_file = coefficient_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix)$infected[[1]], - matrix(0, ncol = 2, nrow = 2)) + expect_equal(pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + use_lethal_temperature = TRUE, + temperature_file = temperature_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix)$infected[[1]], + matrix(0, ncol = 2, nrow = 2)) + expect_equal(pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + use_lethal_temperature = TRUE, + temperature_file = temperature_file, + precip = TRUE, + precipitation_coefficient_file = coefficient_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix)$infected[[1]], + matrix(0, ncol = 2, nrow = 2)) + expect_equal(pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + use_lethal_temperature = TRUE, + temperature_file = temperature_file, + temp = TRUE, + temperature_coefficient_file = coefficient_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix)$infected[[1]], + matrix(0, ncol = 2, nrow = 2)) + expect_equal(pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + use_lethal_temperature = TRUE, + temperature_file = temperature_file, + temp = TRUE, + temperature_coefficient_file = coefficient_file, + precip = TRUE, + precipitation_coefficient_file = coefficient_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix)$infected[[1]], + matrix(0, ncol = 2, nrow = 2)) }) test_that( "Infected results returns less infection after survival rates than before", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") survival_rates_file <- @@ -1013,96 +996,93 @@ test_that( }) -test_that( - "Infected and Susceptible results return all 0's if treatments file is all - 1's but leaves a proportion of susceptibles if treatment method is ratio", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") - coefficient_file <- - system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") - temperature_file <- - system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", package = "PoPS") - start_date <- "2008-01-01" - end_date <- "2010-12-31" - treatments_file <- system.file("extdata", "simple2x2", "treatments.tif", package = "PoPS") - parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) +test_that("Infected and Susceptible results return all 0's if treatments file is all 1's but + leaves a proportion of susceptibles if treatment method is ratio", { + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + coefficient_file <- + system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") + temperature_file <- + system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", + package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2010-12-31" + treatments_file <- system.file("extdata", "simple2x2", "treatments.tif", + package = "PoPS") + parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - data <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - management = TRUE, - treatment_dates = c("2008-12-01"), - treatments_file = treatments_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + management = TRUE, + treatment_dates = c("2008-12-01"), + treatments_file = treatments_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) - expect_equal(data$infected[[1]], matrix(0, ncol = 2, nrow = 2)) - expect_equal(data$susceptible[[1]], matrix(0, ncol = 2, nrow = 2)) + expect_equal(data$infected[[1]], matrix(0, ncol = 2, nrow = 2)) + expect_equal(data$susceptible[[1]], matrix(0, ncol = 2, nrow = 2)) - data <- - pops(infected_file = infected_file, - host_file = host_file, - treatment_method = "all infected", - total_populations_file = host_file, - management = TRUE, - treatment_dates = c("2008-12-01"), - treatments_file = treatments_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) + data <- + pops(infected_file = infected_file, + host_file = host_file, + treatment_method = "all infected", + total_populations_file = host_file, + management = TRUE, + treatment_dates = c("2008-12-01"), + treatments_file = treatments_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) - expect_equal(data$infected[[1]], matrix(0, ncol = 2, nrow = 2)) - expect_equal(data$susceptible[[1]], matrix(0, ncol = 2, nrow = 2)) + expect_equal(data$infected[[1]], matrix(0, ncol = 2, nrow = 2)) + expect_equal(data$susceptible[[1]], matrix(0, ncol = 2, nrow = 2)) - treatments_file <- - system.file("extdata", "simple2x2", "treatmentshalf.tif", package = "PoPS") + treatments_file <- + system.file("extdata", "simple2x2", "treatmentshalf.tif", package = "PoPS") - data <- - pops(infected_file = infected_file, - host_file = host_file, - treatment_method = "ratio", - total_populations_file = host_file, - management = TRUE, - treatment_dates = c("2008-12-01"), - treatments_file = treatments_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) + data <- + pops(infected_file = infected_file, + host_file = host_file, + treatment_method = "ratio", + total_populations_file = host_file, + management = TRUE, + treatment_dates = c("2008-12-01"), + treatments_file = treatments_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) - expect_equal(data$infected[[1]], matrix(c(2, 0, 0, 0), ncol = 2, nrow = 2)) - expect_equal(data$susceptible[[1]], matrix(c(5, 3, 7, 7), ncol = 2, nrow = 2)) + expect_equal(data$infected[[1]], matrix(c(2, 0, 0, 0), ncol = 2, nrow = 2)) + expect_equal(data$susceptible[[1]], matrix(c(5, 3, 7, 7), ncol = 2, nrow = 2)) - data <- - pops(infected_file = infected_file, - host_file = host_file, - treatment_method = "all infected", - total_populations_file = host_file, - management = TRUE, - treatment_dates = c("2008-12-01"), - treatments_file = treatments_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) + data <- + pops(infected_file = infected_file, + host_file = host_file, + treatment_method = "all infected", + total_populations_file = host_file, + management = TRUE, + treatment_dates = c("2008-12-01"), + treatments_file = treatments_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) - expect_equal(data$infected[[1]], matrix(c(0, 0, 0, 0), ncol = 2, nrow = 2)) - expect_equal(data$susceptible[[1]], matrix(c(5, 3, 7, 7), ncol = 2, nrow = 2)) + expect_equal(data$infected[[1]], matrix(c(0, 0, 0, 0), ncol = 2, nrow = 2)) + expect_equal(data$susceptible[[1]], matrix(c(5, 3, 7, 7), ncol = 2, nrow = 2)) -}) + }) test_that("Infected results are greater than initial infected", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") temperature_file <- @@ -1117,13 +1097,12 @@ test_that("Infected results are greater than initial infected", { total_populations_file = host_file, parameter_means = parameter_means, parameter_cov_matrix = parameter_cov_matrix - )$infected[[1]] >= - terra::as.matrix(terra::rast(infected_file), wide = TRUE)), TRUE) + )$infected[[1]] >= + terra::as.matrix(terra::rast(infected_file), wide = TRUE)), TRUE) expect_equal(all( pops(infected_file = infected_file, - host_file = - system.file("extdata", "simple2x2", - "total_plants_host_greater_than_infected.tif", package = "PoPS"), + host_file = system.file("extdata", "simple2x2", + "total_plants_host_greater_than_infected.tif", package = "PoPS"), total_populations_file = host_file, parameter_means = parameter_means, parameter_cov_matrix = parameter_cov_matrix)$infected[[1]] >= @@ -1133,10 +1112,8 @@ test_that("Infected results are greater than initial infected", { test_that("All kernel types lead to spread", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") temperature_file <- @@ -1168,7 +1145,7 @@ test_that("All kernel types lead to spread", { natural_kernel_type = "cauchy") infecteds <- data$infected[[1]] expect_equal(all(infecteds >= - terra::as.matrix(terra::rast(infected_file), wide = TRUE)), TRUE) + terra::as.matrix(terra::rast(infected_file), wide = TRUE)), TRUE) expect_gt(infecteds[1, 2] + infecteds[2, 1] + infecteds[2, 2], 0) data <- pops(infected_file = infected_file, @@ -1344,16 +1321,16 @@ test_that("All kernel types lead to spread", { expect_equal(all(data$infected[[1]] >= terra::as.matrix(terra::rast(infected_file), wide = TRUE)), TRUE) -# -# data <- pops(infected_file = infected_file, -# host_file = host_file, -# total_populations_file = host_file, -# parameter_means = parameter_means, -# parameter_cov_matrix = parameter_cov_matrix, -# anthropogenic_kernel_type = "exponential-power") -# expect_equal(all(data$infected[[1]] >= -# terra::as.matrix(terra::rast(infected_file), wide = TRUE)), -# TRUE) + # + # data <- pops(infected_file = infected_file, + # host_file = host_file, + # total_populations_file = host_file, + # parameter_means = parameter_means, + # parameter_cov_matrix = parameter_cov_matrix, + # anthropogenic_kernel_type = "exponential-power") + # expect_equal(all(data$infected[[1]] >= + # terra::as.matrix(terra::rast(infected_file), wide = TRUE)), + # TRUE) ## currently not working # @@ -1371,10 +1348,8 @@ test_that("All kernel types lead to spread", { }) test_that("Susceptibles are never negative", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") temperature_file <- @@ -1401,9 +1376,8 @@ test_that("Susceptibles are never negative", { parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) data <- pops(infected_file = infected_file, - host_file = - system.file("extdata", "simple2x2", - "total_plants_host_greater_than_infected.tif", package = "PoPS"), + host_file = system.file("extdata", "simple2x2", + "total_plants_host_greater_than_infected.tif", package = "PoPS"), total_populations_file = host_file, parameter_means = parameter_means, parameter_cov_matrix = parameter_cov_matrix, @@ -1418,10 +1392,8 @@ test_that("Susceptibles are never negative", { }) test_that("SEI model works as intended", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") temperature_file <- @@ -1542,10 +1514,8 @@ test_that("SEI model works as intended", { }) test_that("Infected results with weather are less than those without weather", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") temperature_file <- @@ -1554,6 +1524,7 @@ test_that("Infected results with weather are less than those without weather", { end_date <- "2010-12-31" parameter_means <- c(0.4, 21, 1, 500, 0, 0, 0, 0) parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + coefficient_sd_file <- system.file("extdata", "simple2x2", "coefficient_sd.tif", package = "PoPS") data <- pops(infected_file = infected_file, @@ -1564,6 +1535,7 @@ test_that("Infected results with weather are less than those without weather", { random_seed = 42, start_date = start_date, end_date = end_date) + data_temp <- pops(infected_file = infected_file, host_file = host_file, @@ -1575,6 +1547,7 @@ test_that("Infected results with weather are less than those without weather", { random_seed = 42, start_date = start_date, end_date = end_date) + data_precip <- pops(infected_file = infected_file, host_file = host_file, @@ -1586,169 +1559,219 @@ test_that("Infected results with weather are less than those without weather", { random_seed = 42, start_date = start_date, end_date = end_date) + data_weather <- pops(infected_file = infected_file, host_file = host_file, total_populations_file = host_file, temp = TRUE, temperature_coefficient_file = coefficient_file, - precip = TRUE, precipitation_coefficient_file = coefficient_file, + precip = TRUE, + precipitation_coefficient_file = coefficient_file, parameter_means = parameter_means, parameter_cov_matrix = parameter_cov_matrix, random_seed = 42, start_date = start_date, end_date = end_date) - expect_gte(sum(data$infected[[1]]), sum(data_temp$infected[[1]])) - expect_gte(sum(data$infected[[2]]), sum(data_temp$infected[[2]])) - expect_gte(sum(data$infected[[3]]), sum(data_temp$infected[[3]])) + data_temp_wsd <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + temp = TRUE, + temperature_coefficient_file = coefficient_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + random_seed = 42, + start_date = start_date, + end_date = end_date, + weather_type = "probabilistic", + temperature_coefficient_sd_file = coefficient_sd_file) - expect_gte(sum(data$infected[[1]]), sum(data_precip$infected[[1]])) - expect_gte(sum(data$infected[[2]]), sum(data_precip$infected[[2]])) - expect_gte(sum(data$infected[[3]]), sum(data_precip$infected[[3]])) - expect_gte(sum(data$infected[[1]]), sum(data_weather$infected[[1]])) - expect_gte(sum(data$infected[[2]]), sum(data_weather$infected[[2]])) - expect_gte(sum(data$infected[[3]]), sum(data_weather$infected[[3]])) - -}) - -test_that( - "Infected results are greater with same parameters for weekly spread vs. monthly", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") - coefficient_file <- - system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") - temperature_file <- - system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", package = "PoPS") - start_date <- "2008-01-01" - end_date <- "2010-12-31" - parameter_means <- c(0.2, 21, 1, 500, 0, 0, 0, 0) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - - data_week <- + data_precip_wsd <- pops(infected_file = infected_file, host_file = host_file, total_populations_file = host_file, + precip = TRUE, + precipitation_coefficient_file = coefficient_file, parameter_means = parameter_means, parameter_cov_matrix = parameter_cov_matrix, - time_step = "week", random_seed = 42, start_date = start_date, - end_date = end_date) - data_month <- + end_date = end_date, + weather_type = "probabilistic", + precipitation_coefficient_sd_file = coefficient_sd_file) + + data_weather_wsd <- pops(infected_file = infected_file, host_file = host_file, total_populations_file = host_file, + temp = TRUE, + temperature_coefficient_file = coefficient_file, + precip = TRUE, + precipitation_coefficient_file = coefficient_file, parameter_means = parameter_means, parameter_cov_matrix = parameter_cov_matrix, - time_step = "month", random_seed = 42, start_date = start_date, - end_date = end_date) + end_date = end_date, + weather_type = "probabilistic", + temperature_coefficient_sd_file = coefficient_sd_file, + precipitation_coefficient_sd_file = coefficient_sd_file) - expect_equal(all(data_week$infected[[1]] >= data_month$infected[[1]]), TRUE) - expect_equal(all(data_week$infected[[2]] >= data_month$infected[[2]]), TRUE) + expect_gte(sum(data$infected[[1]]), sum(data_temp$infected[[1]])) + expect_gte(sum(data$infected[[2]]), sum(data_temp$infected[[2]])) + expect_gte(sum(data$infected[[3]]), sum(data_temp$infected[[3]])) + expect_gte(sum(data$infected[[1]]), sum(data_precip$infected[[1]])) + expect_gte(sum(data$infected[[2]]), sum(data_precip$infected[[2]])) + expect_gte(sum(data$infected[[3]]), sum(data_precip$infected[[3]])) + + expect_gte(sum(data$infected[[1]]), sum(data_weather$infected[[1]])) + expect_gte(sum(data$infected[[2]]), sum(data_weather$infected[[2]])) + expect_gte(sum(data$infected[[3]]), sum(data_weather$infected[[3]])) + + expect_gte(sum(data$infected[[2]]), sum(data_temp_wsd$infected[[2]])) + expect_gte(sum(data$infected[[3]]), sum(data_temp_wsd$infected[[3]])) + expect_gte(sum(data$infected[[1]]), sum(data_temp_wsd$infected[[1]])) + + expect_gte(sum(data$infected[[1]]), sum(data_precip_wsd$infected[[1]])) + expect_gte(sum(data$infected[[2]]), sum(data_precip_wsd$infected[[2]])) + expect_gte(sum(data$infected[[3]]), sum(data_precip_wsd$infected[[3]])) + + expect_gte(sum(data$infected[[1]]), sum(data_weather_wsd$infected[[1]])) + expect_gte(sum(data$infected[[2]]), sum(data_weather_wsd$infected[[2]])) + expect_gte(sum(data$infected[[3]]), sum(data_weather_wsd$infected[[3]])) }) test_that( - "Infected results are greater with same parameters for daily spread vs. - monthly and weekly", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") - coefficient_file <- - system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") - temperature_file <- - system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", package = "PoPS") - start_date <- "2008-01-01" - end_date <- "2010-12-31" - parameter_means <- c(0.1, 21, 1, 500, 0, 0, 0, 0) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + "Infected results are greater with same parameters for weekly spread vs. monthly", { + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + coefficient_file <- + system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") + temperature_file <- + system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2010-12-31" + parameter_means <- c(0.2, 21, 1, 500, 0, 0, 0, 0) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - data_day <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - time_step = "day", - random_seed = 42) - data_week <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - time_step = "week", - random_seed = 42, - start_date = start_date, - end_date = end_date) - data_month <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - time_step = "month", - random_seed = 42, - start_date = start_date, - end_date = end_date) + data_week <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + time_step = "week", + random_seed = 42, + start_date = start_date, + end_date = end_date) + data_month <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + time_step = "month", + random_seed = 42, + start_date = start_date, + end_date = end_date) - expect_equal(all(data_day$infected[[1]] >= data_month$infected[[1]]), TRUE) - expect_equal(all(data_day$infected[[1]] >= data_week$infected[[1]]), TRUE) - expect_equal(all(data_week$infected[[1]] >= data_month$infected[[1]]), TRUE) -}) + expect_equal(all(data_week$infected[[1]] >= data_month$infected[[1]]), TRUE) + expect_equal(all(data_week$infected[[2]] >= data_month$infected[[2]]), TRUE) + + }) + +test_that("Infected results are greater with same parameters for daily spread vs. monthly and + weekly", { + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + coefficient_file <- + system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") + temperature_file <- + system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", + package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2010-12-31" + parameter_means <- c(0.1, 21, 1, 500, 0, 0, 0, 0) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + + data_day <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + time_step = "day", + random_seed = 42) + data_week <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + time_step = "week", + random_seed = 42, + start_date = start_date, + end_date = end_date) + data_month <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + time_step = "month", + random_seed = 42, + start_date = start_date, + end_date = end_date) + + expect_equal(all(data_day$infected[[1]] >= data_month$infected[[1]]), TRUE) + expect_equal(all(data_day$infected[[1]] >= data_week$infected[[1]]), TRUE) + expect_equal(all(data_week$infected[[1]] >= data_month$infected[[1]]), TRUE) + }) test_that( "Infected results are greater without treatment than with treatment", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") - treatments_file <- - system.file("extdata", "simple2x2", "treatments_1_1.tif", package = "PoPS") - treatment_dates <- c("2008-03-05") - start_date <- "2008-01-01" - end_date <- "2009-12-31" - parameter_means <- c(0.8, 21, 1, 500, 0, 0, 0, 0) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + treatments_file <- system.file("extdata", "simple2x2", "treatments_1_1.tif", package = "PoPS") + treatment_dates <- c("2008-03-05") + start_date <- "2008-01-01" + end_date <- "2009-12-31" + parameter_means <- c(0.8, 21, 1, 500, 0, 0, 0, 0) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - data <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - random_seed = 44, - start_date = start_date, - end_date = end_date) - data_treat <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - management = TRUE, - treatment_dates = treatment_dates, - treatments_file = treatments_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - random_seed = 44, - start_date = start_date, - end_date = end_date) + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + random_seed = 44, + start_date = start_date, + end_date = end_date) + data_treat <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + management = TRUE, + treatment_dates = treatment_dates, + treatments_file = treatments_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + random_seed = 44, + start_date = start_date, + end_date = end_date) - expect_equal(all(data$infected[[1]] >= data_treat$infected[[1]]), TRUE) - expect_equal(all(data$infected[[2]] >= data_treat$infected[[2]]), TRUE) -}) + expect_equal(all(data$infected[[1]] >= data_treat$infected[[1]]), TRUE) + expect_equal(all(data$infected[[2]] >= data_treat$infected[[2]]), TRUE) + }) test_that("Infected results are greater with higher reproductive rate", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") start_date <- "2008-01-01" end_date <- "2010-12-31" parameter_means <- c(1.0, 21, 1, 500, 0, 0, 0, 0) @@ -1829,18 +1852,15 @@ test_that("Infected results are greater with higher reproductive rate", { }) test_that("Treatments apply no matter what time step", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") temperature_file <- system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", package = "PoPS") start_date <- "2009-01-01" end_date <- "2009-12-31" - treatments_file <- - system.file("extdata", "simple2x2", "treatments.tif", package = "PoPS") + treatments_file <- system.file("extdata", "simple2x2", "treatments.tif", package = "PoPS") parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) dates <- seq.Date(as.Date(start_date), as.Date(end_date), by = "days") @@ -1862,18 +1882,15 @@ test_that("Treatments apply no matter what time step", { }) test_that("Pesticide treatments apply no matter what time step", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") coefficient_file <- system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") temperature_file <- system.file("extdata", "simple2x2", "critical_temp_all_below_threshold.tif", package = "PoPS") start_date <- "2009-01-01" end_date <- "2009-12-31" - treatments_file <- - system.file("extdata", "simple2x2", "treatments.tif", package = "PoPS") + treatments_file <- system.file("extdata", "simple2x2", "treatments.tif", package = "PoPS") pesticide_duration <- c(120) pesticide_efficacy <- 1.0 parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) @@ -1922,297 +1939,290 @@ test_that("Pesticide treatments apply no matter what time step", { }) -test_that( - "Changing the output frequency returns the correct number of outputs and - output statistics", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") - start_date <- "2009-01-01" - end_date <- "2009-12-31" - treatment_dates <- c(start_date) - parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - - data <- - pops(output_frequency = "year", - time_step = "month", - treatment_dates = treatment_dates, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 1) - - data <- - pops(output_frequency = "year", - time_step = "week", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 1) - - data <- - pops(output_frequency = "year", - time_step = "day", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 1) - - data <- - pops(output_frequency = "month", - time_step = "week", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 12) - - data <- - pops(output_frequency = "month", - time_step = "day", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 12) - - data <- - pops(output_frequency = "week", - time_step = "week", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 52) - - data <- - pops(output_frequency = "week", - time_step = "day", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 52) - - expect_error(pops(output_frequency = "day", - time_step = "week", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date), output_frequency_error) - - expect_error(pops(output_frequency = "day", - time_step = "month", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date), output_frequency_error) - - expect_error(pops(output_frequency = "week", - time_step = "month", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date), output_frequency_error) - - data <- pops(output_frequency = "day", - time_step = "day", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 364) - - data <- pops(output_frequency = "every_n_steps", - output_frequency_n = 5, - time_step = "day", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 72) -}) - -test_that( - "Outputs occur with non-full year date range for all time step output frequency combinations", { - infected_file <- - system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") - start_date <- "2009-05-01" - end_date <- "2009-10-29" - treatment_dates <- start_date - parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - - data <- pops(output_frequency = "year", - time_step = "month", - treatment_dates = treatment_dates, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 1) - - data <- pops(output_frequency = "year", - time_step = "week", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 1) - - data <- pops(output_frequency = "year", - time_step = "day", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 1) - - data <- pops(output_frequency = "month", - time_step = "week", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 5) - - data <- pops(output_frequency = "month", - time_step = "day", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 5) +test_that("Changing the output frequency returns the correct number of outputs and output + statistics", { + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + start_date <- "2009-01-01" + end_date <- "2009-12-31" + treatment_dates <- c(start_date) + parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - data <- pops(output_frequency = "week", - time_step = "week", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 26) + data <- + pops(output_frequency = "year", + time_step = "month", + treatment_dates = treatment_dates, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 1) + + data <- + pops(output_frequency = "year", + time_step = "week", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 1) + + data <- + pops(output_frequency = "year", + time_step = "day", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 1) + + data <- + pops(output_frequency = "month", + time_step = "week", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 12) + + data <- + pops(output_frequency = "month", + time_step = "day", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 12) + + data <- + pops(output_frequency = "week", + time_step = "week", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 52) + + data <- + pops(output_frequency = "week", + time_step = "day", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 52) + + expect_error(pops(output_frequency = "day", + time_step = "week", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date), output_frequency_error) + + expect_error(pops(output_frequency = "day", + time_step = "month", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date), output_frequency_error) + + expect_error(pops(output_frequency = "week", + time_step = "month", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date), output_frequency_error) + + data <- pops(output_frequency = "day", + time_step = "day", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 364) + + data <- pops(output_frequency = "every_n_steps", + output_frequency_n = 5, + time_step = "day", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 72) + }) - data <- pops(output_frequency = "week", - time_step = "day", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 26) +test_that( + "Outputs occur with non-full year date range for all time step output frequency combinations", { + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + start_date <- "2009-05-01" + end_date <- "2009-10-29" + treatment_dates <- start_date + parameter_means <- c(0, 21, 1, 500, 0, 0, 0, 0) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - data <- - pops(output_frequency = "day" - , time_step = "day", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 182) + data <- pops(output_frequency = "year", + time_step = "month", + treatment_dates = treatment_dates, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 1) + + data <- pops(output_frequency = "year", + time_step = "week", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 1) + + data <- pops(output_frequency = "year", + time_step = "day", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 1) + + data <- pops(output_frequency = "month", + time_step = "week", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 5) + + data <- pops(output_frequency = "month", + time_step = "day", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 5) + + data <- pops(output_frequency = "week", + time_step = "week", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 26) + + data <- pops(output_frequency = "week", + time_step = "day", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 26) - data <- - pops(output_frequency = "time_step", - time_step = "day", - treatment_dates = start_date, - infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date) - expect_equal(length(data$infected), 182) -}) + data <- + pops(output_frequency = "day" + , time_step = "day", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 182) + + data <- + pops(output_frequency = "time_step", + time_step = "day", + treatment_dates = start_date, + infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date) + expect_equal(length(data$infected), 182) + }) test_that("Quarantine and spread rates work at all timings", { - infected_file <- - system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") + host_file <- system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") start_date <- "2009-01-01" end_date <- "2009-12-31" treatment_dates <- start_date @@ -2365,7 +2375,8 @@ test_that("Quarantine and spread rates work at all timings", { start_date = start_date, end_date = end_date, use_quarantine = TRUE, use_spreadrates = TRUE, - quarantine_areas_file = quarantine_areas_file) + quarantine_areas_file = quarantine_areas_file, + quarantine_directions = "N,E,S,W") expect_equal(length(data$infected), 364) expect_equal(length(data$quarantine_escape), 364) expect_equal(length(data$quarantine_escape_distance), 364) @@ -2384,7 +2395,8 @@ test_that("Quarantine and spread rates work at all timings", { end_date = end_date, use_quarantine = TRUE, use_spreadrates = TRUE, - quarantine_areas_file = quarantine_areas_file) + quarantine_areas_file = quarantine_areas_file, + quarantine_directions = "N") expect_equal(length(data$infected), 364) expect_equal(length(data$quarantine_escape), 364) expect_equal(length(data$quarantine_escape_distance), 364) @@ -2394,10 +2406,8 @@ test_that("Quarantine and spread rates work at all timings", { test_that("Mortality works as expected with multiple ", { - infected_file <- - system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") + host_file <- system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") start_date <- "2009-01-01" end_date <- "2009-12-31" treatment_dates <- start_date @@ -2445,8 +2455,7 @@ test_that("Mortality works as expected with multiple ", { expect_equal(length(data$mortality), 12) expect_equal(data$mortality[[1]], matrix(0, ncol = 20, nrow = 20)) expect_equal(data$mortality[[2]], matrix(0, ncol = 20, nrow = 20)) - expect_equal(data$mortality[[3]], - terra::as.matrix(terra::rast(infected_file), wide = TRUE)) + expect_equal(data$mortality[[3]], terra::as.matrix(terra::rast(infected_file), wide = TRUE)) data <- pops(output_frequency = "week", @@ -2470,8 +2479,7 @@ test_that("Mortality works as expected with multiple ", { expect_equal(data$mortality[[2]], matrix(0, ncol = 20, nrow = 20)) expect_equal(data$mortality[[3]], matrix(0, ncol = 20, nrow = 20)) expect_equal(data$mortality[[4]], matrix(0, ncol = 20, nrow = 20)) - expect_equal(data$mortality[[5]], - terra::as.matrix(terra::rast(infected_file), wide = TRUE)) + expect_equal(data$mortality[[5]], terra::as.matrix(terra::rast(infected_file), wide = TRUE)) data <- pops(output_frequency = "week", @@ -2497,8 +2505,7 @@ test_that("Mortality works as expected with multiple ", { expect_equal(data$mortality[[4]], matrix(0, ncol = 20, nrow = 20)) expect_equal(data$mortality[[5]], matrix(0, ncol = 20, nrow = 20)) expect_equal(data$mortality[[6]], matrix(0, ncol = 20, nrow = 20)) - expect_equal(data$mortality[[7]], - terra::as.matrix(terra::rast(infected_file), wide = TRUE)) + expect_equal(data$mortality[[7]], terra::as.matrix(terra::rast(infected_file), wide = TRUE)) data <- pops(output_frequency = "week", time_step = "week", @@ -2527,15 +2534,12 @@ test_that("Mortality works as expected with multiple ", { expect_equal(data$mortality[[8]], matrix(0, ncol = 20, nrow = 20)) expect_equal(data$mortality[[9]], matrix(0, ncol = 20, nrow = 20)) expect_equal(data$mortality[[10]], matrix(0, ncol = 20, nrow = 20)) - expect_equal(data$mortality[[11]], - terra::as.matrix(terra::rast(infected_file), wide = TRUE)) + expect_equal(data$mortality[[11]], terra::as.matrix(terra::rast(infected_file), wide = TRUE)) }) test_that("Movements works as expected", { - infected_file <- - system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") + infected_file <- system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") + host_file <- system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") start_date <- "2009-01-01" end_date <- "2009-12-31" treatment_dates <- start_date @@ -2643,7 +2647,7 @@ test_that("Movements works as expected", { }) test_that( - "OVerpopulation dispersal works as expected with directionality to prevent dispersers from + "Overpopulation dispersal works as expected with directionality to prevent dispersers from leaving the simulated area", { infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") @@ -2672,163 +2676,266 @@ test_that( expect_gte(data$infected[[1]][[4]], test_mat[[4]]) }) -test_that( - "Deterministic dispersal works as expected", { - infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") - host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") - start_date <- "2008-01-01" - end_date <- "2008-12-31" - parameter_means <- c(2, 21, 1, 500, 0, 0, 0, 0) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) +test_that("Deterministic dispersal works as expected", { + infected_file <- system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2008-12-31" + parameter_means <- c(2, 21, 1, 500, 0, 0, 0, 0) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - data <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date, - generate_stochasticity = FALSE, - establishment_stochasticity = FALSE, - movement_stochasticity = FALSE, - dispersal_stochasticity = TRUE) - test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) - expect_gte(data$infected[[1]][[1]], test_mat[[1]]) - expect_gte(data$infected[[1]][[2]], test_mat[[2]]) - expect_gte(data$infected[[1]][[3]], test_mat[[3]]) - expect_gte(data$infected[[1]][[4]], test_mat[[4]]) - }) + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date, + generate_stochasticity = FALSE, + establishment_stochasticity = FALSE, + movement_stochasticity = FALSE, + dispersal_stochasticity = TRUE) + test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) + expect_gte(data$infected[[1]][[1]], test_mat[[1]]) + expect_gte(data$infected[[1]][[2]], test_mat[[2]]) + expect_gte(data$infected[[1]][[3]], test_mat[[3]]) + expect_gte(data$infected[[1]][[4]], test_mat[[4]]) +}) +test_that("Network dispersal works as expected", { + infected_file <- + system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") + host_file <- system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2008-03-31" + parameter_means <- c(2, 21, 1, 500, 0, 0, 100, 1000) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + network_filename <- system.file("extdata", "simple20x20", "segments.csv", package = "PoPS") + anthropogenic_kernel_type <- "network" -test_that( - "Network dispersal works as expected", { - infected_file <- - system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") - host_file <- system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") - start_date <- "2008-01-01" - end_date <- "2008-03-31" - parameter_means <- c(2, 21, 1, 500, 0, 0, 100, 1000) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - network_filename <- system.file("extdata", "simple20x20", "segments.csv", package = "PoPS") - anthropogenic_kernel_type <- "network" + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = host_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date, + anthropogenic_kernel_type = anthropogenic_kernel_type, + network_filename = network_filename) + + test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) + expect_gte(data$infected[[1]][[1]], test_mat[[1]]) + expect_gte(data$infected[[1]][[2]], test_mat[[2]]) + expect_gte(data$infected[[1]][[3]], test_mat[[3]]) + expect_gte(data$infected[[1]][[4]], test_mat[[4]]) +}) - data <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = host_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date, - anthropogenic_kernel_type = anthropogenic_kernel_type, - network_filename = network_filename) +test_that("uncertainty propogation works as expected", { + infected_file <- system.file("extdata", "simple20x20", "infected_wsd.tif", package = "PoPS") + host_file <- system.file("extdata", "simple20x20", "host_w_sd2.tif", package = "PoPS") + total_populations_file <- + system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2008-03-31" + parameter_means <- c(2, 21, 1, 500, 0, 0, 100, 1000) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + anthropogenic_kernel_type <- "cauchy" + use_initial_condition_uncertainty <- TRUE + use_host_uncertainty <- TRUE - test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) - expect_gte(data$infected[[1]][[1]], test_mat[[1]]) - expect_gte(data$infected[[1]][[2]], test_mat[[2]]) - expect_gte(data$infected[[1]][[3]], test_mat[[3]]) - expect_gte(data$infected[[1]][[4]], test_mat[[4]]) - }) + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = total_populations_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date, + anthropogenic_kernel_type = anthropogenic_kernel_type, + use_initial_condition_uncertainty = use_initial_condition_uncertainty, + use_host_uncertainty = use_host_uncertainty) + + test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) + expect_gte(data$infected[[1]][[1]], test_mat[[1]]) + expect_gte(data$infected[[1]][[2]], test_mat[[2]]) + expect_gte(data$infected[[1]][[3]], test_mat[[3]]) + expect_gte(data$infected[[1]][[4]], test_mat[[4]]) + + infected_file <- system.file("extdata", "simple20x20", "infected_wsd.tif", package = "PoPS") + host_file <- system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") + total_populations_file <- system.file("extdata", "simple20x20", "all_plants.tif", + package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2008-03-31" + parameter_means <- c(2, 21, 1, 500, 0, 0, 100, 1000) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + anthropogenic_kernel_type <- "cauchy" + use_initial_condition_uncertainty <- TRUE + use_host_uncertainty <- FALSE + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = total_populations_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date, + anthropogenic_kernel_type = anthropogenic_kernel_type, + use_initial_condition_uncertainty = use_initial_condition_uncertainty, + use_host_uncertainty = use_host_uncertainty) -test_that( - "uncertainty propogation works as expected", { - infected_file <- - system.file("extdata", "simple20x20", "infected_wsd.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple20x20", "host_w_sd2.tif", package = "PoPS") - total_populations_file <- - system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") - start_date <- "2008-01-01" - end_date <- "2008-03-31" - parameter_means <- c(2, 21, 1, 500, 0, 0, 100, 1000) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - anthropogenic_kernel_type <- "cauchy" - use_initial_condition_uncertainty <- TRUE - use_host_uncertainty <- TRUE + test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) + expect_gte(data$infected[[1]][[1]], test_mat[[1]]) + expect_gte(data$infected[[1]][[2]], test_mat[[2]]) + expect_gte(data$infected[[1]][[3]], test_mat[[3]]) + expect_gte(data$infected[[1]][[4]], test_mat[[4]]) - data <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = total_populations_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date, - anthropogenic_kernel_type = anthropogenic_kernel_type, - use_initial_condition_uncertainty = use_initial_condition_uncertainty, - use_host_uncertainty = use_host_uncertainty) + infected_file <- + system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") + host_file <- system.file("extdata", "simple20x20", "host_w_sd2.tif", package = "PoPS") + total_populations_file <- + system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2008-03-31" + parameter_means <- c(2, 21, 1, 500, 0, 0, 100, 1000) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + anthropogenic_kernel_type <- "cauchy" + use_initial_condition_uncertainty <- FALSE + use_host_uncertainty <- TRUE - test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) - expect_gte(data$infected[[1]][[1]], test_mat[[1]]) - expect_gte(data$infected[[1]][[2]], test_mat[[2]]) - expect_gte(data$infected[[1]][[3]], test_mat[[3]]) - expect_gte(data$infected[[1]][[4]], test_mat[[4]]) + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = total_populations_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date, + anthropogenic_kernel_type = anthropogenic_kernel_type, + use_initial_condition_uncertainty = use_initial_condition_uncertainty, + use_host_uncertainty = use_host_uncertainty) + + test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) + expect_gte(data$infected[[1]][[1]], test_mat[[1]]) + expect_gte(data$infected[[1]][[2]], test_mat[[2]]) + expect_gte(data$infected[[1]][[3]], test_mat[[3]]) + expect_gte(data$infected[[1]][[4]], test_mat[[4]]) +}) +test_that("multiple_random seeds works and returns expected results", { + infected_file <- + system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") + host_file <- system.file("extdata", "simple20x20", "host.tif", package = "PoPS") + total_populations_file <- + system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2008-03-31" + parameter_means <- c(5, 21, 1, 500, 0, 0, 100, 1000) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + anthropogenic_kernel_type <- "cauchy" + multiple_random_seeds <- TRUE + file_random_seeds <- NULL - infected_file <- - infected_file <- - system.file("extdata", "simple20x20", "infected_wsd.tif", package = "PoPS") - host_file <- system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") - total_populations_file <- - system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") - start_date <- "2008-01-01" - end_date <- "2008-03-31" - parameter_means <- c(2, 21, 1, 500, 0, 0, 100, 1000) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - anthropogenic_kernel_type <- "cauchy" - use_initial_condition_uncertainty <- TRUE - use_host_uncertainty <- FALSE + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = total_populations_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date, + anthropogenic_kernel_type = anthropogenic_kernel_type, + multiple_random_seeds = multiple_random_seeds, + file_random_seeds = file_random_seeds) - data <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = total_populations_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date, - anthropogenic_kernel_type = anthropogenic_kernel_type, - use_initial_condition_uncertainty = use_initial_condition_uncertainty, - use_host_uncertainty = use_host_uncertainty) + test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) + expect_gte(data$infected[[1]][[1]], test_mat[[1]]) + expect_gte(data$infected[[1]][[2]], test_mat[[2]]) + expect_gte(data$infected[[1]][[3]], test_mat[[3]]) + expect_gte(data$infected[[1]][[4]], test_mat[[4]]) - test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) - expect_gte(data$infected[[1]][[1]], test_mat[[1]]) - expect_gte(data$infected[[1]][[2]], test_mat[[2]]) - expect_gte(data$infected[[1]][[3]], test_mat[[3]]) - expect_gte(data$infected[[1]][[4]], test_mat[[4]]) + file_random_seeds <- system.file("extdata", "simple2x2", "randoms.csv", package = "PoPS") + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = total_populations_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date, + anthropogenic_kernel_type = anthropogenic_kernel_type, + multiple_random_seeds = multiple_random_seeds, + file_random_seeds = file_random_seeds) + + test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) + expect_gte(data$infected[[1]][[1]], test_mat[[1]]) + expect_gte(data$infected[[1]][[2]], test_mat[[2]]) + expect_gte(data$infected[[1]][[3]], test_mat[[3]]) + expect_gte(data$infected[[1]][[4]], test_mat[[4]]) +}) - infected_file <- - system.file("extdata", "simple20x20", "initial_infection.tif", package = "PoPS") - host_file <- - system.file("extdata", "simple20x20", "host_w_sd2.tif", package = "PoPS") - total_populations_file <- - system.file("extdata", "simple20x20", "all_plants.tif", package = "PoPS") - start_date <- "2008-01-01" - end_date <- "2008-03-31" - parameter_means <- c(2, 21, 1, 500, 0, 0, 100, 1000) - parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) - anthropogenic_kernel_type <- "cauchy" - use_initial_condition_uncertainty <- FALSE - use_host_uncertainty <- TRUE - data <- - pops(infected_file = infected_file, - host_file = host_file, - total_populations_file = total_populations_file, - parameter_means = parameter_means, - parameter_cov_matrix = parameter_cov_matrix, - start_date = start_date, - end_date = end_date, - anthropogenic_kernel_type = anthropogenic_kernel_type, - use_initial_condition_uncertainty = use_initial_condition_uncertainty, - use_host_uncertainty = use_host_uncertainty) +test_that("Using soils returns expected results", { + infected_file <- + system.file("extdata", "simple2x2", "infected.tif", package = "PoPS") + host_file <- system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + total_populations_file <- + system.file("extdata", "simple2x2", "total_plants.tif", package = "PoPS") + start_date <- "2008-01-01" + end_date <- "2009-12-31" + parameter_means <- c(5, 21, 1, 500, 0, 0, 100, 1000) + parameter_cov_matrix <- matrix(0, nrow = 8, ncol = 8) + use_soils <- TRUE + dispersers_to_soils_percentage <- 0.05 + coefficient_file <- + system.file("extdata", "simple2x2", "temperature_coefficient.tif", package = "PoPS") - test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) - expect_gte(data$infected[[1]][[1]], test_mat[[1]]) - expect_gte(data$infected[[1]][[2]], test_mat[[2]]) - expect_gte(data$infected[[1]][[3]], test_mat[[3]]) - expect_gte(data$infected[[1]][[4]], test_mat[[4]]) - }) + + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = total_populations_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date, + temp = TRUE, + temperature_coefficient_file = coefficient_file, + use_soils = use_soils, + dispersers_to_soils_percentage = dispersers_to_soils_percentage) + + test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) + expect_gte(data$infected[[1]][[1]], test_mat[[1]]) + expect_gte(data$infected[[1]][[2]], test_mat[[2]]) + expect_gte(data$infected[[1]][[3]], test_mat[[3]]) + expect_gte(data$infected[[1]][[4]], test_mat[[4]]) + expect_equal(length(data$soil_reservoirs[[1]]), 20) + expect_equal(length(data$soil_reservoirs[[2]]), 20) + + data <- + pops(infected_file = infected_file, + host_file = host_file, + total_populations_file = total_populations_file, + parameter_means = parameter_means, + parameter_cov_matrix = parameter_cov_matrix, + start_date = start_date, + end_date = end_date, + temp = TRUE, + temperature_coefficient_file = coefficient_file, + use_soils = use_soils, + dispersers_to_soils_percentage = dispersers_to_soils_percentage, + soil_starting_pest_file = infected_file, + start_with_soil_populations = TRUE) + + test_mat <- terra::as.matrix(terra::rast(infected_file), wide = TRUE) + expect_gte(data$infected[[1]][[1]], test_mat[[1]]) + expect_gte(data$infected[[1]][[2]], test_mat[[2]]) + expect_gte(data$infected[[1]][[3]], test_mat[[3]]) + expect_gte(data$infected[[1]][[4]], test_mat[[4]]) + expect_equal(length(data$soil_reservoirs[[1]]), 20) + expect_equal(length(data$soil_reservoirs[[2]]), 20) +})