Skip to content

Commit

Permalink
Merge branch 'master' into add-rda
Browse files Browse the repository at this point in the history
  • Loading branch information
sbreitbart-NOAA authored Nov 15, 2024
2 parents 06fe5fd + 3a42943 commit d25e83f
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 7 deletions.
107 changes: 101 additions & 6 deletions R/write_captions.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
#' Function to create captions and alternative text that contain
#' key quantities from the model results file.
#'
#' @inheritParams plot_recruitment
#' @inheritParams plot_spawning_biomass
#' @param dir Directory where the output captions and alt text file should be saved
#' @param year the last year of the data or the current year this function is being performed
#'
#' @return Exports .csv with captions and alt text for figures and tables
#' that contain key quantities (e.g., an assessment's start year) that
#' are automatically extracted from the converted model results file.
#'
#' @export

write_captions <- function(dat # converted model output object
){
write_captions <- function(dat, # converted model output object
dir = NULL,
year = NULL){

# import pre-written captions and alt text that include placeholders
# for key quantities (e.g., 'start_year' is the placeholder for the
Expand All @@ -22,8 +25,100 @@ write_captions <- function(dat # converted model output object
)

# extract key quantities (these are examples and are not accurate)
start_year <- as.numeric(dat[3,3])
Fend <- as.numeric(dat$estimate[2])
# REMINDER: the variable names must exactly match those in the captions/alt text csv.
#
# This start_year was written previously. Is it usable for any plots, below?
# start_year <- min(as.numeric(dat$year[dat$year!="S/Rcurve" | dat$year!="Virg" | dat$year!="Init"]), na.rm = TRUE)

## kobe plot
# B_div_BMSY_min <- # (= minimum value of B/B(MSY))
# B_div_BMSY_max <- # (= maximum value of B/B(MSY))
# F_div_FMSY_min <- # (= minimum value of F/F(MSY))
# F_div_FMSY_max <- # (= maximum value of F/F(MSY))
# B_div_BMSY_end_yr <- # (= value of B/B(MSY) at the end year)
# F_div_FMSY_end_yr <- # (= value of F/F(MSY) at the end year)
# overfished_status_is_isnot <- # object that should be "is" or "is not" and answers the question, "the stock overfishing status ___ overfished"
# overfishing_status_is_isnot <- # object that should be "is" or "is not" and answers the question, "the stock ___ experiencing overfishing"
# start_year_kobe <- # start year of kobe plot
# end_year_kobe <- # end year of kobe plot

## Biomass plot
# B_ref_pt <- # biomass reference point
# B_ref_pt_unit <- # biomass reference point unit
# B_start_year_ <- # start year of biomass plot
# B_end_year <- # start year of biomass plot
# B_units <- # units of B (plural)
# B_min <- # minimum B
# B_max <- # maximum B
# Bend <-
# Btarg <-
# Bmsy <-

## mortality (F) plot
# F_ref_pt <- # F reference point
# F_ref_pt_unit <- # F reference point unit
# F_start_year_ <- # start year of F plot
# F_end_year <- # start year of F plot
# F_units <- # units of F (plural)
# F_min <- # minimum F
# F_max <- # maximum F
Fend_df <- dat |>
dplyr::filter(label == "fishing_mortality" & year == year | label == "F_terminal")
Fend <- as.numeric(Fend_df$estimate)
# Ftarg <-
# F_Ftarg <-

## landings plot
# landings_start_year <- # start year of landings plot
# landings_end_year <- # end year of landings plot
# landings_units <- # units of landings (plural)
# landings_min <- # minimum landings
# landings_max <- # maximum landings

## natural mortality (M)
# M_age_min <- # minimum age of M
# M_age_max <- # maximum age of M
# M_units <- # units of M (plural)
# M_rate_min <- # minimum M rate
# M_rate_max <- # maximum M rate

## length-type conversion plot
# total_length_units <- # total length units (plural)
# total_length_min <- # minimum total length
# total_length_max <- # maximum total length
# fork_length_units <- # fork length units (plural)
# fork_length_min <- # minimum fork length
# fork_length_max <- # maximum fork length

## weight-length conversion plot
# wl_length_units <- # length units (plural)
# wl_length_min <- # minimum length
# wl_length_max <- # maximum length
# wl_weight_units, <- # weight units (plural)
# wl_weight_min <- # minimum weight
# wl_weight_max <- # maximum weight

## CPUE indices plot
# cpue_start_year <- # start year of CPUE indices plot
# cpue_end_year <- # end year of CPUE indices plot
# cpue_units <- # CPUE units (plural)
# cpue_min <- # minimum CPUE
# cpue_max <- # maximum CPUE

## SB
# SBmsy <-
# fSB <-
# sbtarg <-

## Other
# tot_catch <-
# M <-
# steep <-
# R0 <-




# add in more quantities here, and update the quantities above

# substitute quantity placeholders in the captions/alt text with
Expand All @@ -41,7 +136,7 @@ write_captions <- function(dat # converted model output object

# export df with substituted captions and alt text to csv
write.csv(x = caps_alttext_subbed,
file = file.path(here::here(),
file = file.path(dir,
"captions_alt_text.csv"),
row.names=FALSE)

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ install.packages("remotes")
remotes::install_github("nmfs-ost/satf")
```

Occassionally, the package can not be installed using the `remotes` package. If this is the case for you and the other two installation options don't work please try:

```r
install.packages("pak")
pak::pak("nmfs-ost/satf")
```

## Example

This is a basic example which shows you how to solve a common problem:
Expand Down
8 changes: 8 additions & 0 deletions inst/resources/captions_alttext.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
label,type,caption,alt_text
kobe,figure,"Kobe plot showing stock status. Triangles delineate start and end years. Horizontal and vertical dashed lines delineate reference points for overfishing (i.e., F/FMSY>1) and overfished status (i.e., B/BMSY <1) where MSY represents either actual maximum sustainable yield or a proxy for MSY.","A Kobe plot showing stock status from start_year_kobe to end_year_kobe. The x axis, showing overfished status (i.e., B/BMSY), spans from B_div_BMSY_min to B_div_BMSY_max and the y axis, showing overfishing (i.e., F/FMSY), spans from F_div_FMSY_min to F_div_FMSY_max. The B/BMSY and F/FMSY for end_year_kobe were B_div_BMSY_end_yr and F_div_FMSY_end_yr, respectively, indicating that the stock overfished_status_is_isnot overfished and overfishing_status_is_is_not experiencing overfishing."
biomass,figure,Biomass (B) time series. The horizontal dashed line represents the limit reference point (B_ref_pt B_ref_pt_unit).,"Line graph showing biomass time series from B_start_year to B_end_year. The x axis, showing the year, spans from B_start_year to B_end_year and the y axis, showing biomass in B_units, spans from B_min to B_max. The limit reference point is (B_ref_pt B_ref_pt_unit)."
fishing_mortality,figure,Fishing mortality (F) over time. The horizontal dashed line represents the target reference point (F_ref_pt F_ref_pt_unit).,"Line graph showing fishing mortality over time from F_start_year to F_end_year . The x axis, showing the year, spans from F_start_year to F_end_year and the y axis, showing fishing mortality in F_units (i.e., F), spans from F_min to F_max. The horizontal dashed line represents the target reference point (F_ref_pt F_ref_pt_unit)."
landings,figure,Historical landings by fleet.,"Cumulative area plot showing historical landings from landings_start_year to landings_end_year. The x axis, showing the year, spans from landings_start_year to landings_end_year and the y axis, showing landings in landings_units, spans from landings_min to landings_max."
natural_mortality,figure,Natural mortality (M) for each age. ,"Line graph showing natural mortality from M_age_min to M_age_max. The x axis, showing age in M_units, spans from M_age_min to M_age_max and the y axis, showing the natural mortality rate per year, spans from M_rate_min to M_rate_max."
length_type_conversion,figure,Length-type conversion relationship between total and fork length where points represent individual fish length measurement observations and the line is the fitted relationship. ,"Point and line graph showing observations of measured fork length and measured total length from the same fish for conversion purposes as points, and a linear fit through those points as a line. The x axis, showing total length in total_length_units, spans from total_length_min to total_length_max and the y axis, showing fork length in fork_length_units, spans from fork_length_min to fork_length_max."
weight_length_converstion,figure,Weight-length conversion relationship where the points represent individual fish observations and the line is the fitted relationship. ,"Point and line graph showing observations of measured length and measured weight from the same fish for conversion purposes as points, and an exponential fit through those points as a line. The x axis, showing length in wl_length_units, spans from wl_length_min to wl_length_max and the y axis, showing weight in wl_weight_units, spans from wl_weight_min to wl_weight_max."
CPUE_indices,figure,Catch per unit effort (CPUE) over time for fleet or survey. 95% confidence intervals are shown for each survey/fleet.,"Line graph showing catch per unit effort (CPUE) over time for fleet or survey from cpue_start_year to cpue_end_year, stratified by survey/fleet. The x axis, showing the year, spans from cpue_start_year to cpue_end_year and the y axis, showing CPUE in cpue_units, spans from cpue_min to cpue_max."
recruitment,figure,recruitment figure caption here. Starts in start_year.,recruitment alt text here
spawning_biomass,figure,spawning biomass figure caption here. ,spawning biomass alt text here. The F(end) = Fend
landings,figure,recruitment figure caption here. Starts in start_year.,landings alt text here
Expand Down
6 changes: 5 additions & 1 deletion man/write_captions.Rd

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

0 comments on commit d25e83f

Please sign in to comment.