Skip to content

Commit

Permalink
add soils file and use soils to all r functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJones687 committed Sep 12, 2023
1 parent e73293e commit 7adae19
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 13 deletions.
4 changes: 1 addition & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Authors@R:
family = "Petrasova",
role = c("aut"),
comment = c(ORCID = "0000-0002-5120-5538")))
Depends: R (>= 3.3.0)
Depends: R (>= 4.0.0)
Imports:
raster (>= 3.5-15),
terra (>= 1.5-17),
Expand All @@ -26,7 +26,6 @@ Imports:
foreach,
parallel,
doParallel,
iterators,
landscapemetrics,
lubridate,
sp,
Expand All @@ -41,7 +40,6 @@ URL: http://www.github.com/ncsu-landscape-dynamics/rpops
Encoding: UTF-8
LazyData: true
SystemRequirements:
C++11,
GNU make
Suggests:
testthat,
Expand Down
7 changes: 5 additions & 2 deletions R/calibrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ calibrate <- function(infected_years_file,
dispersers_to_soils_percentage = 0,
quarantine_directions = "",
multiple_random_seeds = FALSE,
random_seeds = NULL) {
random_seeds = NULL,
use_soils = FALSE,
soil_starting_pest_file = "") {

# add all data to config list
config <- c()
Expand Down Expand Up @@ -289,7 +291,8 @@ calibrate <- function(infected_years_file,
config$dispersers_to_soils_percentage <- dispersers_to_soils_percentage
config$multiple_random_seeds <- multiple_random_seeds
config$random_seeds <-random_seeds

config$use_soils <- use_soils
config$soil_starting_pest_file <- soil_starting_pest_file

# call configuration function to perform data checks and transform data into
# format used in pops c++
Expand Down
22 changes: 22 additions & 0 deletions R/configuration.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,28 @@ configuration <- function(config) {
return(config)
}

# check that soils raster has the same crs, resolutin, and extent.
if (config$use_soils) {
if (config$function_name %in% c("casestudy_creation", "model_api")) {
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
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)
}
return(config)
}
} else {
config$soil_pests <- zero_matrix
}

# check that survival_rates raster has the same crs, resolution, and extent
if (config$use_survival_rates == TRUE) {
if (config$function_name %in% c("casestudy_creation", "model_api")) {
Expand Down
8 changes: 7 additions & 1 deletion R/pops.r
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@
#' 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
#' (allows for performing uncertainty partitioning) or a single random seed (backwards
#' compatibility option). Default is FALSE.
Expand Down Expand Up @@ -293,7 +295,9 @@ pops <- function(infected_file,
dispersers_to_soils_percentage = 0,
quarantine_directions = "",
multiple_random_seeds = FALSE,
random_seeds = NULL) {
random_seeds = NULL,
use_soils = FALSE,
soil_starting_pest_file = "") {

config <- c()
config$random_seed <- random_seed
Expand Down Expand Up @@ -378,6 +382,8 @@ pops <- function(infected_file,
config$dispersers_to_soils_percentage <- dispersers_to_soils_percentage
config$multiple_random_seeds <- multiple_random_seeds
config$random_seeds <-random_seeds
config$use_soils <- use_soils
config$soil_starting_pest_file <- soil_starting_pest_file

config <- configuration(config)

Expand Down
8 changes: 6 additions & 2 deletions R/pops_multirun.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ pops_multirun <- function(infected_file,
dispersers_to_soils_percentage = 0,
quarantine_directions = "",
multiple_random_seeds = FALSE,
random_seeds = NULL) {
random_seeds = NULL,
use_soils = FALSE,
soil_starting_pest_file = "") {
config <- c()
config$random_seed <- random_seed
config$infected_file <- infected_file
Expand Down Expand Up @@ -188,6 +190,8 @@ pops_multirun <- function(infected_file,
config$dispersers_to_soils_percentage <- dispersers_to_soils_percentage
config$multiple_random_seeds <- multiple_random_seeds
config$random_seeds <-random_seeds
config$use_soils <- use_soils
config$soil_starting_pest_file <- soil_starting_pest_file

config <- configuration(config)

Expand All @@ -196,8 +200,8 @@ pops_multirun <- function(infected_file,
}

config$crs <- terra::crs(config$host)
# i <- NULL

i <- NULL
cl <- parallel::makeCluster(config$core_count)
doParallel::registerDoParallel(cl)

Expand Down
6 changes: 5 additions & 1 deletion R/validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ validate <- function(infected_years_file,
dispersers_to_soils_percentage = 0,
quarantine_directions = "",
multiple_random_seeds = FALSE,
random_seeds = NULL) {
random_seeds = NULL,
use_soils = FALSE,
soil_starting_pest_file = "") {
config <- c()
config$infected_years_file <- infected_years_file
config$infected_file <- infected_file
Expand Down Expand Up @@ -207,6 +209,8 @@ validate <- function(infected_years_file,
config$dispersers_to_soils_percentage <- dispersers_to_soils_percentage
config$multiple_random_seeds <- multiple_random_seeds
config$random_seeds <-random_seeds
config$use_soils <- use_soils
config$soil_starting_pest_file <- soil_starting_pest_file

config <- configuration(config)

Expand Down
10 changes: 9 additions & 1 deletion man/calibrate.Rd

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

7 changes: 6 additions & 1 deletion man/pops.Rd

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

10 changes: 9 additions & 1 deletion man/pops_multirun.Rd

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

10 changes: 9 additions & 1 deletion man/validate.Rd

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

0 comments on commit 7adae19

Please sign in to comment.