SpaDES
modulesvignettes/04d-Building_a_module.Rmd
04d-Building_a_module.Rmd
Examine 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
:
First, find and replace all instances of “gameOfLife” with “gameOfLifeError”.
Then, edit line 100 to read:
and edit line 109 to read:
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?