Skip to content

Commit

Permalink
Fix wrong values for forecast depletion
Browse files Browse the repository at this point in the history
* Base omdel RDS fixed on server
  • Loading branch information
cgrandin committed Jan 22, 2024
1 parent b4313bc commit 5031a68
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions R/load-forecasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,22 @@ load_forecasts <- function(model_path = NULL,

# Get the values of interest, namely Spawning biomass and SPR for the two
# decision tables in the executive summary
sb <- mcmc_out %>%
depl <- mcmc_out %>%
select(grep("Bratio_", names(.)))
spr <- mcmc_out %>%
select(grep("SPRratio_", names(.)))
sbzero <- mcmc_out %>%
select(grep("SSB_Initial", names(.))) |>
mutate(across(everything(), ~{.x = .x / 1e6}))
depl <- sb |>
as_tibble() |>
bind_cols(sbzero) |>
mutate(across(everything(), ~{.x = .x / SSB_Initial})) |>
select(-SSB_Initial)

# Strip out the Bratio_ and SPRratio_ headers so columns are years only
names(sb) <- gsub("Bratio_", "", names(sb))
#names(sb) <- gsub("Bratio_", "", names(sb))
names(spr) <- gsub("SPRratio_", "", names(spr))
names(depl) <- gsub("Bratio_", "", names(depl))

# Now, filter out the projected years only
sb_proj_cols <- sb |>
select(all_of(as.character(forecast_yrs)))
spr_proj_cols <- spr |>
select(all_of(as.character(forecast_yrs)))
depl_proj_cols <- depl |>
select(all_of(as.character(forecast_yrs)))
sb_proj_cols <- na.omit(sb_proj_cols)

spr_proj_cols <- na.omit(spr_proj_cols)
depl_proj_cols <- na.omit(depl_proj_cols)

Expand All @@ -129,15 +119,7 @@ load_forecasts <- function(model_path = NULL,
as_tibble() |>
transmute(year = Year, catch = `Catch or F`) |>
mutate(catch = ifelse(catch < 1, 0, catch))
list(biomass = apply(sb_proj_cols,
2,
quantile,
probs = probs_forecast,
na.rm = TRUE) |>
t() |>
as_tibble(rownames = "yr") |>
mutate(yr = as.numeric(yr)),
depl = apply(depl_proj_cols,
list(depl = apply(depl_proj_cols,
2,
quantile,
probs = probs_forecast,
Expand Down

0 comments on commit 5031a68

Please sign in to comment.