Skip to content

Commit

Permalink
spelling, grammar, and other small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
e-perl-NOAA committed Jun 6, 2024
1 parent 72d4645 commit 73b403d
Show file tree
Hide file tree
Showing 61 changed files with 203 additions and 205 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Type: Package
Package: SSMSE
Title: Management Strategy Evaluation (MSE) using Stock Synthesis (SS)
Title: Management Strategy Evaluation (MSE) using Stock Synthesis (SS3)
Version: 0.2.8
Authors@R: c(
person("Kathryn", "Doering", , "kathryn.doering@noaa.gov", role = c("aut", "cre")),
person("Nathan", "Vaughan", , "nathan.vaughan@noaa.gov", role = "aut")
)
Description: An R package for performing Management Strategy Evaluation
(MSE) using Stock Synthesis (SS). SS is used as the Operating Model
(MSE) using Stock Synthesis (SS3). SS3 is used as the Operating Model
(OM) and, if the user desires, the Estimation model (EM). SSMSE allows
existing SS models to be used as the basis for an OM. These OMs are
existing SS3 models to be used as the basis for an OM. These OMs are
used in the MSE framework provided by SSMSE to evaluate the
implications of management actions on a population given uncertainty.
License: MIT + file LICENSE.md
Expand Down
36 changes: 18 additions & 18 deletions R/MS_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#' @param init_loop Logical. If this is the first initialization loop of the
#' MSE, \code{init_loop} should be TRUE. If it is in further loops, it should
#' be FALSE.
#' @param OM_dat An valid SS data file read in using r4ss. In particular,
#' @param OM_dat An valid SS3 data file read in using r4ss. In particular,
#' this should be sampled data.
#' @template verbose
#' @param nyrs_assess The number of years between assessments. E.g., if an
#' assessment is conducted every 3 years, put 3 here. A single integer value.
#' @param nyrs_assess The number of years between assessments (e.g., if an
#' assessment is conducted every 3 years, put 3 here). A single integer value.
#' @param dat_yrs Which years should be added to the new model? Ignored if
#' init_loop is TRUE.
#' @template OM_out_dir
Expand Down Expand Up @@ -91,7 +91,7 @@ EM <- function(EM_out_dir = NULL, init_loop = TRUE, OM_dat, verbose = FALSE,
verbose = verbose
)
}
# Update SS random seed
# Update SS3 random seed
start <- SS_readstarter(file.path(EM_out_dir, "starter.ss"),
verbose = FALSE
)
Expand All @@ -107,7 +107,7 @@ EM <- function(EM_out_dir = NULL, init_loop = TRUE, OM_dat, verbose = FALSE,
readAll = TRUE,
verbose = FALSE
)
# check that it can be used in the EM. fleets shoul
# check that it can be used in the EM.
check_EM_forecast(fcast,
n_flts_catch = length(which(new_EM_dat[["fleetinfo"]][, "type"] %in%
c(1, 2)))
Expand All @@ -124,7 +124,7 @@ EM <- function(EM_out_dir = NULL, init_loop = TRUE, OM_dat, verbose = FALSE,
)
# given all checks are good, run the EM
# check convergence (figure out way to error if need convergence)
# get the future catch using the management strategy used in the SS model.
# get the future catch using the management strategy used in the SS3 model.
run_EM(EM_dir = EM_out_dir, verbose = verbose, check_converged = TRUE)
# get the forecasted catch.
new_catch_list <- get_EM_catch_df(EM_dir = EM_out_dir, dat = new_EM_dat)
Expand All @@ -136,7 +136,7 @@ EM <- function(EM_out_dir = NULL, init_loop = TRUE, OM_dat, verbose = FALSE,
#' Get the data frame of catch for the next iterations when using a Stock
#' Synthesis Estimation model from the Report.sso file.
#' @param EM_dir Path to the EM files
#' @param dat A SS datfile read into R using \code{r4ss::SS_readdat()}
#' @param dat A SS3 datfile read into R using \code{r4ss::SS_readdat()}
#' @author Kathryn Doering
#' @return A data frame of future catch
get_EM_catch_df <- function(EM_dir, dat) {
Expand Down Expand Up @@ -243,7 +243,7 @@ get_EM_catch_df <- function(EM_dir, dat) {
catch_bio_df <- do.call("rbind", bio_df_list)
catch_F_df <- do.call("rbind", F_df_list)

# sum across area - this is necessary fo a multiarea model
# sum across area - this is necessary fo a multi-area model
catch_df <- catch_df %>%
dplyr::group_by(.data[["year"]], .data[["seas"]], .data[["fleet"]]) %>%
dplyr::summarise(catch = sum(.data[["catch"]])) %>%
Expand All @@ -270,7 +270,7 @@ get_EM_catch_df <- function(EM_dir, dat) {
# get discard, if necessary
if (dat[["N_discard_fleets"]] > 0) {
# discard units: 1, biomass/number according to set in catch
# 2, value are fraction (biomass/numbers ) of total catch discarded
# 2, value are fraction (biomass/numbers) of total catch discarded
# 3, values are in numbers(thousands)
se_dis <- get_input_value(dat[["discard_data"]],
method = "most_common_value",
Expand Down Expand Up @@ -333,7 +333,7 @@ get_EM_catch_df <- function(EM_dir, dat) {

#' No Catch in the future management strategy
#'
#' @param OM_dat An valid SS data file read in using r4ss. In particular,
#' @param OM_dat An valid SS3 data file read in using r4ss. In particular,
#' this should be sampled data.
#' @template OM_out_dir
#' @param dat_yrs Which years should be added to the new model? Ignored if
Expand All @@ -358,7 +358,7 @@ no_catch <- function(OM_out_dir, OM_dat, dat_yrs, ...) {

#' Last year catch used in the future for management strategy
#'
#' @param OM_dat An valid SS data file read in using r4ss. In particular,
#' @param OM_dat An valid SS3 data file read in using r4ss. In particular,
#' this should be sampled data.
#' @template OM_out_dir
#' @param dat_yrs Which years should be added to the new model? Ignored if
Expand Down Expand Up @@ -469,7 +469,7 @@ get_no_EM_catch_df <- function(OM_dir, yrs, MS = "last_yr_catch") {
}
df_catch <- do.call("rbind", tmp_df_list)
if (MS == "last_yr_catch") {
# Now, use this to get catch in biomass and catch by F. Need to rerun SS OM
# Now, use this to get catch in biomass and catch by F. Need to rerun SS3 OM
# with no estimation. modify forecast ----
# put in the forecasting catch and make sure using the correct number of years
fore[["ForeCatch"]] <- df_catch[, c("year", "seas", "fleet", "catch")]
Expand All @@ -486,13 +486,13 @@ get_no_EM_catch_df <- function(OM_dir, yrs, MS = "last_yr_catch") {
Fcast_impl_err_line <- grep("^# Fcast_impl_error:$", par) + 1
par[Fcast_impl_err_line] <- paste0(rep(0, fore[["Nforecastyrs"]]), collapse = " ")
writeLines(par, file.path(OM_dir, "ss.par"))
# Run SS with the new catch set as forecast targets. This will use SS to
# Run SS3 with the new catch set as forecast targets. This will use SS3 to
# calculate the F required in the OM to achieve these catches.
run_ss_model(OM_dir, "-maxfn 0 -phase 50 -nohess",
verbose = FALSE,
debug_par_run = TRUE
)
# Load the SS results
# Load the SS3 results
outlist <- r4ss::SS_output(OM_dir,
verbose = FALSE, printstats = FALSE,
covar = FALSE, warn = FALSE, readwt = FALSE
Expand Down Expand Up @@ -546,12 +546,12 @@ get_no_EM_catch_df <- function(OM_dir, yrs, MS = "last_yr_catch") {
#' @param init_loop Logical. If this is the first initialization loop of the
#' MSE, \code{init_loop} should be TRUE. If it is in further loops, it should
#' be FALSE.
#' @param OM_dat An valid SS data file read in using r4ss. In particular,
#' @param OM_dat An valid SS3 data file read in using r4ss. In particular,
#' this should be sampled data.
#' @template OM_out_dir
#' @template verbose
#' @param nyrs_assess The number of years between assessments. E.g., if an
#' assessment is conducted every 3 years, put 3 here. A single integer value.
#' @param nyrs_assess The number of years between assessments (e.g., if an
#' assessment is conducted every 3 years, put 3 here). A single integer value.
#' @param dat_yrs Which years should be added to the new model? Ignored if
#' init_loop is TRUE.
#' @template future_om_list
Expand Down Expand Up @@ -786,7 +786,7 @@ Interim <- function(EM_out_dir = NULL, EM_init_dir = NULL,
# verbose = FALSE)
# # given all checks are good, run the EM
# # check convergence (figure out way to error if need convergence)
# # get the future catch using the management strategy used in the SS model.
# # get the future catch using the management strategy used in the SS3 model.
# run_EM(EM_dir = EM_out_dir, verbose = verbose, check_converged = TRUE)
#
# SS_writeforecast(mylist = fcast,
Expand Down
6 changes: 3 additions & 3 deletions R/SSMSE.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#' SSMSE: A package for Management Strategy Evaluation (MSE) using Stock
#' Synthesis (SS)
#' Synthesis (SS3)
#'
#' SSMSE is an R package for performing Management Strategy Evaluation
#' (MSE) using Stock Synthesis (SS). SS is used as the Operating Model (OM)
#' (MSE) using Stock Synthesis (SS3). SS3 is used as the Operating Model (OM)
#' and, if the user desires, the Estimation model (EM). SSMSE allows existing
#' SS models to be used as the basis for an OM. These OMs are used in the MSE
#' SS3 models to be used as the basis for an OM. These OMs are used in the MSE
#' framework provided by SSMSE to evaluate the implications of management
#' actions on a population given uncertainty.
#'
Expand Down
10 changes: 5 additions & 5 deletions R/calc_F.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @template timeseries
#' @param fleetnames A vector of fleet names, in the order they appear in the
#' ss model.
#' SS3 model.
#' @param fleetnames_all A vector of ALL fleet names that are in the model in
#' the order that they are specified in the model. This vector helps the
#' function know which order the fleets appear in the model.
Expand All @@ -13,8 +13,8 @@
#' and fleet; F_rate, a data frame with F for the time frame of the model
#' only by Yr, Seas, and Fleet, ordered as the ss.par file expects; init_F,
#' a named vector of initial F values by Season and Fleet, ordered (and named)
#' as SS expects; and F_rate_fcast, a dataframe of forecasted F by Yr, Seas,
#' and fleet, ordered as SS would expect in F_rate.
#' as SS3 expects; and F_rate_fcast, a dataframe of forecasted F by Yr, Seas,
#' and fleet, ordered as SS3 would expect in F_rate.
get_F <- function(timeseries, fleetnames, fleetnames_all) {
assertive.types::assert_is_data.frame(timeseries)
# find the F columns
Expand Down Expand Up @@ -56,7 +56,7 @@ get_F <- function(timeseries, fleetnames, fleetnames_all) {
stop("Column names not in the correct order.")
}
# Make sure that the df is ordered correctly;
# verified F rate order by running a multiseason and multifleet model and
# verified F rate order by running a multi-season and multi-fleet model and
# looking at order of F_rate in the PARAMETERS section of the report file.
F_rate <- F_rate[order(F_rate[, "fleet"], F_rate[, "year"], F_rate[, "seas"]), ]
# add a name col that is the same as naming in the Report.sso
Expand Down Expand Up @@ -108,7 +108,7 @@ get_F <- function(timeseries, fleetnames, fleetnames_all) {
F_rate_fcast <- NULL
} else {
# Make sure that the df is ordered correctly;
# verified F rate order by running a multiseason and multifleet model and
# verified F rate order by running a multi-season and multi-fleet model and
# looking at order of F_rate in the PARAMETERS section of the report file.
F_rate_fcast <- F_rate_fcast[order(
F_rate_fcast[, "fleet"],
Expand Down
20 changes: 10 additions & 10 deletions R/checkinput.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ check_catch_df <- function(df) {

#' Check that the directory for an OM is valid
#'
#' Check that the directory contains starter and forecast SS files.
#' Check that the directory contains starter and forecast SS3 files.
#' @param dir Input to check. Should be a directory name that should contain an
#' SS model that can be used as an OM.
#' SS3 model that can be used as an OM.
#' @author Kathryn Doering
check_dir <- function(dir) {
# chack that the dir contains expected SS model files
# chack that the dir contains expected SS3 model files
all_files <- list.files(dir)
errors <- NULL
if (!"starter.ss" %in% all_files) {
Expand All @@ -47,7 +47,7 @@ check_dir <- function(dir) {
stop(
"The file(s): ", paste(errors, collapse = ", "), " is/are missing ",
"from the directory ", dir, ", which suggests that it is not a valid ",
"SS directory. Please change to a directory containing a valid SS ",
"SS3 directory. Please change to a directory containing a valid SS3 ",
"model."
)
}
Expand Down Expand Up @@ -99,7 +99,7 @@ check_OM_dat <- function(OM_dat, EM_dat) {
EM_dat = EM_dat, OM_dat = OM_dat, list_item = "lencomp",
colnames = c("Yr", "Seas", "FltSvy")
)
# there may be more rigorous checks to do (checking that sex and partion
# there may be more rigorous checks to do (checking that sex and partition
# is the same?
}
# check age comp
Expand All @@ -108,7 +108,7 @@ check_OM_dat <- function(OM_dat, EM_dat) {
stop(
"Column names for age composition were not the same for the OM ",
"and EM. Please make the age comp bins the same or use a ",
"custom management strategy that includes steps to rebin the data."
"custom management strategy that includes steps to re-bin the data."
)
}
check_avail_dat(
Expand Down Expand Up @@ -145,7 +145,7 @@ check_OM_dat <- function(OM_dat, EM_dat) {
stop(
"Column names for MeanSize_at_Age_obs were not the same for the OM ",
"and EM. Please make the age comp bins the same or use a ",
"custom management strategy that includes steps to rebin the data."
"custom management strategy that includes steps to re-bin the data."
)
}
}
Expand All @@ -155,8 +155,8 @@ check_OM_dat <- function(OM_dat, EM_dat) {

#' check all index years/fleets in EM available in OM. (but not vice versa)
#' a general function that can be used
#' @param EM_dat An SS data file read in using r4ss for an EM
#' @param OM_dat An SS data file read in using r4ss for an OM
#' @param EM_dat An SS3 data file read in using r4ss for an EM
#' @param OM_dat An SS3 data file read in using r4ss for an OM
#' @param list_item A component in both EM_dat and OM_dat to check values for.
#' This should be a single string value.
#' @param colnames The column names of data to append together.
Expand Down Expand Up @@ -301,7 +301,7 @@ r4ss_obj_err <- function(obj_name = "object ", type = "list") {
#' @template verbose
check_scen_list <- function(list, verbose = FALSE) {
# some columns are required, but others are optional. Check that the required
# columns are there, and warn if the optional ones arent, if verbose.
# columns are there, and warn if the optional ones aren't, if verbose.
# TODO: write this function. Did not want to write until we decide on input
assertive.types::assert_is_list(list)
invisible(list)
Expand Down
26 changes: 13 additions & 13 deletions R/extendOM.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
#' @author Kathryn Doering & Nathan Vaughan
#' @template OM_dir
#' @param catch A dataframe of catch values and its associated information to
#' add to the OM. The column names are the same as in an SS data file (e.g.,
#' add to the OM. The column names are the same as in an SS3 data file (e.g.,
#' year, season, fleet, catch, catch_se). Must input either a catch and/or a harvest rate
#' data frame. If both are input the catch will override harvest rate as the management unit
#' but harvest rate will be used as a starting guess for search.
#' @param harvest_rate A dataframe of harvest rate (F) values and associated information to
#' add to the OM. The column names are as in an SS datafile. If harvest rate is input without
#' add to the OM. The column names are as in an SS3 datafile. If harvest rate is input without
#' a corresponding catch the OM will assume effort based management an use harvest rate directly
#' with implementation error added.
#' @param catch_basis data frame with columns year, seas, fleet, basis that specifies if catch
#' should reference retained biomass (1) or dead biomass (2). Any year/season/fleet not listed will assume
#' a value of 1 referencing retained biomass. Entering -99 for any of year, season, or fleet will
#' apply the basis across all values of that variable (i.e. a single row with -99, -99, -99, 1 would implement
#' apply the basis across all values of that variable (i.e., a single row with -99, -99, -99, 1 would implement
#' retained biomass for all cases)
#' @param F_limit data frame with columns year, fleet, season, limit that specifies a maximum F
#' allowed in the OM or a negative value to specify a multiple of the historic maximum F. Any year/season/fleet
#' not listed will assume a value of 1.5. Entering -99 for any of year, season, or fleet will
#' apply the limit across all values of that variable (i.e. a single row with -99, -99, -99, -2 would implement
#' apply the limit across all values of that variable (i.e., a single row with -99, -99, -99, -2 would implement
#' a cap of twice the historic maximum F for all cases)
#' @param EM_pars a dataframe of parameter value updates to modify OM
#' @param write_dat Should the datafile be overwritten? Defaults to TRUE.
Expand All @@ -31,7 +31,7 @@
#' @template verbose
#' @template F_search_loops
#' @return A new dat list object (format as created by r4ss::SS_readdat) that
#' has been extended forward as if read in by r4ss function SS_readdat
#' has been extended forward as if read in by r4ss function SS_readdat
#' @importFrom r4ss SS_readdat SS_readstarter SS_writestarter
update_OM <- function(OM_dir,
catch = NULL,
Expand Down Expand Up @@ -370,7 +370,7 @@ update_OM <- function(OM_dir,
verbose = verbose,
debug_par_run = TRUE
)
# Load the SS results
# Load the SS3 results
outlist <- r4ss::SS_output(OM_dir,
verbose = FALSE, printstats = FALSE,
covar = FALSE, warn = FALSE, readwt = FALSE
Expand Down Expand Up @@ -435,9 +435,9 @@ update_OM <- function(OM_dir,
} else if (achieved_landings == 0) {
if (achieved_F > 0) {
catch_intended[i, "basis_2"] <- 2
warning(paste0("It appears that you set a fleet basis to retianed catch for a discard only fleet if that is not the case something is wrong.
We automaticaly changed your basis to total dead catch to compensate and allow convervence.
This occured for fleet ", catch_intended[i, "fleet"], "
warning(paste0("It appears that you set a fleet basis to retained catch for a discard only fleet if that is not the case something is wrong.
We automatically changed your basis to total dead catch to compensate and allow convergence.
This occurred for fleet ", catch_intended[i, "fleet"], "
in year ", catch_intended[i, "year"], "
and season ", catch_intended[i, "seas"], "."))
} else {
Expand Down Expand Up @@ -478,8 +478,8 @@ update_OM <- function(OM_dir,
catch_intended[i, "last_adjust"] <- 1
}
} else {
stop(paste0("Error NA F_refs should have been removed already someing is wrong.
This occured for fleet ", catch_intended[i, "fleet"], "
stop(paste0("Error NA F_refs should have been removed already something is wrong.
This occurred for fleet ", catch_intended[i, "fleet"], "
in year ", catch_intended[i, "year"], "
and season ", catch_intended[i, "seas"], "."))
}
Expand Down Expand Up @@ -517,7 +517,7 @@ update_OM <- function(OM_dir,
#' Note that it could still be possible to take out too much catch from the
#' population, so this may not catch all instances of too much catch
#' @param catch A dataframe of catch values and its associated information to
#' add to the OM. The column names are the same as in an SS data file (e.g.,
#' add to the OM. The column names are the same as in an SS3 data file (e.g.,
#' year, season, fleet, catch, catch_se).
#' length of the number of years (only works when catch is for 1 fleet)
#' @template OM_dir
Expand Down Expand Up @@ -561,7 +561,7 @@ check_future_catch <- function(catch, OM_dir, catch_units = "bio",
"file."
)
}
# TODO: check that can you always get biomass for any model? Probalby not if
# TODO: check that can you always get biomass for any model? Probably not if
# catch units are in numbers. Any other scenarios when this is true?
if (catch_units == "bio") {
tot_bio_lyear <-
Expand Down
Loading

0 comments on commit 73b403d

Please sign in to comment.