Skip to content

Commit

Permalink
Updating quantities calculations and naming conventions as per meetin…
Browse files Browse the repository at this point in the history
…g with Sam
  • Loading branch information
sbreitbart-NOAA committed Jan 24, 2025
1 parent f1c8ad8 commit c4848f8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 35 deletions.
73 changes: 40 additions & 33 deletions R/write_captions.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ write_captions <- function(dat, # converted model output object

# R0
R0 <- dat |>
dplyr::filter(grepl('R0', label) | grepl('recruitment_virgin', label)) |>
dplyr::filter(
# pull from BAM
grepl('^recruitment$', label) & module_name == "parms" |
grepl('^R0', label) |
# pull from SS3
grepl('recruitment_virgin', label)
) |>
dplyr::pull(estimate) |>
unique() |>
as.numeric() |>
round(digits = 2)

Expand Down Expand Up @@ -383,28 +390,28 @@ write_captions <- function(dat, # converted model output object

## NAA (numbers at age)
# start year of NAA plot
bubble.start.year.min <- dat |>
pop.naa.start.year.min <- dat |>
dplyr::filter(label == "abundance" & !is.na(year)) |>
dplyr::slice(which.min(year)) |>
dplyr::select(year) |>
as.numeric()

# end year of NAA plot
bubble.end.year.max <- dat |>
pop.naa.end.year.max <- dat |>
dplyr::filter(label == "abundance" & !is.na(year)) |>
dplyr::slice(which.max(year)) |>
dplyr::select(year) |>
as.numeric()

# minimum age
bubble.age.min <- dat |>
pop.naa.age.min <- dat |>
dplyr::filter(label == "abundance" & !is.na(year)) |>
dplyr::slice(which.min(age)) |>
dplyr::select(age) |>
as.numeric()

# maximum age
bubble.age.max <- dat |>
pop.naa.age.max <- dat |>
dplyr::filter(label == "abundance" & !is.na(year)) |>
dplyr::slice(which.max(age)) |>
dplyr::select(age) |>
Expand Down Expand Up @@ -677,7 +684,9 @@ write_captions <- function(dat, # converted model output object
# minimum spr
spr.min <- dat |>
dplyr::filter(c(grepl('spr', label) |
label == "spr") & !is.na(year) & !is.na(estimate)) |>
label == "spr") &
!is.na(year) &
!is.na(estimate)) |>
dplyr::slice(which.min(estimate)) |>
dplyr::select(estimate) |>
as.numeric() |>
Expand All @@ -696,38 +705,35 @@ write_captions <- function(dat, # converted model output object
spr.ref.pt <- dat |>
dplyr::filter(label == "spr_msy") |>
dplyr::select(estimate) |>
as.numeric() |>
as.numeric()# |>
round(digits = 2)


## pop_naa_baa (population numbers at age and population biomass at age)
# start year of pop_naa_baa plot
pop.naa.baa.start.year <- dat |>
## pop.baa (population biomass at age)
# start year of pop.baa plot
pop.baa.start.year <- dat |>
dplyr::filter(label == "abundance") |>
dplyr::slice(which.min(year)) |>
dplyr::select(year) |>
as.numeric()

# end year of pop_naa_baa plot
pop.naa.baa.end.year <- landings.end.year
# end year of pop.baa plot
pop.baa.end.year <- landings.end.year

# minimum number of fish
pop.naa.baa.fish.min <- dat |>
dplyr::filter(label == "abundance") |>
dplyr::group_by(year) |>
dplyr::summarize(val = max(estimate)) |>
dplyr::slice(which.min(val)) |>
dplyr::select(val) |>
pop.baa.fish.min <- dat |>
dplyr::filter(label == "abundance" & !is.na(year)) |>
dplyr::slice(which.min(estimate)) |>
dplyr::select(estimate) |>
as.numeric() |>
round(digits = 2)


# maximum number of fish
pop.naa.baa.fish.max <- dat |>
dplyr::filter(label == "abundance") |>
dplyr::group_by(year) |>
dplyr::summarize(val = max(estimate)) |>
dplyr::slice(which.max(val)) |>
dplyr::select(val) |>
pop.baa.fish.max <- dat |>
dplyr::filter(label == "abundance" & !is.na(year)) |>
dplyr::slice(which.max(estimate)) |>
dplyr::select(estimate) |>
as.numeric() |>
round(digits = 2)

Expand All @@ -749,6 +755,7 @@ write_captions <- function(dat, # converted model output object

# minimum projected catch
proj.catch.min <- dat |>
# no BAM file has catch; will be NA
dplyr::filter(label == "catch" & module_name == "DERIVED_QUANTITIES") |>
dplyr::slice(which.min(estimate)) |>
dplyr::select(estimate) |>
Expand Down Expand Up @@ -879,10 +886,10 @@ write_captions <- function(dat, # converted model output object
# 'cpue.max' = as.character(cpue.max),

## NAA (numbers at age)
'bubble.start.year.min' = as.character(bubble.start.year.min),
'bubble.end.year.max' = as.character(bubble.end.year.max),
'bubble.age.min' = as.character(bubble.age.min),
'bubble.age.max' = as.character(bubble.age.max),
'pop.naa.start.year.min' = as.character(pop.naa.start.year.min),
'pop.naa.end.year.max' = as.character(pop.naa.end.year.max),
'pop.naa.age.min' = as.character(pop.naa.age.min),
'pop.naa.age.max' = as.character(pop.naa.age.max),

## mod_fit_catch (model fit to catch ts)
# 'mod.fit.catch.start.year' = as.character(mod.fit.catch.start.year),
Expand Down Expand Up @@ -948,11 +955,11 @@ write_captions <- function(dat, # converted model output object
'spr.max' = as.character(spr.max),
'spr.ref.pt' = as.character(spr.ref.pt),

# ## pop_naa_baa (population numbers at age and population biomass at age)
'pop.naa.baa.start.year' = as.character(pop.naa.baa.start.year),
'pop.naa.baa.end.year' = as.character(pop.naa.baa.end.year),
'pop.naa.baa.fish.min' = as.character(pop.naa.baa.fish.min),
'pop.naa.baa.fish.max' = as.character(pop.naa.baa.fish.max),
# ## pop.baa (population biomass at age)
'pop.baa.start.year' = as.character(pop.baa.start.year),
'pop.baa.end.year' = as.character(pop.baa.end.year),
'pop.baa.fish.min' = as.character(pop.baa.fish.min),
'pop.baa.fish.max' = as.character(pop.baa.fish.max),

## proj_catch (projected catch)
# 'proj.catch.units' = as.character(proj.catch.units),
Expand Down
4 changes: 2 additions & 2 deletions inst/resources/captions_alt_text_template.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fecundity.at.length,figure,Fecundity (in number of eggs) as a function of fish l
CAA,figure,"Histograms showing the proportion of the catch in each age group for each year in which there is composition data, for fleet or survey fleet.or.survey.name.","Histograms for each year and fleet for which there is data (one per year grouped by fleet or survey), which show the proportion of the catch in each age group. The x axis of each histogram shows age groups that span from caa.age.min to caa.age.max. The y axis of each histogram shows the proportion of the catch and spans from 0--1."
CAL,figure,"Histograms showing the proportion of the catch in each length group, each year for which there is composition data, for fleet or survey fleet.or.survey.name.","Histograms for each year and fleet for which there is data (one per year grouped by fleet or survey), which show the proportion of the catch in each length group. The x axis of each histogram contains length intervals, which span from cal.length.min to cal.length.max. The y axis of each histogram contains the proportion of the catch and spans from 0--1."
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, stratified by survey/fleet. The x axis shows the year, which spans from cpue.start.year to cpue.end.year . The y axis shows CPUE in cpue.units, which spans from cpue.min to cpue.max."
NAA,figure,Model estimate of population numbers at age over time. The relative size of each bubble for a given year and age indicates the relative abundance in that category compared with others. ,"Bubble plot showing relative age proportions over time. The x axis shows the year, which spans from bubble.start.year to bubble.end.year . The y axis shows age in years, which spans from bubble.age.min to bubble.age.max."
pop.naa,figure,Model estimate of population numbers at age over time. The relative size of each bubble for a given year and age indicates the relative abundance in that category compared with others. ,"Bubble plot showing relative age proportions over time. The x axis shows the year, which spans from pop.naa.start.year to pop.naa.end.year . The y axis shows age in years, which spans from pop.naa.age.min to pop.naa.age.max."
mod.fit.catch,figure,Observed catch from the data input file (points) and model estimated catch (line) over time for fleet.or.survey.name. ,"Point and line graph showing observed catch from the data input file as points and model estimated catch as a line over time for fleet.or.survey.name. The x axis shows years, which spans from mod.fit.catch.start.year to mod.fit.catch.end.year . The y axis shows catch in mod.fit.catch.units, which spans from mod.fit.catch.min to mod.fit.catch.max."
mod.fit.abun,figure,Assessment model fits to input catch per unit of effort index values over time calculated from fleet.or.survey.name.,"Point and line graph showing the assessment model fit, displayed as a line, to input catch per unit effort index values, displayed as points over time, for fleet.or.survey.name. The x axis shows years, which spans from mod.fit.abun.start.year to mod.fit.abun.end.year . The y axis shows catch per unit effort in cpue.units, which spans from cpue.min to cpue.max."
mod.fit.discards,figure,Observed discards (points) and model-estimated discards (line).,"Point and line graph showing the assessment model fit to observed discards. Observed discards are represented as points while the model fitted estimates are represented as a line over time for fleet.or.survey.name. The x axis shows the year, which spans from mod.fit.discards.start.year to mod.fit.discards.end.year . The y axis shows discards in mod.fit.discards.units, which spans from mod.fit.discards.min to mod.fit.discards.max."
Expand All @@ -26,7 +26,7 @@ tot.b,figure,Model-estimated biomass (B) time series. The horizontal dashed line
spawning.biomass,figure,Model-estimated spawning stock biomass (SSB) time series. The horizontal dashed line represents the spawning stock biomass associated with the biomass limit reference point (ssb.ref.pt ssb.units).,"Line graph showing model-estimated spawning stock biomass. The x axis shows the year, which spans from ssb.start.year to ssb.end.year . The y axis shows model-estimated spawning stock biomass in ssb.units, which spans from ssb.min to ssb.max."
relative.spawning.biomass,figure,Model-estimated relative spawning stock biomass time series. The horizontal dashed line represents the limit reference point calculated as SSB/SSB(reference point) (ssb.ref.pt ssb.units).,"Line graph showing model-estimated relative spawning stock biomass. The x axis shows the year, which spans from ssb.start.year to ssb.end.year . The y axis shows model-estimated relative spawning stock biomass (SSB/SSB~target~), which spans from rel.ssb.min to rel.ssb.max."
spr,figure,Model-estimated spawning potential ratio (SPR) (SSB~current~/SSB~target~) time series. The horizontal dashed line represents the spawning potential ratio of the limit reference point at spr.ref.pt.,"Line graph showing model-estimated spawning potential ratio over time. The x axis shows the year, which spans from ssb.start.year to ssb.end.year . The y axis shows model-estimated spawning potential ratio in SSB~current~/SSB~target~, which spans from spr.min to spr.max."
pop.naa.baa,figure,Model-estimated population numbers at age and population biomass at age over time. The relative size of each bubble for a given year and age indicates the relative abundance or biomass in that category compared with others. ,"Bubble plot showing model-estimated population numbers at age and population biomass at age. The x axis shows the year, which spans from pop.naa.baa.start.year to pop.naa.baa.end.year . The y axis shows numbers of fish, which spans from pop.naa.baa.fish.min to pop.naa.baa.fish.max."
pop.baa,figure,Model-estimated population numbers at age and population biomass at age over time. The relative size of each bubble for a given year and age indicates the relative abundance or biomass in that category compared with others. ,"Bubble plot showing model-estimated population numbers at age and population biomass at age. The x axis shows the year, which spans from pop.baa.start.year to pop.baa.end.year . The y axis shows numbers of fish, which spans from pop.baa.fish.min to pop.baa.fish.max."
proj.catch,figure,Forecasted catch in proj.catch.units over future years for different fishing mortality scenarios as indicated in the legend.,"Time series line graph showing forecasted catch over future years for different fishing mortality scenarios. The x axis shows the year, which spans from proj.catch.start.year to proj.catch.end.year . The y axis shows catch in proj.catch.units, which spans from proj.catch.min to proj.catch.max."
proj.biomass,table,Forecasted biomass over future years for different fishing mortality scenarios.,
report.version.model.changes,table,Document version history briefly describing when major changes or updates are made to each version of the report.,
Expand Down

0 comments on commit c4848f8

Please sign in to comment.