SeriesAggreg: Conversion of time series to another time step (aggregation...

View source: R/SeriesAggreg.R

SeriesAggregR Documentation

Conversion of time series to another time step (aggregation only) and regime computation

Description

Conversion of time series to another time step (aggregation only) and regime computation.
Warning: on the aggregated outputs, the dates correspond to the beginning of the time step
(e.g. for daily time series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2005-03-01 23:59)
(e.g. for monthly time series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2005-03-31 23:59)
(e.g. for yearly time series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2006-02-28 23:59)

Usage

## S3 method for class 'data.frame'
SeriesAggreg(x,
             Format,
             ConvertFun,
             TimeFormat = NULL,
             NewTimeFormat = NULL,
             YearFirstMonth = 1,
             TimeLag = 0,
             ...)

## S3 method for class 'list'
SeriesAggreg(x,
             Format,
             ConvertFun,
             NewTimeFormat = NULL,
             simplify = FALSE,
             except = NULL,
             recursive = TRUE,
             ...)

## S3 method for class 'InputsModel'
SeriesAggreg(x, Format, ...)

## S3 method for class 'OutputsModel'
SeriesAggreg(x, Format, ...)

Arguments

x

[InputsModel], [OutputsModel], [list] or [data.frame] containing the vector of dates (POSIXt) and the time series of numeric values

Format

[character] output time step format (i.e. yearly times series: "%Y", monthly time series: "%Y%m", daily time series: "%Y%m%d", monthly regimes: "%m", daily regimes: "%d")

TimeFormat

(deprecated) [character] input time step format (i.e. "hourly", "daily", "monthly" or "yearly"). Use the x argument instead

NewTimeFormat

(deprecated) [character] output time step format (i.e. "hourly", "daily", "monthly" or "yearly"). Use the Format argument instead

ConvertFun

[character] names of aggregation functions (e.g. for P[mm], T[degC], Q[mm]: ConvertFun = c("sum", "mean", "sum")) or name of aggregation function to apply to all elements if the parameter 'x' is a [list] . See details

YearFirstMonth

(optional) [numeric] integer used when Format = "%Y" to set when the starting month of the year (e.g. 01 for calendar year or 09 for hydrological year starting in September)

TimeLag

(optional) [numeric] numeric indicating a time lag (in seconds) for the time series aggregation (especially useful to aggregate hourly time series into daily time series)

simplify

(optional) [boolean] if set to TRUE, a data.frame is returned instead of a list. Embedded lists are then ignored. (default = FALSE)

except

(optional) [character] the name of the items to skip in the aggregation (default = NULL)

recursive

(optional) [boolean] if set to FALSE, embedded lists and dataframes are not aggregated (default = TRUE)

...

Arguments passed to SeriesAggreg.list and then to SeriesAggreg.data.frame

Details

SeriesAggreg.InputsModel and SeriesAggreg.OutputsModel call SeriesAggreg.list which itself calls SeriesAggreg.data.frame. So, all arguments passed to any SeriesAggreg method will be passed to SeriesAggreg.data.frame.

Argument ConvertFun also supports quantile calculation by using the syntax "Q[nn]" with [nn] the requested percentile. E.g. use "Q90" for calculating 90th percentile in the aggregation. The formula used is: quantile(x, probs = perc / 100, type = 8, na.rm = TRUE).

As there are multiple ways to take into account missing values in aggregation functions, NAs are not supported by SeriesAggreg and it provides NA values when NAs are present in the x input.

Value

[POSIXct+numeric] data.frame containing a vector of aggregated dates (POSIXct) and time series values numeric)

Author(s)

Olivier Delaigue, David Dorchies

Examples

library(airGR)

## loading catchment data
data(L0123002)

## preparation of the initial time series data frame at the daily time step
TabSeries <- BasinObs[, c("DatesR", "P", "E", "T", "Qmm")]

## monthly time series
NewTabSeries <- SeriesAggreg(TabSeries,
                             Format = "%Y%m",
                             ConvertFun = c("sum", "sum", "mean", "sum"))
str(NewTabSeries)

## monthly regimes
NewTabSeries <- SeriesAggreg(TabSeries,
                             Format = "%m",
                             ConvertFun = c("sum", "sum", "mean", "sum"))
str(NewTabSeries)

## conversion of InputsModel
example("RunModel_GR2M")

## monthly regimes on OutputsModel object
SimulatedMonthlyRegime <- SeriesAggreg(OutputsModel, Format = "%m")
str(SimulatedMonthlyRegime)


airGR documentation built on Oct. 26, 2023, 9:07 a.m.