Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 16, 2025

plotDiet() was plotting diet information all the way to w_max regardless of whether fish were present at those sizes, showing misleading diet data for extremely rare large individuals.

Changes

  • R/plots.R: Added abundance-based filtering to plotDiet()

    • Extract abundance from MizerSim (last time step) or MizerParams (initial values)
    • Calculate per-species threshold: abundance > 1e-5 * max_abundance
    • Filter plot data to exclude sizes beyond the meaningful range
    • Applied per-species to handle faceted plots correctly
  • tests/testthat/test-plots.R: Added test verifying size limiting behavior

Example

For a species with w_max = 1000g where abundance becomes negligible beyond 100g, plots now automatically truncate at ~187g instead of extending to 1000g.

Implementation:

# For each predator species
abundance <- n[pred_idx, ]
max_abundance <- max(abundance)
meaningful_idx <- which(abundance > 1e-5 * max_abundance)
w_max_meaningful <- params@w[max(meaningful_idx)]
plot_dat <- plot_dat[!(plot_dat$Predator == pred & plot_dat$w > w_max_meaningful), ]

Fully backward compatible—no changes to function signature or existing parameters.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.r-project.org
    • Triggering command: /usr/lib/R/bin/exec/R --no-echo --no-restore -e install.packages(c(&#39;devtools&#39;,~&#43;~&#39;testthat&#39;,~&#43;~&#39;roxygen2&#39;,~&#43;~&#39;remotes&#39;),~&#43;~repos=&#39;REDACTED&#39;,~&#43;~Ncpus=4) (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Adjust plotDiet() to Restrict Plots to Relevant Size Ranges</issue_title>
<issue_description>When using the plotDiet() function, the diet plots currently extend all the way to w_max, regardless of whether there are any fish left at those sizes. This can make the plots misleading or less helpful for species with little or no biomass in the largest size classes, as they may show diet information for size ranges where the species is no longer present, extending to rare situations where diets would require negative intake rates for very large fish.

It might be helpful to adjust plotDiet() so that it only plots up to the largest size class where fish are present (i.e., where the abundance is greater than zero). This would ensure the plot better represents the relevant size ranges and provides more useful information to the user.

</issue_description>

Comments on the Issue (you are @copilot in this section)

@gustavdelius Thanks @JamesRimmerEco . That would be a good idea. In practice, the abundance of fish actually stays non-zero all the way up to `w_repro_max` but the abundance can become totally negligibly small long before that. So the relevant size range should not be the entire range where the abundance is greater than 0 but only the range where it is greater than some threshold. The trick will be to automatically find a good value for this threshold. @gustavdelius Let's put the upper limit on the size axis to the size beyond which the abundance density is less than 1e-5 of the maximum density.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Nov 16, 2025
Copilot AI and others added 3 commits November 16, 2025 13:04
Co-authored-by: gustavdelius <1340713+gustavdelius@users.noreply.github.com>
Co-authored-by: gustavdelius <1340713+gustavdelius@users.noreply.github.com>
Co-authored-by: gustavdelius <1340713+gustavdelius@users.noreply.github.com>
Copilot AI changed the title [WIP] Adjust plotDiet function to restrict plots to relevant size ranges Restrict plotDiet() to size ranges with meaningful abundance Nov 16, 2025
Copilot AI requested a review from gustavdelius November 16, 2025 13:11
@gustavdelius gustavdelius marked this pull request as ready for review November 16, 2025 14:11
@gustavdelius gustavdelius merged commit 609bcf3 into master Nov 16, 2025
4 of 5 checks passed
@gustavdelius gustavdelius deleted the copilot/adjust-plotdiet-size-ranges branch November 16, 2025 14:11
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.

Adjust plotDiet() to Restrict Plots to Relevant Size Ranges

2 participants