-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoo2019.R
199 lines (161 loc) · 7.88 KB
/
Boo2019.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Everything in this file gets sourced during simInit, and all functions and objects
# are put into the simList. To use objects, use sim$xxx, and are thus globally available
# to all modules. Functions can be used without sim$ as they are namespaced, like functions
# in R packages. If exact location is required, functions will be: sim$<moduleName>$FunctionName
defineModule(sim, list(
name = "Boo2019",
description = NA, "Testing the Sorensen boreal caribou model given spatially explicit fire and anthropogenic disturbance histories for five boreal caribou herds in Alberta, Canada",
keywords = NA, # c("boreal", "development", "disturbance", "extinction", "fire", "population", "carrying capacity", "Rangifer tarandus caribou"),
authors = c(person(c("Frances", "E.C."), "Stewart", email = "[email protected]", role = c("aut", "cre")),
person(c("J.", "Joshua"), "Nowak", email = "[email protected]", role = c("aut", "cre")),
person(c("Tatianne"), "Micheletti", email = "[email protected]", role = c("aut", "cre")),
person(c("Eliot", "J.B."), "McIntire", email = "[email protected]", role = c("aut", "cre")),
person(c("Fiona", "K.A."), "Schmiegelow", email = "[email protected]", role = c("aut", "cre")),
person(c("Steve", ""), "Cumming", email = "[email protected]", role = c("aut", "cre"))),
childModules = character(0),
version = list(SpaDES.core = "0.2.5", Boo2019 = "0.0.1"),
spatialExtent = raster::extent(rep(NA_real_, 4)), # not needed
timeframe = as.POSIXlt(c(NA, NA)), # not needed
timeunit = "year",
citation = list("citation.bib"),
documentation = list("README.txt", "Boo2019.Rmd"),
reqdPkgs = list(sp, R.utils, dplyr),
parameters = rbind(
#defineParameter("paramName", "paramClass", value, min, max, "parameter description"),
defineParameter(".plotInitialTime", "numeric", NA, NA, NA, "This describes the simulation time at which the first plot event should occur"),
defineParameter(".plotInterval", "numeric", NA, NA, NA, "This describes the simulation time interval between plot events"),
defineParameter(".saveInitialTime", "numeric", NA, NA, NA, "This describes the simulation time at which the first save event should occur"),
defineParameter(".saveInterval", "numeric", NA, NA, NA, "This describes the simulation time interval between save events"),
defineParameter(".useCache", "logical", FALSE, NA, NA, "Should this entire module be run with caching activated? This is generally intended for data-type modules, where stochasticity and time are not relevant")
),
inputObjects = bind_rows(
#expectsInput("objectName", "objectClass", "input object description", sourceURL, ...),
expectsInput(objectName = NA, objectClass = NA, desc = NA, sourceURL = NA)
),
outputObjects = bind_rows(
#createsOutput("objectName", "objectClass", "output object description", ...),
createsOutput(objectName = NA, objectClass = NA, desc = NA)
)
))
## event types
# - type `init` is required for initialization
doEvent.Boo2019 = function(sim, eventTime, eventType) {
switch(
eventType,
init = {
### check for more detailed object dependencies:
### (use `checkObject` or similar)
# do stuff for this event
sim <- Init(sim)
# schedule future event(s)
sim <- scheduleEvent(sim, P(sim)$.plotInitialTime, "Boo2019", "plot")
sim <- scheduleEvent(sim, P(sim)$.saveInitialTime, "Boo2019", "save")
},
plot = {
# ! ----- EDIT BELOW ----- ! #
# do stuff for this event
#plotFun(sim) # uncomment this, replace with object to plot
# schedule future event(s)
# e.g.,
#sim <- scheduleEvent(sim, time(sim) + P(sim)$.plotInterval, "Boo2019", "plot")
# ! ----- STOP EDITING ----- ! #
},
save = {
# ! ----- EDIT BELOW ----- ! #
# do stuff for this event
# e.g., call your custom functions/methods here
# you can define your own methods below this `doEvent` function
# schedule future event(s)
# e.g.,
# sim <- scheduleEvent(sim, time(sim) + P(sim)$.saveInterval, "Boo2019", "save")
# ! ----- STOP EDITING ----- ! #
},
event1 = {
# ! ----- EDIT BELOW ----- ! #
# do stuff for this event
# e.g., call your custom functions/methods here
# you can define your own methods below this `doEvent` function
# schedule future event(s)
# e.g.,
# sim <- scheduleEvent(sim, time(sim) + increment, "Boo2019", "templateEvent")
# ! ----- STOP EDITING ----- ! #
},
event2 = {
# ! ----- EDIT BELOW ----- ! #
# do stuff for this event
# e.g., call your custom functions/methods here
# you can define your own methods below this `doEvent` function
# schedule future event(s)
# e.g.,
# sim <- scheduleEvent(sim, time(sim) + increment, "Boo2019", "templateEvent")
# ! ----- STOP EDITING ----- ! #
},
warning(paste("Undefined event type: '", current(sim)[1, "eventType", with = FALSE],
"' in module '", current(sim)[1, "moduleName", with = FALSE], "'", sep = ""))
)
return(invisible(sim))
}
## event functions
# - keep event functions short and clean, modularize by calling subroutines from section below.
### template initialization
Init <- function(sim) {
# # ! ----- EDIT BELOW ----- ! #
# ! ----- STOP EDITING ----- ! #
return(invisible(sim))
}
### template for save events
Save <- function(sim) {
# ! ----- EDIT BELOW ----- ! #
# do stuff for this event
sim <- saveFiles(sim)
# ! ----- STOP EDITING ----- ! #
return(invisible(sim))
}
### template for plot events
plotFun <- function(sim) {
# ! ----- EDIT BELOW ----- ! #
# do stuff for this event
#Plot(sim$object)
# ! ----- STOP EDITING ----- ! #
return(invisible(sim))
}
### template for your event1
Event1 <- function(sim) {
# ! ----- EDIT BELOW ----- ! #
# THE NEXT TWO LINES ARE FOR DUMMY UNIT TESTS; CHANGE OR DELETE THEM.
# sim$event1Test1 <- " this is test for event 1. " # for dummy unit test
# sim$event1Test2 <- 999 # for dummy unit test
# ! ----- STOP EDITING ----- ! #
return(invisible(sim))
}
### template for your event2
Event2 <- function(sim) {
# ! ----- EDIT BELOW ----- ! #
# THE NEXT TWO LINES ARE FOR DUMMY UNIT TESTS; CHANGE OR DELETE THEM.
# sim$event2Test1 <- " this is test for event 2. " # for dummy unit test
# sim$event2Test2 <- 777 # for dummy unit test
# ! ----- STOP EDITING ----- ! #
return(invisible(sim))
}
.inputObjects <- function(sim) {
# Any code written here will be run during the simInit for the purpose of creating
# any objects required by this module and identified in the inputObjects element of defineModule.
# This is useful if there is something required before simulation to produce the module
# object dependencies, including such things as downloading default datasets, e.g.,
# downloadData("LCC2005", modulePath(sim)).
# Nothing should be created here that does not create a named object in inputObjects.
# Any other initiation procedures should be put in "init" eventType of the doEvent function.
# Note: the module developer can check if an object is 'suppliedElsewhere' to
# selectively skip unnecessary steps because the user has provided those inputObjects in the
# simInit call, or another module will supply or has supplied it. e.g.,
# if (!suppliedElsewhere('defaultColor', sim)) {
# sim$map <- Cache(prepInputs, extractURL('map')) # download, extract, load file from url in sourceURL
# }
#cacheTags <- c(currentModule(sim), "function:.inputObjects") ## uncomment this if Cache is being used
dPath <- asPath(getOption("reproducible.destinationPath", dataPath(sim)), 1)
message(currentModule(sim), ": using dataPath '", dPath, "'.")
# ! ----- EDIT BELOW ----- ! #
# ! ----- STOP EDITING ----- ! #
return(invisible(sim))
}
### add additional events as needed by copy/pasting from above