Skip to content

Commit 7379328

Browse files
committed
add files and update calibrate and tests
1 parent 11e0eaf commit 7379328

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2037
-2534
lines changed

R/calibrate.R

Lines changed: 54 additions & 127 deletions
Large diffs are not rendered by default.

R/configuration.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
#' @export
2323

2424
configuration <- function(config_file, testing = FALSE) {
25-
2625
config <- yaml::yaml.load_file(config_file)
27-
if (testing) {
26+
config$testing <- testing
27+
if (config$testing) {
2828
file_return <- function(x) {system.file(x, package = "PoPS")}
2929
} else {
3030
file_return <- function(x) {file.path(config$input_path, x)}
@@ -1019,9 +1019,9 @@ configuration <- function(config_file, testing = FALSE) {
10191019
config$use_anthropogenic_kernel <- TRUE
10201020
# Load observed data on occurrence
10211021
if (config$county_level_infection_data) {
1022-
config$infection_years <-
1022+
config$infection_comparison <-
10231023
terra::vect(file_return(config$infected_val_cal_file))
1024-
config$num_layers_infected_years <- length(names(config$infection_years))
1024+
config$num_layers_infected_years <- length(names(config$infection_comparison))
10251025
if (config$num_layers_infected_years < config$number_of_outputs) {
10261026
config$failure <-
10271027
infection_years_length_error(config$num_layers_infected_years,

R/helpers.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,12 @@ calculate_all_stats <- function(config, data) {
712712
# need to assign reference, comparison, and mask in inner loop since
713713
# terra objects are pointers
714714

715-
comparison <- terra::rast(config$host_file_list[[1]])[[1]]
715+
if (config$testing) {
716+
file_return <- function(x) {system.file(x, package = "PoPS")}
717+
} else {
718+
file_return <- function(x) {file.path(config$input_path, x)}
719+
}
720+
comparison <- terra::rast(file_return(config$host_files[[1]]))[[1]]
716721
terra::values(comparison) <- 0
717722
reference <- comparison
718723
mask <- comparison
@@ -723,7 +728,7 @@ calculate_all_stats <- function(config, data) {
723728
}
724729
terra::values(mask) <- config$mask_matrix
725730
if (config$county_level_infection_data) {
726-
reference <- terra::vect(config$infected_years_file[[1]])
731+
reference <- terra::vect(file_return(config$infected_val_cal_file[[1]]))
727732
compare_vect <- reference[, c(1, (q + 1))]
728733
names(compare_vect) <- c("FIPS", "reference")
729734
compare_vect$comparison <- terra::extract(comparison, reference, fun = "sum")[, 2]
@@ -734,9 +739,8 @@ calculate_all_stats <- function(config, data) {
734739
ad$allocation_disagreement <- 0
735740
ad$configuration_disagreement <- 0
736741
ad$distance_difference <- 0
737-
738742
} else {
739-
terra::values(reference) <- config$infection_years2[[q]]
743+
terra::values(reference) <- config$infection_comparison2[[q]]
740744
ad <-
741745
quantity_allocation_disagreement(reference,
742746
comparison,

R/pops_simulate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#' @return list of infected and susceptible per year
3535
#' @export
3636

37-
pops_simulate <- function(config_rds_file = "") {
37+
pops_simulate <- function(config_rds_file) {
3838

3939
config <- readRDS(config_rds_file)
4040

952 KB
Binary file not shown.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# File paths for input and output data
2+
input_path: "C:/Users/cjone/Projects/rpops/inst/extdata"
3+
output_path: "C:/Users/cjone/Projects/rpops/inst/extdata/simple2x2/outputs"
4+
5+
# pest parameters
6+
starting_infected_files: ["extdata/simple20x20/initial_infection.tif"]
7+
parameter_means_file: "extdata/parameter_means_default.csv"
8+
parameter_cov_matrix_file: "extdata/parameter_cov_matrix_default.csv"
9+
pest_host_table: "extdata/pest_host_table_singlehost_nomort.csv"
10+
competency_table: "extdata/competency_table_singlehost.csv"
11+
county_level_infection_data: false
12+
use_initial_condition_uncertainty: false
13+
start_exposed: false
14+
latency_period: 14
15+
exposed_files: [""]
16+
17+
# host data
18+
host_files: ["extdata/simple20x20/host.tif"]
19+
total_populations_file: "extdata/simple20x20/all_plants.tif"
20+
use_host_uncertainty: false
21+
# simulation settings
22+
random_seed: null
23+
start_date: "2003-01-01"
24+
end_date: "2003-02-11"
25+
time_step: "week"
26+
model_type: "SI"
27+
season_month_start: 1
28+
season_month_end: 12
29+
number_of_iterations: 10
30+
number_of_cores: 2
31+
output_frequency: "week"
32+
output_frequency_n: 1
33+
mask: "extdata/simple20x20/mask.tif"
34+
35+
# weather
36+
use_lethal_temperature: false
37+
lethal_temperature_file: "extdata/simple2x2/critical_temp_all_below_threshold.tif"
38+
lethal_temperature: -14
39+
lethal_temperature_month: 1
40+
use_overwinter_survival: false
41+
overwinter_survival_rate_month: 3
42+
overwinter_survival_rate_day: 15
43+
overwinter_survival_rates_file: "extdata/simple2x2/survival_rates.tif"
44+
use_temperature: false
45+
temperature_coefficient_file: "extdata/simple2x2/temperature_coefficient.tif"
46+
temperature_coefficient_sd_file: "extdata/simple2x2/coefficient_sd.tif"
47+
use_precipitation: false
48+
precipitation_coefficient_file: "extdata/simple2x2/temperature_coefficient.tif"
49+
precipitation_coefficient_sd_file: "extdata/simple2x2/coefficient_sd.tif"
50+
weather_type: "deterministic"
51+
52+
# mortality
53+
mortality_frequency: "year"
54+
mortality_frequency_n: 1
55+
56+
# treatments
57+
use_treatment: false
58+
treatments_file: "extdata/simple2x2/treatments.tif"
59+
treatment_dates: ["2003-01-01"]
60+
treatment_method: "ratio"
61+
pesticide_durations: [0]
62+
pesticide_efficacy: 0.5
63+
use_quarantine: false
64+
quarantine_areas_file: "extdata/simple20x20/initial_infection.tif"
65+
quarantine_directions: ""
66+
67+
# dispersal
68+
natural_kernel_type: "exponential"
69+
natural_dir: "NONE"
70+
anthropogenic_kernel_type: "cauchy"
71+
anthropogenic_dir: "NONE"
72+
# only used if anthropogenic_kernel_type == "network"
73+
network_files: ["extdata/simple20x20/segments.csv"]
74+
network_movement_types: ["walk"]
75+
network_min_distances: [50]
76+
network_max_distances: [250]
77+
network_weights: [1]
78+
79+
# host movement
80+
use_movements: false
81+
movements_file: ""
82+
83+
# stochasticity
84+
use_multiple_random_seeds: false
85+
multiple_random_seeds_file: null
86+
generate_stochasticity: true
87+
establishment_stochasticity: true
88+
movement_stochasticity: true
89+
dispersal_stochasticity: true
90+
establishment_probability: 0.5
91+
dispersal_percentage: 0.99
92+
use_spreadrates: false
93+
use_overpopulation_movements: false
94+
overpopulation_percentage: 0.75
95+
leaving_percentage: 0.5
96+
leaving_scale_coefficient: 5
97+
98+
# soil_pests
99+
use_soils: false
100+
soil_starting_pest_file: ""
101+
start_with_soil_populations: false
102+
dispersers_to_soils_percentage: 0
103+
104+
# validation and calibration
105+
infected_val_cal_file: "extdata/simple20x20/infected_years.tif"
106+
107+
# calibration only parameters
108+
perform_calibration: true
109+
params_to_estimate: [true, true, true, true, false, false]
110+
prior_means_file: "extdata/prior_means_0s.csv"
111+
prior_cov_matrix_file: "extdata/prior_cov_matrix_0s.csv"
112+
prior_number_of_observations: 0
113+
number_of_observations: 68
114+
success_metric: "quantity, allocation, and configuration"
115+
verbose: true
116+
natural_kappa: 0
117+
anthropogenic_kappa: 0
118+
calibration_method: "MCMC"
119+
# ABC Parameters
120+
generation_size: 5
121+
number_of_generations: 2
122+
123+
# validation only
124+
perform_validation: false
125+
point_file: ""
126+
use_configuration: false
127+
128+
# Model API only never used unless you are pulling data from an S3 bucket in the cloud
129+
use_s3: false
130+
bucket: ""
952 KB
Binary file not shown.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# File paths for input and output data
2+
input_path: "C:/Users/cjone/Projects/rpops/inst/extdata"
3+
output_path: "C:/Users/cjone/Projects/rpops/inst/extdata/simple2x2/outputs"
4+
5+
# pest parameters
6+
starting_infected_files: ["extdata/simple20x20/infected_wsd.tif"]
7+
parameter_means_file: "extdata/parameter_means_default.csv"
8+
parameter_cov_matrix_file: "extdata/parameter_cov_matrix_default.csv"
9+
pest_host_table: "extdata/pest_host_table_singlehost_nomort.csv"
10+
competency_table: "extdata/competency_table_singlehost.csv"
11+
county_level_infection_data: false
12+
use_initial_condition_uncertainty: true
13+
start_exposed: false
14+
latency_period: 14
15+
exposed_files: [""]
16+
17+
# host data
18+
host_files: ["extdata/simple20x20/host_w_sd2.tif"]
19+
total_populations_file: "extdata/simple20x20/all_plants.tif"
20+
use_host_uncertainty: true
21+
22+
# simulation settings
23+
random_seed: null
24+
start_date: "2003-01-01"
25+
end_date: "2003-02-11"
26+
time_step: "week"
27+
model_type: "SI"
28+
season_month_start: 1
29+
season_month_end: 12
30+
number_of_iterations: 10
31+
number_of_cores: 2
32+
output_frequency: "week"
33+
output_frequency_n: 1
34+
mask: "extdata/simple20x20/mask.tif"
35+
36+
# weather
37+
use_lethal_temperature: false
38+
lethal_temperature_file: "extdata/simple2x2/critical_temp_all_below_threshold.tif"
39+
lethal_temperature: -14
40+
lethal_temperature_month: 1
41+
use_overwinter_survival: false
42+
overwinter_survival_rate_month: 3
43+
overwinter_survival_rate_day: 15
44+
overwinter_survival_rates_file: "extdata/simple2x2/survival_rates.tif"
45+
use_temperature: false
46+
temperature_coefficient_file: "extdata/simple2x2/temperature_coefficient.tif"
47+
temperature_coefficient_sd_file: "extdata/simple2x2/coefficient_sd.tif"
48+
use_precipitation: false
49+
precipitation_coefficient_file: "extdata/simple2x2/temperature_coefficient.tif"
50+
precipitation_coefficient_sd_file: "extdata/simple2x2/coefficient_sd.tif"
51+
weather_type: "deterministic"
52+
53+
# mortality
54+
mortality_frequency: "year"
55+
mortality_frequency_n: 1
56+
57+
# treatments
58+
use_treatment: false
59+
treatments_file: "extdata/simple2x2/treatments.tif"
60+
treatment_dates: ["2003-01-01"]
61+
treatment_method: "ratio"
62+
pesticide_durations: [0]
63+
pesticide_efficacy: 0.5
64+
use_quarantine: false
65+
quarantine_areas_file: "extdata/simple20x20/initial_infection.tif"
66+
quarantine_directions: ""
67+
68+
# dispersal
69+
natural_kernel_type: "exponential"
70+
natural_dir: "NONE"
71+
anthropogenic_kernel_type: "cauchy"
72+
anthropogenic_dir: "NONE"
73+
# only used if anthropogenic_kernel_type == "network"
74+
network_files: ["extdata/simple20x20/segments.csv"]
75+
network_movement_types: ["walk"]
76+
network_min_distances: [50]
77+
network_max_distances: [250]
78+
network_weights: [1]
79+
80+
# host movement
81+
use_movements: false
82+
movements_file: ""
83+
84+
# stochasticity
85+
use_multiple_random_seeds: false
86+
multiple_random_seeds_file: null
87+
generate_stochasticity: true
88+
establishment_stochasticity: true
89+
movement_stochasticity: true
90+
dispersal_stochasticity: true
91+
establishment_probability: 0.5
92+
dispersal_percentage: 0.99
93+
use_spreadrates: false
94+
use_overpopulation_movements: false
95+
overpopulation_percentage: 0.75
96+
leaving_percentage: 0.5
97+
leaving_scale_coefficient: 5
98+
99+
# soil_pests
100+
use_soils: false
101+
soil_starting_pest_file: ""
102+
start_with_soil_populations: false
103+
dispersers_to_soils_percentage: 0
104+
105+
# validation and calibration
106+
infected_val_cal_file: "extdata/simple20x20/infected_years.tif"
107+
108+
# calibration only parameters
109+
perform_calibration: true
110+
params_to_estimate: [true, true, true, true, false, false]
111+
prior_means_file: "extdata/prior_means_0s.csv"
112+
prior_cov_matrix_file: "extdata/prior_cov_matrix_0s.csv"
113+
prior_number_of_observations: 0
114+
number_of_observations: 68
115+
success_metric: "quantity, allocation, and configuration"
116+
verbose: true
117+
natural_kappa: 0
118+
anthropogenic_kappa: 0
119+
calibration_method: "MCMC"
120+
# ABC Parameters
121+
generation_size: 5
122+
number_of_generations: 2
123+
124+
# validation only
125+
perform_validation: false
126+
point_file: ""
127+
use_configuration: false
128+
129+
# Model API only never used unless you are pulling data from an S3 bucket in the cloud
130+
use_s3: false
131+
bucket: ""
952 KB
Binary file not shown.

0 commit comments

Comments
 (0)