#' Aggregates sub-daily sapflow measurements to diurnal means
#'
#' @description
#' Subdaily sapflow measurements are difficult to visualize over long time
#' spans. Diurnal means smooth out the data without losing information on
#' total daily transpiration.
#'
#' @param flux 'flux' class object
#' @export
#' @examples
#' myflux <- AggregateDiurnalFlux(flux = myflux)
AggregateDiurnalFlux <- function(flux) {
validObject(flux)
data <- slot(flux, name = "data")
time <- slot(flux, name = "time")
time <- as.Date(time)
days <- unique(time)
diurnal.return <- matrix(data = NA, ncol = ncol(data), nrow = length(days))
meanNA <- function(x) {
mean(x, na.rm = TRUE)
}
for (i in 1:ncol(data)) {
diurnal.return[, i] <- tapply(X = data[, i], INDEX = time, FUN = meanNA)
}
slot(flux, name = "data") <- diurnal.return
slot(flux, name = "time") <- .POSIXct(NULL)
slot(flux, name = "date") <- days
return(flux)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.