Commit 62b0d86b authored by Delaigue Olivier's avatar Delaigue Olivier Committed by Dorchies David
Browse files

v1.4.5.0 feat: new SeriesAggreg2.default function #41

be careful, for the moment all the variables are aggregated using ConvertFun = "sum". The aggregation function has to be adapted to each variable!
parent be0efdf2
Package: airGR
Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.4.4.28
Version: 1.4.5.0
Date: 2020-04-30
Authors@R: c(
person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
......
......@@ -10,6 +10,7 @@ useDynLib(airGR, .registration = TRUE)
#####################################
S3method("plot", "OutputsModel")
S3method("SeriesAggreg2", "data.frame")
S3method("SeriesAggreg2", "default")
......
......@@ -4,12 +4,13 @@
### 1.4.4.28 Release Notes (2020-04-30)
### 1.4.5.0 Release Notes (2020-04-30)
#### New features
- Added <code>SeriesAggreg2()</code> method.
- Added <code>SeriesAggreg2()</code> function. This new verson of the <code>SeriesAggreg()</code> function allows to compute regimes.
- Added <code>SeriesAggreg2</code> method.
- Added <code>SeriesAggreg2.default()</code> function.
- Added <code>SeriesAggreg2.data.frame()</code> function. This new verson of the <code>SeriesAggreg()</code> function allows to compute regimes.
#### Deprecated and defunct
......
SeriesAggreg2.default <- function(TabSeries,
Format,
TimeFormat,
NewTimeFormat,
YearFirstMonth = 1, TimeLag = 0,
verbose = TRUE, ..., simplify = FALSE) {
# if (!inherits(TabSeries, "GR")) {
# stop("to be used with 'InputsModel', or 'OutputsModel' object")
# }
if (!inherits(TabSeries, c("InputsModel", "OutputsModel"))) {
stop("to be used with InputsModel', or 'OutputsModel' object")
}
if (!inherits(TabSeries, "GR") & inherits(TabSeries, "CemaNeige")) {
ClassTabSeries <- class(TabSeries)
zzz <- list(zzz = rep(NaN, length(TabSeries$DatesR)))
TabSeries <- append(TabSeries, values = zzz, after = 1)
class(TabSeries) <- ClassTabSeries
lastCol <- "zzz"
}
if (inherits(TabSeries, "GR")) {
if (inherits(TabSeries, "InputsModel")) {
lastCol <- "PotEvap"
}
if (inherits(TabSeries, "OutputsModel")) {
lastCol <- "Qsim"
}
}
if (inherits(TabSeries, "CemaNeige")) {
if (inherits(TabSeries, "InputsModel")) {
CemaNeigeLayers <- TabSeries[grep("^Layer", names(TabSeries))]
}
if (inherits(TabSeries, "OutputsModel") ){
CemaNeigeLayers <- TabSeries$CemaNeigeLayers
}
CemaNeigeLayersAggreg <- lapply(CemaNeigeLayers, function(iLayer) {
tmp <- cbind(TabSeries$DatesR, as.data.frame(iLayer))
res <- SeriesAggreg2(tmp, Format = Format,
TimeFormat = TimeFormat, NewTimeFormat = NewTimeFormat,
ConvertFun = rep("sum", ncol(tmp)-1),
YearFirstMonth = YearFirstMonth, TimeLag = TimeLag,
verbose = verbose)
res <- res[, -1L]
res <- as.list(res)
})
}
TabSeries2 <- TabSeries[1:which(names(TabSeries) %in% lastCol)]
TabSeries2 <- as.data.frame.list(TabSeries2)
NewTabSeries <- SeriesAggreg2(TabSeries = TabSeries2,
Format = Format,
TimeFormat = TimeFormat, NewTimeFormat = NewTimeFormat,
ConvertFun = rep("sum", ncol(TabSeries2)-1),
YearFirstMonth = YearFirstMonth, TimeLag = TimeLag,
verbose = verbose)
res$zzz <- NULL
if (simplify) {
return(NewTabSeries)
} else {
ClassFormat <- switch(substr(Format, start = nchar(Format), stop = nchar(Format)),
h = "hourly",
d = "daily",
m = "monthly",
Y = "yearly")
## to be consistent with InputsModel class and because plot.OutputsModel use the POSIXlt class
NewTabSeries$DatesR <- as.POSIXlt(NewTabSeries$DatesR)
res <- as.list(NewTabSeries)
if (inherits(TabSeries, "CemaNeige")) {
res$CemaNeigeLayers <- CemaNeigeLayersAggreg
}
class(res) <- gsub("hourly|daily|monthly|yearly", ClassFormat, class(TabSeries))
return(res)
}
}
\ No newline at end of file
Markdown is supported
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