Skip to content

Commit

Permalink
Merge branch 'main' into allow-geographic-coordinate-systems
Browse files Browse the repository at this point in the history
  • Loading branch information
katarzynam-165 authored May 31, 2024
2 parents 8f2c787 + 0560121 commit f6311d7
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/disp.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#' # disp
#' disp_output <- disp(
#' N_t = sim_data$n1_map,
#' id = sim_data$id,
#' id = unwrap(sim_data$id),
#' id_matrix = as.matrix(sim_data$id, wide = TRUE),
#' data_table = sim_data$data_table,
#' kernel = sim_data$kernel,
Expand Down
4 changes: 2 additions & 2 deletions R/initialise.R
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ initialise <- function(
# output list ---------------------------------------------
out <- list(
n1_map = as.matrix(n1_map, wide = TRUE),
id = id,
id = wrap(id),
dist_bin = dist_bin,
dist_resolution = dist_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,7 +32,7 @@ print.sim_data <- function(x, ...) {

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

names <- names(x)
names <- names[(names %in% c(
Expand Down
4 changes: 2 additions & 2 deletions R/sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ sim <- function(
on.exit(pboptions(pbo))

# 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 # grid cells identifiers as raster
id <- unwrap(obj$id) # grid cells identifiers as raster
id_matrix <- as.matrix(id, wide = TRUE) # grid cells identifiers as matrix
ncells <- obj$ncells # number of cells in the study area
data_table <- obj$data_table
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
5 changes: 5 additions & 0 deletions R/update.sim_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ 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)

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 @@ -558,6 +558,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")
})

0 comments on commit f6311d7

Please sign in to comment.