SpaDESmodule - seed establishment
We can imagine a set of sources (e.g., trees with seeds) and a map of “quality” which will affect whether the things (e.g., seeds) will land and establish.
This code does a few things:
# Load some libraries library(raster) library(SpaDES) set.seed(321) # so we can compare amongst ourselves # Parameters Nsource <- 20 establishThresh <- 0.1 # Initial Map of Quality -- make a dummy one quality <- raster(extent(0, 100, 0, 100), res = c(1, 1)) %>% gaussMap(speedup = 1) # SpaDES function to generate a random map quality <- scale(quality, center = maxValue(quality), # rescales from 0 to 1 scale = minValue(quality) - maxValue(quality)) # Initial Map of sources (e.g., seed trees maybe) sourceLocations = initiateAgents(quality, Nsource) # SpaDES function # Create a distance from source map distFromSource <- distanceFromPoints(quality, sourceLocations) # raster function # Create establishment map, a function of inverse distance and quality, # Actual establishment is determined with a threshold parameter establish <- (1/distFromSource * quality) > establishThresh clearPlot() Plot(distFromSource, title = "Distance from source") Plot(establish, title = "Establishment successful") Plot(sourceLocations, addTo = "establish", title = "Establishment successful")
newModule()to create a blank template.
.Rfile that shows up.
.inputObjectssection to create the needed inputs.
establishin the “init” event.
So far, this only calculates the “establish” map once. What if we had another module that updates “sourceLocation” every year. So, we have to run
establish every year. There are 2 options for this: add it all in this module, or make a new module that would generate the sourceLocations.
Move the 3 lines that make new
sourceLocation, make new
distFromSource, and make
establish into an event called “annualEstablishment”. You can delete it from the “init” event, or keep it there
within the “init” block, scheduling the “annualEstablishment” event in this (“establishment”) module. We can schedule it for “the beginning”, which would be start(sim).
within the “annualEstablishment” block that will schedule the “plot” event, “now”. That way, it will plot immediately after this event.
within the “annualEstablishment” block, scheduling the “annualEstablishment” event in this (“establishment”) module. We can schedule it for “now” + 1, which would be
time(sim) + 1. This creates the time sequence.
This is “better” because it emulates how the normal situation would be, but it takes a few more steps. But, as we get more agile with modules, this step would take 3 minutes. Basically all the steps are the same as above, but in a different module, rather than within this module.
This solution follows Option 1.