Skip to content

Add gear argument to getYieldVsF() and plotYieldVsF() - #72

Open
gustavdelius wants to merge 1 commit into
masterfrom
feature/yield-vs-f-gear
Open

Add gear argument to getYieldVsF() and plotYieldVsF()#72
gustavdelius wants to merge 1 commit into
masterfrom
feature/yield-vs-f-gear

Conversation

@gustavdelius

Copy link
Copy Markdown
Member

Summary

getYieldVsF() and plotYieldVsF() gain a gear argument (default NULL) that selects which gear's fishing mortality is varied when several gears catch the target species. The fishing mortality that the other gears exert on that species is kept fixed, and the F values in the result then refer to the selected gear alone.

Both functions already worked by adding a temporary gear whose effort is swept over F_range; the change is in which gear-params rows get zeroed:

  • gear given: only the row for that gear/species pair is selected. Its catchability is set to 0 and the temporary gear inherits that gear's selectivity, so all other gears keep fishing the species unchanged. current_FMort, which decides whether the sweep works up or down from the current state, is that gear's contribution only.
  • gear = NULL: unchanged behaviour (all gears catching the species are replaced), but a message now points at the new argument when more than one gear catches the species.

Invalid gears and multi-element gear values error out, and the species/gear checks were moved ahead of the initial projectToSteady() call so bad arguments fail immediately rather than after a projection.

plotYieldVsF() labels the x-axis "Fishing mortality from <gear> (1/yr)" when a gear is selected.

Verification

Setting the temporary gear's effort to the selected gear's current F reproduces getFMort(params) exactly (max abs difference 0), and doubling it changes only the target species' F — including when the selected gear also catches other species.

New tests/testthat/test-getYieldVsF.R covers the error paths, the multiple-gear message, and that F = 0 on one gear still gives a positive yield while F = 0 without a gear selection gives zero yield. 7 passing, ~11s. The one failure in the full suite (test-manipulateParams.R:68) is pre-existing on master.

Note

getYieldVsF() is called with gear as the third positional argument now. A positional numeric F_range in third position raises a clear error rather than being silently misread.

Unrelated pre-existing bug spotted but not touched: yieldCalculator() indexes y[(ft - 30):ft, ] on non-convergence, which errors for small t_max.

🤖 Generated with Claude Code

When several gears catch the target species, `gear` selects the one whose
fishing mortality is varied. Only that gear's catchability for the species
is zeroed and taken over by the temporary gear whose effort is swept, so
the fishing mortality that the other gears exert on the species is kept
fixed and the returned `F` values refer to the selected gear alone.

Without a `gear` the previous behaviour is retained (the fishing mortality
from all gears on the species is replaced), but a message now points at the
new argument when more than one gear catches the species.

The species and gear checks now happen before the initial projection to
steady state so that invalid arguments fail fast.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant