forked from achubaty/LandR_MPB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09-main-sim.R
66 lines (56 loc) · 2.24 KB
/
09-main-sim.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
## run the simulation
do.call(SpaDES.core::setPaths, paths3)
data.table::setDTthreads(useParallel)
timesPredict <- list(start = 2016, end = 2016) ## 2017-2020
paramsPredict <- paramsFit
paramsPredict[["mpbRedTopSpread"]][["advectionDir"]] <- bestFitVals$advectionDir
paramsPredict[["mpbRedTopSpread"]][["p_advectionMag"]] <- bestFitVals$p_advectionMag
# paramsPredict[["mpbRedTopSpread"]][["bgSettlingProp"]] <- bestFitVals$bgSettlingProp
paramsPredict[["mpbRedTopSpread"]][["p_meanDist"]] <- bestFitVals$p_meanDist
tryCatch({
mySimOut <- Cache(simInitAndSpades, times = timesPredict, #cl = cl,
params = paramsPredict,
modules = modules3,
#outputs = outputs3,
objects = objects3,
paths = paths3,
loadOrder = unlist(modules3),
debug = list(file = list(file = file.path(Paths$outputPath, "sim.log"),
append = TRUE), debug = 1),
useCloud = FALSE,
cloudFolderID = cloudCacheFolderID,
omitArgs = c("debug", "paths", ".plotInitialTime"),
.plotInitialTime = .plotInitialTime)
}, error = function(e) {
if (requireNamespace("slackr") & file.exists("~/.slackr")) {
slackr::slackr_setup()
slackr::text_slackr(
paste0("ERROR in simulation `", runName, "` on host `", Sys.info()[["nodename"]], "`.\n",
"```\n", e$message, "\n```"),
channel = config::get("slackchannel"), preformatted = FALSE
)
stop(e$message)
}
})
cat(capture.output(warnings()), file = file.path(Paths$outputPath, "warnings.txt"))
fsim <- simFile("mySimOut", Paths$outputPath, SpaDES.core::end(mySimOut), "qs")
message("Saving simulation to: ", fsim)
saveSimList(sim = mySimOut, filename = fsim)
## simulation diagrams
if (FALSE) {
clearPlot()
vcol <- sapply(names(V(depsGraph(MPB))), function(v) {
if (v == "_INPUT_") {
"orange"
} else if (v %in% c("mpbRedTopGrowth", "mpbRedTopSpread", "mpbManagement")) {
"pink"
} else {
"lightblue"
}
})
moduleDiagram(MPB, vertex.color = vcol, vertex.size = 30)
clearPlot()
objectDiagram(MPB)
clearPlot()
eventDiagram(MPB2)
}