R/calc_mean.R

Defines functions calc_mean

Documented in calc_mean

#' Calculate mean TRUE
#'
#' @param x SpatRaster list - logical - with time attribute
#' @returns SpatRaster - logical - with time attribute
#' @family Calculation
#' @keywords internal
#' @description Takes multiple logical SpatRasters with time attribute and
#' returns SpatRaster with the mean time serial number of first and last TRUE
#' value.

calc_mean <- function(x) {

  time <- get_time(x[[1]])
  #lyr <- 1:terra::nlyr(x[[1]])

  x <- lapply(x, convert_logical_to_doy)
  x <- terra::app(terra::rast(x), mean)
  x <- round(x)

  x <- convert_doy_to_logical(x, from = min(time), to = max(time))

  return(x)

}

Try the PHENTHAUproc package in your browser

Any scripts or data that you put into this service are public.

PHENTHAUproc documentation built on June 22, 2024, 7:12 p.m.