SpaDES
modulesExamine the LCC2005
group of modules:
What versions of each of the modules are you using?
Identify the timestep used for each module? How do they differ?
Identify the input and output data (object) dependencies for these modules. Which are shared among them?
What external data dependencies must be downloaded?
Examine the SpaDES
sample modules:
Identify the types of events found in each module. Which event types are “shared” among these modules?
Compare the scheduling of plot events in each of the modules:
what is the default plot interval for each module?
at what times in the simulation are plot events scheduled and executed for each module? (hint: what is the default timeunit for each)
## caribouMovement
sim <- scheduleEvent(sim, time(sim) + P(sim)$.plotInterval,
"caribouMovement", "plot", .last())
## fireSpread
sim <- scheduleEvent(sim, time(sim) + P(sim)$.plotInterval,
"fireSpread", "plot", .last())
Identify the input and output data (object) dependencies for these modules. Which are shared among them?
What external data dependencies must be downloaded?
Reminder: see the debugging info at the wiki.
Let’s cause an error in an existing module:
Create a copy of the gameOfLife
module, called gameOfLifeError
:
module.path <- file.path(dirname(tempdir()), "modules")
## hint: you'll need to download this module first
downloadModule("gameOfLife", module.path)
## make a copy and open for editing
copyModule("gameOfLife", "gameOfLifeError", module.path)
openModules("gameOfLifeError", module.path)
First, find and replace all instances of “gameOfLife” with “gameOfLifeError”.
Then, edit line 100 to read:
sim$world[r*f <= 2] <- FALSE
and edit line 109 to read:
sim$world[!r*f == 3] <- TRUE
Run the working module normally:
setPaths(modulePath = module.path)
library(igraph)
library(raster)
X <- 10
Y <- 10
TYPE <- "blinker" ## see Rmd for other types
modules <- list("gameOfLife")
parameters <- list(
gameOfLife = list(X = X, Y = Y, initialType = TYPE)
)
times <- list(start = 1, end = 20)
clearPlot()
dev()
mySim_OK <- simInit(times = times, params = parameters, modules = modules)
mySim_OK1 <- spades(Copy(mySim_OK))
Run the broken version and confirm that you get an error:
X <- 10
Y <- 10
TYPE <- "blinker" ## see Rmd for other types
modules <- list("gameOfLifeError")
parameters <- list(
gameOfLifeError = list(X = X, Y = Y, initialType = TYPE)
)
times <- list(start = 1, end = 20)
clearPlot()
dev()
mySim_ERR <- simInit(times = times, params = parameters, modules = modules)
mySim_ERR1 <- spades(Copy(mySim_ERR))
Without knowing where the errors occur, how would you start debugging the error?
Create a simple module that does one of the following:
generates a random map (hint: see ?gaussMap
) and updates the values in the raster cells;
model population dynamics as subpopulations within each raster cell.