Aggregate values of time series over phenological time windows.
aggregate_pheno(
data,
pheno,
metrics = c("begin", "end"),
fun = "median",
reshape = TRUE,
skip_fun = TRUE,
include_pheno = FALSE,
...
)List of fitted time series as generated by function fit_curve()
or time series in s2ts format (generated using fill_s2ts()).
(optional) Output of extract_pheno() or cut_cycles().
If missing, the whole windows are used (in this case, data can only be
a list of fitted time series as generated by function fit_curve()).
(optional) Two-length character: name of metrics to be used
as beginning and ending dates of the windows. Object pheno must contain
two fields with the corresponding names.
Default is c("begin", "end") (but they could be e.g. c("sos", "eos")).
This parameter is skipped if pheno is missing.
(optional) A vector of aggregation function names
(default is "median").
(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 fun argument are returned
instead than columns fun and value.
(optional) Logical: return also the aggregation function name
among outputs (default is FALSE)?
This parameter is used only if fun is 1-length (otherwise it is coerced
to TRUE) and if reshape = TRUE.
(optional) Logical: return also the input information
provided in argument pheno (default is FALSE)?
Additional arguments passed to fun.
A data table with the following fields:
id: the time series ID (see s2ts);
year: the year (integer);
cycle: the cycle ID (integer);
fun: the aggregation function (if skip_fun = TRUE and fun is a
1-length argument value, this is skipped);
value: output aggregated value.
# 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
#> id year cycle value
#> 1: 1 2020 1 0.4956109
#> 2: 2 2020 1 0.3652678
#> 3: 2 2020 2 0.1298273
# 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
#> id year cycle value
#> 1: 1 2020 1 0.9102608
#> 2: 2 2020 1 0.8379835
#> 3: 2 2020 2 0.4919376