Skip to content

Commit 6e86680

Browse files
Interim red tide
remove red tide mortality in interim period that could cause crashes when population was very depleted.
1 parent 23e82a0 commit 6e86680

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

red_tide_sim_loop.R

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ rt_mean <- sort(c(0.01,0.03,0.06))
4949
#How many random red tide replicates to run
5050
n_rand_reps <- 500
5151

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+
5257
#Set seed to allow replication of results
5358
global.seed <- 1234
5459
set.seed(global.seed)
@@ -111,7 +116,7 @@ for(i in seq_along(rt_proj_ave)){
111116
#simulation because ABC is supposed to account for unknown uncertainty not
112117
#offset an avoidable bias such as this.
113118
#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))
115120

116121
r4ss::SS_writeforecast(mylist=forecast_base,dir=file.path(proj_dir,"Base"),overwrite=TRUE)
117122

@@ -142,20 +147,20 @@ for(i in seq_along(rt_proj_ave)){
142147
#draw a random number of red tide events from a uniform distribution between min and max number specified
143148
n_rt_events <- sample(n_rt_events_min:n_rt_events_max,1) #
144149
#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)
146151
#calculate random mortality rates from each event from a uniform distribution between min and max number specified
147152
rt_mags <- runif(n_rt_events,rt_min,rt_max)
148153
#rescale the red tide magnitudes so that they sum to the expected total mortality
149154
rt_mags <- rt_mags*(rt_total/sum(rt_mags))
150155
#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))
152157
#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
154159

155160

156161
#Modify forecast file to include random red tide mortality sequence
157162
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]
159164
#Write out the new forecast file and run model with new random mortality vector
160165
r4ss::SS_writeforecast(mylist=forecast_rt,dir=file.path(rt_dir,k),overwrite=TRUE)
161166
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]))
234239
{
235240
if(results_summary_setup[i,"rt_mean"]==0.06){
236241
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)
238243
}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)
240245
}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)
242247
}
243248
}
244249
}
@@ -248,11 +253,11 @@ for(i in seq_along(results_SSB_summary_mean[,1]))
248253
{
249254
if(results_summary_setup[i,"rt_mean"]==0.06){
250255
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)
252257
}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)
254259
}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)
256261
}
257262
}
258263
}
@@ -262,11 +267,11 @@ for(i in seq_along(results_SPR_summary_mean[,1]))
262267
{
263268
if(results_summary_setup[i,"rt_mean"]==0.06){
264269
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)
266271
}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)
268273
}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)
270275
}
271276
}
272277
}
@@ -276,11 +281,11 @@ for(i in seq_along(results_dep_summary_mean[,1]))
276281
{
277282
if(results_summary_setup[i,"rt_mean"]==0.06){
278283
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)
280285
}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)
282287
}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)
284289
}
285290
}
286291
}

0 commit comments

Comments
 (0)