Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
de6a717
feat: plot_age_to_length_conversion
Schiano-NOAA Nov 20, 2026
424fdcc
chore: update SS3 r4ss example_data from converter resource changes (…
github-actions[bot] Nov 20, 2026
f86790d
fix BAM and Rceattle ex dat script issues
Schiano-NOAA Nov 20, 2026
24c53f2
fix rceattle update ex data script and change to cod
Schiano-NOAA Nov 23, 2026
1ed89d7
chore: update BAM vermilion snapper example from converter resource c…
github-actions[bot] Nov 23, 2026
419e67c
replace instances of pollock with cod
Schiano-NOAA Nov 23, 2026
e218d27
fix fixtures and adjust argument name from deprecation warning
Schiano-NOAA Nov 23, 2026
d2db1e9
chore: update rceattle cod example from converter resource changes (t…
github-actions[bot] Nov 23, 2026
f199e43
Fix model conversion and stabilize failing tests
Schiano-NOAA Nov 24, 2026
2dfe2af
[docs] Improve accuracy and consistency of B/SB captions (#527)
sbreitbart-NOAA Nov 23, 2026
2afddc7
make adjustments to tests and utils to solve one failing test
Schiano-NOAA Nov 24, 2026
f7770b4
chore: update rceattle cod example from converter resource changes (t…
github-actions[bot] Nov 24, 2026
3d5a444
Revert "Fix model conversion and stabilize failing tests"
Schiano-NOAA Nov 24, 2026
e18be6f
fix discard plot tests and examples; standardize length_bins type
Schiano-NOAA Nov 25, 2026
01c902c
std length_bins type
Schiano-NOAA Nov 25, 2026
fe7d5f4
chore: update SS3 r4ss example_data from converter resource changes (…
github-actions[bot] Nov 25, 2026
42bd301
chore: update BAM vermilion snapper example from converter resource c…
github-actions[bot] Nov 25, 2026
ccd78c4
chore: update SS3 example_data from converter resource changes (trigg…
github-actions[bot] Nov 25, 2026
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
13 changes: 9 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"features": {
"ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": {},
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
"packages": "make,gcc,g++,cmake,clang-tidy,clang-format"
"packages": "make,gcc,g++,cmake,clang-tidy,clang-format,libuv1-dev"
},
"ghcr.io/rocker-org/devcontainer-features/r-packages:1": {
"packages": "cli,rlang,usethis,devtools,ggplot2,remotes,pak",
"ghcr.io/rocker-org/devcontainer-features/r-packages:1": {
"packages": "cli,rlang,usethis,devtools,ggplot2,gt,remotes,pak",
"cranMirror": "https://cloud.r-project.org",
"installSystemRequirements": true
}
},
Expand Down Expand Up @@ -42,7 +43,11 @@
"requireLocalPort": true,
"onAutoForward": "ignore"
}
},
},
"postCreateCommand": [
"sudo", "-n", "Rscript", "-e",
"write('options(repos = c(CRAN = \"https://cloud.r-project.org\"))', file = file.path(R.home('etc'), 'Rprofile.site'), append = TRUE)"
],
"postAttachCommand": "sudo rstudio-server start",
"remoteUser": "rstudio"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/contrib-checklist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- [ ] I have kept this PR focused on one plot where applicable. For multiple features, I have used separate PRs (stacked PRs are welcome if needed).
- [ ] I have aimed to keep this PR to no more than 750 lines, excluding tests and example data (for example, up to 750 lines for a new function).
- [ ] If I have provided an example dataset, I have explained why the existing sample datasets are not sufficient.
- [ ] I have tested that my changes are compatible with all example outputs in the "data" folder (example_data.rda; pollock.rda; ss3_simple.rda; vermilion_snapper.rda).
- [ ] I have tested that my changes are compatible with all example outputs in the "data" folder (example_data.rda; cod.rda; ss3_simple.rda; vermilion_snapper.rda).
- [ ] If I didn't follow the [development workflow](https://github.com/nmfs-ost/stockplotr/blob/main/CONTRIBUTING.md#overview), I have explained why in this PR.
- [ ] If applicable, I've added the plot to save_all_plots() and updated the associated tests in test-save_all_plots.R.
- [ ] After opening this PR, I have checked that my own tests and spellcheck pass (spelling::spell_check_package()). If other checks fail, I have flagged them for the package maintainers to help diagnose and remedy.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-rceattle-example-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ jobs:
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add data/pollock.rda
git diff --cached --quiet || git commit -m "chore: update rceattle pollock example from converter resource changes (triggered by $(git log -1 --pretty=format:'%h %s' HEAD)) [skip ci]"
git add data/cod.rda
git diff --cached --quiet || git commit -m "chore: update rceattle cod example from converter resource changes (triggered by $(git log -1 --pretty=format:'%h %s' HEAD)) [skip ci]"
git push
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Imports:
Suggests:
FIMS,
flextable,
ggridges,
here,
kableExtra,
knitr,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export(extract_sis_data)
export(filter_data)
export(plot_aa)
export(plot_abundance_at_age)
export(plot_age_to_length_conversion)
export(plot_biomass)
export(plot_biomass_at_age)
export(plot_catch_at_age)
Expand All @@ -24,6 +25,7 @@ export(plot_composition_residuals)
export(plot_composition_samples)
export(plot_composition_sexratio)
export(plot_data_availability)
export(plot_density)
export(plot_discard)
export(plot_fishing_mortality)
export(plot_index)
Expand Down
37 changes: 28 additions & 9 deletions R/conout_bam.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ conout_bam <- function(
fleet_names = NULL
) {
# Extract values from BAM output - model file after following ADMB2R
dat <- dget(file)
if (is.character(file)) {
dat <- dget(file)
} else {
dat <- file
}

# Find fleet names
if (is.null(fleet_names)) {
Expand Down Expand Up @@ -106,7 +110,7 @@ conout_bam <- function(
),
year
)
if (grepl("lcomp", names(extract[[1]][i]))) {
if (grepl("lcomp|len", names(extract[[1]][i]))) {
namesto <- "len_bins"
} else if (grepl("acomp", names(extract[[1]][i]))) {
namesto <- "age"
Expand All @@ -131,13 +135,28 @@ conout_bam <- function(
grepl(paste0(fleet_names, collapse = "|"), tolower(label)) ~ stringr::str_replace(tolower(label), paste0(".", fleet_names, collapse = "|"), ""),
TRUE ~ names(extract[[1]][i])
)
# label_init = names(extract[[1]][i]),

# label = dplyr::case_when(
# is.na(fleet) ~ names(extract[[1]][i]),
# TRUE ~ stringr::str_replace(tolower(label), paste(".", fleet_names, sep = "", collapse = "|"), "")
# )
) # stringr::str_replace(module_name, "\\.[^.]+\\.", "."))
)
# remove age_a and set to just age
if ("age_a" %in% colnames(df2)) {
if ("age" %in% colnames(df2)) {
if (all(is.na(df2$age))) {
df2 <- df2 |>
dplyr::mutate(age = age_a,
age_n = NA)
}
# check if age column values are equal to age_a
if (all(df2$age == df2$age_a, na.rm = TRUE)) {
df2 <- df2 |>
dplyr::mutate(age = age_a,
age_n = NA)
}
} else {
df2 <- df2 |>
dplyr::mutate(age = age_a,
age_a = NA)
}
if (all(is.na(df2$age_a))) df2 <- dplyr::select(df2, -age_a)
}
df2[setdiff(tolower(names(out_new)), tolower(names(df2)))] <- NA
extract_list[[names(extract[[1]][i])]] <- df2
} # close if statement
Expand Down
22 changes: 21 additions & 1 deletion R/conout_rceattle.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ conout_rceattle <- function(
# comp_data?, index_data, catch_data, weight, Ftarget, Flimit
data_list_list <- list()

####### Indices ####
####### Indices ----
# Extract index_data
df_index <- extract[[1]]$index_data |>
# rename all columns to lower case to match standard
Expand Down Expand Up @@ -366,6 +366,26 @@ conout_rceattle <- function(
df_comp[setdiff(tolower(names(out_new)), tolower(names(df_comp)))] <- NA
data_list_list[["comp_data"]] <- df_comp

#### Age length key ----
module_name <- "age_trans_matrix"
alk_raw <- dat$data_list$age_trans_matrix |>
dplyr::rename_with(tolower)
df_alk <- alk_raw |>
dplyr::select(-c(age_transition_name, age_transition_index, species)) |> # not sure what these are for |>
tidyr::pivot_longer(
cols = -intersect(colnames(alk_raw), factors),
names_to = "len_bins",
values_to = "estimate"
) |>
dplyr::mutate(
label = "age_to_length_conversion",
module_name = module_name,
len_bins = as.numeric(stringr::str_remove(len_bins, "length_"))
)

df_alk[setdiff(tolower(names(out_new)), tolower(names(df_alk)))] <- NA
data_list_list[[module_name]] <- df_alk

# final df for data_list module
# rbind() rather than bind_rows(): every frame has already been padded
# to the standard column set above, so rbind() succeeds and keeps the
Expand Down
53 changes: 51 additions & 2 deletions R/conout_ss3.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ conout_ss3 <- function(
rand <- c(
"SPAWN_RECRUIT_CURVE", # RAND
"sprseries", # RAND
"parameters" # RAND
"parameters", # RAND
# "equil_yeild", # SKIP FOR NOW - RAND
"ALK"
# "AAK"
)
aa.al <- c(
"sizeselex", # AA.AL
Expand Down Expand Up @@ -231,7 +233,7 @@ conout_ss3 <- function(
extract <- file[[parm_sel]]
}

if (!is.data.frame(extract)) {
if (!is.data.frame(extract) && parm_sel %notin% c("ALK")) {
if (is.numeric(extract)) {
df <- data.frame(
label = parm_sel,
Expand Down Expand Up @@ -678,6 +680,8 @@ conout_ss3 <- function(
# "SPAWN_RECR_CURVE"
# "Biology_at_age_in_endyr"
# "PARAMETERS"
# "ALK"
# "AAK"

if (parm_sel %in% c("SPAWN_RECR_CURVE", "SPAWN_RECRUIT_CURVE")) {
# 32
Expand Down Expand Up @@ -986,6 +990,51 @@ conout_ss3 <- function(
df4[setdiff(tolower(names(out_new)), tolower(names(df4)))] <- NA
# Add to out list
out_list[[parm_sel]] <- df4
} else if (parm_sel == "ALK") {
# extract matrix into df
# ID dimensions and assign
df1 <- as.data.frame.table(extract, responseName = "value", stringsAsFactors = FALSE)
colnames(df1)[1:3] <- c("len_bins", "age", "slice_label")

# Dynamically extract all "Key: Value" pairs and pivot
df2 <- df1 |>
# Match every 'Word: Number' pair (supporting decimals and negative numbers)
dplyr::mutate(pairs = stringr::str_extract_all(slice_label, "([A-Za-z0-9_]+):\\s*([-+]?\\d*\\.?\\d+)")) |>
tidyr::unnest(pairs) |>
tidyr::separate_wider_delim(
cols = pairs,
delim = ":",
names = c("variable", "val")
) |>
dplyr::mutate(
variable = stringr::str_trim(variable),
val = type.convert(stringr::str_trim(val), as.is = TRUE) # Automatically parses numeric types
) |>
tidyr::pivot_wider(
names_from = variable,
values_from = val
) |>
dplyr::select(-slice_label) |>
dplyr::relocate(len_bins, age, tidyselect::where(is.numeric), value)
colnames(df2) <- tolower(colnames(df2))
# rename columns if not std & add module_name + label
# I believe this is the only ones
rename_map <- c(
season = "seas",
subseason = "sub_seas" ,
estimate = "value"
# gp = "growth_pattern"
)
df3 <- df2 |>
dplyr::rename(dplyr::any_of(rename_map)) |>
dplyr::mutate(
module_name = parm_sel,
label = "age_to_length_conversion")
df3[setdiff(tolower(names(out_new)), tolower(names(df3)))] <- NA
# Add to out list
out_list[[parm_sel]] <- df3
} else if (parm_sel == "AAK") {
miss_parms <- c(miss_parms, parm_sel)
} else {
miss_parms <- c(miss_parms, parm_sel)
next
Expand Down
19 changes: 12 additions & 7 deletions R/convert_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ convert_output <- function(
# Is user inputs a single model file and doesn't wrap it as a list object
# First check handles WHAM and Rceattle models, second check handles single model input,
# final check handles FIMS models
if (any(grepl("Data_File|data_list", names(files))) || is.character(files) || is.data.frame(files)) {
if(any(grepl("Data_File|data_list|info|TMBfilename", names(files))) || is.character(files) || is.data.frame(files)){
cli::cli_alert("`files` is a single model. Converting to list object.")
files <- list(files)
names(files) <- "model_1"
Expand All @@ -137,7 +137,6 @@ convert_output <- function(
cli::cli_alert(glue::glue("Fleets names are: {str(fleet_names)}"))
}


processed <- purrr::imap(files, function(file, model_name) {
i <- which(names(files) == model_name)
if (is.character(file) && grepl("Report.sso", file)) {
Expand Down Expand Up @@ -235,7 +234,8 @@ convert_output <- function(
}
if (is.character(file)) {
if (is.null(models) || is.na(models[i])) {
model <- switch(stringr::str_extract(file, "\\.([^.]+)$"),
model <- switch(
stringr::str_extract(file, "\\.([^.]+)$"),
".sso" = {
cli::cli_alert_info("Processing Stock Synthesis output file...")
"ss3"
Expand All @@ -255,8 +255,9 @@ convert_output <- function(
cli::cli_abort("Unknown file type. Please indicate model.")
)
}
} else if (is.null(models) || is.na(models[i])) {
model <- switch(class(file)[1],
} else if (is.null(models) || is.na(models[i])){
model <- switch(
class(file)[1],
"FIMSFit" = {
cli::cli_alert_info("Processing FIMS output file...")
"fims"
Expand All @@ -273,14 +274,17 @@ convert_output <- function(
if (any(grepl("wham_version", names(file)))) {
cli::cli_alert_info("Processing WHAM output file...")
"wham"
} else if (any(grepl("SEDAR", file))) {
cli::cli_alert_info("Processing BAM output file...")
"bam"
} else {
cli::cli_alert_info("Processing SS3 r4ss output file...")
"ss3"
}
},
cli::cli_abort("Unknown file type. Please indicate model.")
)
} else {
} else{
model <- models[i]
}

Expand Down Expand Up @@ -370,7 +374,8 @@ convert_output <- function(
year = as.character(year),
month = as.character(month),
block = as.character(.data$block),
fleet = as.character(fleet)
fleet = as.character(fleet),
length_bins = as.numeric(length_bins)
)
return(tibble::tibble(out_new))
})
Expand Down
17 changes: 9 additions & 8 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@
#'
"example_data"

#' 2018 Gulf of Alaska Pollock stock assessment output
#' 2018 Gulf of Alaska Cod stock assessment output
#'
#' Output of the 2018 Gulf of Alaska Pollock stock assessment produced from Rceattle, standardized
#' Output of the 2018 Gulf of Alaska Cod stock assessment produced from Rceattle, standardized
#' using `stockplotr::convert_output()`. The example can be found and run from the Rceattle repository.
#'
#' @docType data
#'
#' @usage data(pollock)
#' @usage data(cod)
#'
#' @format A tibble (\code{tbl_df}, \code{tbl}, \code{data.frame}) with 9,983 rows and 35 variables:
#' @format A tibble (\code{tbl_df}, \code{tbl}, \code{data.frame}) with 589,809 rows and 36 variables:
#' \describe{
#' \item{label}{Standard name for estimate or value name}
#' \item{estimate}{Actual value of the label}
Expand Down Expand Up @@ -86,6 +86,7 @@
#' \item{length_bins}{Length bins for composition or other length based data}
#' \item{count}{Indexing column of data}
#' \item{block}{Indexing column of data}
#' \item{model}{Indexing column of data}
#' }
#'
#' @keywords datasets
Expand All @@ -96,10 +97,10 @@
#' @source \href{https://github.com/afsc-assessments/Rceattle/blob/main/examples/Fit_2018_GOA_single-species_models.R}{Rceattle Example}
#'
#' @examples
#' data(pollock)
#' head(pollock)
#' unique(pollock$label)
"pollock"
#' data(cod)
#' head(cod)
#' unique(cod$label)
"cod"

#' SEDAR 55 South Atlantic Vermilion Snapper
#'
Expand Down
Loading