diff --git a/DESCRIPTION b/DESCRIPTION index 00b5589d42b3f82eb4c7574702cc8e6348248322..83c5ba3280a2b8f20537c2d7069af81eaaef6880 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: airGR Type: Package Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling -Version: 1.6.8.10 -Date: 2020-11-20 +Version: 1.6.8.11 +Date: 2020-11-24 Authors@R: c( 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"), diff --git a/NAMESPACE b/NAMESPACE index 067f5e391acee4c748aa33335eb24559fa35cf8e..7c6fd5c88e1a7d9271ffbc4c7854533b8184f809 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,10 +9,10 @@ useDynLib(airGR, .registration = TRUE) ## S3 methods ## ##################################### S3method("plot", "OutputsModel") -S3method("SeriesAggreg2", "data.frame") -S3method("SeriesAggreg2", "list") -S3method("SeriesAggreg2", "InputsModel") -S3method("SeriesAggreg2", "OutputsModel") +S3method("SeriesAggreg", "data.frame") +S3method("SeriesAggreg", "list") +S3method("SeriesAggreg", "InputsModel") +S3method("SeriesAggreg", "OutputsModel") @@ -51,11 +51,10 @@ export(RunModel_GR5J) export(RunModel_GR6J) export(RunModel_Lag) export(SeriesAggreg) -export(SeriesAggreg2) -export(SeriesAggreg2.list) -export(SeriesAggreg2.data.frame) -export(SeriesAggreg2.InputsModel) -export(SeriesAggreg2.OutputsModel) +export(SeriesAggreg.list) +export(SeriesAggreg.data.frame) +export(SeriesAggreg.InputsModel) +export(SeriesAggreg.OutputsModel) export(TransfoParam) export(TransfoParam_CemaNeige) export(TransfoParam_CemaNeigeHyst) diff --git a/NEWS.md b/NEWS.md index 9e82f16aedc0c9333b551596322288de7d95dd1c..6fdd93f079db1a45f4e07800481dc3f8f578f8e4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,12 +6,12 @@ #### 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. #### 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>. ____________________________________________________________________________________ diff --git a/R/SeriesAggreg2.InputsModel.R b/R/SeriesAggreg.InputsModel.R similarity index 60% rename from R/SeriesAggreg2.InputsModel.R rename to R/SeriesAggreg.InputsModel.R index c969f36a9f77b345185e43acc8a6dbeb1afa6bfe..26ebb067a9d643d58b7aa0325ab5144b4e82e7ef 100644 --- a/R/SeriesAggreg2.InputsModel.R +++ b/R/SeriesAggreg.InputsModel.R @@ -1,10 +1,10 @@ -SeriesAggreg2.InputsModel <- function(TabSeries, Format, ...) { +SeriesAggreg.InputsModel <- function(TabSeries, Format, ...) { if (!inherits(TabSeries, "InputsModel")) { stop("to be used with 'InputsModel' object") } - res <- SeriesAggreg2.list(TabSeries = TabSeries, Format, ...) + res <- SeriesAggreg.list(TabSeries = TabSeries, Format, ...) if (inherits(TabSeries, "CemaNeige")) { res$ZLayers <- TabSeries$ZLayers diff --git a/R/SeriesAggreg2.OutputsModel.R b/R/SeriesAggreg.OutputsModel.R similarity index 56% rename from R/SeriesAggreg2.OutputsModel.R rename to R/SeriesAggreg.OutputsModel.R index 978ffc1315ae8a8834be3b6096dfb75dd8440c4f..a1179e3e5ffcb2da5e295bf3c3fa388bf1b81af3 100644 --- a/R/SeriesAggreg2.OutputsModel.R +++ b/R/SeriesAggreg.OutputsModel.R @@ -1,10 +1,10 @@ -SeriesAggreg2.OutputsModel <- function(TabSeries, Format, ...) { +SeriesAggreg.OutputsModel <- function(TabSeries, Format, ...) { if (!inherits(TabSeries, "OutputsModel")) { stop("to be used with 'OutputsModel' object") } - res <- SeriesAggreg2.list(TabSeries, Format, ...) + res <- SeriesAggreg.list(TabSeries, Format, ...) res$StateEnd <- TabSeries$StateEnd diff --git a/R/SeriesAggreg.R b/R/SeriesAggreg.R index 209afb36de7f5ce2d05b6d93a08a74aa0d25550d..b4fd59fd619e8b17da1f4c9de8d8e6a9d86dbc92 100644 --- a/R/SeriesAggreg.R +++ b/R/SeriesAggreg.R @@ -1,174 +1,3 @@ -SeriesAggreg <- function(TabSeries, - TimeFormat, NewTimeFormat, - 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 +SeriesAggreg <- function(TabSeries, Format, ...) { + UseMethod("SeriesAggreg") +} diff --git a/R/SeriesAggreg2.data.frame.R b/R/SeriesAggreg.data.frame.R similarity index 98% rename from R/SeriesAggreg2.data.frame.R rename to R/SeriesAggreg.data.frame.R index f50fa3adf753b716818990f83949bb2cfe6cd684..cb6320fe2ead581cd7bab381d6f5d17272bc1c77 100644 --- a/R/SeriesAggreg2.data.frame.R +++ b/R/SeriesAggreg.data.frame.R @@ -1,4 +1,4 @@ -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, ...) { ## Arguments checks diff --git a/R/SeriesAggreg2.list.R b/R/SeriesAggreg.list.R similarity index 88% rename from R/SeriesAggreg2.list.R rename to R/SeriesAggreg.list.R index fbf7ec495fff2e5c3e452206d50dac5ac99de613..c8dacf1fd6296dabe1b23e668b142c60edf99635 100644 --- a/R/SeriesAggreg2.list.R +++ b/R/SeriesAggreg.list.R @@ -1,4 +1,4 @@ -SeriesAggreg2.list <- function(TabSeries, Format, simplify = FALSE, ...) { +SeriesAggreg.list <- function(TabSeries, Format, simplify = FALSE, ...) { if (!inherits(TabSeries, c("InputsModel", "OutputsModel"))) { stop("to be used with InputsModel', or 'OutputsModel' object") @@ -35,7 +35,7 @@ SeriesAggreg2.list <- function(TabSeries, Format, simplify = FALSE, ...) { } CemaNeigeLayersAggreg <- lapply(CemaNeigeLayers, function(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] colnames(res) <- gsub(".*[.]", "", colnames(res)) res <- as.list(res) @@ -45,7 +45,7 @@ SeriesAggreg2.list <- function(TabSeries, Format, simplify = FALSE, ...) { TabSeries2 <- TabSeries[1:which(names(TabSeries) %in% lastCol)] 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 diff --git a/R/SeriesAggreg2.R b/R/SeriesAggreg2.R deleted file mode 100644 index 3dabbcabc641dbbf2487a35f02a12b7374da7f8a..0000000000000000000000000000000000000000 --- a/R/SeriesAggreg2.R +++ /dev/null @@ -1,3 +0,0 @@ -SeriesAggreg2 <- function(TabSeries, Format, ...) { - UseMethod("SeriesAggreg2") -} diff --git a/man/SeriesAggreg.Rd b/man/SeriesAggreg.Rd index 4498eb6e09ef89614ef7561ff74e7e061e581363..3c15f379a355109c10c9ded24382ee913b4d8394 100644 --- a/man/SeriesAggreg.Rd +++ b/man/SeriesAggreg.Rd @@ -3,6 +3,10 @@ \name{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)} @@ -10,34 +14,59 @@ \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) +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{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{ -SeriesAggreg(TabSeries, TimeFormat, NewTimeFormat, ConvertFun, - YearFirstMonth = 1, TimeLag = 0, verbose = TRUE) +\method{SeriesAggreg}{data.frame}(TabSeries, +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{ \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{ [POSIXct+numeric] data.frame containing a vector of aggregated dates (POSIXct) and time series values numeric) } @@ -52,20 +81,21 @@ data(L0123002) ## preparation of the initial time series data frame at the daily time step TabSeries <- BasinObs[, c("DatesR", "P", "E", "T", "Qmm")] -## conversion at the monthly time step +## monthly time series NewTabSeries <- SeriesAggreg(TabSeries = TabSeries, - TimeFormat = "daily", NewTimeFormat = "monthly", - ConvertFun = c("sum", "sum", "mean", "sum")) + Format = "\%Y\%m", + ConvertFun = c("sum", "sum", "mean", "sum")) +str(NewTabSeries) -## conversion at the yearly time step +## monthly regimes NewTabSeries <- SeriesAggreg(TabSeries = TabSeries, - TimeFormat = "daily", NewTimeFormat = "yearly", - ConvertFun = c("sum", "sum", "mean", "sum")) - + Format = "\%m", + ConvertFun = c("sum", "sum", "mean", "sum")) +str(NewTabSeries) } \author{ -Laurent Coron +Olivier Delaigue } diff --git a/man/SeriesAggreg2.Rd b/man/SeriesAggreg2.Rd deleted file mode 100644 index a67601e021b7983c9bf58b83b4d8c4eb0c2bdd3c..0000000000000000000000000000000000000000 --- a/man/SeriesAggreg2.Rd +++ /dev/null @@ -1,101 +0,0 @@ -\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 -} - diff --git a/tests/testthat/test-SeriesAggreg2.R b/tests/testthat/test-SeriesAggreg.R similarity index 88% rename from tests/testthat/test-SeriesAggreg2.R rename to tests/testthat/test-SeriesAggreg.R index 677e2e524cfbe08fb2aab7c72bb000a54607d8ba..6a29bcffcf9c9540d6df9b0ecc9341a023b1322b 100644 --- a/tests/testthat/test-SeriesAggreg2.R +++ b/tests/testthat/test-SeriesAggreg.R @@ -1,4 +1,4 @@ -context("SeriesAggreg2") +context("SeriesAggreg") test_that("No warning with InputsModel Cemaneige'", { ## load of catchment data @@ -9,6 +9,6 @@ test_that("No warning with InputsModel Cemaneige'", { ZInputs = BasinInfo$HypsoData[51], HypsoData=BasinInfo$HypsoData, NLayers = 5) expect_warning( - SeriesAggreg2(InputsModel, "%m"), + SeriesAggreg(InputsModel, "%m"), regexp = NA) })