Skip to content

Commit

Permalink
Changed parameter name to w_repro_max
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavdelius committed Aug 19, 2024
1 parent 55c23ce commit b03f2f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Development version

- New species parameter `w_repro_max` giving the size at which a species
invests 100% of its energy into reproduction. Set to `w_max` by default.
- `getDiet()` now also includes the contribution of the external encounter rate
to the diet.
- Improved scaling of the y-axis in `plotGrowthCurves()`.
Expand Down
24 changes: 12 additions & 12 deletions R/setReproduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#' that is invested into reproduction is the product of two factors: the
#' proportion `maturity` of individuals that are mature and the proportion
#' `repro_prop` of the energy available to a mature individual that is
#' invested into reproduction. There is a size `w_mat_max` at which all the
#' invested into reproduction. There is a size `w_repro_max` at which all the
#' energy is invested into reproduction and therefore all growth stops. There
#' can be no fish larger than `w_mat_max`. If you have not specified the
#' `w_mat_max` column in the species parameter data frame, then the maximum size
#' can be no fish larger than `w_repro_max`. If you have not specified the
#' `w_repro_max` column in the species parameter data frame, then the maximum size
#' `w_max` is used instead.
#'
#' \subsection{Maturity ogive}{
Expand All @@ -38,7 +38,7 @@
#'
#' The sigmoidal function given above would strictly reach 1 only
#' asymptotically. Mizer instead sets the function equal to 1 already at a size
#' taken from the `w_mat_max` column in the species parameter data frame, if it
#' taken from the `w_repro_max` column in the species parameter data frame, if it
#' exists, or otherwise from the `w_max` column. Also, for computational
#' simplicity, any proportion smaller than `1e-8` is set to `0`.
#' }
Expand All @@ -48,14 +48,14 @@
#' invested into reproduction is not supplied via the `repro_prop` argument,
#' it is set to the allometric form
#' \deqn{{\tt repro\_prop}(w) = \left(\frac{w}{w_{mat_max}}\right)^{m-n}.}{
#' repro_prop(w) = (w/w_mat_max)^(m - n).}
#' repro_prop(w) = (w/w_repro_max)^(m - n).}
#' Here \eqn{n} is the scaling exponent of the energy income rate. Hence
#' the exponent \eqn{m} determines the scaling of the investment into
#' reproduction for mature individuals. By default it is chosen to be
#' \eqn{m = 1} so that the rate at which energy is invested into reproduction
#' scales linearly with the size. This default can be overridden by including a
#' column `m` in the species parameter dataframe. The maximum sizes are taken
#' from the `w_mat_max` column in the species parameter data frame, if it
#' from the `w_repro_max` column in the species parameter data frame, if it
#' exists, or otherwise from the `w_max` column.
#'
#' The total proportion of energy invested into reproduction of an individual
Expand Down Expand Up @@ -281,15 +281,15 @@ setReproduction <- function(params, maturity = NULL,
if (any(species_params$m < species_params[["n"]])) {
stop("The exponent `m` must not be smaller than the exponent `n`.")
}
# Set defaults for w_mat_max
species_params <- set_species_param_default(species_params, "w_mat_max",
# Set defaults for w_repro_max
species_params <- set_species_param_default(species_params, "w_repro_max",
params@species_params$w_max)

repro_prop <- array(
unlist(
tapply(params@w, seq_along(params@w),
function(wx, w_mat_max, mn) (wx / w_mat_max)^(mn),
w_mat_max = species_params$w_mat_max,
function(wx, w_repro_max, mn) (wx / w_repro_max)^(mn),
w_repro_max = species_params$w_repro_max,
mn = species_params[["m"]] - species_params[["n"]]
)
), dim = c(nrow(species_params), length(params@w)))
Expand All @@ -299,8 +299,8 @@ setReproduction <- function(params, maturity = NULL,
psi <- params@maturity * repro_prop
# psi should never be larger than 1
psi[psi > 1] <- 1
# Set psi for all w > w_mat_max to 1
psi[outer(species_params$w_mat_max, params@w, "<")] <- 1
# Set psi for all w > w_repro_max to 1
psi[outer(species_params$w_repro_max, params@w, "<")] <- 1
assert_that(all(psi >= 0 & psi <= 1))

# if the slot is protected and the user did not supply a new repro_prop
Expand Down
6 changes: 3 additions & 3 deletions R/species_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#' * `k`, `ks` and `p` are used to set activity and basic metabolic rate,
#' see [setMetabolicRate()].
#' * `z0` is used to set the external mortality rate, see [setExtMort()].
#' * `w_mat`, `w_mat25`, `w_mat_max` and `m` are used to set the allocation to
#' * `w_mat`, `w_mat25`, `w_repro_max` and `m` are used to set the allocation to
#' reproduction, see [setReproduction()].
#' * `pred_kernel_type` specifies the shape of the predation kernel. The default
#' is a "lognormal", for other options see the "Setting predation kernel"
Expand Down Expand Up @@ -72,7 +72,7 @@
#' relationship \eqn{w = a l ^ b}.
#'
#' If you have supplied the `a` and `b` parameters, then you can replace weight
#' parameters like `w_max`, `w_mat`, `w_mat25`, w_mat_max and `w_min` by their
#' parameters like `w_max`, `w_mat`, `w_mat25`, w_repro_max and `w_min` by their
#' corresponding length parameters `l_max`, `l_mat`, `l_mat25`, `l_mat_max` and
#' `l_min`.
#'
Expand Down Expand Up @@ -579,7 +579,7 @@ validSpeciesParams <- function(species_params) {
sp <- sp %>%
set_species_param_from_length("w_mat", "l_mat") %>%
set_species_param_from_length("w_mat25", "l_mat25") %>%
set_species_param_from_length("w_mat_max", "l_mat_max") %>%
set_species_param_from_length("w_repro_max", "l_mat_max") %>%
set_species_param_from_length("w_max", "l_max") %>%
set_species_param_from_length("w_min", "l_min")
}
Expand Down

0 comments on commit b03f2f4

Please sign in to comment.