-
Notifications
You must be signed in to change notification settings - Fork 0
/
1. Example Analysis - Base Case OM.R
241 lines (155 loc) · 6.3 KB
/
1. Example Analysis - Base Case OM.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
# ---- Install SAMSE R Package ----
# Install the latest version of the SAMSE R package and its dependencies
# Install `remotes` package (if required)
if(!require('remotes')) install.packages('remotes')
# Install latest version of MSEtool Package
remotes::install_github('blue-matter/MSEtool')
# Install latest version of openMSE Package
remotes::install_github('blue-matter/openMSE')
# Install SAMSE R Package (and dependencies)
remotes::install_github('blue-matter/SAFMC-MSE')
# ---- Simulate Historical Fishery Dynamics ----
# needs to be done anytime the Operating Models have changed/been updated
library(SAMSE)
run_hist <- FALSE
if (run_hist) {
# Simulate Base Case OM (OM_01)
multiHist <- SimulateMOM(OM_01)
# Save to disk
if (!dir.exists('Hist_Objects'))
dir.create('Hist_Objects')
saveRDS(multiHist, 'Hist_Objects/01.hist')
} else {
# Load from disk
multiHist <- readRDS('Hist_Objects/01.hist')
}
# ---- Make DataList ----
# This creates the DataList object from the end of the historical period
# DataList is updated in the Projection period with simulated data.
# The DataList object can be used for stepping through the MP code
# to see how the management recommendations are set for the
# first projection year
DataList <- list()
for (p in 1:2) {
DataList[[p]] <- list()
for (f in 1:7) {
DataList[[p]][[f]] <-multiHist[[p]][[f]]@Data
}
}
x <- 1 # for stepping through MP code
# ----- Specify Management Procedures -----
# F for all fleets is fixed to the mean F from 2017 -- 2019
StatusQuo <- function(x, DataList, ...) {
stocks <- unique(Fleet_Management$Stock)
fleets <- unique(Fleet_Management$Fleet)
nstocks <- length(stocks)
nfleets <- length(fleets)
# copy the internal `Fleet_Management` object
this_Fleet_Management <- Fleet_Management
# loop over stocks and fleets
for (s in 1:nstocks) {
for (f in 1:nfleets) {
# calculate mean F from 3 last historical years
meanF <- mean(DataList[[s]][[f]]@Misc$FleetPars$Fishing_Mortality[x,68:70])
# populate the `F` value in `this_Fleet_Management` object
this_Fleet_Management <- this_Fleet_Management %>%
dplyr::mutate(F=replace(F, Stock==stocks[s] &Fleet==fleets[f], meanF))
}
}
# call internal `Fleet_MMP` function with `this_Fleet_Management` object
Fleet_MMP(x, DataList, Fleet_Management=this_Fleet_Management)
}
# define as class `MMP`
class(StatusQuo) <- 'MMP'
# Overall fishing mortality is set to the respective MFMT for each stock
# Relative F of each fleet (and season) remains unchanged
Ftarget <- function(x, DataList, ...) {
MFMT <- data.frame(Stock=c('Red Snapper', 'Gag Grouper'),
MFMT=c(0.21, 0.42))
stocks <- unique(Fleet_Management$Stock)
fleets <- unique(Fleet_Management$Fleet)
nstocks <- length(stocks)
nfleets <- length(fleets)
# copy the internal `Fleet_Management` object
this_Fleet_Management <- Fleet_Management
# loop over stocks and fleets
for (s in 1:nstocks) {
for (f in 1:nfleets) {
# calculate mean F from 3 last historical years
meanF <- mean(DataList[[s]][[f]]@Misc$FleetPars$Fishing_Mortality[x,68:70])
# populate the `F` value in `this_Fleet_Management` object
this_Fleet_Management <- this_Fleet_Management %>%
dplyr::mutate(F=replace(F, Stock==stocks[s] &Fleet==fleets[f], meanF))
}
}
# Calculate relative F for each fleet (by Stock)
this_Fleet_Management <- this_Fleet_Management %>% group_by(Stock) %>% mutate(Frat=F/sum(F))
# Set overall F to MFMT for each stock
this_Fleet_Management <- left_join(this_Fleet_Management, MFMT, by='Stock')
this_Fleet_Management <- this_Fleet_Management %>% mutate(F=MFMT*Frat)
# call internal `Fleet_MMP` function with `this_Fleet_Management` object
Fleet_MMP(x, DataList, this_Fleet_Management)
}
# define as class `MMP`
class(Ftarget) <- 'MMP'
# Status Quo but Reduce Rec Effort 20%
SQRecEffort20 <- function(x, DataList, ...) {
stocks <- unique(Fleet_Management$Stock)
fleets <- unique(Fleet_Management$Fleet)
nstocks <- length(stocks)
nfleets <- length(fleets)
# copy the internal `Fleet_Management` object
this_Fleet_Management <- Fleet_Management
# loop over stocks and fleets
for (s in 1:nstocks) {
for (f in 1:nfleets) {
# calculate mean F from 3 last historical years
meanF <- mean(DataList[[s]][[f]]@Misc$FleetPars$Fishing_Mortality[x,68:70])
# populate the `F` value in `this_Fleet_Management` object
this_Fleet_Management <- this_Fleet_Management %>%
dplyr::mutate(F=replace(F, Stock==stocks[s] &Fleet==fleets[f], meanF))
}
}
# reduce rec effort by 20%
rec_fleets <- fleets[grepl('General Recreational', fleets)]
this_Fleet_Management <- this_Fleet_Management %>% mutate(F = ifelse(Fleet%in% rec_fleets, 0.8*F, F))
# call internal `Fleet_MMP` function with `this_Fleet_Management` object
Fleet_MMP(x, DataList, Fleet_Management=this_Fleet_Management)
}
# define as class `MMP`
class(SQRecEffort20) <- 'MMP'
# ----- Run Projections -----
run_projections <- TRUE
if (run_projections) {
# Run Projections with MPs
MMSE <- ProjectMOM(multiHist, MPs=c('StatusQuo',
'StatusQuo_MLL',
'SQRecEffort20',
'Ftarget'),
dropHist = FALSE)
# Save to disk
if (!dir.exists('MSE_Objects'))
dir.create('MSE_Objects')
saveRDS(MMSE, 'MSE_Objects/01.mmse')
} else {
MMSE <- readRDS('MSE_Objects/01.mmse')
}
# ---- Time-Series Plots -----
plot_Fmort(MMSE)
ggsave('img/MSE/F.png', width=12, height=6)
plot_Catch(MMSE)
ggsave('img/MSE/Catch.png', width=12, height=6)
plot_SB(MMSE)
ggsave('img/MSE/SB.png', width=12, height=6)
# ----- Calculate Performance Metrics -----
P_MFMT(MMSE) # Probability F < MFMT
P_MSST(MMSE) # Probability SB>MSST
Landings_10(MMSE) # mean landings in first 10 years
Landings_20(MMSE) # mean landings in last 10 years
P_rebuild(MMSE) # probability of rebuilding by end of projection period
Landings_Removals(MMSE) # mean ratio of landings to overall removals (landings + discards)
# ----- Trade-Off Plots of Performance Metrics ----
TradeOff(MMSE, c('P_MSST', 'P_MFMT'))
ggsave('img/MSE/TO_1.png', width=8, height=6)
TradeOff(MMSE, c('Landings_10', 'Landings_20'))
ggsave('img/MSE/TO_2.png', width=8, height=6)