Commit 4c632fc5 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

v1.6.8.35 refactor: rename getSeriesAggreg* functions into .GetSeriesAggreg*

Refs #41, #77, !12
Showing with 18 additions and 15 deletions
+18 -15
Package: airGR
Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.6.8.34
Version: 1.6.8.35
Date: 2021-01-05
Authors@R: c(
person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
......
......@@ -7,7 +7,7 @@
#### New features
- 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 also allows to compute regimes. ([#25](https://gitlab.irstea.fr/HYCAR-Hydro/airgr/-/issues/25))
- Added <code>getAggregConvertFun()</code> private function in order to choose automatically the <code>ConvertFun</code> to apply on each element of objects used in <code>SeriesAggreg</code>.
- Added <code>.GetAggregConvertFun()</code> private function in order to choose automatically the <code>ConvertFun</code> to apply on each element of objects used in <code>SeriesAggreg.InputsModel</code> and <code>SeriesAggreg.OutputsModel</code>.
- Added <code>.AggregConvertFunTable</code> data.frame that allows the user to see what names of list items or data.frame column names are guessed and eventually customise this correspondence table.
#### Bug fixes
......
SeriesAggreg.InputsModel <- function(x, ...) {
SeriesAggreg.list(x,
ConvertFun = getAggregConvertFun(names(x)),
ConvertFun = .GetAggregConvertFun(names(x)),
except = c("ZLayers", "LengthHydro", "BasinAreas"),
...)
}
SeriesAggreg.OutputsModel <- function(x, ...) {
SeriesAggreg.list(x,
ConvertFun = getAggregConvertFun(names(x)),
ConvertFun = .GetAggregConvertFun(names(x)),
except = "StateEnd",
...)
}
......@@ -11,7 +11,7 @@ SeriesAggreg.data.frame <- function(x,
warning("deprecated 'TimeFormat' argument", call. = FALSE)
}
if (missing(Format)) {
Format <- getSeriesAggregFormat(NewTimeFormat)
Format <- .GetSeriesAggregFormat(NewTimeFormat)
} else if (!is.null(NewTimeFormat)) {
warning("deprecated 'NewTimeFormat' argument: 'Format' argument is used instead",
call. = FALSE)
......
......@@ -7,7 +7,7 @@ SeriesAggreg.list <- function(x,
recursive = TRUE,
...) {
if (missing(Format)) {
Format <- getSeriesAggregFormat(NewTimeFormat)
Format <- .GetSeriesAggregFormat(NewTimeFormat)
} else if (!is.null(NewTimeFormat)) {
warning("deprecated 'NewTimeFormat' argument: 'Format' argument is used instead",
call. = FALSE)
......@@ -59,7 +59,7 @@ SeriesAggreg.list <- function(x,
}
dfOut <- NULL
if (length(cols)) {
ConvertFun2 <- getAggregConvertFun(names(cols))
ConvertFun2 <- .GetAggregConvertFun(names(cols))
if (is.null(recursive)) {
if (missing(ConvertFun)) {
stop("'ConvertFun' argument should provided if 'recursive = NULL'")
......@@ -94,7 +94,7 @@ SeriesAggreg.list <- function(x,
listCols <- listCols[setdiff(names(listCols), names(dfCols))]
if (length(listCols) > 0) {
# Check for predefined ConvertFun for all sub-elements
ConvertFun <- getAggregConvertFun(names(listCols))
ConvertFun <- .GetAggregConvertFun(names(listCols))
# Run SeriesAggreg for each embedded list
listRes <- lapply(names(listCols), function(x) {
listCols[[x]]$DatesR <- DatesR
......@@ -129,7 +129,7 @@ SeriesAggreg.list <- function(x,
"), it will be ignored in the aggregation"
)
} else {
ConvertFun <- rep(getAggregConvertFun(key), ncol(m))
ConvertFun <- rep(.GetAggregConvertFun(key), ncol(m))
res[[key]] <- SeriesAggreg(data.frame(DatesR, m),
Format = Format,
ConvertFun = ConvertFun)
......@@ -142,7 +142,7 @@ SeriesAggreg.list <- function(x,
res <- c(res, x[setdiff(names(x), names(res))])
class(res) <- gsub("hourly|daily|monthly|yearly",
getSeriesAggregClass(Format),
.GetSeriesAggregClass(Format),
class(x))
return(res)
......
getSeriesAggregFormat <- function(NewTimeFormat) {
.GetSeriesAggregFormat <- function(NewTimeFormat) {
errNewTimeFormat <- FALSE
if (missing(NewTimeFormat)) {
errNewTimeFormat <- TRUE
......@@ -25,7 +25,7 @@ getSeriesAggregFormat <- function(NewTimeFormat) {
return(NULL)
}
getSeriesAggregClass <- function(Format) {
.GetSeriesAggregClass <- function(Format) {
Format <- substr(Format,
start = nchar(Format),
stop = nchar(Format))
......@@ -36,18 +36,18 @@ getSeriesAggregClass <- function(Format) {
Y = "yearly")
}
getAggregConvertFun <- function(Outputs) {
.GetAggregConvertFun <- function(Outputs) {
AggregConvertFunTable <- rbind(
data.frame(ConvertFun = "mean",
Outputs = c("Prod","Rout","Exp","SnowPack","ThermalState",
"Gratio","Temp","Gthreshold","Glocalmax","LayerTempMean", "T"),
stringsAsFactors = FALSE), # R < 4.0 compatibility: avoids mixing numeric and factor into numeric in getAggregConvertFun()
stringsAsFactors = FALSE), # R < 4.0 compatibility: avoids mixing numeric and factor into numeric
data.frame(ConvertFun = "sum",
Outputs = c("PotEvap","Precip","Pn","Ps","AE","Perc","PR","Q9",
"Q1","Exch","AExch1","AExch2","AExch","QR","QRExp",
"QD","Qsim","Pliq","Psol","PotMelt","Melt","PliqAndMelt",
"LayerPrecip","LayerFracSolidPrecip", "Qmm", "Qls", "E", "P", "Qupstream"),
stringsAsFactors = FALSE) # R < 4.0 compatibility: avoids mixing numeric and factor into numeric in getAggregConvertFun()
stringsAsFactors = FALSE) # R < 4.0 compatibility: avoids mixing numeric and factor into numeric
)
res <- sapply(Outputs, function(iOutputs) {
iRes <- AggregConvertFunTable$ConvertFun[AggregConvertFunTable$Outputs == iOutputs]
......
......@@ -20,11 +20,14 @@ Warning: on the aggregated outputs, the dates correspond to the beginning of the
(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{
\method{SeriesAggreg}{data.frame}(x,
Format,
......
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