@@ -72,7 +72,12 @@ for(irun in 1:1000){
7272
7373 # Calculate baseline biomass values
7474 bio <- as.data.table(base $ annual_Biomass )
75- bio.mean.base <- bio [41 : 50 , lapply(.SD , mean ), .SDcols = names(bio )]
75+ bio.mean.base <- bio [91 : 100 , lapply(.SD , mean ), .SDcols = names(bio )]
76+
77+ # Calculate baseline fisheries values
78+ catch <- as.data.table(base $ annual_Catch )
79+ catch.mean.base <- catch [91 : 100 , lapply(.SD , mean ), .SDcols = names(catch )]
80+ catch.base <- sum(catch.mean.base )
7681
7782 # Run perturbations - Living groups
7883 Groups <- c(' Phytoplankton' , ' Small pelagics' , ' Seals' )
@@ -90,13 +95,20 @@ for(irun in 1:1000){
9095 # Diagnostic plots
9196 # plot(plus$annual_Biomass[, 26])
9297 # rsim.plot(plus)
98+ # rsim.plot(plus, "Phytoplankton", indplot = T)
9399
94100 # Calculate perturbed biomass
95101 bio <- as.data.table(plus $ annual_Biomass )
96- bio.mean.plus <- bio [41 : 50 , lapply(.SD , mean ), .SDcols = names(bio )]
102+ bio.mean.plus <- bio [91 : 100 , lapply(.SD , mean ), .SDcols = names(bio )]
103+
104+ # Calculate perturbed catch
105+ catch <- as.data.table(plus $ annual_Catch )
106+ catch.mean.plus <- catch [91 : 100 , lapply(.SD , mean ), .SDcols = names(catch )]
107+ catch.plus <- sum(catch.mean.plus )
97108
98- # Save difference between base and perturbed
99- plus.output <- bio.mean.plus - bio.mean.base
109+ # Save percent difference between base and perturbed
110+ plus.output <- (bio.mean.plus - bio.mean.base ) / bio.mean.base
111+ plus.output [, Fishery : = (catch.plus - catch.base ) / catch.base ]
100112
101113 # Add meta data
102114 plus.output [, Group : = Groups [igrp ]]
@@ -115,10 +127,16 @@ for(irun in 1:1000){
115127
116128 # Calculate perturbed biomass
117129 bio <- as.data.table(neg $ annual_Biomass )
118- bio.mean.neg <- bio [41 : 50 , lapply(.SD , mean ), .SDcols = names(bio )]
130+ bio.mean.neg <- bio [91 : 100 , lapply(.SD , mean ), .SDcols = names(bio )]
131+
132+ # Calculate perturbed catch
133+ catch <- as.data.table(neg $ annual_Catch )
134+ catch.mean.neg <- catch [91 : 100 , lapply(.SD , mean ), .SDcols = names(catch )]
135+ catch.neg <- sum(catch.mean.neg )
119136
120- # Save difference between base and perturbed
121- neg.output <- bio.mean.neg - bio.mean.base
137+ # Save percent difference between base and perturbed
138+ neg.output <- (bio.mean.neg - bio.mean.base ) / bio.mean.base
139+ neg.output [, Fishery : = (catch.neg - catch.base ) / catch.base ]
122140
123141 # Add meta data
124142 neg.output [, Group : = Groups [igrp ]]
@@ -142,10 +160,16 @@ for(irun in 1:1000){
142160
143161 # Calculate perturbed biomass
144162 bio <- as.data.table(plus $ annual_Biomass )
145- bio.mean.plus <- bio [41 : 50 , lapply(.SD , mean ), .SDcols = names(bio )]
163+ bio.mean.plus <- bio [91 : 100 , lapply(.SD , mean ), .SDcols = names(bio )]
146164
147- # Save difference between base and perturbed
148- plus.output <- bio.mean.plus - bio.mean.base
165+ # Calculate perturbed catch
166+ catch <- as.data.table(plus $ annual_Catch )
167+ catch.mean.plus <- catch [91 : 100 , lapply(.SD , mean ), .SDcols = names(catch )]
168+ catch.plus <- sum(catch.mean.plus )
169+
170+ # Save percent difference between base and perturbed
171+ plus.output <- (bio.mean.plus - bio.mean.base ) / bio.mean.base
172+ plus.output [, Fishery : = (catch.plus - catch.base ) / catch.base ]
149173
150174 # Add meta data
151175 plus.output [, Group : = ' Fishery' ]
@@ -166,8 +190,14 @@ for(irun in 1:1000){
166190 bio <- as.data.table(neg $ annual_Biomass )
167191 bio.mean.neg <- bio [41 : 50 , lapply(.SD , mean ), .SDcols = names(bio )]
168192
169- # Save difference between base and perturbed
170- neg.output <- bio.mean.neg - bio.mean.base
193+ # Calculate perturbed catch
194+ catch <- as.data.table(neg $ annual_Catch )
195+ catch.mean.neg <- catch [91 : 100 , lapply(.SD , mean ), .SDcols = names(catch )]
196+ catch.neg <- sum(catch.mean.neg )
197+
198+ # Save percent difference between base and perturbed
199+ neg.output <- (bio.mean.neg - bio.mean.base ) / bio.mean.base
200+ neg.output [, Fishery : = (catch.neg - catch.base ) / catch.base ]
171201
172202 # Add meta data
173203 neg.output [, Group : = ' Fishery' ]
@@ -182,8 +212,34 @@ for(irun in 1:1000){
182212}
183213
184214# Summarize output
185- WSS28.results <- output [, lapply(.SD , function (x ) sum(x > 0 )),
186- by = c(' Group' , ' Direction' )]
215+ Groups <- c(Groups , ' Fishery' )
216+ Direction <- c(' Plus' , ' Minus' )
217+ WSS28.results <- c()
218+ for (igrp in Groups ){
219+ for (idir in Direction ){
220+ out.scene <- output [Group == igrp & Direction == idir , ]
221+ # Sum by number of outcomes in a specific direction
222+ # Set a cut-off for essentially no change
223+ cutoff <- 0.02
224+
225+ pos <- out.scene [, lapply(.SD , function (x ) sum(x > cutoff )),
226+ by = c(' Group' , ' Direction' )]
227+ neu <- out.scene [, lapply(.SD , function (x ) sum(x < cutoff & x > - 1 * cutoff )),
228+ by = c(' Group' , ' Direction' )]
229+ neg <- out.scene [, lapply(.SD , function (x ) sum(x < - 1 * cutoff )),
230+ by = c(' Group' , ' Direction' )]
231+
232+ # Add outcome to the results
233+ pos [, Outcome : = ' Positive' ]
234+ neu [, Outcome : = ' Neutral' ]
235+ neg [, Outcome : = ' Negative' ]
236+
237+ scene.combo <- rbindlist(list (pos , neu , neg ))
238+ WSS28.results <- rbindlist(list (WSS28.results , scene.combo ))
239+ }
240+ }
241+ setcolorder(WSS28.results , c(' Group' , ' Direction' , ' Outcome' ))
242+
187243usethis :: use_data(WSS28.results , overwrite = TRUE )
188244
189245
0 commit comments