aggregate_pheno: Temporally aggregate time series values

View source: R/aggregate_pheno.R

aggregate_phenoR Documentation

Temporally aggregate time series values

Description

Aggregate values of time series over phenological time windows.

Usage

aggregate_pheno(
  data,
  pheno,
  metrics = c("begin", "end"),
  fun = "median",
  reshape = TRUE,
  skip_fun = TRUE,
  include_pheno = FALSE,
  ...
)

Arguments

data

List of fitted time series as generated by function fit_curve() or time series in s2ts format (generated using fill_s2ts()).

pheno

(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()).

metrics

(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.

fun

(optional) A vector of aggregation function names (default is "median").

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 fun argument are returned instead than columns fun and value.

skip_fun

(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.

include_pheno

(optional) Logical: return also the input information provided in argument pheno (default is FALSE)?

...

Additional arguments passed to fun.

Value

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.

Author(s)

Luigi Ranghetti, PhD (2021) luigi@ranghetti.info

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

ranghetti/sen2rts documentation built on March 31, 2024, 1:18 a.m.