Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify and fix creation of rasters within foreach loops #182

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/calibrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,10 @@ calibrate <- function(infected_years_file,
.final = colSums
) %do% {
comparison <- terra::rast(config$infected_file)[[1]]
reference <- terra::rast(config$infected_file)[[1]]
reference <- comparison
mask <- comparison
terra::values(comparison) <- data$infected[[q]]
terra::values(reference) <- config$infection_years2[[q]]
mask <- terra::rast(config$infected_file)[[1]]
terra::values(mask) <- config$mask_matrix
quantity_allocation_disagreement(reference,
comparison,
Expand Down
9 changes: 3 additions & 6 deletions R/pops_multirun.R
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,10 @@ pops_multirun <- function(infected_file,
run$exposed_runs <- data$exposed

if (config$write_outputs == "all_simulations") {
infected_out <- terra::rast(config$infected_file)
susectible_out <- terra::rast(config$infected_file)
exposed_out <- terra::rast(config$infected_file)
infected_out <- terra::rast(config$infected_file)[[1]]
susectible_out <- infected_out
exposed_out <- infected_out
for (q in seq_len(length(data$infected))) {
terra::values(infected_out[[q]]) <-
terra::values(terra::rast(data$infected[[q]],
crs = crs(infected_out), extent = ext(infected_out)))
terra::values(infected_out[[q]]) <- data$infected[[q]]
terra::values(susectible_out[[q]]) <- data$susceptible[[q]]
for (p in seq_len(length(data$exposed[[q]])))
Expand Down
4 changes: 2 additions & 2 deletions R/validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ validate <- function(infected_years_file,
# need to assign reference, comparison, and mask in inner loop since
# terra objects are pointers and pointers using %dopar%
comparison <- terra::rast(config$infected_file)[[1]]
reference <- terra::rast(config$infected_file)[[1]]
reference <- comparison
mask <- comparison
terra::values(comparison) <- data$infected[[q]]
terra::values(reference) <- config$infection_years2[[q]]
mask <- terra::rast(config$infected_file)[[1]]
terra::values(mask) <- config$mask_matrix
ad <-
quantity_allocation_disagreement(reference,
Expand Down
Loading