library(FLCore)
library(FLXSA)
#> Error in library(FLXSA): there is no package called 'FLXSA'
library(ggplotFL)
library(patchwork)
library(tidyverse)
library(fishvice)
Convert rbx to flr
rbx <- fishvice::mup_rbx("/u2/reikn/Tac/2022/01-cod/ass/mup/smx", scale = 1000)
rbx$rby <- rbx$rby %>% filter(year %in% 1985:2022)
rbx$rbya <- rbx$rbya %>% filter(year %in% 1985:2022)
# set maturity such that SSB is actually B4+
if(TRUE) {
rbx$rbya <-
rbx$rbya %>%
mutate(mat = replace_na(mat, 0),
mat = ifelse(age >= 4, 1, 0),
ssbW = cW,
ssbW = replace_na(ssbW, 0))
}
fls <- rbx %>% rbx_to_flstock(pf = 0, pm = 0, fage = c(5, 10))
fls %>% plot()
Run a default xsa
… i.e. no fine tweeking of the default xsa setup
ind.smb <- rbx_to_flindex(rbx, "U1") %>% trim(year = years)
ind.smh <- rbx_to_flindex(rbx, "U2", time = c(10/12, 10.5/12)) %>% trim(year = 1996:2021)
ind <- FLIndices(ind.smb)
cntr <- FLXSA.control(maxit = 70, rage = 5, qage = 14)
#> Error in FLXSA.control(maxit = 70, rage = 5, qage = 14): could not find function "FLXSA.control"
xsa <- FLXSA(fls, ind, cntr)
#> Error in FLXSA(fls, ind, cntr): could not find function "FLXSA"
#diagnostics(xsa)
fls.new <- fls + xsa
#> Error in eval(expr, envir, enclos): object 'xsa' not found
plot(fls.new) +
geom_vline(xintercept = 2021)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'fls.new' not found
Compare muppet and xsa
… check terminal biomass for xsa, not the same as the plot above
fls.new %>%
fishvice::flstock_to_rbya() %>%
group_by(year) %>%
summarise(fbar = mean(f[age %in% 5:10]),
bio = sum(n[age %in% 4:14] * cW[age %in% 4:14])) %>%
mutate(run = "xsa") %>%
bind_rows(rbx$rby %>%
filter(year %in% 1985:2022) %>%
select(year, fbar, bio) %>%
mutate(run = "mup")) %>%
gather(var, val, -c(year, run)) %>%
ggplot(aes(year, val, colour = run)) +
theme_bw(base_size = 15) +
geom_line(lwd = 1) +
scale_colour_brewer(palette = "Set1") +
facet_wrap(~ var, scales = "free_y")
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'data' in selecting a method for function 'ggplot': object 'fls.new' not found