Skip to content

[Feat]: age-to-length conversion plot - #512

Open
MOshima-PIFSC wants to merge 17 commits into
mainfrom
feat-plot-age-length
Open

MOshima-PIFSC wants to merge 17 commits into
mainfrom
feat-plot-age-length

Conversation

@MOshima-PIFSC

@MOshima-PIFSC MOshima-PIFSC commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What is the feature?

  • adding a figure for the age to length conversion.

How have you implemented the solution?

  • added plot_age_to_length() and plot_density()

Does the PR impact any other area of the project, maybe another repo?

  • I don't think so

I'm not sure if this is fully ready to be merged in so I am making it a draft for now.

PR contribution checklist

Thank you for contributing to stockplotr! Please check the boxes below to confirm this pull request (PR) is ready for review. Edit this PR description to add the release indicator and any explanations.

  • I have read and adhered to the contributor guide.
  • 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).
  • If I didn't follow the development workflow, 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.
  • I have requested review from one package maintainer (Sam or Sophie).

MOshima-PIFSC and others added 10 commits November 17, 2026 14:50
Co-authored-by: Sam (Schiano) Bredeck <Schiano-NOAA@users.noreply.github.com>
* add age length key into conout for ss3

* fix issue with ALK in r4ss

* update example data
Co-authored-by: Sam (Schiano) Bredeck <Schiano-NOAA@users.noreply.github.com>
Co-authored-by: Sam (Schiano) Bredeck <Schiano-NOAA@users.noreply.github.com>
Co-authored-by: Ian Taylor <iantaylor-NOAA@users.noreply.github.com>
Co-authored-by: Sam (Schiano) Bredeck <Schiano-NOAA@users.noreply.github.com>
@MOshima-PIFSC MOshima-PIFSC linked an issue Nov 17, 2026 that may be closed by this pull request
…ered by ef0c8d7 add make RDA section. Make alt text dynamic.) [skip ci]
@github-actions

Copy link
Copy Markdown
Contributor

Code Metrics Report

Coverage Code to Test Ratio Test Execution Time
76.7% 1:0.2 6m21s

Code coverage of files in pull request scope (77.9%, patch 30.0%)

Files Coverage Patch Coverage
R/conout_ss3.R 87.3% 97.1%
R/convert_output.R 84.5% -
R/plot_age_to_length.R 5.6% 5.6%
R/utils_plot.R 77.7% 53.3%

Reported by octocov

@Schiano-NOAA
Schiano-NOAA marked this pull request as ready for review November 18, 2026 20:35
@Schiano-NOAA

Copy link
Copy Markdown
Collaborator

Note for @sbreitbart-NOAA : we incorporated a new approach that looks over and describes trends of each facet (up to 2 facets) that is replacing a placeholder in the alt text. This was because the way these plots get described is easy to automate comparatively to other trends you see on other plots like plot_spawning_biomass. Let us know what you think of this approach! I think this has solid potential to apply it for multiple models on plots.

@Schiano-NOAA Schiano-NOAA changed the title Feat age to length conversion plot [Feat]: age-to-length conversion plot Nov 18, 2026
@iantaylor-NOAA

Copy link
Copy Markdown
Contributor

@MOshima-PIFSC and @Schiano-NOAA, I mentioned yesterday that the one SS3 production assessment that I knew of which has more than 2 growth morphs is the Gulf of Alaska Rex Sole assessment developed by @careymcgilliard.

The plot below is the result of running the following code to read the input files, run the model, and make the plot.

The alt-text looks reasonable to me:

A set of density plots showing the age-to-length conversion for species, with one panel for each morph. The x axis shows age in years which spans from 0 to 20 and the y axis shows lengths from 9 to 65 (in cm). At each age, a vertical density curve shows the distribution of lengths. For morph 1, mean length increases from about 9.6 cm at age 0 to about 46 cm at age 20. For morph 2, mean length increases from about 9.5 cm at age 0 to about 36 cm at age 20.

For others watching this, we discussed in our meeting yesterday that repeating the summary of the pattern in each panel for more than 2 panels in this plot could make for really long alt-text not necessarily make better alt-text and would only apply to a tiny fraction of models.

# define a directory (change as needed)
goa_rex_dir <- file.path(getwd(), "goa_rex") 

# load input files from github
goa_rex_inputs <- r4ss::SS_read("https://raw.githubusercontent.com/noaa-afsc/goa_rex/refs/heads/main/runs/2025_models/2021_accepted_model_inputs/")

# save files to local directory
r4ss::SS_write(goa_rex_inputs, dir = goa_rex_dir)

# get SS3 exe if needed
r4ss::get_ss3_exe(dir = goa_rex_dir)

# run model without Hessian (no uncertainty needed for growth plot)
r4ss::run(goa_rex_dir, extras = "-nohess")

# load model output
goa_rex_out <- r4ss::SS_output(goa_rex_dir)

# convert output to stockplotr standard format
goa_rex_std <- stockplotr::convert_output(goa_rex_out)
stockplotr::plot_age_to_length_conversion(goa_rex_std) + 
  ggplot2::theme_minimal() # works better with Ian's github dark mode setting
ggsave(file.path(goa_rex_dir, "age_to_length.png"), width = 7, height = 7)
age_to_length

@MOshima-PIFSC

Copy link
Copy Markdown
Collaborator Author

Thanks @iantaylor-NOAA for testing that! Looks like its working how we wanted it to :)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat]: plot_age_to_length

3 participants