Skip to content

Commit

Permalink
Updates per Schiano-NOAA's comments on PR (minor edits to code, docum…
Browse files Browse the repository at this point in the history
…entation)
  • Loading branch information
sbreitbart-NOAA committed Feb 24, 2025
1 parent 1fe2cc3 commit 1634874
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 61 deletions.
12 changes: 8 additions & 4 deletions R/exp_all_figs_tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#' Export all figures and tables to Rda files within one function.
#'
#' @inheritParams plot_recruitment
#' @param recruitment_scale_amount The exact amount of scale for recruitment (i.e. 1000)
#' @param recruitment_scale_amount A number describing how much to scale down
#' the recruitment quantities shown on the y axis. For example,
#' recruitment_scale_amount = 100 would scale down a value from 500,000 -->
#' 5,000. This scale will be reflected in the y axis label.
#' @param recruitment_unit_label Units for recruitment
#' @param ref_line A string specifying the type of reference you want to
#' compare biomass to. The default is `"target"`, which looks for
Expand All @@ -16,12 +19,13 @@
#' for the reference point as specified in the output file. Please use this
#' option if the ref_line cannot find your desired point. Indicate the
#' reference point in the form c("label" = value).
#' @param biomass_scale_amount The exact amount of scale for biomass (i.e. 1000)
#' @param biomass_scale_amount A number describing how much to scale down the
#' biomass quantities shown on the y axis. See `recruitment_scale_amount`.
#' @param landings_unit_label Units for landings
#' @param biomass_unit_label Units for biomass
#' @param spawning_biomass_label Units for spawning biomass
#' @param spawning_biomass_scale_amount The exact amount of scale for spawning
#' biomass (i.e. 1000)
#' @param spawning_biomass_scale_amount A number describing how much to scale down the
#' spawning biomass quantities shown on the y axis. See `recruitment_scale_amount`.
#' @param ref_line_sb Identical definition as `ref_line`, but this argument is
#' applied to plot_spawning_biomass.
#' @param ref_point_sb Identical definition as `ref_point`, but this argument is
Expand Down
4 changes: 3 additions & 1 deletion R/plot_recruitment.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#'
#' @param dat A data frame returned from `asar::convert_output()`.
#' @param unit_label units for recruitment
#' @param scale_amount indicate the exact amount of scale (i.e. 1000)
#' @param scale_amount A number describing how much to scale down the quantities
#' shown on the y axis. For example, scale_amount = 100 would scale down a value
#' from 500,000 --> 5,000. This scale will be reflected in the y axis label.
#' @param end_year last year of assessment
#' @param n_projected_years Number of years spawning biomass is projected for.
#' By default this number is set to 10
Expand Down
101 changes: 52 additions & 49 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,40 @@ add_more_key_quants <- function(
## 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)
if (is.null(dat)){
message("Some key quantities associated with fishing mortality were not extracted and added to captions_alt_text.csv due to missing data file (i.e., 'dat' argument).")
} else {
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)
}
}
}

Expand All @@ -82,7 +86,9 @@ add_more_key_quants <- function(
# ssbtarg, and R0)
## biomass
if (topic_cap_alt$label == "biomass") {

if (is.null(dat)){
message("Some key quantities associated with biomass were not extracted and added to captions_alt_text.csv due to missing data file (i.e., 'dat' argument).")
} else {
# minimum biomass
B.min <- dat |>
dplyr::filter(label == "biomass",
Expand All @@ -91,6 +97,7 @@ add_more_key_quants <- function(
is.na(age)) |>
dplyr::slice(which.min(estimate)) |>
dplyr::select(estimate) |>
dplyr::mutate(estimate = estimate/scaling) |>
as.numeric() |>
round(digits = 2)

Expand All @@ -102,14 +109,10 @@ add_more_key_quants <- function(
is.na(age)) |>
dplyr::slice(which.max(estimate)) |>
dplyr::select(estimate) |>
dplyr::mutate(estimate = estimate/scaling) |>
as.numeric() |>
round(digits = 2)

if (!is.null(scaling)){
B.min <- B.min / scaling
B.max <- B.max / scaling
}

# replace B.min and B.max placeholders within topic_cap_alt
topic_cap_alt <- topic_cap_alt |>
dplyr::mutate(alt_text = stringr::str_replace_all(alt_text,
Expand All @@ -119,10 +122,13 @@ add_more_key_quants <- function(
"B.max",
as.character(B.max)))
}
}

## spawning biomass
if (topic_cap_alt$label == "spawning.biomass") {

if (is.null(dat)){
message("Some key quantities associated with spawning biomass were not extracted and added to captions_alt_text.csv due to missing data file (i.e., 'dat' argument).")
} else {
# minimum ssb
sr.ssb.min <- dat |>
dplyr::filter(label == "spawning_biomass",
Expand All @@ -136,6 +142,7 @@ add_more_key_quants <- function(
) |> # SS3 and BAM target module names
dplyr::slice(which.min(estimate)) |>
dplyr::select(estimate) |>
dplyr::mutate(estimate = estimate/scaling) |>
as.numeric() |>
round(digits = 2)

Expand All @@ -152,14 +159,10 @@ add_more_key_quants <- function(
) |> # SS3 and BAM target module names
dplyr::slice(which.max(estimate)) |>
dplyr::select(estimate) |>
dplyr::mutate(estimate = estimate/scaling) |>
as.numeric() |>
round(digits = 2)

if (!is.null(scaling)){
sr.ssb.min <- sr.ssb.min / scaling
sr.ssb.max <- sr.ssb.max / scaling
}

# replace sr.ssb.min and sr.ssb.max placeholders within topic_cap_alt
topic_cap_alt <- topic_cap_alt |>
dplyr::mutate(alt_text = stringr::str_replace_all(alt_text,
Expand All @@ -169,10 +172,13 @@ add_more_key_quants <- function(
"sr.ssb.max",
as.character(sr.ssb.max)))
}
}

## recruitment
if (topic_cap_alt$label == "recruitment") {

if (is.null(dat)){
message("Some key quantities associated with recruitment were not extracted and added to captions_alt_text.csv due to missing data file (i.e., 'dat' argument).")
} else {
# minimum recruitment
sr.min <- dat |>
dplyr::filter(label == "recruitment",
Expand All @@ -186,6 +192,7 @@ add_more_key_quants <- function(
) |> # SS3 and BAM target module names
dplyr::slice(which.min(estimate)) |>
dplyr::select(estimate) |>
dplyr::mutate(estimate = estimate/scaling) |>
as.numeric() |>
round(digits = 2)

Expand All @@ -202,14 +209,10 @@ add_more_key_quants <- function(
) |> # SS3 and BAM target module names
dplyr::slice(which.max(estimate)) |>
dplyr::select(estimate) |>
dplyr::mutate(estimate = estimate/scaling) |>
as.numeric() |>
round(digits = 2)

if (!is.null(scaling)){
sr.min <- sr.min / scaling
sr.max <- sr.max / scaling
}

# replace sr.min and sr.max placeholders within topic_cap_alt
topic_cap_alt <- topic_cap_alt |>
dplyr::mutate(alt_text = stringr::str_replace_all(alt_text,
Expand All @@ -220,7 +223,7 @@ add_more_key_quants <- function(
as.character(sr.max)))

}

}

# replace placeholders (e.g., if "end.year" is found in topic_alt, replace it with end_year)
## end_year-----
Expand Down
12 changes: 8 additions & 4 deletions man/exp_all_figs_tables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/plot_biomass.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/plot_recruitment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/plot_spawning_biomass.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1634874

Please sign in to comment.