R/active_pool.R

Defines functions active_y active_y_ss k_a

Documented in active_y active_y_ss k_a

###########################################################
# functions comprise algorithm to calculate active C pool #
###########################################################

#' @title Calculate the \code{k_a} parameter
#' @description Calculates the model \code{k_a} parameter, a precursor parameter to calculating the
#' steady-state active carbon pool.
#' @param tfac A numeric vector indicating the model temperature factor, calculated using
#' \code{tfac()}.
#' @param wfac A numeric vector indicating the model water factor, calculated using \code{wfac()}.
#' @param tillfac A numeric vector indicating the model tillage factor, selected with
#' \code{tillfac()}.
#' @param sand_frac A numeric scalar or vector indicating the sand proportion in the soil mineral
#' makeup, fractional.
#' @param params A named list containing model parameters. Defaults to the package default parameter
#' set \code{soilc_params}.
#' @export
k_a <- function(tfac, wfac, tillfac, sand_frac, params = soilc_params) {
  params$kfaca$be * tfac * wfac * (params$k3par1$be + (params$k3par2$be * sand_frac)) * tillfac
}

#' @title Calculate the steady-state active soil carbon pool
#' @description Calculates the steady-state version of the modelled active soil carbon pool, in
#' tonnes C ha^-1.
#' @param k_a Numeric vector containing the model \code{k_a} parameter, calculated using
#' \code{k_a()}.
#' @param alpha Numeric vector containing the model \code{alpha} parameter, calculated using
#' \code{alpha()}.
#' @export
active_y_ss <- function(k_a, alpha) alpha / k_a

#' @title Calculate the active soil carbon pool
#' @description Calculates the rolling version of the modelled active soil carbon pool, in
#' tonnes C ha^-1.
#' @param k_a A numeric vector containing the model \code{k_a} parameter, calculated using
#' \code{k_a()}.
#' @param active_y_ss A numeric vector containing the steady-state version of the modelled active
#' soil carbon pool, in tonnes C ha^-1.
#' @importFrom purrr accumulate2
#' @export
active_y <- function(k_a, active_y_ss) {
  active_y_ss %>%
    accumulate2(k_a[2:length(k_a)], function(x, y, z) x + (y - x) * min(1, z)) %>%
    as.numeric()
}
aj-sykes92/soilc.ipcc documentation built on March 19, 2021, 11:52 a.m.