@@ -49,6 +49,11 @@ rt_mean <- sort(c(0.01,0.03,0.06))
49
49
# How many random red tide replicates to run
50
50
n_rand_reps <- 500
51
51
52
+ # How many years of known catch are entered in the projections
53
+ # Red tide mortality will not be added in these years for projections or
54
+ # randomization.
55
+ N_fixed_years <- 3
56
+
52
57
# Set seed to allow replication of results
53
58
global.seed <- 1234
54
59
set.seed(global.seed )
@@ -111,7 +116,7 @@ for(i in seq_along(rt_proj_ave)){
111
116
# simulation because ABC is supposed to account for unknown uncertainty not
112
117
# offset an avoidable bias such as this.
113
118
# This uses the average red tide rate in every projection year
114
- forecast_base $ ForeCatch [forecast_base $ ForeCatch $ Fleet == rt_fleet ,4 ] <- rep(rt_proj_ave [i ],forecast_base $ Nforecastyrs )
119
+ forecast_base $ ForeCatch [forecast_base $ ForeCatch $ Fleet == rt_fleet & forecast_base $ ForeCatch $ Year > ( base_output $ endyr + N_fixed_years ) ,4 ] <- rep(rt_proj_ave [i ],( forecast_base $ Nforecastyrs - N_fixed_years ) )
115
120
116
121
r4ss :: SS_writeforecast(mylist = forecast_base ,dir = file.path(proj_dir ," Base" ),overwrite = TRUE )
117
122
@@ -142,20 +147,20 @@ for(i in seq_along(rt_proj_ave)){
142
147
# draw a random number of red tide events from a uniform distribution between min and max number specified
143
148
n_rt_events <- sample(n_rt_events_min : n_rt_events_max ,1 ) #
144
149
# calculate the total red tide mortality expected from the specified mean and number of projection years
145
- rt_total <- rt_mean [j ]* forecast_base $ Nforecastyrs
150
+ rt_total <- rt_mean [j ]* ( forecast_base $ Nforecastyrs - N_fixed_years )
146
151
# calculate random mortality rates from each event from a uniform distribution between min and max number specified
147
152
rt_mags <- runif(n_rt_events ,rt_min ,rt_max )
148
153
# rescale the red tide magnitudes so that they sum to the expected total mortality
149
154
rt_mags <- rt_mags * (rt_total / sum(rt_mags ))
150
155
# create a zero mortality vector for all years
151
- rand_red_tide <- rep(0 ,forecast_base $ Nforecastyrs )
156
+ rand_red_tide <- rep(0 ,( forecast_base $ Nforecastyrs ) )
152
157
# randomly select years for the red tide mortality to occur and replace zero's with random mortality rates
153
- rand_red_tide [sample(1 : forecast_base $ Nforecastyrs ,n_rt_events )] <- rt_mags
158
+ rand_red_tide [sample(( N_fixed_years + 1 ) : forecast_base $ Nforecastyrs ,n_rt_events )] <- rt_mags
154
159
155
160
156
161
# Modify forecast file to include random red tide mortality sequence
157
162
forecast_rt <- r4ss :: SS_readforecast(file = file.path(rt_dir ,k ," forecast.ss" ))
158
- forecast_rt $ ForeCatch [forecast_rt $ ForeCatch $ Fleet == rt_fleet ,4 ] <- rand_red_tide
163
+ forecast_rt $ ForeCatch [forecast_rt $ ForeCatch $ Fleet == rt_fleet & forecast_rt $ ForeCatch $ Year > ( base_output $ endyr + N_fixed_years ) ,4 ] <- rand_red_tide [( N_fixed_years + 1 ) : forecast_base $ Nforecastyrs ]
159
164
# Write out the new forecast file and run model with new random mortality vector
160
165
r4ss :: SS_writeforecast(mylist = forecast_rt ,dir = file.path(rt_dir ,k ),overwrite = TRUE )
161
166
shell(paste(" cd /d " ,file.path(rt_dir ,k )," && ss -nohess" ,sep = " " ))
@@ -234,11 +239,11 @@ for(i in seq_along(results_landings_summary_mean[,1]))
234
239
{
235
240
if (results_summary_setup [i ," rt_mean" ]== 0.06 ){
236
241
if (results_summary_setup [i ," rt_projected" ]< results_summary_setup [i ," rt_mean" ]){
237
- lines(x = years ,y = results_landings_summary_mean [i ,],col = " red" )
242
+ lines(x = years ,y = results_landings_summary_mean [i ,],col = " red" , lwd = 2 )
238
243
}else if (results_summary_setup [i ," rt_projected" ]> results_summary_setup [i ," rt_mean" ]){
239
- lines(x = years ,y = results_landings_summary_mean [i ,],col = " blue" )
244
+ lines(x = years ,y = results_landings_summary_mean [i ,],col = " blue" , lwd = 2 )
240
245
}else {
241
- lines(x = years ,y = results_landings_summary_mean [i ,],col = " green" )
246
+ lines(x = years ,y = results_landings_summary_mean [i ,],col = " green" , lwd = 2 )
242
247
}
243
248
}
244
249
}
@@ -248,11 +253,11 @@ for(i in seq_along(results_SSB_summary_mean[,1]))
248
253
{
249
254
if (results_summary_setup [i ," rt_mean" ]== 0.06 ){
250
255
if (results_summary_setup [i ," rt_projected" ]< results_summary_setup [i ," rt_mean" ]){
251
- lines(x = years ,y = results_SSB_summary_mean [i ,],col = " red" )
256
+ lines(x = years ,y = results_SSB_summary_mean [i ,],col = " red" , lwd = 2 )
252
257
}else if (results_summary_setup [i ," rt_projected" ]> results_summary_setup [i ," rt_mean" ]){
253
- lines(x = years ,y = results_SSB_summary_mean [i ,],col = " blue" )
258
+ lines(x = years ,y = results_SSB_summary_mean [i ,],col = " blue" , lwd = 2 )
254
259
}else {
255
- lines(x = years ,y = results_SSB_summary_mean [i ,],col = " green" )
260
+ lines(x = years ,y = results_SSB_summary_mean [i ,],col = " green" , lwd = 2 )
256
261
}
257
262
}
258
263
}
@@ -262,11 +267,11 @@ for(i in seq_along(results_SPR_summary_mean[,1]))
262
267
{
263
268
if (results_summary_setup [i ," rt_mean" ]== 0.06 ){
264
269
if (results_summary_setup [i ," rt_projected" ]< results_summary_setup [i ," rt_mean" ]){
265
- lines(x = years ,y = results_SPR_summary_mean [i ,],col = " red" )
270
+ lines(x = years ,y = results_SPR_summary_mean [i ,],col = " red" , lwd = 2 )
266
271
}else if (results_summary_setup [i ," rt_projected" ]> results_summary_setup [i ," rt_mean" ]){
267
- lines(x = years ,y = results_SPR_summary_mean [i ,],col = " blue" )
272
+ lines(x = years ,y = results_SPR_summary_mean [i ,],col = " blue" , lwd = 2 )
268
273
}else {
269
- lines(x = years ,y = results_SPR_summary_mean [i ,],col = " green" )
274
+ lines(x = years ,y = results_SPR_summary_mean [i ,],col = " green" , lwd = 2 )
270
275
}
271
276
}
272
277
}
@@ -276,11 +281,11 @@ for(i in seq_along(results_dep_summary_mean[,1]))
276
281
{
277
282
if (results_summary_setup [i ," rt_mean" ]== 0.06 ){
278
283
if (results_summary_setup [i ," rt_projected" ]< results_summary_setup [i ," rt_mean" ]){
279
- lines(x = years ,y = results_dep_summary_mean [i ,],col = " red" )
284
+ lines(x = years ,y = results_dep_summary_mean [i ,],col = " red" , lwd = 2 )
280
285
}else if (results_summary_setup [i ," rt_projected" ]> results_summary_setup [i ," rt_mean" ]){
281
- lines(x = years ,y = results_dep_summary_mean [i ,],col = " blue" )
286
+ lines(x = years ,y = results_dep_summary_mean [i ,],col = " blue" , lwd = 2 )
282
287
}else {
283
- lines(x = years ,y = results_dep_summary_mean [i ,],col = " green" )
288
+ lines(x = years ,y = results_dep_summary_mean [i ,],col = " green" , lwd = 2 )
284
289
}
285
290
}
286
291
}
0 commit comments