Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 16, 2025

Due to mizer's numerical integration scheme, zero growth rate at the start of a size class can produce non-zero abundance in that class. When w_repro_max falls within a size class, fish can incorrectly grow beyond it.

Changes

Core logic (R/setReproduction.R:296-310)

  • Round w_repro_max down to largest grid point ≤ current value
  • Only applies when params@mizer_version > "2.5.3.9000" for backward compatibility
  • Handles edge case where w_repro_max < all grid points

Documentation (R/setReproduction.R:15-17, 62-66)

  • Note rounding behavior in main description and Investment into reproduction subsection

Tests (tests/testthat/test-reproduction.R:59-102)

  • Verify rounding for new versions using off-grid values
  • Verify no rounding for old versions (≤ 2.5.3.9000)

Example

params <- NS_params
# w_repro_max between grid points gets rounded down
params@species_params$w_repro_max <- 1500.5  # not on grid
params <- setReproduction(params)
params@species_params$w_repro_max[1]  # now equals max(w[w <= 1500.5])

Existing models continue to work unchanged. New models automatically get the corrected behavior.

Original prompt

This section details on the original issue you should resolve

<issue_title>Round down w_repro_max to next-lower point on w grid</issue_title>
<issue_description>Due to mizer's numerical integration scheme, when the growth rate is zero at the start of a size class, this can nevertheless lead to a non-zero abundance in that size class. This is potentially confusing because it means that if w_repro_max falls within one size class, and hence the growth rate at the end of that size class is zero, individuals can nevertheless grow into the next larger size class, clashing with the idea that w_repro_max is the maximum size. @LucaBroadbentCefas proposed therefore to round down w_repro_max to the next-lower point on the w grid, so that the growth rate would be zero already at that point and hence no fish would grow beyond the size class containing w_repro_max.

I have no objection to this change, as long as it is done in a way that does not confuse people with existing models. So I propose that the rounding down takes place in setReproduction() where repro_prop is calculated, but only for params objects that were created in a newer version of mizer, i.e., when getMetadata(params)$mizer_version > "2.5.3.9000".
</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Round down w_repro_max to next-lower point on w grid Round down w_repro_max to next-lower grid point for mizer > 2.5.3.9000 Nov 16, 2025
Copilot AI requested a review from gustavdelius November 16, 2025 13:12
Copilot finished work on behalf of gustavdelius November 16, 2025 13:12
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.

Round down w_repro_max to next-lower point on w grid

2 participants