Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions R/plot_spr.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ plot_spr <- function(
group = NULL,
facet = NULL,
ref_line = "target",
era = "time",
era = NULL,
module = NULL,
model = NULL,
interactive = TRUE,
Expand All @@ -55,8 +55,7 @@ plot_spr <- function(
dat = dat,
label_name = "spr",
geom = geom,
# TODO: change this to era once stockplotr::example_data updated
era = NULL,
era = era,
group = group,
facet = facet,
module = module,
Expand Down Expand Up @@ -131,9 +130,7 @@ plot_spr <- function(

### Make RDA ----
if (make_rda) {
# TODO: Update caption, alt text, and quantities once plot is finalized
# Obtain relevant key quantities for captions/alt text

spr.start.year <- min(prepared_data$year)
spr.end.year <- max(prepared_data$year)
spr.min <- min(prepared_data$estimate) |> round(digits = 3)
Expand Down
32 changes: 0 additions & 32 deletions R/utils.R
Comment thread
sbreitbart-NOAA marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,6 @@
# General utility functions
############################################################################

# Check end_year isn't past current year for non-projections plots
# make year character if not null
check_year <- function(
end_year = NULL,
topic = NULL,
fig_or_table = NULL
) {
if (!is.null(end_year)) {
# TODO: Update this to work for projections plots when developed
# stop if end year is past current year for non-projections plots
projections_plots <- c("proj.catch", "proj.biomass", "projection.ts", "sensitivity.runs")

if (!is.null(topic)) {
if (topic %in% projections_plots == FALSE) {
if (!is.null(fig_or_table)) {
if (as.numeric(end_year) > format(Sys.Date(), "%Y")) {
cli::cli_abort("end_year is past the current year for a non-projections plot ({topic} {fig_or_table})", wrap = TRUE)
}
} else {
cli::cli_abort("fig_or_table is NULL")
}
}
} else {
cli::cli_abort("topic is NULL")
}
} else {
cli::cli_abort("end_year is NULL")
}
}

#------------------------------------------------------------------------------

# create notin operator
`%notin%` <- Negate(`%in%`)

Expand Down
18 changes: 0 additions & 18 deletions R/utils_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -634,23 +634,6 @@ axis_breaks <- function(data_col) {
scales::breaks_pretty()(x_range)
}

# y_axis_breaks <- function(data){
Comment thread
sbreitbart-NOAA marked this conversation as resolved.
Resolved
# # TODO: generalize this so we can input any column for the y-axis values
# y_n_breaks <- round(length(unique(data[["age"]])))
# if (y_n_breaks > 80) {
# y_n_breaks <- round(length(unique(data[["age"]])) / 6)
# } else if (y_n_breaks > 40) {
# y_n_breaks <- round(length(unique(data[["age"]])) / 3)
# }
# y_n_breaks_minor <- as.vector(unique(data[["age"]]))
# if (length(y_n_breaks_minor) > 40) {
# y_n_breaks_minor <- NULL
# } else if (length(y_n_breaks_minor) > 20) {
# y_n_breaks_minor <- y_n_breaks_minor[c(TRUE, FALSE)]
# }
# list(y_n_breaks_minor, y_n_breaks)
# }

#------------------------------------------------------------------------------

cap_first_letter <- function(s) {
Expand Down Expand Up @@ -719,7 +702,6 @@ filter_data <- function(
selected_model <<- model_select$selected

# TODO: add method to filter by units once added into the converter
# TODO: add option to scale data
# Replace all spaces with underscore if not in proper format
label_name <- gsub(" ", "_", tolower(label_name))

Expand Down
234 changes: 0 additions & 234 deletions R/utils_rda.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,6 @@ calc_kqs <- function(returned_kq,
rm(selected_module)
}

# TODO: update key quantities functions to work with a specified 'dir' instead of default 'getwd()'?
# TODO: update key quantities functions for plots that need to extract values from KQs csv to calculate their own, dependent KQs (none present in current plotting functions)

#' Substitute key quantities' values into template
#'
#' @param df Data frame. Dataframe created by importing "key_quantity_template.csv" or
Expand Down Expand Up @@ -614,237 +611,6 @@ create_rda <- function(
)
}

#------------------------------------------------------------------------------
# NOTE: this code was taken from the former write_captions() function
# Leaving it here to pull from as we develop more figure and table functions
# which will have associated captions/alt text containing key quantities
# with the following object names and calculations

# FIGURES-----

## kobe plot- don't code quantities yet
# kobe.end.year <-
# value of B/B(MSY) at the end year
# B.BMSY.end.yr <- B/BMSY
# --B = time series of biomass, last year
# --BMSY = dplyr::filter(grepl('b_target', label) | grepl('b_msy', label) | c(grepl('fishing_mortality_msy', label) & is.na(year)))
# CHECK: if length > 1, then select b_target

# value of F/F(MSY) at the end year
# F.FMSY.end.yr <-

# object that should be "is" or "is not" and answers the question,
# "the stock overfishing status ... overfished"
# overfished.status.is.isnot <-

# object that should be "is" or "is not" and answers the question,
# "the stock ... experiencing overfishing"
# overfishing.status.is.isnot <-


# TODO: uncomment and recode once we get clarity about how to extract this value properly
# R0
# R0 <- dat |>
# 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)

# Bend <-

# TODO: uncomment and recode once we get clarity about how to extract this value properly
# Target biomass
# Btarg <- dat |>
# dplyr::filter(c(grepl('biomass', label) & grepl('target', label) & estimate >1) | label == 'biomass_msy') |>
# dplyr::pull(estimate) |>
# as.numeric() |>
# round(digits = 2)

# Bmsy <-

## vonB LAA (von Bertalanffy growth function + length at age)- don't code quantities yet
# vonb.age.min <- # minimum vonB age
# vonb.age.max <- # maximum vonB age

# vonB length units (plural)
# vonb.length.units

# vonb.length.min <- # minimum vonB length
# vonb.length.max <- # minimum vonB length


## length-type conversion plot- don't code quantities yet
# total length units (plural)
# total.length.units

# total.length.min <- # minimum total length
# total.length.max <- # maximum total length
# fork length units (plural)
# fork.length.units

# fork.length.min <- # minimum fork length
# fork.length.max <- # maximum fork length


## weight-length conversion plot- don't code quantities yet
# length units (plural)
# wl.length.units

# wl.length.min <- # minimum length
# wl.length.max <- # maximum length

# weight units (plural)
# wl.weight.units

# wl.weight.min <- # minimum weight
# wl.weight.max <- # maximum weight


## maturity schedule (proportion mature)- don't code quantities yet
# length units (plural)
# prop.mat.length.units

# prop.mat.length.min <- # minimum length
# prop.mat.length.max <- # maximum length


## fecundity at length- don't code quantities yet
# length units (plural)
# fecundity.length.units

# fecundity.length.min <- # minimum length
# fecundity.length.max <- # maximum length

# fecundity units (plural)
# fecundity.units

# fecundity.min <- # minimum fecundity
# fecundity.max <- # maximum fecundity

## CAL (catch at length)- don't code quantities yet
# cal.length.min <- # minimum length group
# cal.length.max <- # maximum length group
# fleet.or.survey.name <- # fleet or survey name

## mod_fit_catch (model fit to catch ts)- don't code quantities yet
# mod.fit.catch.start.year <- # start year of model fit to catch ts plot
# mod.fit.catch.end.year <- # end year of model fit to catch ts plot

# catch units (plural)
# mod.fit.catch.units

# mod.fit.catch.min <- # minimum catch
# mod.fit.catch.max <- # maximum catch


## mod_fit_abun (model fit to abundance index plot)- don't code quantities yet
# start year of model fit to abundance index plot
# mod.fit.abun.start.year <-

# end year of model fit to abundance index plot
# mod.fit.abun.end.year <-

## mod_fit_discards- will be by fleet
## for ss3, obs discards not in output file
## -filter labels as discard_observed | discard_predicted | discard
## -then group_by(year, fleet, label), then summarize(estimate_y = sum(estimate))
## ---then, get the following:
## -change alt text so that we add the line's min/max, but analyst has to describe further
# mod.fit.discards.start.year <- # start year of model fit to discards plot
# mod.fit.discards.end.year <- # end year of F
# mod.fit.discards.units <- # discards units (plural)
# mod.fit.discards.min <- # minimum discards
# mod.fit.discards.max <- # maximum discards

## selectivity- don't code quantities yet
# selectivity.start.year <- # start year of selectivity plot
# selectivity.end.year <- # end year of selectivity plot
# selectivity.length.units <- # length units (plural)
# selectivity.length.min <- # minimum length
# selectivity.length.max <- # maximum length

## tot_b (total biomass): same as B plot above

# ssbtarg

## spr (spawning potential ratio)
# minimum spr
# spr.min <- dat |>
# dplyr::filter(c(grepl("spr", label) |
# label == "spr") &
# !is.na(year) &
# !is.na(estimate)) |>
# dplyr::slice(which.min(estimate)) |>
# dplyr::select(estimate) |>
# as.numeric() |>
# round(digits = 2)
#
# # maximum spr
# spr.max <- dat |>
# dplyr::filter(c(grepl("spr", label) |
# label == "spr") & !is.na(year) & !is.na(estimate)) |>
# dplyr::slice(which.max(estimate)) |>
# dplyr::select(estimate) |>
# as.numeric() |>
# round(digits = 2)

# TODO: uncomment and recode once we get clarity about how to extract this value properly
# spr reference point
# spr.ref.pt <- dat |>
# dplyr::filter(label == "spr_msy") |>
# dplyr::select(estimate) |>
# as.numeric()# |>
# round(digits = 2)


## proj_catch (projected catch)
# projected catch units (plural)
# proj.catch.units <- # probably mt, but wait until figure coded

# start year of projected catch plot
# proj.catch.start.year <- landings.end.year + 1

# end year of projected catch plot
# proj.catch.end.year <- dat |>
# dplyr::filter(label == "catch" & module_name == "DERIVED_QUANTITIES") |>
# dplyr::slice(which.max(year)) |>
# dplyr::select(year) |>
# as.numeric()

# 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) |>
# as.numeric()

# maximum projected catch
# proj.catch.max <- dat |>
# dplyr::filter(label == "catch" & module_name == "DERIVED_QUANTITIES") |>
# dplyr::slice(which.max(estimate)) |>
# dplyr::select(estimate) |>
# as.numeric()

# TABLES-----

## catch
# catch.fleet <- # fleet

## discards
# discards.tbl.units <- # discards units

## catchability
# catchability.fleet <- # fleet


#------------------------------------------------------------------------------

#' Extract captions and alternative texts
Expand Down
Binary file modified data/example_data.rda
Binary file not shown.
Binary file modified data/ss3_simple.rda
Binary file not shown.
1 change: 1 addition & 0 deletions inst/resources/ss3_var_names.csv
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ SPAWN_RECRUIT,bias_adjusted,,
SPAWN_RECRUIT,pred_recr,predicted_recruitment,
INDEX_2,dev,,
SPAWN_RECRUIT,dev,recruitment_deviations,
SPAWN_RECRUIT_CURVE,dev,recruitment_deviations,
Comment thread
Schiano-NOAA marked this conversation as resolved.
Resolved
SPAWN_RECRUIT,biasadjuster,,
SPAWN_RECRUIT,mature_bio,mature_biomass,kg
TIME_SERIES,mature_bio,mature_biomass,kg
Expand Down
2 changes: 1 addition & 1 deletion man/plot_spr.Rd

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

Loading