Indian Ocean Skipjack
performance.hpp
1 #pragma once
2 
3 #include "model.hpp"
4 
5 namespace IOSKJ {
6 
10 class Performance : public Structure<Performance> {
11 public:
12 
14  replicate(replicate),
15  procedure(procedure)
16  {}
17 
22  int replicate;
23 
28  int procedure;
29 
34  Count times;
35 
40 
44  Mean catches_ps;
45 
49  Mean catches_pl;
50 
54  Mean catches_gn;
55 
59  Variance catches_var;
60 
65 
71 
77 
83  Mean control_downs;
84 
88  GeometricMean status_mean;
89 
93  Mean status_b10;
94 
98  Mean status_b20;
99 
103  GeometricMean f_ratio;
104 
108  GeometricMean b_ratio;
109 
118  Mean kobe_a;
119  Mean kobe_b;
120  Mean kobe_c;
121  Mean kobe_d;
122 
127  Mean kobe_to_a;
128  int kobe_out_a;
129 
134  Array<double,Region,Method> cpue_baseline;
135 
142  Array<GeometricMean,Region,Method> cpue_mean;
143 
147  template<class Mirror>
148  void reflect(Mirror& mirror){
149  mirror
150  .data(replicate,"replicate")
151  .data(procedure,"procedure")
152  .data(times,"times")
153  .data(catches_total,"catches_total")
154  .data(catches_ps,"catches_ps")
155  .data(catches_pl,"catches_pl")
156  .data(catches_gn,"catches_gn")
157  .data(catches_var,"catches_var")
158  .data(catches_mapc,"catches_mapc")
159  .data(catches_shut,"catches_shut")
160  .data(catches_lower,"catches_lower")
161  .data(control_ups,"control_ups")
162  .data(control_downs,"control_downs")
163  .data(status_mean,"status_mean")
164  .data(status_b10,"status_b10")
165  .data(status_b20,"status_b20")
166  .data(f_ratio,"f_ratio")
167  .data(b_ratio,"b_ratio")
168  .data(kobe_a,"kobe_a")
169  .data(kobe_b,"kobe_b")
170  .data(kobe_c,"kobe_c")
171  .data(kobe_d,"kobe_d")
172  .data(kobe_to_a,"kobe_to_a")
173  .data(cpue_mean(WE,PS),"cpue_mean_we_ps")
174  .data(cpue_mean(MA,PL),"cpue_mean_ma_pl")
175  .data(cpue_mean(EA,GN),"cpue_mean_ea_gn")
176  ;
177  }
178 
182  void record(uint time, const Model& model, double control = 1){
183  //uint year = IOSKJ::year(time);
184  uint quarter = IOSKJ::quarter(time);
185 
186  times.append();
187 
188  // Catch magnitude
189  auto catch_total = model.catches_taken(sum);
190  catches_total.append(catch_total);
191  auto catches_by_method = model.catches_taken(sum,by(methods));
192  catches_ps.append(catches_by_method(PS));
193  catches_pl.append(catches_by_method(PL));
194  catches_gn.append(catches_by_method(GN));
195 
196  // Years catch goes below baseline
197  catches_lower.append(catch_total < 425000/4.0);
198 
199  // Catch variability
200  if(quarter == 0 and catch_total>0){
201  catches_var.append(catch_total);
202  catches_mapc.append(catch_total);
203  }
204  // Shutdown defined as quarterly catches <10% of recent average
205  // catches of about 400000t
206  catches_shut.append(catch_total<1000);
207 
208  // Changes in MP control e.g. catch or effort limit
209  if (quarter == 0) {
210  if (std::isfinite(control_last_)) {
211  control_ups.append(control>control_last_);
212  control_downs.append(control<control_last_);
213  }
214  control_last_ = control;
215  }
216 
217  // Stock status relative to unfished
218  auto status = model.biomass_status();
219  status_mean.append(status);
220  status_b10.append(status<0.1);
221  status_b20.append(status<0.2);
222 
223  // Biomass relative to B40
224  auto b = model.biomass_spawners(sum)/model.biomass_spawners_40;
225  b_ratio.append(b);
226  // F relative to F40
227  auto f = model.fishing_mortality_get()/model.f_40;
228  f_ratio.append(f);
229 
230  // Kobe plot
231  // Determine quadrant
232  char quadrant;
233  if(b>=1){
234  if(f<=1) quadrant = 'a';
235  else quadrant = 'b';
236  } else {
237  if(f<=1) quadrant = 'c';
238  else quadrant = 'd';
239  }
240  // Update performance measures for proportion of time spent in each quadrant
241  kobe_a.append(quadrant=='a');
242  kobe_b.append(quadrant=='b');
243  kobe_c.append(quadrant=='c');
244  kobe_d.append(quadrant=='d');
245  // Update performance measure for time taken to get back into quadrant A
246  if(quadrant=='a'){
247  // If previously outside of A then append the time that
248  // have been outside to the mean and reset time counter to zero.
249  if(kobe_out_a>0){
250  kobe_to_a.append(kobe_out_a);
251  kobe_out_a = 0;
252  }
253  } else {
254  // Outside of A so increment time counter.
255  kobe_out_a++;
256  }
257 
258  // Catch rates
259  // Use vulnerable (i.e. selected) biomass for the three main regions/gears
260  // relative to the start year as a measure of catch rates (CPUE)
261  if(times==1){
262  // Record baselines
263  for(auto region : regions){
264  for(auto method : methods){
265  cpue_baseline(region,method) = model.biomass_vulnerable(region,method);
266  }
267  }
268  } else {
269  // Record relative to baseline
270  for(auto region : regions){
271  for(auto method : methods){
272  cpue_mean(region,method).append(
273  model.biomass_vulnerable(region,method)/cpue_baseline(region,method)
274  );
275  }
276  }
277  }
278  }
279 
280  private:
281 
282  // Last value of MP control
283  double control_last_ = NAN;
284 };
285 
286 }
Mean control_ups
Definition: performance.hpp:82
Definition: data.hpp:6
Array< double, Region > biomass_spawners
Definition: model.hpp:29
Mean kobe_to_a
Definition: performance.hpp:127
Mean kobe_a
Definition: performance.hpp:118
Definition: model.hpp:13
Mean catches_gn
Definition: performance.hpp:54
Array< GeometricMean, Region, Method > cpue_mean
Definition: performance.hpp:142
Mean catches_shut
Definition: performance.hpp:76
Count times
Definition: performance.hpp:34
GeometricMean b_ratio
Definition: performance.hpp:108
void reflect(Mirror &mirror)
Definition: performance.hpp:148
Mean status_b20
Definition: performance.hpp:98
GeometricMean status_mean
Definition: performance.hpp:88
Mean catches_lower
Definition: performance.hpp:70
double biomass_status(void) const
Definition: model.hpp:399
GeometricMean f_ratio
Definition: performance.hpp:103
Mean catches_ps
Definition: performance.hpp:44
Array< double, Region, Method > catches_taken
Definition: model.hpp:339
Array< double, Region, Method > cpue_baseline
Definition: performance.hpp:134
Mean catches_pl
Definition: performance.hpp:49
double fishing_mortality_get(void) const
Definition: model.hpp:484
Mean catches_total
Definition: performance.hpp:39
Variance catches_var
Definition: performance.hpp:59
Definition: performance.hpp:10
Mapc catches_mapc
Definition: performance.hpp:64
Array< double, Region, Method > biomass_vulnerable
Definition: model.hpp:301
Mean status_b10
Definition: performance.hpp:93
int replicate
Definition: performance.hpp:22
void record(uint time, const Model &model, double control=1)
Definition: performance.hpp:182
int procedure
Definition: performance.hpp:28