-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_7_simulations.R
232 lines (174 loc) · 6.02 KB
/
_7_simulations.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
library(mizer)
library(tidyverse)
library(gridExtra)
library(ggrepel)
# Load projection function
source("_5_project_scenario_functions.R")
source("_6_plotting_functions.R")
# Load params
params <- readRDS("mizer_output/final_params_exp.RDS")
# Scenario Run Individual Effects -----------------------------------------
# Set base static scenario
sta <- list(type ="static",
dam_mortality =
list(
e1 = 0,
t1 = 5,
e2 = 0,
t2 = 45
),
resource_rate =
list(
r1 = 10,
t1 = 20,
r2 = 10,
t2 = 30
)
,
recruitment_max =
list(
rm1 = 0,
t1 = 10,
rm2 = 0,
t2 = 40
)
)
orsta <- sta #keep original static for new runs
out <- project(params, t_max = 50) # create base community
many_dms <- list() #create container for projections
dms <- seq(0,2,length.out =30) #create range of mortality values
for (i in 1:length(dms)) { #Project different mortality values
sta$dam_mortality$e1 <- dms[i]
many_dms[[i]] <- project_dam_removal(params = params, sta)
}
# Export model projections
write_rds(many_dms, "mizer_output/dms_scenarios.rds")
# many_dms <- readRDS("mizer_output/dms_scenarios.rds")
# Plot scenarios
dmbio <- comm_plot(many_dms, out, dms, sz = 15, ptype = "bio") #plot projections
dmbio
sta <- orsta #refresh static scenario
# do same thing for resource rate
many_rrs <- list()
rrs <- seq(10,0.1,length.out = 30)
for (i in 1:length(dms)) {
sta$resource_rate$r1 <- rrs[i]
many_rrs[[i]] <- project_dam_removal(params = params, sta)
}
# Export model projections
write_rds(many_rrs, "mizer_output/rrs_scenarios.rds")
# many_rrs <- read_rds("mizer_output/rrs_scenarios.rds")
# Plot scenarios
rrbio <- comm_plot(many_rrs, out, rrs, sz = 15, ptype = "bio") + scale_colour_viridis_d(direction = -1)
rrbio
sta <- orsta
# do same thing for recruitment
many_rms <- list()
rms <- seq(2, 0, length.out = 30)
for (i in 1:length(dms)) {
sta$recruitment_max$rm2 <- rms[i]
# print(sta)
many_rms[[i]] <- project_dam_removal(params = params, sta)
}
# Export model projections
write_rds(many_rms, "mizer_output/rms_scenarios.rds")
# many_rms <- read_rds("mizer_output/rms_scenarios.rds")
# Plot scenarios
rmsbio <- comm_plot(many_rms, out, rms, sz = 15, ptype = "bio") + scale_colour_viridis_d(direction = -1)
rmsbio
sta <- orsta
# now combine all 3 and plot
many_syn <- list()
for (i in 1:length(dms)) {
sta$dam_mortality$e1 <- dms[i]
sta$resource_rate$r1 <- rrs[i]
sta$recruitment_max$rm2 <- rms[i]
many_syn[[i]] <- project_dam_removal(params = params, sta)
}
# Export model projections
write_rds(many_syn, "mizer_output/synergistic_scenarios.rds")
# many_syn <- read_rds("mizer_output/synergistic_scenarios.rds")
synbio <- comm_plot(many_syn, out, dms, sz = 15, ptype = "bio")
synbio
# Plot scenarios
# combined <- grid.arrange)
library(cowplot)
combined <- plot_grid(dmbio, rrbio + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.y = element_blank() ),
rmsbio + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.y = element_blank() ),
synbio + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.y = element_blank() ), nrow =1,labels = c("A", "B", "C", "D"))
combined
ggsave2(file = "mizer_figures/individual_effects.jpeg",
combined,
units = "px",
height = 1500,
width = 4000)
# Run simulation for Dynamic Long Term Outcomes ---------------------------
# Set base dynamic run
dyn <- list(type ="dynamic",
dam_mortality =
list(
a = 5,
k = 0.5,
b = 0),
resource_rate =
list(
m = 10,
u = -1.5,
b = -1,
start = 0.01,
finish = 10),
recruitment_max = list(
l = 0,
k = .5,
x0 = 10
))
# dyn <- list(type ="dynamic",
# dam_mortality =
# list(
# a = 1,
# k = 0.5,
# b = -0),
# resource_rate = 0,
# recruitment_max = 0)
#
# plotBiomass(project_dam_removal(params, dyn))
many_dyn <- list() #Create container for dynamic runs
d_dms <- seq(-3,-0.05,length.out =30) #create a range of values for each function and parameter change
d_rrs <- seq(-1, -0.05, length.out = 30)
d_rms <- seq(3,0.01,length.out = 30)
for (i in 1:length(d_dms)) {
dyn$dam_mortality$b <- d_dms[i]
dyn$resource_rate$b <- d_rrs[i]
dyn$recruitment_max$l <- d_rms[i]
many_dyn[[i]] <- project_dam_removal(params = params, dyn, t_max = 200)
}
# Export model projections
write_rds(many_dyn, "mizer_output/dynamic_scenarios.rds")
many_dyn <- read_rds("mizer_output/dynamic_scenarios.rds")
# Plot scenarios
dyn_combo <- comm_plot(many_dyn, values = d_dms, LFI_label = "Proportion of big fish",
sz = 20)
dyn_combo
ggsave(file = "mizer_figures/dynamic_effects.png",
dyn_combo,
units = "px",
height = 4000,
width = 4000)
# Compare output from 1st scenario to last scenario -----------------------
rp1 <- rank_plot(many_dyn[[1]], params = params, sz = 20, ssz = 5)
rp30 <- rank_plot(many_dyn[[30]], params = params, sz = 20, ssz = 5)
all_combo <- grid.arrange(dyn_combo,rp1, rp30,
layout_matrix = rbind(c(1, 1), c(2, 3)))
all_combo
# combine dynamic plots together
ggsave(file = "mizer_figures/dynamic_effects.png",
all_combo,
units = "px",
height = 5000,
width = 5000)