Commit 3ae9b8e2 authored by Dorchies David's avatar Dorchies David
Browse files

v1.6.8.17 feat: SeriesAggreg.OutputsModel implementation and test

Refs #41
Showing with 61 additions and 13 deletions
+61 -13
Package: airGR
Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.6.8.16
Date: 2020-11-30
Version: 1.6.8.17
Date: 2020-12-01
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"),
......
......@@ -4,9 +4,7 @@ SeriesAggreg.OutputsModel <- function(TabSeries, ...) {
stop("to be used with 'OutputsModel' object")
}
res <- SeriesAggreg.list(TabSeries, ...)
res$StateEnd <- TabSeries$StateEnd
res <- SeriesAggreg.list(TabSeries, except = "StateEnd", ...)
return(res)
......
......@@ -68,15 +68,22 @@ test_that("Check SeriesAggreg output values on yearly aggregation", {
GoodValues <- apply(BasinObs[BasinObs$DatesR >= "1984-09-01" &
BasinObs$DatesR < "1985-09-01",
c("P", "E", "Qmm")], 2, sum)
TestedValues <- unlist(SeriesAggreg(
TabSeries,
Format = "%Y",
ConvertFun = rep("sum", 3),
YearFirstMonth = 9
)[1, c("P", "E", "Qmm")])
TestedValues <- unlist(SeriesAggreg(TabSeries,
Format = "%Y",
YearFirstMonth = 9)[1, c("P", "E", "Qmm")])
expect_equal(GoodValues, TestedValues)
})
test_that("No DatesR should warning", {
TabSeries <- list(
Dates = BasinObs$DatesR,
P = BasinObs$P,
E = BasinObs$E,
Qmm = BasinObs$Qmm
)
expect_warning(SeriesAggreg(TabSeries, "%Y%m"), regexp = "has been automatically chosen")
})
test_that("Check SeriesAggreg.list 'DatesR' argument", {
InputsModel <-
CreateInputsModel(
......@@ -95,7 +102,7 @@ test_that("Check SeriesAggreg.list 'DatesR' argument", {
# Wrong InputsModel$DatesR
InputsModel$DatesR <- BasinObs$P
expect_error(SeriesAggreg(InputsModel, "%Y%m"), regexp = "'POSIXt'")
})
test_that("Check SeriesAggreg.list with embedded lists", {
......@@ -113,4 +120,47 @@ test_that("Check SeriesAggreg.list with embedded lists", {
expect_equal(length(I2$ZLayers), 5)
expect_null(I2$LayerPrecip$DatesR)
expect_equal(length(I2$DatesR), length(I2$LayerPrecip$L1))
})
\ No newline at end of file
})
test_that("Check SeriesAggreg.outputsModel", {
InputsModel <-
CreateInputsModel(
FUN_MOD = RunModel_CemaNeigeGR4J,
DatesR = BasinObs$DatesR,
Precip = BasinObs$P,
PotEvap = BasinObs$E,
TempMean = BasinObs$T,
ZInputs = median(BasinInfo$HypsoData),
HypsoData = BasinInfo$HypsoData,
NLayers = 5
)
## run period selection
Ind_Run <-
seq(which(format(BasinObs$DatesR, format = "%Y-%m-%d") == "1990-01-01"),
which(format(BasinObs$DatesR, format = "%Y-%m-%d") == "1999-12-31"))
## preparation of the RunOptions object
RunOptions <-
CreateRunOptions(FUN_MOD = RunModel_CemaNeigeGR4J,
InputsModel = InputsModel,
IndPeriod_Run = Ind_Run)
## simulation
Param <- c(
X1 = 408.774,
X2 = 2.646,
X3 = 131.264,
X4 = 1.174,
CNX1 = 0.962,
CNX2 = 2.249
)
OutputsModel <- RunModel_CemaNeigeGR4J(InputsModel = InputsModel,
RunOptions = RunOptions,
Param = Param)
O2 <- SeriesAggreg(OutputsModel, "%Y%m")
expect_equal(length(O2$StateEnd), 3)
expect_equal(length(O2$DatesR),
length(O2$CemaNeigeLayers$Layer01$Pliq))
})
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