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

Wrap and unwrap rasters #4

Merged
merged 2 commits into from
May 13, 2024
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
2 changes: 1 addition & 1 deletion R/disp.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#' # disp
#' disp_output <- disp(
#' N_t = sim_data$n1_map,
#' id = sim_data$id,
#' id = unwrap(sim_data$id),
#' data_table = sim_data$data_table,
#' kernel = sim_data$kernel,
#' dens_dep = sim_data$dens_dep,
Expand Down
4 changes: 2 additions & 2 deletions R/initialise.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ initialise <- function(
# output list
out <- list(
n1_map = as.matrix(n1_map, wide = TRUE),
id = id,
id = wrap(id),
resolution = resolution,
r = r,
r_sd = r_sd,
K_map = K_map,
K_map = wrap(K_map),
K_sd = K_sd,
growth = growth,
A = A,
Expand Down
2 changes: 1 addition & 1 deletion R/print.sim_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

# prepare output
n1_sm <- summary(as.numeric(x$n1_map))
K_sm <- x$K_map
K_sm <- unwrap(x$K_map)

Check warning on line 36 in R/print.sim_data.R

View check run for this annotation

Codecov / codecov/patch

R/print.sim_data.R#L35-L36

Added lines #L35 - L36 were not covered by tests
names <- names(x)
names <- names[(names %in% c(
"resolution", "r", "r_sd", "K_sd", "growth", "A",
Expand Down
4 changes: 2 additions & 2 deletions R/sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ sim <- function(
options(warn = -1)

# Extract data from the sim_data object
K_map <- obj$K_map # carrying capacity
K_map <- unwrap(obj$K_map) # carrying capacity
K_sd <- obj$K_sd # sd of carrying capacity (additional cell specific variation) #nolint
dynamics <- obj$dynamics # population growth function
n1_map <- obj$n1_map # population numbers at the first time step
r <- obj$r # intrinsic population growth rate
r_sd <- obj$r_sd # sd of intrinsic growth rate (time specific variation)
A <- obj$A # Allee effect coefficient
id <- obj$id # square identifiers
id <- unwrap(obj$id) # square identifiers
ncells <- obj$ncells # number of cells in the study area
data_table <- obj$data_table
changing_env <- obj$changing_env
Expand Down
2 changes: 1 addition & 1 deletion R/summary.sim_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ summary.sim_data <- function(object, ...) {

# prepare summaries
n1_sm <- summary(as.numeric(object$n1_map))
K_sm <- summary(as.numeric(as.matrix(object$K_map)))
K_sm <- summary(as.numeric(as.matrix(unwrap(object$K_map))))

names <- c(
"growth", "r", "A", "kernel_fun", "dens_dep", "border",
Expand Down
6 changes: 5 additions & 1 deletion R/update.sim_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ update.sim_data <- function(object, ..., evaluate = TRUE) {
}
}

# unwrap K_map if not updated
if(!"K_map" %in% names(extras)) {
call$K_map <- unwrap(object$K_map)
}

# transform call to call object
call <- as.call(call)



# evaluate or return the call
if (evaluate) {
eval(call, parent.frame())
Expand Down
2 changes: 1 addition & 1 deletion man/disp.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-initialise.R
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,6 @@ test_that("K_add_stochasticity works", {
)


expect_s4_class(test_sim_data_1$K_map, "SpatRaster")
expect_s4_class(test_sim_data_2$K_map, "SpatRaster")
expect_s4_class(test_sim_data_1$K_map, "PackedSpatRaster")
expect_s4_class(test_sim_data_2$K_map, "PackedSpatRaster")
})
Loading