Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sizespectrum/mizer
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavdelius committed Oct 14, 2024
2 parents f02b493 + 765d6d7 commit a975f29
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 9 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mizer
Title: Dynamic Multi-Species Size Spectrum Modelling
Date: 2024-11-13
Date: 2024-11-14
Type: Package
Description: A set of classes and methods to set up and run multi-species, trait
based and community size spectrum ecological models, focused on the marine
Expand All @@ -19,7 +19,7 @@ Authors@R: c(person("Gustav", "Delius", email="[email protected]",
comment = c(ORCID = "0000-0002-8478-3430")),
person("Richard", "Southwell", email="[email protected]",
role=c("ctb", "cph")))
Version: 2.5.2
Version: 2.5.2.1
License: GPL-3
Imports:
assertthat,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export(validEffortVector)
export(validGearParams)
export(validGivenSpeciesParams)
export(validParams)
export(validSim)
export(validSpeciesParams)
export(valid_gears_arg)
export(valid_species_arg)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# mizer 2.5.2.1

A patch update so that users who had changed `w_max` manually in their model
will not get unhelpful error messages when trying to use this model in the
new version.

# mizer 2.5.2

- Fixed bug that had led `newCommunityParams()` to set up resource parameters
Expand Down
22 changes: 22 additions & 0 deletions R/MizerSim-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,28 @@ MizerSim <- function(params, t_dimnames = NA, t_max = 100, t_save = 1) {
return(sim)
}

#' Validate MizerParams object and upgrade if necessary
#'
#' Checks that the given MizerParams object is valid and upgrades it if
#' necessary by calling [upgradeParams()].
#'
#' Besides upgrading if necessary, the only change that may be made to the
#' given MizerParams object is that the `w_min_idx` slot is recalculated.
#'
#' @param params The MizerParams object to validate
#' @return A valid MizerParams object
#' @export
validSim <- function(sim) {
assert_that(is(sim, "MizerSim"))
if (needs_upgrading(sim)) {
params <- suppressWarnings(upgradeSim(sim))
warning("Your MizerSim object was created with an earlier version of mizer. You can upgrade it with `sim <- upgradeSim(sim)` where you should replace `sim` by the name of the variable that holds your MizerSim object.")
}
sim@params <- validParams(sim@params)
validObject(sim)
sim
}

#' Time series of size spectra
#'
#' Fetch the simulation results for the size spectra over time.
Expand Down
2 changes: 0 additions & 2 deletions R/compareParams.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#' species_params(params2)$w_mat[1] <- 10
#' compareParams(params1, params2)
compareParams <- function(params1, params2) {
validObject(params1)
validObject(params2)
assert_that(is(params1, "MizerParams"))
assert_that(is(params2, "MizerParams"))

Expand Down
3 changes: 1 addition & 2 deletions R/extension.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ setRateFunction <- function(params, rate, fun) {
#' `rate` argument.
#' @export
getRateFunction <- function(params, rate) {
assert_that(is(params, "MizerParams"))
validObject(params)
params <- validParams(params)
if (missing(rate)) {
return(params@rates_funcs)
}
Expand Down
1 change: 0 additions & 1 deletion R/newMultispeciesParams.R
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ setParams <- function(params, interaction = NULL, ...) {
params@ft_mask <- t(sapply(params@species_params$w_max,
function(x) params@w_full < x))

params <- suppressWarnings(validParams(params))
params <- setInteraction(params, interaction)
params <- setPredKernel(params, ...)
params <- setMaxIntakeRate(params, ...)
Expand Down
14 changes: 13 additions & 1 deletion R/upgrade.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ needs_upgrading <- function(object) {
stop("The object you supplied is neither a MizerParams nor a MizerSim object.")
}
!.hasSlot(params, "mizer_version") ||
params@mizer_version < "2.4.1.9002"
params@mizer_version < "2.5.2"
}

#' Upgrade MizerParams object from earlier mizer versions
Expand Down Expand Up @@ -360,6 +360,18 @@ upgradeParams <- function(params) {
params@species_params$w_mat / (3 ^ (1 / 10)))
}

# Before 2.5.2 ----
if (version < "2.5.2") {
# setParams() will update the ft_mask if necessary
# It will also warn if `w_max` is not valid
ft_mask <- params@ft_mask
params <- setParams(params)
if (!identical(as.vector(params@ft_mask),
as.vector(ft_mask))) {
warning("The ft_mask slot has been updated.")
}
}

params@mizer_version <- packageVersion("mizer")
params@time_modified <- lubridate::now()
validObject(params)
Expand Down
2 changes: 1 addition & 1 deletion R/validSpeciesParams.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ validGivenSpeciesParams <- function(species_params) {
if (any(wrong)) {
warning("For the species ",
paste(sp$species[wrong], collapse = ", "),
" the value for `w_max` is smaller than that of `w_repro_max`.",
" the value for `w_max` is larger than that of `w_repro_max`.",
" I have corrected that by setting `w_max` equal to `w_repro_max`.")
sp$w_max[wrong] <- sp$w_repro_max[wrong]
}
Expand Down
22 changes: 22 additions & 0 deletions man/validSim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a975f29

Please sign in to comment.