Skip to content

Commit

Permalink
Add c0_band
Browse files Browse the repository at this point in the history
see #75
  • Loading branch information
wilsonsj100 committed Oct 21, 2024
1 parent b46d451 commit d2433b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion R/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,17 @@ ffi_normalize_time <- function(time, normalize = TRUE) {
#' \code{data}, character
#' @param dead_band Length of dead band, the equilibration period at the
#' beginning of the time series during which data are ignore, in seconds (numeric)
#' @param c0_band Length of the period at the beginning of the time series
#' that is used to determine an ambient or pre-flux concentration, in second (numeric)
#' @param normalize_time Normalize the values so that first is zero? Logical
#' @param fit_function Optional flux-fit function;
#' default is \code{\link{ffi_fit_models}}
#' @param ... Other parameters passed to \code{fit_function}
#' @return A data.frame with one row per \code{group_column} value. It will
#' always include the mean, minimum, and maximum values of \code{time_column}
#' for that group, but other
#' columns depend on what is returned by the \code{fit_function}.
#' columns depend on what is returned by the \code{fit_function}. The \code{c0} column
#' is the average concentration over the first \code{c0_band} in seconds.
#' @seealso \code{\link{ffi_fit_models}}
#' @export
#' @examples
Expand All @@ -226,6 +229,7 @@ ffi_compute_fluxes <- function(data,
time_column,
gas_column,
dead_band = 0,
c0_band = 5,
normalize_time = TRUE,
fit_function = ffi_fit_models,
...) {
Expand All @@ -249,11 +253,13 @@ ffi_compute_fluxes <- function(data,
# passing volume and area?
f <- function(x, ...) {
x$.norm_time <- ffi_normalize_time(x[,time_column], normalize_time)
c0 <- mean(x[x$.norm_time <= c0_band, gas_column])
x <- x[x$.norm_time >= dead_band,] # exclude dead band data
out <- fit_function(x$.norm_time, x[,gas_column], ...)
out[time_column] <- mean(x[,time_column])
out[paste0(time_column, "_min")] <- min(x[,time_column])
out[paste0(time_column, "_max")] <- max(x[,time_column])
out$c0 <- c0
return(out)
}

Expand Down
7 changes: 6 additions & 1 deletion man/ffi_compute_fluxes.Rd

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

0 comments on commit d2433b0

Please sign in to comment.