Commit 2cae2dd8 authored by Dorchies David's avatar Dorchies David
Browse files

v1.6.8.11 refactor: Rename functions SeriesAggreg2 to SeriesAggreg

Refs #
Showing with 75 additions and 321 deletions
+75 -321
Package: airGR Package: airGR
Type: Package Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.6.8.10 Version: 1.6.8.11
Date: 2020-11-20 Date: 2020-11-24
Authors@R: c( Authors@R: c(
person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
person("Olivier", "Delaigue", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7668-8468"), email = "airGR@inrae.fr"), person("Olivier", "Delaigue", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7668-8468"), email = "airGR@inrae.fr"),
......
...@@ -9,10 +9,10 @@ useDynLib(airGR, .registration = TRUE) ...@@ -9,10 +9,10 @@ useDynLib(airGR, .registration = TRUE)
## S3 methods ## ## S3 methods ##
##################################### #####################################
S3method("plot", "OutputsModel") S3method("plot", "OutputsModel")
S3method("SeriesAggreg2", "data.frame") S3method("SeriesAggreg", "data.frame")
S3method("SeriesAggreg2", "list") S3method("SeriesAggreg", "list")
S3method("SeriesAggreg2", "InputsModel") S3method("SeriesAggreg", "InputsModel")
S3method("SeriesAggreg2", "OutputsModel") S3method("SeriesAggreg", "OutputsModel")
...@@ -51,11 +51,10 @@ export(RunModel_GR5J) ...@@ -51,11 +51,10 @@ export(RunModel_GR5J)
export(RunModel_GR6J) export(RunModel_GR6J)
export(RunModel_Lag) export(RunModel_Lag)
export(SeriesAggreg) export(SeriesAggreg)
export(SeriesAggreg2) export(SeriesAggreg.list)
export(SeriesAggreg2.list) export(SeriesAggreg.data.frame)
export(SeriesAggreg2.data.frame) export(SeriesAggreg.InputsModel)
export(SeriesAggreg2.InputsModel) export(SeriesAggreg.OutputsModel)
export(SeriesAggreg2.OutputsModel)
export(TransfoParam) export(TransfoParam)
export(TransfoParam_CemaNeige) export(TransfoParam_CemaNeige)
export(TransfoParam_CemaNeigeHyst) export(TransfoParam_CemaNeigeHyst)
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
#### New features #### New features
- Added <code>SeriesAggreg2</code> S3 method with functions for `InputsModel`, `OutputsModel`, `list`, `data.frame` class objects. This new version of the <code>SeriesAggreg()</code> function allows to compute regimes. - Added <code>SeriesAggreg</code> S3 method with functions for `InputsModel`, `OutputsModel`, `list`, `data.frame` class objects. This new version of the <code>SeriesAggreg()</code> function allows to compute regimes.
- Added<code>.AggregConvertFun()</code> private function in order to choose automatically the <code>ConvertFun</code> to apply on each element of <code>InputsModel</code> and <code>OutputsModel</code> objects. - Added<code>.AggregConvertFun()</code> private function in order to choose automatically the <code>ConvertFun</code> to apply on each element of <code>InputsModel</code> and <code>OutputsModel</code> objects.
#### Bug fixes #### Bug fixes
- <code>TimeLag</code> of the <code>SeriesAggreg2()</code> function now runs when <code>TimeLag >= 3600</code>. - <code>TimeLag</code> of the <code>SeriesAggreg()</code> function now runs when <code>TimeLag >= 3600</code>.
____________________________________________________________________________________ ____________________________________________________________________________________
......
SeriesAggreg2.InputsModel <- function(TabSeries, Format, ...) { SeriesAggreg.InputsModel <- function(TabSeries, Format, ...) {
if (!inherits(TabSeries, "InputsModel")) { if (!inherits(TabSeries, "InputsModel")) {
stop("to be used with 'InputsModel' object") stop("to be used with 'InputsModel' object")
} }
res <- SeriesAggreg2.list(TabSeries = TabSeries, Format, ...) res <- SeriesAggreg.list(TabSeries = TabSeries, Format, ...)
if (inherits(TabSeries, "CemaNeige")) { if (inherits(TabSeries, "CemaNeige")) {
res$ZLayers <- TabSeries$ZLayers res$ZLayers <- TabSeries$ZLayers
......
SeriesAggreg2.OutputsModel <- function(TabSeries, Format, ...) { SeriesAggreg.OutputsModel <- function(TabSeries, Format, ...) {
if (!inherits(TabSeries, "OutputsModel")) { if (!inherits(TabSeries, "OutputsModel")) {
stop("to be used with 'OutputsModel' object") stop("to be used with 'OutputsModel' object")
} }
res <- SeriesAggreg2.list(TabSeries, Format, ...) res <- SeriesAggreg.list(TabSeries, Format, ...)
res$StateEnd <- TabSeries$StateEnd res$StateEnd <- TabSeries$StateEnd
......
SeriesAggreg <- function(TabSeries, SeriesAggreg <- function(TabSeries, Format, ...) {
TimeFormat, NewTimeFormat, UseMethod("SeriesAggreg")
ConvertFun, }
YearFirstMonth = 1, TimeLag = 0,
verbose = TRUE) {
##_Arguments_check
##check_TabSeries
if (!is.data.frame(TabSeries)) {
stop("'TabSeries' must be a data.frame containing the dates and data to be aggregated")
}
if (ncol(TabSeries) < 2) {
stop("'TabSeries' must contain at least two columns (including the column of dates)")
}
##check_TimeFormat
if (!any(class(TabSeries[, 1]) %in% "POSIXt")) {
stop("'TabSeries' first column must be a vector of class 'POSIXlt' or 'POSIXct'")
}
if (any(class(TabSeries[, 1]) %in% "POSIXlt")) {
TabSeries[, 1] <- as.POSIXct(TabSeries[, 1])
}
for (iCol in 2:ncol(TabSeries)) {
if (!is.numeric(TabSeries[,iCol])) {
stop("'TabSeries' columns (other than the first one) be of numeric class")
}
}
##check TimeFormat and NewTimeFormat
TimeStep <- c("hourly", "daily", "monthly", "yearly")
TimeFormat <- match.arg(TimeFormat , choices = TimeStep)
NewTimeFormat <- match.arg(NewTimeFormat, choices = TimeStep)
##check_ConvertFun
if (!is.vector(ConvertFun)) {
stop("'ConvertFun' must be a vector of character")
}
if (!is.character(ConvertFun)) {
stop("'ConvertFun' must be a vector of character")
}
if (length(ConvertFun) != (ncol(TabSeries) - 1)) {
stop(
paste("'ConvertFun' must be of length", ncol(TabSeries) - 1, "(length=ncol(TabSeries)-1)")
)
}
if (sum(ConvertFun %in% c("sum", "mean") == FALSE) != 0) {
stop("'ConvertFun' elements must be one of 'sum' or 'mean'")
}
##check_YearFirstMonth
if (!is.vector(YearFirstMonth)) {
stop("'YearFirstMonth' must be an integer between 1 and 12")
}
if (!is.numeric(YearFirstMonth)) {
stop("'YearFirstMonth' must be an integer between 1 and 12")
}
YearFirstMonth <- as.integer(YearFirstMonth)
if (length(YearFirstMonth) != 1) {
stop("'YearFirstMonth' must be only one integer between 1 and 12")
}
if (YearFirstMonth %in% (1:12) == FALSE) {
stop("'YearFirstMonth' must be only one integer between 1 and 12")
}
##check_DatesR_integrity
by <- switch(TimeFormat,
'hourly' = "hours",
'daily' = "days",
'monthly' = "months",
'yearly' = "years")
TmpDatesR <- seq(from = TabSeries[1, 1], to = tail(TabSeries[, 1], 1), by = by)
if (!identical(TabSeries[, 1], TmpDatesR)) {
stop("some dates might not be ordered or are missing in 'TabSeries'")
}
##check_conversion_direction
if ((TimeFormat == "daily" & NewTimeFormat %in% c("hourly") ) |
(TimeFormat == "monthly" & NewTimeFormat %in% c("hourly","daily") ) |
(TimeFormat == "yearly" & NewTimeFormat %in% c("hourly","daily","monthly"))) {
stop("only time aggregation can be performed")
}
##check_if_conversion_not_needed
if ((TimeFormat == "hourly" & NewTimeFormat == "hourly" ) |
(TimeFormat == "daily" & NewTimeFormat == "daily" ) |
(TimeFormat == "monthly" & NewTimeFormat == "monthly") |
(TimeFormat == "yearly" & NewTimeFormat == "yearly" )) {
if (verbose) {
warning("the old and new format are identical \n\t -> no time-step conversion was performed")
return(TabSeries)
}
}
##_Time_step_conversion
##_Handle_conventional_difference_between_hourly_series_and_others
TmpDatesR <- TabSeries[, 1]
#if (TimeFormat=="hourly") { TmpDatesR <- TmpDatesR - 60*60; }
TmpDatesR <- TmpDatesR + TimeLag
Hmax <- "00"
if (TimeFormat == "hourly") {
Hmax <- "23"
}
##_Identify_the_part_of_the_series_to_be_aggregated
NDaysInMonth <- list("31", c("28", "29"), "31", "30", "31", "30", "31", "31", "30", "31", "30", "31")
NDaysAndMonth <- sprintf("%02i%s", c(1:2, 2:12), unlist(NDaysInMonth))
YearLastMonth <- YearFirstMonth + 11
if (YearLastMonth > 12) {
YearLastMonth <- YearLastMonth - 12
}
YearFirstMonthTxt <- formatC(YearFirstMonth, format = "d", width = 2, flag = "0")
YearLastMonthTxt <- formatC(YearLastMonth , format = "d", width = 2, flag = "0")
if (NewTimeFormat == "daily") {
Ind1 <- which(format(TmpDatesR, "%H") == "00")
Ind2 <- which(format(TmpDatesR, "%H") == Hmax)
if (Ind2[1] < Ind1[1]) {
Ind2 <- Ind2[2:length(Ind2)]
}
if (tail(Ind1, 1) > tail(Ind2, 1)) {
Ind1 <- Ind1[1:(length(Ind1) - 1)]
}
### Aggr <- NULL; iii <- 0; for(kkk in 1:length(Ind1)) {
### iii <- iii+1; Aggr <- c(Aggr,rep(iii,length(Ind1[kkk]:Ind2[kkk]))); }
Aggr <- as.numeric(format(TmpDatesR[min(Ind1):max(Ind2)], "%Y%m%d"))
### more efficient
NewDatesR <- data.frame(seq(from = TmpDatesR[min(Ind1)], to = TmpDatesR[max(Ind2)], by = "days"))
}
if (NewTimeFormat=="monthly") {
Ind1 <- which(format(TmpDatesR, "%d%H") == "0100")
Ind2 <- which(format(TmpDatesR,"%m%d%H") %in% paste0(NDaysAndMonth, Hmax))
Ind2[1:(length(Ind2) - 1)][diff(Ind2) == 1] <- NA
Ind2 <- Ind2[!is.na(Ind2)] ### to keep only feb 29 if both feb 28 and feb 29 exists
if (Ind2[1] < Ind1[1]) {
Ind2 <- Ind2[2:length(Ind2)]
}
if (tail(Ind1, 1) > tail(Ind2, 1)) {
Ind1 <- Ind1[1:(length(Ind1) - 1)]
}
### Aggr <- NULL; iii <- 0; for(kkk in 1:length(Ind1)) {
### iii <- iii+1; Aggr <- c(Aggr,rep(iii,length(Ind1[kkk]:Ind2[kkk]))); }
Aggr <- as.numeric(format(TmpDatesR[min(Ind1):max(Ind2)],"%Y%m")); ### more efficient
NewDatesR <- data.frame(seq(from=TmpDatesR[min(Ind1)],to=TmpDatesR[max(Ind2)],by="months"))
}
if (NewTimeFormat == "yearly") {
Ind1 <- which(format(TmpDatesR, "%m%d%H") %in% paste0(YearFirstMonthTxt, "0100"))
Ind2 <- which(format(TmpDatesR, "%m%d%H") %in% paste0(YearLastMonthTxt, NDaysInMonth[[YearLastMonth]], Hmax))
Ind2[1:(length(Ind2) - 1)][diff(Ind2) == 1] <- NA
Ind2 <- Ind2[!is.na(Ind2)]
### to keep only feb 29 if both feb 28 and feb 29 exists
if (Ind2[1] < Ind1[1]) {
Ind2 <- Ind2[2:length(Ind2)]
}
if (tail(Ind1, 1) > tail(Ind2, 1)) {
Ind1 <- Ind1[1:(length(Ind1) - 1)]
}
Aggr <- NULL
iii <- 0
for (kkk in 1:length(Ind1)) {
iii <- iii + 1
Aggr <- c(Aggr, rep(iii, length(Ind1[kkk]:Ind2[kkk])))
}
### Aggr <- as.numeric(format(TmpDatesR[min(Ind1):max(Ind2)],"%Y")); ### not working if YearFirstMonth != 01
NewDatesR <- data.frame(seq(from = TmpDatesR[min(Ind1)], to = TmpDatesR[max(Ind2)], by = "years"))
}
##_Aggreation_and_export
NewTabSeries <- data.frame(NewDatesR)
for (iCol in 2:ncol(TabSeries)) {
AggregData <- aggregate(TabSeries[min(Ind1):max(Ind2), iCol],
by = list(Aggr),
FUN = ConvertFun[iCol - 1], na.rm = FALSE)[, 2]
NewTabSeries <- data.frame(NewTabSeries, AggregData)
}
names(NewTabSeries) <- names(TabSeries)
return(NewTabSeries)
}
\ No newline at end of file
SeriesAggreg2.data.frame <- function(TabSeries, Format, ConvertFun, TimeFormat = NULL, NewTimeFormat = NULL, SeriesAggreg.data.frame <- function(TabSeries, Format, ConvertFun, TimeFormat = NULL, NewTimeFormat = NULL,
YearFirstMonth = 1, TimeLag = 0, verbose = TRUE, ...) { YearFirstMonth = 1, TimeLag = 0, verbose = TRUE, ...) {
## Arguments checks ## Arguments checks
......
SeriesAggreg2.list <- function(TabSeries, Format, simplify = FALSE, ...) { SeriesAggreg.list <- function(TabSeries, Format, simplify = FALSE, ...) {
if (!inherits(TabSeries, c("InputsModel", "OutputsModel"))) { if (!inherits(TabSeries, c("InputsModel", "OutputsModel"))) {
stop("to be used with InputsModel', or 'OutputsModel' object") stop("to be used with InputsModel', or 'OutputsModel' object")
...@@ -35,7 +35,7 @@ SeriesAggreg2.list <- function(TabSeries, Format, simplify = FALSE, ...) { ...@@ -35,7 +35,7 @@ SeriesAggreg2.list <- function(TabSeries, Format, simplify = FALSE, ...) {
} }
CemaNeigeLayersAggreg <- lapply(CemaNeigeLayers, function(iLayer) { CemaNeigeLayersAggreg <- lapply(CemaNeigeLayers, function(iLayer) {
tmp <- cbind(TabSeries$DatesR, as.data.frame(iLayer)) tmp <- cbind(TabSeries$DatesR, as.data.frame(iLayer))
res <- SeriesAggreg2(tmp, Format, ..., ConvertFun = .AggregConvertFun(gsub("[.].*", "", colnames(tmp)[-1L]))) res <- SeriesAggreg(tmp, Format, ..., ConvertFun = .AggregConvertFun(gsub("[.].*", "", colnames(tmp)[-1L])))
res <- res[, -1L] res <- res[, -1L]
colnames(res) <- gsub(".*[.]", "", colnames(res)) colnames(res) <- gsub(".*[.]", "", colnames(res))
res <- as.list(res) res <- as.list(res)
...@@ -45,7 +45,7 @@ SeriesAggreg2.list <- function(TabSeries, Format, simplify = FALSE, ...) { ...@@ -45,7 +45,7 @@ SeriesAggreg2.list <- function(TabSeries, Format, simplify = FALSE, ...) {
TabSeries2 <- TabSeries[1:which(names(TabSeries) %in% lastCol)] TabSeries2 <- TabSeries[1:which(names(TabSeries) %in% lastCol)]
TabSeries2 <- as.data.frame.list(TabSeries2) TabSeries2 <- as.data.frame.list(TabSeries2)
NewTabSeries <- SeriesAggreg2(TabSeries = TabSeries2, Format, ..., ConvertFun = .AggregConvertFun(colnames(TabSeries2)[-1L])) NewTabSeries <- SeriesAggreg(TabSeries = TabSeries2, Format, ..., ConvertFun = .AggregConvertFun(colnames(TabSeries2)[-1L]))
NewTabSeries$zzz <- NULL NewTabSeries$zzz <- NULL
......
SeriesAggreg2 <- function(TabSeries, Format, ...) {
UseMethod("SeriesAggreg2")
}
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
\name{SeriesAggreg} \name{SeriesAggreg}
\alias{SeriesAggreg} \alias{SeriesAggreg}
\alias{SeriesAggreg.list}
\alias{SeriesAggreg.data.frame}
\alias{SeriesAggreg.InputsModel}
\alias{SeriesAggreg.OutputsModel}
\title{Conversion of time series to another time step (aggregation only)} \title{Conversion of time series to another time step (aggregation only)}
...@@ -10,34 +14,59 @@ ...@@ -10,34 +14,59 @@
\description{ \description{
Conversion of time series to another time step (aggregation only). \cr Conversion of time series to another time step (aggregation only). \cr
Warning : on the aggregated outputs, the dates correspond to the beginning of the time step \cr Warning: on the aggregated outputs, the dates correspond to the beginning of the time step \cr
(e.g. for daily time-series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2005-03-01 23:59) \cr (e.g. for daily time series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2005-03-01 23:59) \cr
(e.g. for monthly time-series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2005-03-31 23:59) \cr (e.g. for monthly time series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2005-03-31 23:59) \cr
(e.g. for yearly time-series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2006-02-28 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)
}
\details{
\code{\link{SeriesAggreg.InputsModel}} and \code{\link{SeriesAggreg.OutputsModel}}
call \code{\link{SeriesAggreg.list}} which itself calls \code{\link{SeriesAggreg.data.frame}}.
So, all arguments passed to any \code{\link{SeriesAggreg}} method will be passed to \code{\link{SeriesAggreg.data.frame}}.
} }
\usage{ \usage{
SeriesAggreg(TabSeries, TimeFormat, NewTimeFormat, ConvertFun, \method{SeriesAggreg}{data.frame}(TabSeries,
YearFirstMonth = 1, TimeLag = 0, verbose = TRUE) Format, ConvertFun, TimeFormat = NULL, NewTimeFormat = NULL,
YearFirstMonth = 1, TimeLag = 0,
verbose = TRUE, \dots)
\method{SeriesAggreg}{list}(TabSeries,
Format, simplify = FALSE, \dots)
\method{SeriesAggreg}{InputsModel}(TabSeries,
Format, \dots)
\method{SeriesAggreg}{OutputsModel}(TabSeries,
Format, \dots)
} }
\arguments{ \arguments{
\item{TabSeries}{[POSIXt+numeric] data.frame containing the vector of dates (POSIXt) and the time series values numeric)} \item{TabSeries}{[POSIXt+numeric] data.frame containing the vector of dates (POSIXt) and the time series values numeric)}
\item{TimeFormat}{[character] input time-step format (i.e. \code{"hourly"}, \code{"daily"}, \code{"monthly"} or \code{"yearly"})} \item{Format}{[character] output time step format (i.e. yearly times series: \code{"\%Y"}, monthly time series: \code{"\%Y\%m"}, daily time series: \code{"\%Y\%m\%d"}, monthly regimes \code{"\%m"}, daily regimes \code{"\%d"})}
\item{TimeFormat}{(deprecated) [character] input time step format (i.e. \code{"hourly"}, \code{"daily"}, \code{"monthly"} or \code{"yearly"})}
\item{NewTimeFormat}{[character] output time-step format (i.e. \code{"hourly"}, \code{"daily"}, \code{"monthly"} or \code{"yearly"})} \item{NewTimeFormat}{(deprecated) [character] output time step format (i.e. \code{"hourly"}, \code{"daily"}, \code{"monthly"} or \code{"yearly"}). Use the \code{TabSeries} argument instead}
\item{ConvertFun}{[character] names of aggregation functions (e.g. for P[mm], T[degC], Q[mm] : \code{ConvertFun = c("sum", "mean", "sum"}))} \item{ConvertFun}{[character] names of aggregation functions (e.g. for P[mm], T[degC], Q[mm]: \code{ConvertFun = c("sum", "mean", "sum"}))}
\item{YearFirstMonth}{(optional) [numeric] integer used when \code{NewTimeFormat = "yearly"} to set when the starting month of the year (e.g. 01 for calendar year or 09 for hydrological year starting in September)} \item{YearFirstMonth}{(optional) [numeric] integer used when \code{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)}
\item{TimeLag}{(optional) [numeric] numeric indicating a time lag (in seconds) for the time series aggregation (especially useful to aggregate hourly time series in daily time series)} \item{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)}
\item{verbose}{(optional) [boolean] boolean indicating if the function is run in verbose mode or not, default = \code{FALSE}} \item{verbose}{(optional) [boolean] boolean indicating if the function is run in verbose mode or not, default = \code{TRUE}}
\item{simplify}{(optional) [boolean] XXXXXX, default = \code{FALSE}}
\item{\dots}{Arguments passed to \code{\link{SeriesAggreg.list}} and then to \code{\link{SeriesAggreg.data.frame}}}
} }
\value{ \value{
[POSIXct+numeric] data.frame containing a vector of aggregated dates (POSIXct) and time series values numeric) [POSIXct+numeric] data.frame containing a vector of aggregated dates (POSIXct) and time series values numeric)
} }
...@@ -52,20 +81,21 @@ data(L0123002) ...@@ -52,20 +81,21 @@ data(L0123002)
## preparation of the initial time series data frame at the daily time step ## preparation of the initial time series data frame at the daily time step
TabSeries <- BasinObs[, c("DatesR", "P", "E", "T", "Qmm")] TabSeries <- BasinObs[, c("DatesR", "P", "E", "T", "Qmm")]
## conversion at the monthly time step ## monthly time series
NewTabSeries <- SeriesAggreg(TabSeries = TabSeries, NewTabSeries <- SeriesAggreg(TabSeries = TabSeries,
TimeFormat = "daily", NewTimeFormat = "monthly", Format = "\%Y\%m",
ConvertFun = c("sum", "sum", "mean", "sum")) ConvertFun = c("sum", "sum", "mean", "sum"))
str(NewTabSeries)
## conversion at the yearly time step ## monthly regimes
NewTabSeries <- SeriesAggreg(TabSeries = TabSeries, NewTabSeries <- SeriesAggreg(TabSeries = TabSeries,
TimeFormat = "daily", NewTimeFormat = "yearly", Format = "\%m",
ConvertFun = c("sum", "sum", "mean", "sum")) ConvertFun = c("sum", "sum", "mean", "sum"))
str(NewTabSeries)
} }
\author{ \author{
Laurent Coron Olivier Delaigue
} }
\encoding{UTF-8}
\name{SeriesAggreg2}
\alias{SeriesAggreg2}
\alias{SeriesAggreg2.list}
\alias{SeriesAggreg2.data.frame}
\alias{SeriesAggreg2.InputsModel}
\alias{SeriesAggreg2.OutputsModel}
\title{Conversion of time series to another time step (aggregation only)}
\description{
Conversion of time series to another time step (aggregation only). \cr
Warning: on the aggregated outputs, the dates correspond to the beginning of the time step \cr
(e.g. for daily time series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2005-03-01 23:59) \cr
(e.g. for monthly time series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2005-03-31 23:59) \cr
(e.g. for yearly time series 2005-03-01 00:00 = value for period 2005-03-01 00:00 - 2006-02-28 23:59)
}
\details{
\code{\link{SeriesAggreg2.InputsModel}} and \code{\link{SeriesAggreg2.OutputsModel}}
call \code{\link{SeriesAggreg2.list}} which itself calls \code{\link{SeriesAggreg2.data.frame}}.
So, all arguments passed to any \code{\link{SeriesAggreg2}} method will be passed to \code{\link{SeriesAggreg2.data.frame}}.
}
\usage{
\method{SeriesAggreg2}{data.frame}(TabSeries,
Format, ConvertFun, TimeFormat = NULL, NewTimeFormat = NULL,
YearFirstMonth = 1, TimeLag = 0,
verbose = TRUE, \dots)
\method{SeriesAggreg2}{list}(TabSeries,
Format, simplify = FALSE, \dots)
\method{SeriesAggreg2}{InputsModel}(TabSeries,
Format, \dots)
\method{SeriesAggreg2}{OutputsModel}(TabSeries,
Format, \dots)
}
\arguments{
\item{TabSeries}{[POSIXt+numeric] data.frame containing the vector of dates (POSIXt) and the time series values numeric)}
\item{Format}{[character] output time step format (i.e. yearly times series: \code{"\%Y"}, monthly time series: \code{"\%Y\%m"}, daily time series: \code{"\%Y\%m\%d"}, monthly regimes \code{"\%m"}, daily regimes \code{"\%d"})}
\item{TimeFormat}{(deprecated) [character] input time step format (i.e. \code{"hourly"}, \code{"daily"}, \code{"monthly"} or \code{"yearly"})}
\item{NewTimeFormat}{(deprecated) [character] output time step format (i.e. \code{"hourly"}, \code{"daily"}, \code{"monthly"} or \code{"yearly"}). Use the \code{TabSeries} argument instead}
\item{ConvertFun}{[character] names of aggregation functions (e.g. for P[mm], T[degC], Q[mm]: \code{ConvertFun = c("sum", "mean", "sum"}))}
\item{YearFirstMonth}{(optional) [numeric] integer used when \code{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)}
\item{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)}
\item{verbose}{(optional) [boolean] boolean indicating if the function is run in verbose mode or not, default = \code{TRUE}}
\item{simplify}{(optional) [boolean] XXXXXX, default = \code{FALSE}}
\item{\dots}{Arguments passed to \code{\link{SeriesAggreg2.list}} and then to \code{\link{SeriesAggreg2.data.frame}}}
}
\value{
[POSIXct+numeric] data.frame containing a vector of aggregated dates (POSIXct) and time series values numeric)
}
\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 <- SeriesAggreg2(TabSeries = TabSeries,
Format = "\%Y\%m",
ConvertFun = c("sum", "sum", "mean", "sum"))
str(NewTabSeries)
## monthly regimes
NewTabSeries <- SeriesAggreg2(TabSeries = TabSeries,
Format = "\%m",
ConvertFun = c("sum", "sum", "mean", "sum"))
str(NewTabSeries)
}
\author{
Olivier Delaigue
}
context("SeriesAggreg2") context("SeriesAggreg")
test_that("No warning with InputsModel Cemaneige'", { test_that("No warning with InputsModel Cemaneige'", {
## load of catchment data ## load of catchment data
...@@ -9,6 +9,6 @@ test_that("No warning with InputsModel Cemaneige'", { ...@@ -9,6 +9,6 @@ test_that("No warning with InputsModel Cemaneige'", {
ZInputs = BasinInfo$HypsoData[51], HypsoData=BasinInfo$HypsoData, ZInputs = BasinInfo$HypsoData[51], HypsoData=BasinInfo$HypsoData,
NLayers = 5) NLayers = 5)
expect_warning( expect_warning(
SeriesAggreg2(InputsModel, "%m"), SeriesAggreg(InputsModel, "%m"),
regexp = NA) regexp = NA)
}) })
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment