Skip to content

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

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

MOshima-PIFSC wants to merge 18 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 MOshima-PIFSC linked an issue Nov 17, 2026 that may be closed by this pull request
@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 :)

Comment thread data/example_data.rda Resolved
Comment thread R/plot_age_to_length.R Resolved
Comment thread R/plot_age_to_length.R Resolved
Comment thread R/plot_age_to_length.R Resolved
Comment thread R/plot_age_to_length_conversion.R Resolved
Comment thread R/plot_age_to_length_conversion.R Resolved
Comment thread R/utils_plot.R Resolved

@sbreitbart-NOAA sbreitbart-NOAA left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plots look great! I'm able to specify different arguments for ss3_simple and get some awesome-looking plots. I get the same error msg for the other built-in datasets (pollock, example_data, vermilion_snapper). This may be addressed if I convert these datasets myself before testing, but I think an existing bug in convert_output() (which may be addressed by Eric's existing PR) prevents this, so I'm unable to test. Otherwise, I had some relatively minor comments. And the captions/alt text setup seems to work well too!

Error in filter_data() at stockplotr/R/plot_age_to_length.R:66:3:
! age_to_length_conversion not found.
Run rlang::last_trace() to see where the error occurred.

Comment thread R/utils_plot.R Resolved
@Schiano-NOAA

Copy link
Copy Markdown
Collaborator

The plots look great! I'm able to specify different arguments for ss3_simple and get some awesome-looking plots. I get the same error msg for the other built-in datasets (pollock, example_data, vermilion_snapper). This may be addressed if I convert these datasets myself before testing, but I think an existing bug in convert_output() (which may be addressed by Eric's existing PR) prevents this, so I'm unable to test. Otherwise, I had some relatively minor comments. And the captions/alt text setup seems to work well too!

Error in filter_data() at stockplotr/R/plot_age_to_length.R:66:3: ! age_to_length_conversion not found. Run rlang::last_trace() to see where the error occurred.

I added a fix for BAM, but there is no age length for BAM in the example data set. I might be able to grab one from the BAMextras package and replace the current example so it exists. I am working on getting this working for Rceattle as well, so it currently should only work for SS3 r4ss object. I was not planning to add it for the report.sso file. I think FIMS should have it since I think they merged in the PR with age length that originally had this plot but we don't have example data in the package for them (just something to note).

Lastly, I will add back in the example_data.

Comment thread man/plot_age_to_length_conversion.Rd Resolved
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Schiano-NOAA and others added 5 commits November 25, 2026 09:25
…hanges (triggered by fe7d5f4 chore: update SS3 r4ss example_data from converter resource changes (triggered by 01c902c std length_bins type) [skip ci]) [skip ci]
…ered by 42bd301 chore: update BAM vermilion snapper example from converter resource changes (triggered by fe7d5f4 chore: update SS3 r4ss example_data from converter resource changes (triggered by 01c902c std length_bins type) [skip ci]) [skip ci]) [skip ci]

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.

[Bug]: single bam file not being converted with convert_output() [feat]: plot_age_to_length

4 participants