Skip to content

Commit

Permalink
Updating F-related key quantities' calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
sbreitbart-NOAA committed Jan 17, 2025
1 parent 5ab2a8f commit 59be9e1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
39 changes: 39 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,45 @@ add_more_key_quants <- function(
dplyr::filter(label == topic,
type == fig_or_table)


# calculate key quantities that rely on end_year for calculation
## terminal fishing mortality
if (topic_cap_alt$label == "fishing.mortality") {

F.end.year <- dat |>
dplyr::filter(
c(label == 'fishing_mortality' &
year == end_year) |
c(label == 'terminal_fishing_mortality' & is.na(year))
) |>
dplyr::pull(estimate) |>
as.numeric() |>
round(digits = 2)

# COMMENTING OUT THESE LINES because the current alt text/captions csv
# doesn't include Ftarg or F.Ftarg. If we alter them to include them,
# then uncomment these lines and add code that would substitute the key
# quantities into the df, like at the bottom of write_captions.
#
# # recalculate Ftarg for F.Ftarg, below
# Ftarg <- dat |>
# dplyr::filter(grepl('f_target', label) |
# grepl('f_msy', label) |
# c(grepl('fishing_mortality_msy', label) &
# is.na(year))) |>
# dplyr::pull(estimate) |>
# as.numeric() |>
# round(digits = 2)
#
# # Terminal year F respective to F target
# F.Ftarg <- F.end.year / Ftarg

if (!is.null(F.end.year)){
end_year <- as.character(F.end.year)
}
}


# replace placeholders (e.g., if "end.year" is found in topic_alt, replace it with end_year)
## end_year-----
if(!is.null(end_year)){
Expand Down
25 changes: 10 additions & 15 deletions R/write_captions.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ write_captions <- function(dat, # converted model output object
dplyr::filter(
label == stringr::str_to_lower("F_targ") |
label == stringr::str_to_lower("F_proxy") |
label == stringr::str_to_lower("F_msy")
label == stringr::str_to_lower("F_msy") |
label == "F_target"
# label == "F40"
# label == "F30"
# label == "F50"
# label == "F_initial"
# label == "Fmsy"
) |>
dplyr::filter(module_name == "DERIVED_QUANTITIES" | module_name == "parms") |>
dplyr::pull(estimate) |>
as.numeric() |>
round(digits = 2)
Expand All @@ -149,16 +156,7 @@ write_captions <- function(dat, # converted model output object
as.numeric()

# terminal fishing mortality
# TODO: Put this in utils function, since F.end.year needs end_year
# F.end.year <- dat |>
# dplyr::filter(
# c(label == 'fishing_mortality' &
# year == end_year) |
# c(label == 'terminal_fishing_mortality' & is.na(year))
# ) |>
# dplyr::pull(estimate) |>
# as.numeric() |>
# round(digits = 2)
# F.end.year : added with add_more_key_quants

# minimum F
F.min <- dat |>
Expand Down Expand Up @@ -216,8 +214,7 @@ write_captions <- function(dat, # converted model output object
round(digits = 2)

# Terminal year F respective to F target
# TODO: Put this in utils function, since F.end.year needs end_year
# F.Ftarg <- F.end.year / Ftarg
# F.Ftarg : added with add_more_key_quants


## landings plot
Expand Down Expand Up @@ -809,11 +806,9 @@ write_captions <- function(dat, # converted model output object
## mortality (F) plot
'F.ref.pt' = as.character(F.ref.pt),
'F.start.year' = as.character(F.start.year),
# 'F.end.year' = as.character(F.end.year),
'F.min' = as.character(F.min),
'F.max' = as.character(F.max),
'Ftarg' = as.character(Ftarg),
# 'F.Ftarg' = as.character(F.Ftarg),

## landings plot
'landings.start.year' = as.character(landings.start.year),
Expand Down

0 comments on commit 59be9e1

Please sign in to comment.