Skip to content

Commit

Permalink
Pull request to add in county level data for calibration and running …
Browse files Browse the repository at this point in the history
…the model (#196)

* add parameter for county level infection data.

* add data

* add error for county level infection data

* add function for county level data to raster data

* update config to handle county level infection and exposed data inputs.

* add test for county level input

* add data for cal and val testing of county level

* add county level data check for cal and val input at county level

* lint

* lint

* add tests for cal and val

* add function for county level stats

* update validate to use county level calibration

* update calibrate

* move calculation of stats to a seperate function and update val and cal functions to use it.

* update XML for windows

* Update CHANGELOG.md
  • Loading branch information
ChrisJones687 authored Feb 12, 2024
1 parent 7f565f0 commit 575764e
Show file tree
Hide file tree
Showing 21 changed files with 1,176 additions and 266 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ this repository.
- Added ability to use mean and sd for temp and precip coefficient. Uses 3 new parameters: weather_type, temperature_coefficient_sd_file, and precipitation_coefficient_sd_file. This is added to help understand uncertainty in model predictions due to weather drivers (@ChrisJones687, #168).

- Added the ability to use different seeds for all processes within pops-core. Adds 2 new parameters: multiple_random_seeds (boolean for using this functionality) and random_seeds (set to NULL to allow internal model selection of kernels or pass a CSV with the number of rows being the number of model runs and columns being the kernels in order (@ChrisJones687, #168).

- Added ability for model to simulate pathogen/pest survival in soil and then emergence/rain splash in an area (@ChrisJones687, #178).

- Model can now write out forecast ensemble members (@ChrisJones687, #179)

- Added ability for model to use multi-host pops-core API. The model now takes 2 new parameter tables for hosts. It also takes a list of rasters for each host allowing testing of hypothesis related to different host combinations being more conducive to spread on the landscape (@petrasovaa, @ChrisJones687, @wenzeslaus, #186 and #188).

- Added the ability to calibrate, validate, and simulate from county level infection data (@ChrisJones687, #196).

### Changed

Expand All @@ -34,7 +42,7 @@ this repository.

### Removed

- Removed dependencies: packages rgdal, raster, sp
- Removed dependencies: packages rgdal, raster, sp (@petrasovaa, #187)

## [2.0.1] 2022-11-16

Expand Down
83 changes: 10 additions & 73 deletions R/calibrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ calibrate <- function(infected_years_file,
file_random_seeds = NULL,
use_soils = FALSE,
soil_starting_pest_file = "",
start_with_soil_populations = FALSE) {
start_with_soil_populations = FALSE,
county_level_infection_data = FALSE) {

# add all data to config list
config <- c()
Expand Down Expand Up @@ -292,8 +293,10 @@ calibrate <- function(infected_years_file,
config$use_soils <- use_soils
config$soil_starting_pest_file <- soil_starting_pest_file
config$start_with_soil_populations <- start_with_soil_populations
config$county_level_infection_data <- county_level_infection_data
config$pest_host_table <- pest_host_table
config$competency_table <- competency_table
config$point_file <- ""

# call configuration function to perform data checks and transform data into
# format used in pops c++
Expand Down Expand Up @@ -547,30 +550,8 @@ calibrate <- function(infected_years_file,

# calculate comparison metrics for simulation data for each time step in
# the simulation
all_disagreement <-
foreach::foreach(
q = seq_len(length(data$host_pools[[1]]$infected)),
.combine = rbind,
.packages = c("terra", "PoPS"),
.final = colSums
) %do% {
comparison <- terra::rast(config$infected_file_list[[1]])[[1]]
reference <- comparison
mask <- comparison
terra::values(comparison) <- 0
infections <- comparison
for (p in seq_len(length(data$host_pools))) {
terra::values(infections) <- data$host_pools[[p]]$infected[[q]]
comparison <- comparison + infections
}
terra::values(reference) <- config$infection_years2[[q]]
terra::values(mask) <- config$mask_matrix
quantity_allocation_disagreement(reference,
comparison,
use_configuration = config$use_configuration,
mask = mask,
use_distance = config$use_distance)
}
all_disagreement <- calculate_all_stats(config, data)
all_disagreement <- colSums(all_disagreement)

all_disagreement <- as.data.frame(t(all_disagreement))
all_disagreement <- all_disagreement / length(data$host_pools[[1]]$infected)
Expand Down Expand Up @@ -890,30 +871,8 @@ calibrate <- function(infected_years_file,
proposed_network_max_distance
)

all_disagreement <-
foreach::foreach(
q = seq_len(length(data$host_pools[[1]]$infected)),
.combine = rbind,
.packages = c("terra", "PoPS"),
.final = colSums
) %do% {
comparison <- terra::rast(config$infected_file_list[[1]])[[1]]
reference <- comparison
mask <- comparison
terra::values(comparison) <- 0
infections <- comparison
for (p in seq_len(length(data$host_pools))) {
terra::values(infections) <- data$host_pools[[p]]$infected[[q]]
comparison <- comparison + infections
}
terra::values(reference) <- config$infection_years2[[q]]
terra::values(mask) <- config$mask_matrix
quantity_allocation_disagreement(reference,
comparison,
use_configuration = config$use_configuration,
mask = mask,
use_distance = config$use_distance)
}
all_disagreement <- calculate_all_stats(config, data)
all_disagreement <- colSums(all_disagreement)

all_disagreement <- as.data.frame(t(all_disagreement))
all_disagreement <- all_disagreement / length(data$host_pools[[1]]$infected)
Expand Down Expand Up @@ -1069,30 +1028,8 @@ calibrate <- function(infected_years_file,
)

# set up comparison
all_disagreement <-
foreach::foreach(
q = seq_len(length(data$host_pools[[1]]$infected)),
.combine = rbind,
.packages = c("terra", "PoPS"),
.final = colSums
) %do% {
comparison <- terra::rast(config$infected_file_list[[1]])[[1]]
reference <- comparison
mask <- comparison
terra::values(comparison) <- 0
infections <- comparison
for (p in seq_len(length(data$host_pools))) {
terra::values(infections) <- data$host_pools[[p]]$infected[[q]]
comparison <- comparison + infections
}
terra::values(reference) <- config$infection_years2[[q]]
terra::values(mask) <- config$mask_matrix
quantity_allocation_disagreement(reference,
comparison,
use_configuration = config$use_configuration,
mask = mask,
use_distance = config$use_distance)
}
all_disagreement <- calculate_all_stats(config, data)
all_disagreement <- colSums(all_disagreement)

all_disagreement <- as.data.frame(t(all_disagreement))
all_disagreement <- all_disagreement / length(data$host_pools[[1]]$infected)
Expand Down
Loading

0 comments on commit 575764e

Please sign in to comment.