Skip to content

Commit

Permalink
rm globals(sim) from sampleModules
Browse files Browse the repository at this point in the history
Bump
  • Loading branch information
Eliot McIntire committed Jun 8, 2024
1 parent 58a3d19 commit 40ab4b4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ URL:
https://spades-core.predictiveecology.org/,
https://github.com/PredictiveEcology/SpaDES.core
Date: 2024-06-07
Version: 2.1.4
Version: 2.1.5
Authors@R: c(
person("Alex M", "Chubaty", , "achubaty@for-cast.ca", role = c("aut"),
comment = c(ORCID = "0000-0001-7146-8135")),
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SpaDES.core 2.1.3
# SpaDES.core 2.1.5

* fix issue with Windows short paths in tests;
* improved documentation;
* removal of `globals(sim)` in Sample modules

# SpaDES.core 2.1.2

Expand Down
17 changes: 9 additions & 8 deletions inst/sampleModules/fireSpread/fireSpread.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ defineModule(sim, list(
reqdPkgs = list("methods", "RColorBrewer", "SpaDES.tools (>= 2.0.0)", "terra"),
parameters = rbind(
defineParameter("stackName", "character", "landscape", NA, NA, "name of the RasterStack"),
defineParameter("burnStats", "character", "nPixelsBurned", NA, NA, "name of the burn statistics reported"),
defineParameter("nFires", "numeric", 10L, 1L, 100L, "number of fires to initiate"),
defineParameter("its", "numeric", 1e6, 1e6, 1e6, "number of iterations for fire spread"),
defineParameter("persistprob", "numeric", 0.00, 0, 1, "probability of fire persisting in a pixel"),
Expand All @@ -51,13 +52,13 @@ defineModule(sim, list(
inputObjects = bindrows(
expectsInput(objectName = SpaDES.core::P(sim, module = "fireSpread")$stackName,
objectClass = "SpatRaster", desc = NA_character_, sourceURL = NA_character_),
expectsInput(objectName = SpaDES.core::globals(sim)$burnStats, objectClass = "numeric",
expectsInput(objectName = P(sim)$burnStats, objectClass = "numeric",
desc = NA_character_, sourceURL = NA_character_)
),
outputObjects = bindrows(
createsOutput(objectName = SpaDES.core::P(sim, module = "fireSpread")$stackName,
createsOutput(objectName = P(sim, module = "fireSpread")$stackName,
objectClass = "SpatRaster", desc = NA_character_, other = NA_character_),
createsOutput(objectName = SpaDES.core::globals(sim)$burnStats, objectClass = "numeric",
createsOutput(objectName = P(sim)$burnStats, objectClass = "numeric",
desc = NA_character_, other = NA_character_)
)
))
Expand All @@ -72,10 +73,10 @@ doEvent.fireSpread <- function(sim, eventTime, eventType, debug = FALSE) {
### (use `checkObject` or similar)
SpaDES.core::checkObject(sim, Par$stackName, layer = "habitatQuality")

if (is.null(sim[[SpaDES.core::globals(sim)$burnStats]])) {
sim[[SpaDES.core::globals(sim)$burnStats]] <- numeric()
if (is.null(sim[[P(sim)$burnStats]])) {
sim[[P(sim)$burnStats]] <- numeric()
} else {
npix <- sim[[(SpaDES.core::globals(sim)$burnStats)]]
npix <- sim[[(P(sim)$burnStats)]]
stopifnot("numeric" %in% is(npix), "vector" %in% is(npix))
}

Expand Down Expand Up @@ -189,11 +190,11 @@ Burn <- function(sim) {
}

Stats <- function(sim) {
npix <- sim[[SpaDES.core::globals(sim)$burnStats]]
npix <- sim[[P(sim)$burnStats]]

landscapes <- sim[[Par$stackName]]

sim[[SpaDES.core::globals(sim)$burnStats]] <- c(npix, length(which(values(landscapes$Fires) > 0)))
sim[[P(sim)$burnStats]] <- c(npix, length(which(values(landscapes$Fires) > 0)))

return(invisible(sim))
}
2 changes: 1 addition & 1 deletion tests/testthat/test-simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_that("simulation runs with simInit and spades with set.seed; events arg", {

times <- list(start = 0.0, end = 1, timeunit = "year")
params <- list(
.globals = list(burnStats = "npixelsburned", stackName = "landscape"),
# .globals = list(burnStats = "npixelsburned", stackName = "landscape"),
randomLandscapes = list(.plotInitialTime = NA, .plotInterval = NA, .seed = list("init" = 321)),
caribouMovement = list(.plotInitialTime = NA, .plotInterval = NA, torus = TRUE),
fireSpread = list(.plotInitialTime = NA, .plotInterval = NA)
Expand Down

0 comments on commit 40ab4b4

Please sign in to comment.