Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4.9001
Version: 2.5.4.9011
License: GPL-3
Imports:
assertthat,
Expand Down
169 changes: 169 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,174 @@
# Generated by roxygen2: do not edit by hand

S3method("catchability<-",MizerParams)
S3method("diffusion<-",MizerParams)
S3method("ext_encounter<-",MizerParams)
S3method("ext_mort<-",MizerParams)
S3method("gear_params<-",MizerParams)
S3method("given_species_params<-",MizerParams)
S3method("initialN<-",MizerParams)
S3method("initialNResource<-",MizerParams)
S3method("initial_effort<-",MizerParams)
S3method("intake_max<-",MizerParams)
S3method("interaction_matrix<-",MizerParams)
S3method("maturity<-",MizerParams)
S3method("metab<-",MizerParams)
S3method("pred_kernel<-",MizerParams)
S3method("repro_prop<-",MizerParams)
S3method("resource_capacity<-",MizerParams)
S3method("resource_dynamics<-",MizerParams)
S3method("resource_level<-",MizerParams)
S3method("resource_params<-",MizerParams)
S3method("resource_rate<-",MizerParams)
S3method("search_vol<-",MizerParams)
S3method("selectivity<-",MizerParams)
S3method("species_params<-",MizerParams)
S3method(addSpecies,MizerParams)
S3method(age_mat,MizerParams)
S3method(age_mat_vB,MizerParams)
S3method(age_mat_vB,data.frame)
S3method(age_mat_vB,default)
S3method(animateSpectra,MizerSim)
S3method(calculated_species_params,MizerParams)
S3method(calibrateBiomass,MizerParams)
S3method(calibrateNumber,MizerParams)
S3method(calibrateYield,MizerParams)
S3method(catchability,MizerParams)
S3method(compareParams,MizerParams)
S3method(diffusion,MizerParams)
S3method(distanceMaxRelRDI,MizerParams)
S3method(distanceSSLogN,MizerParams)
S3method(dw,MizerParams)
S3method(dw_full,MizerParams)
S3method(ext_encounter,MizerParams)
S3method(ext_mort,MizerParams)
S3method(gear_params,MizerParams)
S3method(getBiomass,MizerParams)
S3method(getBiomass,MizerSim)
S3method(getCatchability,MizerParams)
S3method(getColours,MizerParams)
S3method(getCommunitySlope,MizerSim)
S3method(getCriticalFeedingLevel,MizerParams)
S3method(getDiet,MizerParams)
S3method(getEGrowth,MizerParams)
S3method(getERepro,MizerParams)
S3method(getEReproAndGrowth,MizerParams)
S3method(getEncounter,MizerParams)
S3method(getExtEncounter,MizerParams)
S3method(getExtMort,MizerParams)
S3method(getFMort,MizerParams)
S3method(getFMort,MizerSim)
S3method(getFMortGear,MizerParams)
S3method(getFMortGear,MizerSim)
S3method(getFeedingLevel,MizerParams)
S3method(getFeedingLevel,MizerSim)
S3method(getGrowthCurves,MizerParams)
S3method(getGrowthCurves,MizerSim)
S3method(getInitialEffort,MizerParams)
S3method(getInteraction,MizerParams)
S3method(getLinetypes,MizerParams)
S3method(getMaturityProportion,MizerParams)
S3method(getMaxIntakeRate,MizerParams)
S3method(getMeanMaxWeight,MizerSim)
S3method(getMeanWeight,MizerSim)
S3method(getMetabolicRate,MizerParams)
S3method(getMetadata,MizerParams)
S3method(getMort,MizerParams)
S3method(getN,MizerParams)
S3method(getN,MizerSim)
S3method(getPredKernel,MizerParams)
S3method(getPredMort,MizerParams)
S3method(getPredMort,MizerSim)
S3method(getPredRate,MizerParams)
S3method(getProportionOfLargeFish,MizerSim)
S3method(getRDD,MizerParams)
S3method(getRDI,MizerParams)
S3method(getRates,MizerParams)
S3method(getReproductionLevel,MizerParams)
S3method(getReproductionProportion,MizerParams)
S3method(getRequiredRDD,MizerParams)
S3method(getResourceMort,MizerParams)
S3method(getSSB,MizerParams)
S3method(getSSB,MizerSim)
S3method(getSearchVolume,MizerParams)
S3method(getSelectivity,MizerParams)
S3method(getYield,MizerParams)
S3method(getYield,MizerSim)
S3method(getYieldGear,MizerParams)
S3method(getYieldGear,MizerSim)
S3method(given_species_params,MizerParams)
S3method(initialN,MizerParams)
S3method(initialN,MizerSim)
S3method(initialNResource,MizerParams)
S3method(initialNResource,MizerSim)
S3method(initial_effort,MizerParams)
S3method(intake_max,MizerParams)
S3method(interaction_matrix,MizerParams)
S3method(matchBiomasses,MizerParams)
S3method(matchGrowth,MizerParams)
S3method(matchNumbers,MizerParams)
S3method(matchYields,MizerParams)
S3method(maturity,MizerParams)
S3method(metab,MizerParams)
S3method(plotBiomass,MizerSim)
S3method(plotBiomassObservedVsModel,MizerParams)
S3method(plotBiomassObservedVsModel,MizerSim)
S3method(plotDiet,MizerParams)
S3method(plotDiet,MizerSim)
S3method(plotFMort,MizerParams)
S3method(plotFMort,MizerSim)
S3method(plotFeedingLevel,MizerParams)
S3method(plotFeedingLevel,MizerSim)
S3method(plotGrowthCurves,MizerParams)
S3method(plotGrowthCurves,MizerSim)
S3method(plotPredMort,MizerParams)
S3method(plotPredMort,MizerSim)
S3method(plotSpectra,MizerParams)
S3method(plotSpectra,MizerSim)
S3method(plotYield,MizerSim)
S3method(plotYieldGear,MizerSim)
S3method(plotYieldObservedVsModel,MizerParams)
S3method(plotYieldObservedVsModel,MizerSim)
S3method(pred_kernel,MizerParams)
S3method(project,MizerParams)
S3method(project,MizerSim)
S3method(projectToSteady,MizerParams)
S3method(project_simple,MizerParams)
S3method(removeSpecies,MizerParams)
S3method(renameGear,MizerParams)
S3method(renameSpecies,MizerParams)
S3method(repro_prop,MizerParams)
S3method(resource_capacity,MizerParams)
S3method(resource_dynamics,MizerParams)
S3method(resource_level,MizerParams)
S3method(resource_params,MizerParams)
S3method(resource_rate,MizerParams)
S3method(saveParams,MizerParams)
S3method(scaleModel,MizerParams)
S3method(search_vol,MizerParams)
S3method(selectivity,MizerParams)
S3method(setBevertonHolt,MizerParams)
S3method(setColours,MizerParams)
S3method(setDiffusion,MizerParams)
S3method(setExtEncounter,MizerParams)
S3method(setExtMort,MizerParams)
S3method(setFishing,MizerParams)
S3method(setInitialValues,MizerParams)
S3method(setInteraction,MizerParams)
S3method(setLinetypes,MizerParams)
S3method(setMaxIntakeRate,MizerParams)
S3method(setMetabolicRate,MizerParams)
S3method(setMetadata,MizerParams)
S3method(setParams,MizerParams)
S3method(setPredKernel,MizerParams)
S3method(setReproduction,MizerParams)
S3method(setResource,MizerParams)
S3method(setSearchVolume,MizerParams)
S3method(species_params,MizerParams)
S3method(steady,MizerParams)
S3method(steadySingleSpecies,MizerParams)
S3method(w,MizerParams)
S3method(w_full,MizerParams)
export("catchability<-")
export("diffusion<-")
export("ext_encounter<-")
Expand Down
16 changes: 16 additions & 0 deletions R/MizerParams-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,10 @@ emptyParams <- function(species_params,
#' # Summing to get total biomass
#' sum(biomass)
w <- function(params) {
UseMethod("w")
}
#' @export
w.MizerParams <- function(params) {
params@w
}

Expand All @@ -798,6 +802,10 @@ w <- function(params) {
#' the consumer spectrum.
#' @export
w_full <- function(params) {
UseMethod("w_full")
}
#' @export
w_full.MizerParams <- function(params) {
params@w_full
}

Expand All @@ -806,6 +814,10 @@ w_full <- function(params) {
#' consumer spectrum.
#' @export
dw <- function(params) {
UseMethod("dw")
}
#' @export
dw.MizerParams <- function(params) {
params@dw
}

Expand All @@ -814,6 +826,10 @@ dw <- function(params) {
#' resource spectrum.
#' @export
dw_full <- function(params) {
UseMethod("dw_full")
}
#' @export
dw_full.MizerParams <- function(params) {
params@dw_full
}

Expand Down
46 changes: 34 additions & 12 deletions R/age_mat.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,42 @@
#' missing. If `w_inf` is missing, `w_max` is used instead.
#'
#' @param object A MizerParams object or a species_params data frame
#' @param ... Additional arguments
#'
#' @return A named vector. The names are the species names and the values are
#' the ages at maturity.
#' @export
age_mat_vB <- function(object) {
if (is(object, "MizerParams")) {
sp <- object@species_params
} else {
if (!is.data.frame(object)) {
stop("The first argument must be either a MizerParams object or a species_params data frame.")
}
sp <- validSpeciesParams(object)
}
#' @rdname age_mat_vB
age_mat_vB <- function(object, ...) {
UseMethod("age_mat_vB")
}

#' @rdname age_mat_vB
#' @export
age_mat_vB.MizerParams <- function(object, ...) {
age_mat_vB.data.frame(object@species_params)
}

#' @rdname age_mat_vB
#' @export
age_mat_vB.data.frame <- function(object, ...) {
sp <- object
sp <- set_species_param_default(sp, "t0", 0)
sp <- set_species_param_default(sp, "b", 3)
sp <- set_species_param_default(sp, "k_vb", NA)
sp <- set_species_param_default(sp, "w_inf", sp$w_max)

a_mat <- -log(1 - (sp$w_mat / sp$w_inf) ^ (1/sp$b)) / sp$k_vb + sp$t0
a_mat <- -log(1 - (sp$w_mat / sp$w_inf)^(1 / sp$b)) / sp$k_vb + sp$t0
names(a_mat) <- sp$species
a_mat
}

#' @rdname age_mat_vB
#' @export
age_mat_vB.default <- function(object, ...) {
stop("The first argument must be either a MizerParams object or a species_params data frame.")
}

#' Calculate age at maturity
#'
#' Uses the growth rate and the size at maturity to calculate the age at
Expand All @@ -45,14 +59,22 @@ age_mat_vB <- function(object) {
#' \deqn{\mathrm{age_{mat}} = \int_0^{w_{mat}.}\frac{dw}{g(w)}}{age_mat = \int_0^w_mat 1/g(w) dw.}
#'
#' @param params A MizerParams object
#' @param ... Additional arguments
#'
#' @return A named vector. The names are the species names and the values are
#' the ages at maturity.
#' @export
#' @concept helper
#' @examples
#' age_mat(NS_params)
age_mat <- function(params) {
assert_that(is(params, "MizerParams"))
#' @rdname age_mat
#' @export
age_mat <- function(params, ...) {
UseMethod("age_mat")
}

#' @export
age_mat.MizerParams <- function(params, ...) {
sp <- params@species_params
no_sp <- nrow(sp)

Expand Down
32 changes: 19 additions & 13 deletions R/animateSpectra.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' `r lifecycle::badge("experimental")`
#'
#' @param sim A MizerSim object
#' @param species Name or vector of names of the species to be plotted. By
#' @param species Name or vector of names of the species to be plotted. By
#' default all species are plotted.
#' @param time_range The time range to animate over. Either a vector of values
#' or a vector of min and max time. Default is the entire time range of the
Expand All @@ -21,24 +21,29 @@
#' species in the system is plotted as well. Default is FALSE.
#' @param resource A boolean value that determines whether resource is included.
#' Default is TRUE.
#'
#' @param ... Additional arguments passed to the method.
#'
#' @return A plotly object
#' @export
#' @family plotting functions
#' @examples
#' \donttest{
#' animateSpectra(NS_sim, power = 2, wlim = c(0.1, NA), time_range = 1997:2007)
#' }
animateSpectra <- function(sim,
species = NULL,
time_range,
wlim = c(NA, NA),
ylim = c(NA, NA),
power = 1,
total = FALSE,
resource = TRUE) {
animateSpectra <- function(sim, species, time_range,
wlim,
ylim,
power,
total,
resource, ...)
UseMethod("animateSpectra")

#' @export
animateSpectra.MizerSim <- function(sim, species = NULL, time_range = NULL,
wlim = c(NA, NA), ylim = c(NA, NA),
power = 1, total = FALSE, resource = TRUE, ...) {
assert_that(is.flag(total), is.flag(resource),
is.number(power),
is.number(power),
length(wlim) == 2,
length(ylim) == 2)

Expand All @@ -47,7 +52,7 @@ animateSpectra <- function(sim,
time_range <- as.numeric(dimnames(sim@n)$time)
}
time_elements <- get_time_elements(sim, time_range)

nf <- melt(sim@n[time_elements,
as.character(dimnames(sim@n)$sp) %in% species,
, drop = FALSE])
Expand Down Expand Up @@ -90,7 +95,7 @@ animateSpectra <- function(sim,
value <= ylim[2],
w >= wlim[1],
w <= wlim[2])

# Order legend to follow params@species_params$species via linecolour order ----
# Keep only groups present in data, but preserve the order given by
# names(sim@params@linecolour) which follows params@species_params$species.
Expand Down Expand Up @@ -120,3 +125,4 @@ animateSpectra <- function(sim,
title = y_label),
legend = list(traceorder = "normal"))
}

Loading