diff --git a/DESCRIPTION b/DESCRIPTION index b9904fa0..e6fe30a5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,8 +25,6 @@ Imports: R6, loggr, crayon, - nleqslv, - BB, magrittr, tibble, rlang, @@ -46,7 +44,6 @@ Suggests: rmarkdown, markdown, bench, - dplyr, ggplot2, ggridges, patchwork, diff --git a/NAMESPACE b/NAMESPACE index a6004a41..b7fd528d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand S3method(resource_compensation_point,Plant) +S3method(validate,Parameters) export("%>%") export(Control) export(Disturbance_Regime) @@ -32,7 +33,6 @@ export(K93_Strategy) export(K93_fixed_environment) export(K93_hyperpar) export(K93_make_environment) -export(K93_test_environment) export(No_Disturbance) export(NodeSchedule) export(TF24_Environment) @@ -43,7 +43,6 @@ export(TF24_fixed_environment) export(TF24_generate_stand_report) export(TF24_hyperpar) export(TF24_make_environment) -export(TF24_test_environment) export(Weibull_Disturbance_Regime) export(build_schedule) export(environment_type) diff --git a/R/RcppR6.R b/R/RcppR6.R index 8a04fb2b..9e05c41f 100644 --- a/R/RcppR6.R +++ b/R/RcppR6.R @@ -1,6 +1,6 @@ ## Generated by RcppR6: do not edit by hand ## Version: 0.2.4 -## Hash: 1e61b714fa073aff744206eaac010b91 +## Hash: 1c60048bc1d88826061cc8bb250fbbc8 ##' @importFrom Rcpp evalCpp ##' @importFrom R6 R6Class @@ -5829,9 +5829,10 @@ StochasticPatchRunner <- function(T, E) { ret } -##' FF16_Environment object -##' @param light_availability_spline_rescale_usually whether to rescale intervals when estimating light environment +##' Create an FF16_Environment object. ##' @param soil_number_of_depths Number of soil layers to include +##' @param light_availability_spline_rescale_usually whether to rescale intervals when estimating light environment +##' @rdname FF16_Environment ##' @export `FF16_Environment` <- function(light_availability_spline_rescale_usually, soil_number_of_depths) { FF16_Environment__ctor(light_availability_spline_rescale_usually, soil_number_of_depths) @@ -5945,7 +5946,7 @@ StochasticPatchRunner <- function(T, E) { ret } -##' K93_Environment object +##' @rdname FF16_Environment ##' @export `K93_Environment` <- function() { K93_Environment__ctor() @@ -6066,9 +6067,7 @@ StochasticPatchRunner <- function(T, E) { ret } -##' TF24_Environment object -##' @param light_availability_spline_rescale_usually whether to rescale intervals when estimating light environment -##' @param soil_number_of_depths Number of soil layers to include +##' @rdname FF16_Environment ##' @export `TF24_Environment` <- function(light_availability_spline_rescale_usually, soil_number_of_depths) { TF24_Environment__ctor(light_availability_spline_rescale_usually, soil_number_of_depths) diff --git a/R/benchmark.R b/R/benchmark.R index 3cfd35f9..52bc329e 100644 --- a/R/benchmark.R +++ b/R/benchmark.R @@ -25,7 +25,8 @@ run_plant_benchmarks <- function(strategy_types = list(FF16 = FF16_Strategy, } message("Running benchmarks via `run_plant_benchmarks`") - bench::press(strategy = names(strategy_types), + strategy <- names(strategy_types) + bench::press(strategy = strategy, { bench::mark( check = FALSE, @@ -58,7 +59,8 @@ run_resource_consumption_benchmarks <- function(its = 10) { } message("Running resource consumption benchmarks`") - bench::press(soil_layers = c(1, 10, 50, 100), + soil_layers <- c(1, 10, 50, 100) + bench::press(soil_layers = soil_layers, { bench::mark( check = FALSE, diff --git a/R/ff16.R b/R/ff16.R index 6fc7f671..60abedbc 100644 --- a/R/ff16.R +++ b/R/ff16.R @@ -1,8 +1,8 @@ -##' Create a FF16 Plant or Node -##' @title Create a FF16 Plant or Node +##' Create a FF16 Individual +##' @title Create a FF16 Individual ##' @param s A \code{\link{FF16_Strategy}} object ##' @export -##' @rdname FF16 +##' @rdname FF16_individual ##' @examples ##' pl <- FF16_Individual() ##' pl$height @@ -10,21 +10,34 @@ FF16_Individual <- function(s=FF16_Strategy()) { Individual("FF16", "FF16_Env")(s) } +##' @title Setup an a model system with default or specified parameters +##' +##' @description Setup an a model system with default or specified parameters. +##' This function enables you initialize a model system. Use the model name to start different models. +##' @param ... Arguments to be passed to the model constructor. These include +##' +##' *`patch_area`: Area of idnividfual patch. Only relevant for stochastic model. Default is 1.0m2. +##' *`max_patch_lifetime`: The maximum time in years we want to simulate +##' *`strategies`: A list of stratgies to simulate. The default is an empty list. +##' *`strategy_default`: Values for the default startegy. The default values are those specified in the C++ code for the model. +##' *`node_schedule_times_default`: Default vector of times at which to introduce nodes. The default is chosen to have close spacing at the start of the simulation. +##' *`node_schedule_times`: A list with each element containing the vector of times we want to introduce nodes for each strategy. The default is an empty list. +##' *`ode_times`: A vector of patch ages we want the ode solver to stop at ##' @export -##' @rdname FF16 -FF16_Parameters <- function() { - Parameters("FF16","FF16_Env")() +##' @rdname FF16_Parameters +##' @examples +##' p1 <- FF16_Parameters() +##' p2 <- FF16_Parameters(max_patch_lifetime = 10.0, patch_area = 1.0, strategies = list(FF16_Strategy()), strategy_default = FF16_Strategy(), node_schedule_times_default = node_schedule_times_default(10.0), node_schedule_times = list(node_schedule_times_default(10.0)), ode_times = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) +FF16_Parameters <- function(...) { + Parameters("FF16","FF16_Env")(...) } - -## Helper to create FF16_environment object. Useful for running individuals -##' @title create FF16_environment object -##' @param light_availability_spline_tol -##' -##' @param light_availability_spline_nbase -##' @param light_availability_spline_max_depth -##' @param light_availability_spline_rescale_usually -##' +## Helper functions to create an XXX_Environment object. Useful for running individuals +##' @title create a model Environment object +##' @param light_availability_spline_tol Error tolerance of adpative spline method. Deafult is 1e-4. +##' @param light_availability_spline_nbase Parameter used in adaptive spline method. Default is 17. +##' @param light_availability_spline_max_depth Parameter used in adaptive spline method. Default is 16. +##' @inheritParams FF16_Environment ##' @export ##' @rdname FF16_make_environment FF16_make_environment <- function(light_availability_spline_tol = 1e-4, @@ -44,15 +57,16 @@ FF16_make_environment <- function(light_availability_spline_tol = 1e-4, return(e) } -##' Construct a fixed environment for FF16 strategy +##' Construct a fixed environment for a model ##' ##' @param e Value of environment (deafult = 1.0) -##' @param height_max = 150.0 maximum possible height in environment -##' @rdname FF16_Environment +##' @param height_max maximum possible height in environment +##' @param ... Additional parameters to be passed to \code{XXXX_make_environment}, where XXXX referes to model name. +##' @rdname FF16_fixed_environment ##' ##' @export -FF16_fixed_environment <- function(e=1.0, height_max = 150.0) { - env <- FF16_make_environment() +FF16_fixed_environment <- function(e=1.0, height_max = 150.0, ...) { + env <- FF16_make_environment(...) env$set_fixed_environment(e, height_max) env } @@ -165,7 +179,7 @@ FF16_generate_stand_report <- function(results, ##' @param latitude degrees from equator (0-90), used in solar model [deg] ##' @importFrom stats coef nls ##' @export -##' @rdname FF16_hyperpar +##' @rdname make_FF16_hyperpar make_FF16_hyperpar <- function( lma_0=0.1978791, B_kl1=0.4565855, @@ -349,5 +363,6 @@ make_FF16_hyperpar <- function( ##' @param s A strategy object ##' @param filter A flag indicating whether to filter columns. If TRUE, any numbers ##' that are within eps of the default strategy are not replaced. +##' @rdname FF16_hyperpar ##' @export FF16_hyperpar <- make_FF16_hyperpar() diff --git a/R/ff16r.R b/R/ff16r.R index c39dbf6a..bcdfea3c 100644 --- a/R/ff16r.R +++ b/R/ff16r.R @@ -4,7 +4,7 @@ ##' @title Create a FF16r Plant or Node ##' @param s A \code{\link{FF16r_Strategy}} object ##' @export -##' @rdname FF16r +##' @rdname FF16r_Individual ##' @examples ##' pl <- FF16r_Individual() ##' pl$height @@ -13,50 +13,17 @@ FF16r_Individual <- function(s=FF16r_Strategy()) { } ##' @export -##' @rdname FF16r +##' @rdname FF16_Parameters FF16r_Parameters <- function() { Parameters("FF16r","FF16_Env")() } -## Helper: ##' @export -##' @rdname FF16_Environment -##' @param light_availability_spline_rescale_usually turns on environment rescaling (default = TRUE) -FF16r_make_environment <- function(light_availability_spline_rescale_usually = TRUE) { - - FF16_make_environment(light_availability_spline_rescale_usually) -} - - -##' This makes a pretend light environment over the plant height, -##' slightly concave up, whatever. -##' @title Create a test environment for FF16r startegy -##' @param height top height of environment object -##' @param n number of points -##' @param light_env function for light environment in test object -##' @param n_strategies number of strategies for test environment -##' @rdname FF16r_test_environment -##' @examples -##' environment <- plant:::FF16r_test_environment(10) -FF16r_test_environment <- function(height, n=101, light_env=NULL, - n_strategies=1) { - hh <- seq(0, height, length.out=n) - if (is.null(light_env)) { - light_env <- function(x) { - exp(x/(height*2)) - 1 + (1 - (exp(.5) - 1))/2 - } - } - ee <- light_env(hh) - interpolator <- Interpolator() - interpolator$init(hh, ee) - - ret <- FF16r_make_environment() - ret$light_availability$spline <- interpolator - attr(ret, "light_env") <- light_env - ret -} - +##' @rdname FF16_make_environment +FF16r_make_environment <- FF16_make_environment +##' @rdname FF16_test_environment +FF16r_test_environment <- FF16_test_environment ##' Hyperparameters for FF16r physiological model ##' @title Hyperparameters for FF16r physiological model @@ -82,7 +49,6 @@ FF16r_test_environment <- function(height, n=101, light_env=NULL, ##' @param latitude degrees from equator (0-90), used in solar model [deg] ##' @importFrom stats coef nls ##' @export -##' @rdname FF16r_hyperpar make_FF16r_hyperpar <- function( lma_0=0.1978791, B_kl1=0.4565855, @@ -256,9 +222,6 @@ make_FF16r_hyperpar <- function( ##' Hyperparameter function for FF16r physiological model ##' @title Hyperparameter function for FF16r physiological model -##' @param m A matrix of trait values, as returned by \code{trait_matrix} -##' @param s A strategy object -##' @param filter A flag indicating whether to filter columns. If TRUE, any numbers -##' that are within eps of the default strategy are not replaced. +##' @inheritParams FF16_hyperpar ##' @export FF16r_hyperpar <- make_FF16r_hyperpar() diff --git a/R/ff16w.R b/R/ff16w.R index f3b4f2ca..5adc3ad2 100644 --- a/R/ff16w.R +++ b/R/ff16w.R @@ -17,11 +17,12 @@ FF16w_Parameters <- function() { } -## Helper: ##' @export -##' @rdname FF16_Environment +##' @inheritParams FF16_Environment ##' @param soil_number_of_depths the number of soil layers +##' @param soil_initial_state the initial state of the soil layers ##' @param rainfall constant function value for rainfall driver, y = rainfall +##' @rdname FF16_make_environment FF16w_make_environment <- function(light_availability_spline_tol = 1e-4, light_availability_spline_nbase = 17, light_availability_spline_max_depth = 16, @@ -70,7 +71,7 @@ FF16w_make_environment <- function(light_availability_spline_tol = 1e-4, ##' ##' @param e Value of environment (deafult = 1.0) ##' @param height_max = 150.0 maximum possible height in environment -##' @rdname FF16_Environment +##' @rdname FF16_fixed_environment ##' ##' @export FF16w_fixed_environment <- function(e=1.0, height_max = 150.0) { @@ -79,15 +80,7 @@ FF16w_fixed_environment <- function(e=1.0, height_max = 150.0) { env } - -##' This makes a pretend light environment over the plant height, -##' slightly concave up, whatever. -##' @title Create a test environment for FF16w startegy -##' @param height top height of environment object -##' @param n number of points -##' @param light_env function for light environment in test object -##' @param n_strategies number of strategies for test environment -##' @rdname FF16w_test_environment +##' @rdname FF16_test_environment ##' @examples ##' environment <- plant:::FF16w_test_environment(10) FF16w_test_environment <- function(height, diff --git a/R/individual.R b/R/individual.R index 8176192a..3c278460 100644 --- a/R/individual.R +++ b/R/individual.R @@ -240,17 +240,17 @@ resource_compensation_point.Plant <- function(p, ...) { #' The function `optimise_individual_rate_at_height_by_trait` and `optimise_individual_rate_at_size_by_trait` solve for the maximum of #' some rate (e.g. growth rate) at a specified height within #' the interval of the bounds of a given trait -#' @param type -#' @param bounds -#' @param log_scale -#' @param tol -#' @param size -#' @param size_name -#' @param rate -#' @param params -#' @param env -#' @param hyperpars -#' +#' @param type The type of model to use (e.g. "FF16"). Defaults to "FF16" +#' @param bounds A vector giving the lower and upper bounds of the trait +#' @param log_scale Should the trait be optimised on a log scale? Defaults to TRUE +#' @param tol The tolerance for the optimisation +#' @param size The size of the individual to optimise the rate at +#' @param size_name The name of the size variable specified by \code{size} +#' @param rate The name of the rate to optimise. Defaults to \code{size_name} +#' @param params The parameters of the model +#' @param env The environment of the model +#' @param hyperpars The hyperparameter function of the model +#' @param set_state_directly If TRUE, set the state directly to the size, otherwise grows the plant to that size. Defaults to FALSE #' @export #' @rdname optimise_individual_rate_at_size_by_trait #' @author Isaac Towers, Daniel Falster and Andrew O'Reilly-Nugent @@ -332,6 +332,8 @@ optimise_individual_rate_at_size_by_trait <- function( return(ret) } +##' @param height Heigh at which grow is optimsied. Defaults to 1 +##' @param ... Additional parameters passed to \code{optimise_individual_rate_at_size_by_trait} #' @export #' @rdname optimise_individual_rate_at_size_by_trait optimise_individual_rate_at_height_by_trait <- function(..., height = 1) { @@ -350,13 +352,13 @@ solve_max_worker <- function(bounds, f, tol = 1e-3, outcome) { ## NA/Inf replaced by maximum positive value ## ## which is probably the desired behaviour here. - out <- suppressWarnings(optimise(f, interval = bounds, maximum = TRUE, tol = tol)) + out <- suppressWarnings(stats::optimise(f, interval = bounds, maximum = TRUE, tol = tol)) # browser() ret <- out$maximum attr(ret, outcome) <- out$objective } else { ## This is not very well tested, and the tolerance is not useful: - out <- optim(rowMeans(bounds), f, + out <- stats::optim(rowMeans(bounds), f, method = "L-BFGS-B", lower = bounds[, "lower"], upper = bounds[, "upper"], control = list(fnscale = -1, factr = 1e10) diff --git a/R/k93.R b/R/k93.R index 84e6eefe..46036f54 100644 --- a/R/k93.R +++ b/R/k93.R @@ -4,7 +4,7 @@ ##' @title Create a K93 Individual or Node ##' @param s A \code{\link{K93_Strategy}} object ##' @export -##' @rdname K93 +##' @rdname K93_Individual ##' @examples ##' pl <- K93_Individual() ##' pl$height @@ -13,21 +13,13 @@ K93_Individual <- function(s=K93_Strategy()) { } ##' @export -##' @rdname K93 +##' @rdname FF16_Parameters K93_Parameters <- function() { Parameters("K93","K93_Env")() } - -## Helper to create K93_environment object. Useful for running individuals -##' create K93_environment object -##' @param light_availability_spline_tol -##' @param light_availability_spline_nbase -##' @param light_availability_spline_max_depth -##' @param light_availability_spline_rescale_usually -##' ##' @export -##' @rdname K93_make_environment +##' @rdname FF16_make_environment K93_make_environment <- function(light_availability_spline_tol = 1e-4, light_availability_spline_nbase = 17, light_availability_spline_max_depth = 16, @@ -47,29 +39,15 @@ K93_make_environment <- function(light_availability_spline_tol = 1e-4, return(e) } -##' Construct a fixed environment for K93 strategy -##' -##' @param e Value of environment (default=1.0) -##' @param height_max = 300.0 maximum possible height in environment -##' @rdname K93_Environment -##' +##' @rdname FF16_fixed_environment ##' @export -K93_fixed_environment <- function(e=1.0, height_max = 300.0) { - env <- K93_make_environment() +K93_fixed_environment <- function(e=1.0, height_max = 300.0, ...) { + env <- K93_make_environment(...) env$set_fixed_environment(e, height_max) env } - -##' This makes a pretend light environment over the plant height, -##' slightly concave up, whatever. -##' @title Create a test environment for K93 startegy -##' @param height top height of environment object -##' @param n number of points -##' @param light_env function for light environment in test object -##' @param n_strategies number of strategies for test environment -##' @export -##' @rdname K93_test_environment +##' @rdname FF16_test_environment ##' @examples ##' environment <- plant:::K93_test_environment(10) K93_test_environment <- function(height, n=101, light_env=NULL, @@ -86,10 +64,6 @@ K93_test_environment <- function(height, n=101, light_env=NULL, interpolator <- Interpolator() interpolator$init(hh, ee) - # parameters <- K93_Parameters() - # parameters$strategies <- rep(list(K93_Strategy()), n_strategies) - # - ret <- K93_make_environment() ret$light_availability$spline <- interpolator attr(ret, "light_env") <- light_env @@ -108,7 +82,6 @@ K93_test_environment <- function(height, n=101, light_env=NULL, ##' @param eta Crown shape parameter ##' @param k_I Extinction coefficient used when estimating competitive effect ##' @export -##' @rdname make_K93_hyperpar make_K93_hyperpar <- function( b_0 = 0.059, # Growth intercept year-1 b_1 = 0.012, # Growth asymptote year-1.(ln cm)-1 @@ -150,10 +123,6 @@ make_K93_hyperpar <- function( ##' Hyperparameter function for K93 physiological model ##' @title Hyperparameter function for K93 physiological model -##' @param m A matrix of trait values, as returned by \code{trait_matrix} -##' @param s A strategy object -##' @param filter A flag indicating whether to filter columns. If TRUE, any numbers -##' that are within eps of the default strategy are not replaced. -##' @rdname K93_hyperpar +##' @inheritParams FF16_hyperpar ##' @export K93_hyperpar <- make_K93_hyperpar() diff --git a/R/stochastic.R b/R/stochastic.R index 320dedf3..fd2c201a 100644 --- a/R/stochastic.R +++ b/R/stochastic.R @@ -44,7 +44,7 @@ stochastic_schedule <- function(p) { max_time <- p$max_patch_lifetime n_species <- length(p$strategies) - sched <- plant:::NodeSchedule(n_species) + sched <- NodeSchedule(n_species) sched$max_time <- max_time for (i in 1:n_species) { diff --git a/R/tf24.R b/R/tf24.R index a377a2e0..ec2e4571 100644 --- a/R/tf24.R +++ b/R/tf24.R @@ -3,7 +3,7 @@ ##' @title Create a TF24 Plant or Node ##' @param s A \code{\link{TF24_Strategy}} object ##' @export -##' @rdname TF24 +##' @rdname TF24_Individual ##' @examples ##' pl <- TF24_Individual() ##' pl$height @@ -12,21 +12,17 @@ TF24_Individual <- function(s=TF24_Strategy()) { } ##' @export -##' @rdname TF24 -TF24_Parameters <- function() { - Parameters("TF24","TF24_Env")() +##' @rdname FF16_Parameters +##' @examples +##' p1 <- TF24_Parameters() +##' p2 <- TF24_Parameters(max_patch_lifetime = 10.0) +TF24_Parameters <- function(...) { + Parameters("TF24","TF24_Env")(...) } -## Helper to create TF24_environment object. Useful for running individuals -##' @title create TF24_environment object -##' @param light_availability_spline_tol -##' -##' @param light_availability_spline_nbase -##' @param light_availability_spline_max_depth -##' @param light_availability_spline_rescale_usually -##' +##' @inheritParams FF16_make_environment ##' @export -##' @rdname TF24_make_environment +##' @rdname FF16_make_environment TF24_make_environment <- function(light_availability_spline_tol = 1e-4, light_availability_spline_nbase = 17, light_availability_spline_max_depth = 16, @@ -44,29 +40,16 @@ TF24_make_environment <- function(light_availability_spline_tol = 1e-4, return(e) } -##' Construct a fixed environment for TF24 strategy -##' -##' @param e Value of environment (deafult = 1.0) -##' @param height_max = 150.0 maximum possible height in environment -##' @rdname TF24_Environment +##' @rdname FF16_fixed_environment ##' ##' @export -TF24_fixed_environment <- function(e=1.0, height_max = 150.0) { - env <- TF24_make_environment() +TF24_fixed_environment <- function(e=1.0, height_max = 150.0, ...) { + env <- TF24_make_environment(...) env$set_fixed_environment(e, height_max) env } - -##' This makes a pretend light environment over the plant height, -##' slightly concave up, whatever. -##' @title Create a test environment for TF24 startegy -##' @param height top height of environment object -##' @param n number of points -##' @param light_env function for light environment in test object -##' @param n_strategies number of strategies for test environment -##' @export -##' @rdname TF24_test_environment +##' @rdname FF16_test_environment ##' @examples ##' environment <- plant:::TF24_test_environment(10) TF24_test_environment <- function(height, n=101, light_env=NULL, @@ -166,7 +149,6 @@ TF24_generate_stand_report <- function(results, ##' @param latitude degrees from equator (0-90), used in solar model [deg] ##' @importFrom stats coef nls ##' @export -##' @rdname TF24_hyperpar make_TF24_hyperpar <- function( lma_0=0.1978791, B_kl1=0.4565855, @@ -346,9 +328,6 @@ make_TF24_hyperpar <- function( ##' Hyperparameter function for TF24 physiological model ##' @title Hyperparameter function for TF24 physiological model -##' @param m A matrix of trait values, as returned by \code{trait_matrix} -##' @param s A strategy object -##' @param filter A flag indicating whether to filter columns. If TRUE, any numbers -##' that are within eps of the default strategy are not replaced. +##' @inheritParams FF16_hyperpar ##' @export TF24_hyperpar <- make_TF24_hyperpar() diff --git a/R/tidy_outputs.R b/R/tidy_outputs.R index 353c5b0b..149945c4 100644 --- a/R/tidy_outputs.R +++ b/R/tidy_outputs.R @@ -196,7 +196,7 @@ tidy_individual <- function(results) { integrate_over_size_distribution <- function(tidy_species_data) { tidy_species_data %>% - dplyr::select(-node) %>% stats::na.omit() %>% + dplyr::select(-dplyr::any_of("node")) %>% stats::na.omit() %>% dplyr::filter(.data$step > 1) %>% dplyr::group_by(.data$step, .data$time, .data$patch_density, .data$species) %>% dplyr::reframe( diff --git a/R/util.R b/R/util.R index 3360332f..23faa8f9 100644 --- a/R/util.R +++ b/R/util.R @@ -93,6 +93,7 @@ validate <- function(x, ...) { UseMethod("validate") } +##' @export `validate.Parameters` <- function(x, ...) { plant <- parent.env(environment()) ## TODO: This uses an implementation detail of RcppR6 that is not diff --git a/R/util_model.R b/R/util_model.R index 32671cd5..d81be353 100644 --- a/R/util_model.R +++ b/R/util_model.R @@ -81,7 +81,7 @@ expand_parameters <- function(trait_matrix, p, hyperpar=param_hyperpar(p), birth if(nrow(trait_matrix) != length(birth_rate_list)) { stop("Must provide exactly one birth rate input for each species") } - extra <- plant:::strategy_list(trait_matrix, p, hyperpar, birth_rate_list) + extra <- strategy_list(trait_matrix, p, hyperpar, birth_rate_list) n_extra <- length(extra) ret <- p <- validate(p) # Ensure times are set up correctly. @@ -110,6 +110,7 @@ expand_parameters <- function(trait_matrix, p, hyperpar=param_hyperpar(p), birth } ##' @export +##' @param ... Arguments to \code{\link{expand_parameters}} ##' @rdname expand_parameters mutant_parameters <- function(..., keep_existing_strategies = FALSE) { expand_parameters(..., keep_existing_strategies = keep_existing_strategies) diff --git a/inst/RcppR6_classes.yml b/inst/RcppR6_classes.yml index 1f4e1750..7fa3d50b 100644 --- a/inst/RcppR6_classes.yml +++ b/inst/RcppR6_classes.yml @@ -392,7 +392,6 @@ Node: return_type: void args: [environment: E, pr_patch_survival: double, birth_rate: double] -# For now, also not templated Species: name_cpp: "plant::Species" templates: @@ -877,9 +876,10 @@ FF16_Environment: - light_availability_spline_rescale_usually: bool - soil_number_of_depths: int roxygen: | - FF16_Environment object - @param light_availability_spline_rescale_usually whether to rescale intervals when estimating light environment + Create an FF16_Environment object. @param soil_number_of_depths Number of soil layers to include + @param light_availability_spline_rescale_usually whether to rescale intervals when estimating light environment + @rdname FF16_Environment @export methods: get_environment_at_height: @@ -990,8 +990,9 @@ K93_Environment: name_cpp: "plant::K93_Environment" constructor: roxygen: | - K93_Environment object + @rdname FF16_Environment @export + methods: get_environment_at_height: args: [height: double] @@ -1132,9 +1133,7 @@ TF24_Environment: - light_availability_spline_rescale_usually: bool - soil_number_of_depths: int roxygen: | - TF24_Environment object - @param light_availability_spline_rescale_usually whether to rescale intervals when estimating light environment - @param soil_number_of_depths Number of soil layers to include + @rdname FF16_Environment @export methods: get_environment_at_height: diff --git a/man/FF16_Environment.Rd b/man/FF16_Environment.Rd index 520e01f0..a23834a6 100644 --- a/man/FF16_Environment.Rd +++ b/man/FF16_Environment.Rd @@ -1,46 +1,28 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RcppR6.R, R/ff16.R, R/ff16r.R, R/ff16w.R +% Please edit documentation in R/RcppR6.R \name{FF16_Environment} \alias{FF16_Environment} -\alias{FF16_fixed_environment} -\alias{FF16r_make_environment} -\alias{FF16w_make_environment} -\alias{FF16w_fixed_environment} -\title{FF16_Environment object} +\alias{K93_Environment} +\alias{TF24_Environment} +\title{Create an FF16_Environment object.} \usage{ -FF16_Environment(light_availability_spline_rescale_usually, soil_number_of_depths) - -FF16_fixed_environment(e = 1, height_max = 150) +FF16_Environment( + light_availability_spline_rescale_usually, + soil_number_of_depths +) -FF16r_make_environment(light_availability_spline_rescale_usually = TRUE) +K93_Environment() -FF16w_make_environment( - light_availability_spline_tol = 1e-04, - light_availability_spline_nbase = 17, - light_availability_spline_max_depth = 16, - light_availability_spline_rescale_usually = TRUE, - soil_number_of_depths = 1, - soil_initial_state = 0, - rainfall = 1 +TF24_Environment( + light_availability_spline_rescale_usually, + soil_number_of_depths ) - -FF16w_fixed_environment(e = 1, height_max = 150) } \arguments{ -\item{light_availability_spline_rescale_usually}{turns on environment rescaling (default = TRUE)} - -\item{soil_number_of_depths}{the number of soil layers} +\item{light_availability_spline_rescale_usually}{whether to rescale intervals when estimating light environment} -\item{e}{Value of environment (deafult = 1.0)} - -\item{height_max}{= 150.0 maximum possible height in environment} - -\item{rainfall}{constant function value for rainfall driver, y = rainfall} +\item{soil_number_of_depths}{Number of soil layers to include} } \description{ -FF16_Environment object - -Construct a fixed environment for FF16 strategy - -Construct a fixed environment for FF16w strategy +Create an FF16_Environment object. } diff --git a/man/FF16_Parameters.Rd b/man/FF16_Parameters.Rd new file mode 100644 index 00000000..8bbab96a --- /dev/null +++ b/man/FF16_Parameters.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ff16.R, R/ff16r.R, R/k93.R, R/tf24.R +\name{FF16_Parameters} +\alias{FF16_Parameters} +\alias{FF16r_Parameters} +\alias{K93_Parameters} +\alias{TF24_Parameters} +\title{Setup an a model system with default or specified parameters} +\usage{ +FF16_Parameters(...) + +FF16r_Parameters() + +K93_Parameters() + +TF24_Parameters(...) +} +\arguments{ +\item{...}{Arguments to be passed to the model constructor. These include + + *`patch_area`: Area of idnividfual patch. Only relevant for stochastic model. Default is 1.0m2. + *`max_patch_lifetime`: The maximum time in years we want to simulate + *`strategies`: A list of stratgies to simulate. The default is an empty list. + *`strategy_default`: Values for the default startegy. The default values are those specified in the C++ code for the model. + *`node_schedule_times_default`: Default vector of times at which to introduce nodes. The default is chosen to have close spacing at the start of the simulation. + *`node_schedule_times`: A list with each element containing the vector of times we want to introduce nodes for each strategy. The default is an empty list. + *`ode_times`: A vector of patch ages we want the ode solver to stop at} +} +\description{ +Setup an a model system with default or specified parameters. +This function enables you initialize a model system. Use the model name to start different models. +} +\examples{ +p1 <- FF16_Parameters() +p2 <- FF16_Parameters(max_patch_lifetime = 10.0, patch_area = 1.0, strategies = list(FF16_Strategy()), strategy_default = FF16_Strategy(), node_schedule_times_default = node_schedule_times_default(10.0), node_schedule_times = list(node_schedule_times_default(10.0)), ode_times = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) +p1 <- TF24_Parameters() +p2 <- TF24_Parameters(max_patch_lifetime = 10.0) +} diff --git a/man/FF16_fixed_environment.Rd b/man/FF16_fixed_environment.Rd new file mode 100644 index 00000000..7ae14961 --- /dev/null +++ b/man/FF16_fixed_environment.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ff16.R, R/ff16w.R, R/k93.R, R/tf24.R +\name{FF16_fixed_environment} +\alias{FF16_fixed_environment} +\alias{FF16w_fixed_environment} +\alias{K93_fixed_environment} +\alias{TF24_fixed_environment} +\title{Construct a fixed environment for a model} +\usage{ +FF16_fixed_environment(e = 1, height_max = 150, ...) + +FF16w_fixed_environment(e = 1, height_max = 150) + +K93_fixed_environment(e = 1, height_max = 300, ...) + +TF24_fixed_environment(e = 1, height_max = 150, ...) +} +\arguments{ +\item{e}{Value of environment (deafult = 1.0)} + +\item{height_max}{= 150.0 maximum possible height in environment} + +\item{...}{Additional parameters to be passed to \code{XXXX_make_environment}, where XXXX referes to model name.} +} +\description{ +Construct a fixed environment for a model + +Construct a fixed environment for FF16w strategy +} diff --git a/man/FF16_hyperpar.Rd b/man/FF16_hyperpar.Rd index a15feb37..643bf771 100644 --- a/man/FF16_hyperpar.Rd +++ b/man/FF16_hyperpar.Rd @@ -1,76 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/ff16.R -\name{make_FF16_hyperpar} -\alias{make_FF16_hyperpar} +\name{FF16_hyperpar} \alias{FF16_hyperpar} -\title{Hyperparameters for FF16 physiological model} +\title{Hyperparameter function for FF16 physiological model} \usage{ -make_FF16_hyperpar( - lma_0 = 0.1978791, - B_kl1 = 0.4565855, - B_kl2 = 1.71, - rho_0 = 608, - B_dI1 = 0.01, - B_dI2 = 0, - B_ks1 = 0.2, - B_ks2 = 0, - B_rs1 = 4012, - B_rb1 = 2 * 4012, - B_f1 = 3, - narea = 0.00187, - narea_0 = 0.00187, - B_lf1 = 5120.738 * 0.00187 * 24 * 3600/1e+06, - B_lf2 = 0.5, - B_lf3 = 0.04, - B_lf4 = 21000, - B_lf5 = 1, - k_I = 0.5, - latitude = 0 -) - FF16_hyperpar(m, s, filter = TRUE) } \arguments{ -\item{lma_0}{Central (mean) value for leaf mass per area [kg /m2]} - -\item{B_kl1}{Rate of leaf turnover at lma_0 [/yr]} - -\item{B_kl2}{Scaling slope for phi in leaf turnover [dimensionless]} - -\item{rho_0}{Central (mean) value for wood density [kg /m3]} - -\item{B_dI1}{Rate of instantaneous mortality at rho_0 [/yr]} - -\item{B_dI2}{Scaling slope for wood density in intrinsic mortality [dimensionless]} - -\item{B_ks1}{Rate of sapwood turnover at rho_0 [/yr]} - -\item{B_ks2}{Scaling slope for rho in sapwood turnover [dimensionless]} - -\item{B_rs1}{CO_2 respiration per unit sapwood volume [mol / yr / m3 ]} - -\item{B_rb1}{CO_2 respiration per unit sapwood volume [mol / yr / m3 ]} - -\item{B_f1}{Cost of seed accessories per unit seed mass [dimensionless]} - -\item{narea}{nitrogen per leaf area [kg / m2]} - -\item{narea_0}{central (mean) value for nitrogen per leaf area [kg / m2]} - -\item{B_lf1}{Potential CO_2 photosynthesis at average leaf nitrogen [mol / d / m2]} - -\item{B_lf2}{Curvature of leaf photosynthetic light response curve [dimensionless]} - -\item{B_lf3}{Quantum yield of leaf photosynthetic light response curve [dimensionless]} - -\item{B_lf4}{CO_2 respiration per unit leaf nitrogen [mol / yr / kg]} - -\item{B_lf5}{Scaling exponent for leaf nitrogen in maximum leaf photosynthesis [dimensionless]} - -\item{k_I}{light extinction coefficient [dimensionless]} - -\item{latitude}{degrees from equator (0-90), used in solar model [deg]} - \item{m}{A matrix of trait values, as returned by \code{trait_matrix}} \item{s}{A strategy object} @@ -79,7 +15,5 @@ FF16_hyperpar(m, s, filter = TRUE) that are within eps of the default strategy are not replaced.} } \description{ -Hyperparameters for FF16 physiological model - Hyperparameter function for FF16 physiological model } diff --git a/man/FF16.Rd b/man/FF16_individual.Rd similarity index 64% rename from man/FF16.Rd rename to man/FF16_individual.Rd index e61e6215..a8bacebe 100644 --- a/man/FF16.Rd +++ b/man/FF16_individual.Rd @@ -1,19 +1,16 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in r/ff16.R +% Please edit documentation in R/ff16.R \name{FF16_Individual} \alias{FF16_Individual} -\alias{FF16_Parameters} -\title{Create a FF16 Plant or Node} +\title{Create a FF16 Individual} \usage{ FF16_Individual(s = FF16_Strategy()) - -FF16_Parameters() } \arguments{ \item{s}{A \code{\link{FF16_Strategy}} object} } \description{ -Create a FF16 Plant or Node +Create a FF16 Individual } \examples{ pl <- FF16_Individual() diff --git a/man/FF16_make_environment.Rd b/man/FF16_make_environment.Rd index 4fa2a1b0..6b80fc6b 100644 --- a/man/FF16_make_environment.Rd +++ b/man/FF16_make_environment.Rd @@ -1,8 +1,12 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ff16.R +% Please edit documentation in R/ff16.R, R/ff16r.R, R/ff16w.R, R/k93.R, R/tf24.R \name{FF16_make_environment} \alias{FF16_make_environment} -\title{create FF16_environment object} +\alias{FF16r_make_environment} +\alias{FF16w_make_environment} +\alias{K93_make_environment} +\alias{TF24_make_environment} +\title{create a model Environment object} \usage{ FF16_make_environment( light_availability_spline_tol = 1e-04, @@ -10,16 +14,53 @@ FF16_make_environment( light_availability_spline_max_depth = 16, light_availability_spline_rescale_usually = TRUE ) + +FF16r_make_environment( + light_availability_spline_tol = 1e-04, + light_availability_spline_nbase = 17, + light_availability_spline_max_depth = 16, + light_availability_spline_rescale_usually = TRUE +) + +FF16w_make_environment( + light_availability_spline_tol = 1e-04, + light_availability_spline_nbase = 17, + light_availability_spline_max_depth = 16, + light_availability_spline_rescale_usually = TRUE, + soil_number_of_depths = 1, + soil_initial_state = 0, + rainfall = 1 +) + +K93_make_environment( + light_availability_spline_tol = 1e-04, + light_availability_spline_nbase = 17, + light_availability_spline_max_depth = 16, + light_availability_spline_rescale_usually = TRUE +) + +TF24_make_environment( + light_availability_spline_tol = 1e-04, + light_availability_spline_nbase = 17, + light_availability_spline_max_depth = 16, + light_availability_spline_rescale_usually = TRUE +) } \arguments{ -\item{light_availability_spline_tol}{} +\item{light_availability_spline_tol}{Error tolerance of adpative spline method. Deafult is 1e-4.} + +\item{light_availability_spline_nbase}{Parameter used in adaptive spline method. Default is 17.} + +\item{light_availability_spline_max_depth}{Parameter used in adaptive spline method. Default is 16.} + +\item{light_availability_spline_rescale_usually}{whether to rescale intervals when estimating light environment} -\item{light_availability_spline_nbase}{} +\item{soil_number_of_depths}{the number of soil layers} -\item{light_availability_spline_max_depth}{} +\item{soil_initial_state}{the initial state of the soil layers} -\item{light_availability_spline_rescale_usually}{} +\item{rainfall}{constant function value for rainfall driver, y = rainfall} } \description{ -create FF16_environment object +create a model Environment object } diff --git a/man/FF16_test_environment.Rd b/man/FF16_test_environment.Rd index 5d28420f..1045089e 100644 --- a/man/FF16_test_environment.Rd +++ b/man/FF16_test_environment.Rd @@ -1,10 +1,22 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ff16.R +% Please edit documentation in R/ff16.R, R/ff16r.R, R/ff16w.R, R/k93.R, R/tf24.R \name{FF16_test_environment} \alias{FF16_test_environment} +\alias{FF16r_test_environment} +\alias{FF16w_test_environment} +\alias{K93_test_environment} +\alias{TF24_test_environment} \title{Create a test environment for FF16 startegy} \usage{ FF16_test_environment(height, n = 101, light_env = NULL, n_strategies = 1) + +FF16r_test_environment(height, n = 101, light_env = NULL, n_strategies = 1) + +FF16w_test_environment(height, n = 101, light_env = NULL, n_strategies = 1) + +K93_test_environment(height, n = 101, light_env = NULL, n_strategies = 1) + +TF24_test_environment(height, n = 101, light_env = NULL, n_strategies = 1) } \arguments{ \item{height}{top height of environment object} @@ -21,4 +33,7 @@ slightly concave up, whatever. } \examples{ environment <- plant:::FF16_test_environment(10) +environment <- plant:::FF16w_test_environment(10) +environment <- plant:::K93_test_environment(10) +environment <- plant:::TF24_test_environment(10) } diff --git a/man/FF16r.Rd b/man/FF16r_Individual.Rd similarity index 79% rename from man/FF16r.Rd rename to man/FF16r_Individual.Rd index 9758dfd9..ae47de71 100644 --- a/man/FF16r.Rd +++ b/man/FF16r_Individual.Rd @@ -1,13 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in r/ff16r.R +% Please edit documentation in R/ff16r.R \name{FF16r_Individual} \alias{FF16r_Individual} -\alias{FF16r_Parameters} \title{Create a FF16r Plant or Node} \usage{ FF16r_Individual(s = FF16r_Strategy()) - -FF16r_Parameters() } \arguments{ \item{s}{A \code{\link{FF16r_Strategy}} object} diff --git a/man/FF16r_hyperpar.Rd b/man/FF16r_hyperpar.Rd index 640ae0ec..bade7cd8 100644 --- a/man/FF16r_hyperpar.Rd +++ b/man/FF16r_hyperpar.Rd @@ -1,76 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/ff16r.R -\name{make_FF16r_hyperpar} -\alias{make_FF16r_hyperpar} +\name{FF16r_hyperpar} \alias{FF16r_hyperpar} -\title{Hyperparameters for FF16r physiological model} +\title{Hyperparameter function for FF16r physiological model} \usage{ -make_FF16r_hyperpar( - lma_0 = 0.1978791, - B_kl1 = 0.4565855, - B_kl2 = 1.71, - rho_0 = 608, - B_dI1 = 0.01, - B_dI2 = 0, - B_ks1 = 0.2, - B_ks2 = 0, - B_rs1 = 4012, - B_rb1 = 2 * 4012, - B_f1 = 3, - narea = 0.00187, - narea_0 = 0.00187, - B_lf1 = 5120.738 * 0.00187 * 24 * 3600/1e+06, - B_lf2 = 0.5, - B_lf3 = 0.04, - B_lf4 = 21000, - B_lf5 = 1, - k_I = 0.5, - latitude = 0 -) - FF16r_hyperpar(m, s, filter = TRUE) } \arguments{ -\item{lma_0}{Central (mean) value for leaf mass per area [kg /m2]} - -\item{B_kl1}{Rate of leaf turnover at lma_0 [/yr]} - -\item{B_kl2}{Scaling slope for phi in leaf turnover [dimensionless]} - -\item{rho_0}{Central (mean) value for wood density [kg /m3]} - -\item{B_dI1}{Rate of instantaneous mortality at rho_0 [/yr]} - -\item{B_dI2}{Scaling slope for wood density in intrinsic mortality [dimensionless]} - -\item{B_ks1}{Rate of sapwood turnover at rho_0 [/yr]} - -\item{B_ks2}{Scaling slope for rho in sapwood turnover [dimensionless]} - -\item{B_rs1}{CO_2 respiration per unit sapwood volume [mol / yr / m3 ]} - -\item{B_rb1}{CO_2 respiration per unit sapwood volume [mol / yr / m3 ]} - -\item{B_f1}{Cost of seed accessories per unit seed mass [dimensionless]} - -\item{narea}{nitrogen per leaf area [kg / m2]} - -\item{narea_0}{central (mean) value for nitrogen per leaf area [kg / m2]} - -\item{B_lf1}{Potential CO_2 photosynthesis at average leaf nitrogen [mol / d / m2]} - -\item{B_lf2}{Curvature of leaf photosynthetic light response curve [dimensionless]} - -\item{B_lf3}{Quantum yield of leaf photosynthetic light response curve [dimensionless]} - -\item{B_lf4}{CO_2 respiration per unit leaf nitrogen [mol / yr / kg]} - -\item{B_lf5}{Scaling exponent for leaf nitrogen in maximum leaf photosynthesis [dimensionless]} - -\item{k_I}{light extinction coefficient [dimensionless]} - -\item{latitude}{degrees from equator (0-90), used in solar model [deg]} - \item{m}{A matrix of trait values, as returned by \code{trait_matrix}} \item{s}{A strategy object} @@ -79,7 +15,5 @@ FF16r_hyperpar(m, s, filter = TRUE) that are within eps of the default strategy are not replaced.} } \description{ -Hyperparameters for FF16r physiological model - Hyperparameter function for FF16r physiological model } diff --git a/man/FF16r_test_environment.Rd b/man/FF16r_test_environment.Rd deleted file mode 100644 index f96fa79a..00000000 --- a/man/FF16r_test_environment.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ff16r.R -\name{FF16r_test_environment} -\alias{FF16r_test_environment} -\title{Create a test environment for FF16r startegy} -\usage{ -FF16r_test_environment(height, n = 101, light_env = NULL, n_strategies = 1) -} -\arguments{ -\item{height}{top height of environment object} - -\item{n}{number of points} - -\item{light_env}{function for light environment in test object} - -\item{n_strategies}{number of strategies for test environment} -} -\description{ -This makes a pretend light environment over the plant height, -slightly concave up, whatever. -} -\examples{ -environment <- plant:::FF16r_test_environment(10) -} diff --git a/man/FF16w.Rd b/man/FF16w.Rd index d7bc9269..f1ad71c2 100644 --- a/man/FF16w.Rd +++ b/man/FF16w.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in r/ff16w.R +% Please edit documentation in R/ff16w.R \name{FF16w_Individual} \alias{FF16w_Individual} \alias{FF16w_Parameters} diff --git a/man/FF16w_test_environment.Rd b/man/FF16w_test_environment.Rd deleted file mode 100644 index bcea3401..00000000 --- a/man/FF16w_test_environment.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ff16w.R -\name{FF16w_test_environment} -\alias{FF16w_test_environment} -\title{Create a test environment for FF16w startegy} -\usage{ -FF16w_test_environment(height, n = 101, light_env = NULL, n_strategies = 1) -} -\arguments{ -\item{height}{top height of environment object} - -\item{n}{number of points} - -\item{light_env}{function for light environment in test object} - -\item{n_strategies}{number of strategies for test environment} -} -\description{ -This makes a pretend light environment over the plant height, -slightly concave up, whatever. -} -\examples{ -environment <- plant:::FF16w_test_environment(10) -} diff --git a/man/K93_Environment.Rd b/man/K93_Environment.Rd deleted file mode 100644 index f9149b67..00000000 --- a/man/K93_Environment.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RcppR6.R, R/k93.R -\name{K93_Environment} -\alias{K93_Environment} -\alias{K93_fixed_environment} -\title{K93_Environment object} -\usage{ -K93_Environment() - -K93_fixed_environment(e = 1, height_max = 300) -} -\arguments{ -\item{e}{Value of environment (default=1.0)} - -\item{height_max}{= 300.0 maximum possible height in environment} -} -\description{ -K93_Environment object - -Construct a fixed environment for K93 strategy -} diff --git a/man/K93.Rd b/man/K93_Individual.Rd similarity index 80% rename from man/K93.Rd rename to man/K93_Individual.Rd index b5f9d758..a7ba507f 100644 --- a/man/K93.Rd +++ b/man/K93_Individual.Rd @@ -1,13 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in r/k93.R +% Please edit documentation in R/k93.R \name{K93_Individual} \alias{K93_Individual} -\alias{K93_Parameters} \title{Create a K93 Individual or Node} \usage{ K93_Individual(s = K93_Strategy()) - -K93_Parameters() } \arguments{ \item{s}{A \code{\link{K93_Strategy}} object} diff --git a/man/K93_make_environment.Rd b/man/K93_make_environment.Rd deleted file mode 100644 index 2ae210e3..00000000 --- a/man/K93_make_environment.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/k93.R -\name{K93_make_environment} -\alias{K93_make_environment} -\title{create K93_environment object} -\usage{ -K93_make_environment( - light_availability_spline_tol = 1e-04, - light_availability_spline_nbase = 17, - light_availability_spline_max_depth = 16, - light_availability_spline_rescale_usually = TRUE -) -} -\arguments{ -\item{light_availability_spline_tol}{} - -\item{light_availability_spline_rescale_usually}{} -} -\description{ -create K93_environment object -} diff --git a/man/K93_test_environment.Rd b/man/K93_test_environment.Rd deleted file mode 100644 index ce7fd81b..00000000 --- a/man/K93_test_environment.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/k93.R -\name{K93_test_environment} -\alias{K93_test_environment} -\title{Create a test environment for K93 startegy} -\usage{ -K93_test_environment(height, n = 101, light_env = NULL, n_strategies = 1) -} -\arguments{ -\item{height}{top height of environment object} - -\item{n}{number of points} - -\item{light_env}{function for light environment in test object} - -\item{n_strategies}{number of strategies for test environment} -} -\description{ -This makes a pretend light environment over the plant height, -slightly concave up, whatever. -} -\examples{ -environment <- plant:::K93_test_environment(10) -} diff --git a/man/TF24_Individual.Rd b/man/TF24_Individual.Rd new file mode 100644 index 00000000..3711c34a --- /dev/null +++ b/man/TF24_Individual.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tf24.R +\name{TF24_Individual} +\alias{TF24_Individual} +\title{Create a TF24 Plant or Node} +\usage{ +TF24_Individual(s = TF24_Strategy()) +} +\arguments{ +\item{s}{A \code{\link{TF24_Strategy}} object} +} +\description{ +Create a TF24 Plant or Node +} +\examples{ +pl <- TF24_Individual() +pl$height +} diff --git a/man/TF24_Strategy.Rd b/man/TF24_Strategy.Rd new file mode 100644 index 00000000..5b36c740 --- /dev/null +++ b/man/TF24_Strategy.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppR6.R +\name{TF24_Strategy} +\alias{TF24_Strategy} +\title{Strategy parameters} +\usage{ +TF24_Strategy(..., values = list(...)) +} +\arguments{ +\item{..., values}{Values to initialise the struct with (either as +variadic arguments, or as a list, but not both).} +} +\description{ +Strategy parameters that tune various aspects of the biological model. +} diff --git a/man/TF24_generate_stand_report.Rd b/man/TF24_generate_stand_report.Rd new file mode 100644 index 00000000..a6d23cd5 --- /dev/null +++ b/man/TF24_generate_stand_report.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tf24.R +\name{TF24_generate_stand_report} +\alias{TF24_generate_stand_report} +\title{Generates a report on stand grown with TF24 strategy} +\usage{ +TF24_generate_stand_report( + results, + output_file = "TF24_report.html", + overwrite = FALSE, + target_ages = NA, + input_file = system.file("reports", "TF24_report.Rmd", package = "plant"), + quiet = TRUE +) +} +\arguments{ +\item{results}{results of runnning \code{run_scm_collect}} + +\item{output_file}{name of output file} + +\item{overwrite}{logical value to determine whether to overwrite existing report} + +\item{target_ages}{Patches ages at which to make plots} + +\item{input_file}{report script (.Rmd) file to build study report} + +\item{quiet}{An option to suppress printing during rendering from knitr, pandoc command line and others.} +} +\value{ +html file of the rendered report located in the specified output folder. +} +\description{ +Builds a detailed report on stand grown with TF24 strategy, based on the template Rmd file provided. The reports are +rendered as html files and saved in the specified output folder. +} diff --git a/man/TF24_hyperpar.Rd b/man/TF24_hyperpar.Rd new file mode 100644 index 00000000..5fc25add --- /dev/null +++ b/man/TF24_hyperpar.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tf24.R +\name{TF24_hyperpar} +\alias{TF24_hyperpar} +\title{Hyperparameter function for TF24 physiological model} +\usage{ +TF24_hyperpar(m, s, filter = TRUE) +} +\arguments{ +\item{m}{A matrix of trait values, as returned by \code{trait_matrix}} + +\item{s}{A strategy object} + +\item{filter}{A flag indicating whether to filter columns. If TRUE, any numbers +that are within eps of the default strategy are not replaced.} +} +\description{ +Hyperparameter function for TF24 physiological model +} diff --git a/man/build_schedule.Rd b/man/build_schedule.Rd index cff24a41..63f0165b 100644 --- a/man/build_schedule.Rd +++ b/man/build_schedule.Rd @@ -23,7 +23,7 @@ output offspring produced is also available as an attribute \code{birth_rate}. } \description{ -Build an appropriately refined schedule. +Build an appropriately refined schedule for node introduction. } \details{ There are control options (within the \code{Parameters} object) diff --git a/man/expand_parameters.Rd b/man/expand_parameters.Rd index dc9e4407..1d833d2c 100644 --- a/man/expand_parameters.Rd +++ b/man/expand_parameters.Rd @@ -30,6 +30,8 @@ to standard function for this strategy type.} x. Birth rates can take the form of a scalar (constant) or a vector. In either case birth rates are set as \code{strategy$birth_rate_y}, however varying birth rates will also have \code{strategy$birth_rate_x} and} + +\item{...}{Arguments to \code{\link{expand_parameters}}} } \description{ The functions expand_parameters and mutant_parameters convert trait values into parametr objects for the model. By default, expand_parameters adds an extra strategy to existing. diff --git a/man/make_FF16_hyperpar.Rd b/man/make_FF16_hyperpar.Rd new file mode 100644 index 00000000..32e87b95 --- /dev/null +++ b/man/make_FF16_hyperpar.Rd @@ -0,0 +1,73 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ff16.R +\name{make_FF16_hyperpar} +\alias{make_FF16_hyperpar} +\title{Hyperparameters for FF16 physiological model} +\usage{ +make_FF16_hyperpar( + lma_0 = 0.1978791, + B_kl1 = 0.4565855, + B_kl2 = 1.71, + rho_0 = 608, + B_dI1 = 0.01, + B_dI2 = 0, + B_ks1 = 0.2, + B_ks2 = 0, + B_rs1 = 4012, + B_rb1 = 2 * 4012, + B_f1 = 3, + narea = 0.00187, + narea_0 = 0.00187, + B_lf1 = 5120.738 * 0.00187 * 24 * 3600/1e+06, + B_lf2 = 0.5, + B_lf3 = 0.04, + B_lf4 = 21000, + B_lf5 = 1, + k_I = 0.5, + latitude = 0 +) +} +\arguments{ +\item{lma_0}{Central (mean) value for leaf mass per area [kg /m2]} + +\item{B_kl1}{Rate of leaf turnover at lma_0 [/yr]} + +\item{B_kl2}{Scaling slope for phi in leaf turnover [dimensionless]} + +\item{rho_0}{Central (mean) value for wood density [kg /m3]} + +\item{B_dI1}{Rate of instantaneous mortality at rho_0 [/yr]} + +\item{B_dI2}{Scaling slope for wood density in intrinsic mortality [dimensionless]} + +\item{B_ks1}{Rate of sapwood turnover at rho_0 [/yr]} + +\item{B_ks2}{Scaling slope for rho in sapwood turnover [dimensionless]} + +\item{B_rs1}{CO_2 respiration per unit sapwood volume [mol / yr / m3 ]} + +\item{B_rb1}{CO_2 respiration per unit sapwood volume [mol / yr / m3 ]} + +\item{B_f1}{Cost of seed accessories per unit seed mass [dimensionless]} + +\item{narea}{nitrogen per leaf area [kg / m2]} + +\item{narea_0}{central (mean) value for nitrogen per leaf area [kg / m2]} + +\item{B_lf1}{Potential CO_2 photosynthesis at average leaf nitrogen [mol / d / m2]} + +\item{B_lf2}{Curvature of leaf photosynthetic light response curve [dimensionless]} + +\item{B_lf3}{Quantum yield of leaf photosynthetic light response curve [dimensionless]} + +\item{B_lf4}{CO_2 respiration per unit leaf nitrogen [mol / yr / kg]} + +\item{B_lf5}{Scaling exponent for leaf nitrogen in maximum leaf photosynthesis [dimensionless]} + +\item{k_I}{light extinction coefficient [dimensionless]} + +\item{latitude}{degrees from equator (0-90), used in solar model [deg]} +} +\description{ +Hyperparameters for FF16 physiological model +} diff --git a/man/make_FF16r_hyperpar.Rd b/man/make_FF16r_hyperpar.Rd new file mode 100644 index 00000000..e5274adc --- /dev/null +++ b/man/make_FF16r_hyperpar.Rd @@ -0,0 +1,73 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ff16r.R +\name{make_FF16r_hyperpar} +\alias{make_FF16r_hyperpar} +\title{Hyperparameters for FF16r physiological model} +\usage{ +make_FF16r_hyperpar( + lma_0 = 0.1978791, + B_kl1 = 0.4565855, + B_kl2 = 1.71, + rho_0 = 608, + B_dI1 = 0.01, + B_dI2 = 0, + B_ks1 = 0.2, + B_ks2 = 0, + B_rs1 = 4012, + B_rb1 = 2 * 4012, + B_f1 = 3, + narea = 0.00187, + narea_0 = 0.00187, + B_lf1 = 5120.738 * 0.00187 * 24 * 3600/1e+06, + B_lf2 = 0.5, + B_lf3 = 0.04, + B_lf4 = 21000, + B_lf5 = 1, + k_I = 0.5, + latitude = 0 +) +} +\arguments{ +\item{lma_0}{Central (mean) value for leaf mass per area [kg /m2]} + +\item{B_kl1}{Rate of leaf turnover at lma_0 [/yr]} + +\item{B_kl2}{Scaling slope for phi in leaf turnover [dimensionless]} + +\item{rho_0}{Central (mean) value for wood density [kg /m3]} + +\item{B_dI1}{Rate of instantaneous mortality at rho_0 [/yr]} + +\item{B_dI2}{Scaling slope for wood density in intrinsic mortality [dimensionless]} + +\item{B_ks1}{Rate of sapwood turnover at rho_0 [/yr]} + +\item{B_ks2}{Scaling slope for rho in sapwood turnover [dimensionless]} + +\item{B_rs1}{CO_2 respiration per unit sapwood volume [mol / yr / m3 ]} + +\item{B_rb1}{CO_2 respiration per unit sapwood volume [mol / yr / m3 ]} + +\item{B_f1}{Cost of seed accessories per unit seed mass [dimensionless]} + +\item{narea}{nitrogen per leaf area [kg / m2]} + +\item{narea_0}{central (mean) value for nitrogen per leaf area [kg / m2]} + +\item{B_lf1}{Potential CO_2 photosynthesis at average leaf nitrogen [mol / d / m2]} + +\item{B_lf2}{Curvature of leaf photosynthetic light response curve [dimensionless]} + +\item{B_lf3}{Quantum yield of leaf photosynthetic light response curve [dimensionless]} + +\item{B_lf4}{CO_2 respiration per unit leaf nitrogen [mol / yr / kg]} + +\item{B_lf5}{Scaling exponent for leaf nitrogen in maximum leaf photosynthesis [dimensionless]} + +\item{k_I}{light extinction coefficient [dimensionless]} + +\item{latitude}{degrees from equator (0-90), used in solar model [deg]} +} +\description{ +Hyperparameters for FF16r physiological model +} diff --git a/man/make_TF24_hyperpar.Rd b/man/make_TF24_hyperpar.Rd new file mode 100644 index 00000000..34ac06a8 --- /dev/null +++ b/man/make_TF24_hyperpar.Rd @@ -0,0 +1,73 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tf24.R +\name{make_TF24_hyperpar} +\alias{make_TF24_hyperpar} +\title{Hyperparameters for TF24 physiological model} +\usage{ +make_TF24_hyperpar( + lma_0 = 0.1978791, + B_kl1 = 0.4565855, + B_kl2 = 1.71, + rho_0 = 608, + B_dI1 = 0.01, + B_dI2 = 0, + B_ks1 = 0.2, + B_ks2 = 0, + B_rs1 = 4012, + B_rb1 = 2 * 4012, + B_f1 = 3, + narea = 0.00187, + narea_0 = 0.00187, + B_lf1 = 5120.738 * 0.00187 * 24 * 3600/1e+06, + B_lf2 = 0.5, + B_lf3 = 0.04, + B_lf4 = 21000, + B_lf5 = 1, + k_I = 0.5, + latitude = 0 +) +} +\arguments{ +\item{lma_0}{Central (mean) value for leaf mass per area [kg /m2]} + +\item{B_kl1}{Rate of leaf turnover at lma_0 [/yr]} + +\item{B_kl2}{Scaling slope for phi in leaf turnover [dimensionless]} + +\item{rho_0}{Central (mean) value for wood density [kg /m3]} + +\item{B_dI1}{Rate of instantaneous mortality at rho_0 [/yr]} + +\item{B_dI2}{Scaling slope for wood density in intrinsic mortality [dimensionless]} + +\item{B_ks1}{Rate of sapwood turnover at rho_0 [/yr]} + +\item{B_ks2}{Scaling slope for rho in sapwood turnover [dimensionless]} + +\item{B_rs1}{CO_2 respiration per unit sapwood volume [mol / yr / m3 ]} + +\item{B_rb1}{CO_2 respiration per unit sapwood volume [mol / yr / m3 ]} + +\item{B_f1}{Cost of seed accessories per unit seed mass [dimensionless]} + +\item{narea}{nitrogen per leaf area [kg / m2]} + +\item{narea_0}{central (mean) value for nitrogen per leaf area [kg / m2]} + +\item{B_lf1}{Potential CO_2 photosynthesis at average leaf nitrogen [mol / d / m2]} + +\item{B_lf2}{Curvature of leaf photosynthetic light response curve [dimensionless]} + +\item{B_lf3}{Quantum yield of leaf photosynthetic light response curve [dimensionless]} + +\item{B_lf4}{CO_2 respiration per unit leaf nitrogen [mol / yr / kg]} + +\item{B_lf5}{Scaling exponent for leaf nitrogen in maximum leaf photosynthesis [dimensionless]} + +\item{k_I}{light extinction coefficient [dimensionless]} + +\item{latitude}{degrees from equator (0-90), used in solar model [deg]} +} +\description{ +Hyperparameters for TF24 physiological model +} diff --git a/man/optimise_individual_rate_at_size_by_trait.Rd b/man/optimise_individual_rate_at_size_by_trait.Rd index 4cdb13dc..b77ec7b0 100644 --- a/man/optimise_individual_rate_at_size_by_trait.Rd +++ b/man/optimise_individual_rate_at_size_by_trait.Rd @@ -18,13 +18,37 @@ optimise_individual_rate_at_size_by_trait( params = scm_base_parameters(type), env = make_environment(type), hyperpars = hyperpar(type), - set_state_by_ode = FALSE + set_state_directly = FALSE ) optimise_individual_rate_at_height_by_trait(..., height = 1) } \arguments{ -\item{hyperpars}{} +\item{type}{The type of model to use (e.g. "FF16"). Defaults to "FF16"} + +\item{bounds}{A vector giving the lower and upper bounds of the trait} + +\item{log_scale}{Should the trait be optimised on a log scale? Defaults to TRUE} + +\item{tol}{The tolerance for the optimisation} + +\item{size}{The size of the individual to optimise the rate at} + +\item{size_name}{The name of the size variable specified by \code{size}} + +\item{rate}{The name of the rate to optimise. Defaults to \code{size_name}} + +\item{params}{The parameters of the model} + +\item{env}{The environment of the model} + +\item{hyperpars}{The hyperparameter function of the model} + +\item{set_state_directly}{If TRUE, set the state directly to the size, otherwise grows the plant to that size. Defaults to FALSE} + +\item{...}{Additional parameters passed to \code{optimise_individual_rate_at_size_by_trait}} + +\item{height}{Heigh at which grow is optimsied. Defaults to 1} } \description{ The function `optimise_individual_rate_at_height_by_trait` and `optimise_individual_rate_at_size_by_trait` solve for the maximum of diff --git a/man/strategy_list.Rd b/man/strategy_list.Rd index 067bf6e3..4dc88cc1 100644 --- a/man/strategy_list.Rd +++ b/man/strategy_list.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in r/util_model.R +% Please edit documentation in R/util_model.R \name{strategy_list} \alias{strategy_list} \title{Create a list of Strategies} diff --git a/man/util_colour_set_opacity.Rd b/man/util_colour_set_opacity.Rd index f906d977..3f799de7 100644 --- a/man/util_colour_set_opacity.Rd +++ b/man/util_colour_set_opacity.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in r/util.R +% Please edit documentation in R/util.R \name{util_colour_set_opacity} \alias{util_colour_set_opacity} \title{Make colours transparent} diff --git a/src/qag_internals.cpp b/src/qag_internals.cpp index cb90269f..83c60ac6 100644 --- a/src/qag_internals.cpp +++ b/src/qag_internals.cpp @@ -108,7 +108,7 @@ intervals_type rescale_intervals(intervals_type x, // This is useful in debugging, but never actually used. void print_intervals(intervals_type x) { - const size_t n = x[0].size(); + const int n = x[0].size(); Rprintf("%d intervals:", n); for (size_t i = 0; i < n; ++i) { Rprintf(" [%2.7f, %2.7f]", x[0][i], x[1][i]); diff --git a/tests/testthat/test-stochastic-patch.R b/tests/testthat/test-stochastic-patch.R index 7c8167e9..4c5bc91f 100644 --- a/tests/testthat/test-stochastic-patch.R +++ b/tests/testthat/test-stochastic-patch.R @@ -42,8 +42,6 @@ test_that("non empty", { patch <- StochasticPatch(x, e)(p, env, ctrl) cmp <- Individual(x, e)(p$strategies[[1]]) - patch - expect_error(patch$introduce_new_node(0), "Invalid value") expect_error(patch$introduce_new_node(10), "out of bounds")