% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/aggregate_pheno.R
\name{aggregate_pheno}
\alias{aggregate_pheno}
\title{Temporally aggregate time series values}
\usage{
aggregate_pheno(
  data,
  pheno,
  metrics = c("begin", "end"),
  fun = "median",
  reshape = TRUE,
  skip_fun = TRUE,
  include_pheno = FALSE,
  ...
)
}
\arguments{
\item{data}{List of fitted time series as generated by function \code{fit_curve()}
or time series in \code{s2ts} format (generated using \code{fill_s2ts()}).}

\item{pheno}{(optional) Output of \code{extract_pheno()} or \code{cut_cycles()}.
If missing, the whole windows are used (in this case, \code{data} can only be
a list of fitted time series as generated by function \code{fit_curve()}).}

\item{metrics}{(optional) Two-length character: name of metrics to be used
as beginning and ending dates of the windows. Object \code{pheno} must contain
two fields with the corresponding names.
Default is \code{c("begin", "end")} (but they could be e.g. \code{c("sos", "eos")}).
This parameter is skipped if \code{pheno} is missing.}

\item{fun}{(optional) A vector of aggregation function names
(default is \code{"median"}).}

\item{reshape}{(optional) Logical: should outputs be wide-to-log reshaped?
If TRUE (default), the output is returned in the "long" format (as described)
here below); if FALSE, n columns named as \code{fun} argument are returned
instead than columns \code{fun} and \code{value}.}

\item{skip_fun}{(optional) Logical: return also the aggregation function name
among outputs (default is FALSE)?
This parameter is used only if \code{fun} is 1-length (otherwise it is coerced
to TRUE) and if \code{reshape = TRUE}.}

\item{include_pheno}{(optional) Logical: return also the input information
provided in  argument \code{pheno} (default is FALSE)?}

\item{...}{Additional arguments passed to \code{fun}.}
}
\value{
A data table with the following fields:
\itemize{
\item \code{id}: the time series ID (see \code{s2ts});
\item \code{year}: the year (integer);
\item \code{cycle}: the cycle ID (integer);
\item \code{fun}: the aggregation function (if \code{skip_fun = TRUE} and \code{fun} is a
1-length argument value, this is skipped);
\item \code{value}: output aggregated value.
}
}
\description{
Aggregate values of time series over phenological
time windows.
}
\examples{
# Load input data
data("ts_filled")
data("dt_cycles")
data("dt_pheno")

# Aggregate time series over detected cycles (computing the median, as default)
dt_aggr_0 <- aggregate_pheno(ts_filled, dt_cycles)
dt_aggr_0

# Aggregate time series over phenological metrics using 95\% percentile
dt_aggr <- aggregate_pheno(
  ts_filled, dt_pheno, 
  metrics = c("sos", "eos"), 
  fun = "quantile", probs = 0.95, na.rm = TRUE
)
dt_aggr
}
\author{
Luigi Ranghetti, PhD (2021) \email{luigi@ranghetti.info}
}
