Skip to content

Commit

Permalink
addSpecies() no longer requires new species to grow to maximum size…
Browse files Browse the repository at this point in the history
…, only maturity size is required.
  • Loading branch information
gustavdelius committed Oct 6, 2024
1 parent 83a4952 commit c487498
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Authors@R: c(person("Gustav", "Delius", email="gustav.delius@york.ac.uk",
comment = c(ORCID = "0000-0002-8478-3430")),
person("Richard", "Southwell", email="richard.southwell@york.ac.uk",
role=c("ctb", "cph")))
Version: 2.5.1.9004
Version: 2.5.1.9005
License: GPL-3
Imports:
assertthat,
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# mizer 2.5.1.9004
# mizer 2.5.1.9005

- `addSpecies()` now correctly preserves all `species_params` of the existing
model.
- `addSpecies()` no longer requires new species to grow to maximum size, only
maturity size is required.
- 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
Expand Down
18 changes: 3 additions & 15 deletions R/manipulate_species.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,24 +267,12 @@ addSpecies <- function(params, species_params,
# Turn off self-interaction among the new species, so we can determine the
# growth rates, and death rates induced upon them by the pre-existing species
p@interaction[new_sp, new_sp] <- 0
mumu <- getMort(p)
gg <- getEGrowth(p)

# Compute solution for new species
p <- steadySingleSpecies(p, species = new_sp)

# set low abundance ----
for (i in new_sp) {
g <- gg[i, ]
mu <- mumu[i, ]
w_max_idx <- sum(p@w < p@species_params$w_max[i])
idx <- p@w_min_idx[i]:(w_max_idx - 1)
if (any(g[idx] == 0)) {
stop("Can not compute steady state due to zero growth rates for ",
p@species_params$species[i])
}
p@initial_n[i, ] <- 0
p@initial_n[i, p@w_min_idx[i]:w_max_idx] <-
c(1, cumprod(g[idx] / ((g + mu * p@dw)[idx + 1])))

# set low abundance ----
# Normalise solution so that it is never more than 1/100th of the
# Sheldon spectrum.
# We look at the maximum of abundance times w^lambda
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-manipulate_species.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test_that("addSpecies handles interaction matrix correctly", {
interaction <- matrix(1:16/16, ncol = 4)
(pa <- addSpecies(p, sp, interaction = interaction)) |>
expect_message() |>
expect_warning("The following species require an unrealistic reproductive efficiency greater than 1: new2")
expect_warning("The following species require an unrealistic value greater than 1 for `erepro`: new2")
expect_equal(pa@interaction, interaction, ignore_attr = TRUE)

addSpecies(p, sp, interaction = matrix(1:9, ncol = 3)) |>
Expand Down

0 comments on commit c487498

Please sign in to comment.