knitr::opts_chunk$set(cache = TRUE, echo = TRUE, eval = FALSE)
We can share modules in any number of ways
SpaDES-Modules
)These are all simple, "toy" modules so far
When you go to the next steps, try things out... ask some of these questions:
library(SpaDES) tmpdir <- file.path(dirname(tempdir()), "Modules") downloadModule("fireSpreadLcc", path = tmpdir)
library(SpaDES) tmpdir <- file.path(dirname(tempdir()), "Modules") downloadModule("caribouMovementLcc", path = tmpdir)
downloadModule("caribou2Movements", path = tmpdir) downloadModule("wolfAlps", path = tmpdir) # ignore warning about file size # Can open the .Rmd (how to run it) or .R (module code) file.edit(file.path(tmpdir, "caribou2Movements", "caribou2Movements.Rmd")) file.edit(file.path(tmpdir, "wolfAlps", "wolfAlps.Rmd"))
?spades
has new section on debugging that complements the above wikiA model (as defined in the SpaDES
world) consists of multiple interacting components (sub-models), which in the vocabulary of SpaDES
we have been referring to as 'modules'
One could imagine an example model:
And we would give this ensemble of modules a name, like "LCC2005" (or maybe even a better name, but we will go with this)
library(igraph) library(SpaDES) setPaths(cachePath = "~/temp_SpaDESws/cache", inputPath = "~/temp_SpaDESws/inputs", modulePath = "~/temp_SpaDESws/modules", outputPath = "~/temp_SpaDESws/outputs") openModules("LCC2005", getPaths()$modulePath)
What is different about it?
SpaDES
developers) create problems?library(igraph) g <- data.frame(from = c("grandparentModule", "grandparentModule", "parentModuleA", "parentModuleA", "parentModuleB", "parentModuleB"), to = c("parentModuleA", "parentModuleB", "childModuleA1", "childModuleA2", "childModuleB1", "childModuleB2")) %>% graph_from_data_frame() plot(g, mark.groups = list(1:7, c(2,4,5), c(3,6,7))) ### NOT RENDERING IN THE WEBSITE!
moduleRepo/ |_ childModuleA1/ |_ childModuleA2/ |_ childModuleB1/ |_ childModuleB2/ |_ grandparentModule/ |_ parentModuleA/ |_ parentModuleB/
If you restarted your R session, first prepare the global setup again:
library(SpaDES) # Remember, if you changed it in the previous step, keep it the same. Otherwise it won't find your modules! setPaths(cachePath = "~/temp_SpaDESws/cache", inputPath = "~/temp_SpaDESws/inputs", modulePath = "~/temp_SpaDESws/modules", outputPath = "~/temp_SpaDESws/outputs")
Then, prepare the simulation:
# setup simulation times <- list(start = 2005.0, end = 2015.0, timeunit = "year") parameters <- list( .globals = list(burnStats = "fireStats"), fireSpreadLcc = list(drought = 1.2), caribouMovementLcc = list(N = 1e3, startTime = times$start + 1, glmInitialTime = NA_real_) ) modules <- list("LCC2005") paths <- list( cachePath = getPaths()$cachePath, modulePath = getPaths()$modulePath, inputPath = getPaths()$inputPath, outputPath = getPaths()$outputPath ) mySim <- simInit(modules = modules, paths = paths, params = parameters, times = times)
The LCC2005 is a parent module that contains several children (What are they?). Now make a new parent module from several of the LCC2005 modules, but without, say, fire.
allButFire <- unlist(modules(mySim))[-6] newModule("LCC2005NoFire", children = allButFire) openModules("LCC2005NoFire", getPaths()$modulePath)
Go ahead and open the LCC2005NoFire.R and check the child modules in the metadata.
There are a few tools that can help visualize the relationships between modules:
# This next step will download data if they do not yet exist locally lcc <- simInit(times = times, params = parameters, modules = modules, paths = paths) objectDiagram(lcc) moduleDiagram(lcc) eventDiagram(lcc) lcc <- spades(lcc) ## compare the diagrams after running sim
simInit
?The newModule
function creates a module template for you to edit to suit your needs:
newModule('moduleName', file.path('path/to/my/module/directory'), type = 'parent', children = c('child1', 'child2'))
Alternatively, use the RStudio addin which is simply a GUI wrapper for this function (select 'parent' type):
The new CFS-FD model (Forest Dynamics Model)
But the vegetation module is actually a parent module with 3 modules:
fire module is actually 4 modules:
SpaDES
function defineModule
# What are the 15 items?
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.