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

v1.6.8.17 feat: SeriesAggreg.OutputsModel implementation and test

Refs #41
parent abb5a04f
Pipeline #17964 passed with stages
in 11 minutes and 19 seconds
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.16 Version: 1.6.8.17
Date: 2020-11-30 Date: 2020-12-01
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"),
......
...@@ -4,9 +4,7 @@ SeriesAggreg.OutputsModel <- function(TabSeries, ...) { ...@@ -4,9 +4,7 @@ SeriesAggreg.OutputsModel <- function(TabSeries, ...) {
stop("to be used with 'OutputsModel' object") stop("to be used with 'OutputsModel' object")
} }
res <- SeriesAggreg.list(TabSeries, ...) res <- SeriesAggreg.list(TabSeries, except = "StateEnd", ...)
res$StateEnd <- TabSeries$StateEnd
return(res) return(res)
......
...@@ -68,15 +68,22 @@ test_that("Check SeriesAggreg output values on yearly aggregation", { ...@@ -68,15 +68,22 @@ test_that("Check SeriesAggreg output values on yearly aggregation", {
GoodValues <- apply(BasinObs[BasinObs$DatesR >= "1984-09-01" & GoodValues <- apply(BasinObs[BasinObs$DatesR >= "1984-09-01" &
BasinObs$DatesR < "1985-09-01", BasinObs$DatesR < "1985-09-01",
c("P", "E", "Qmm")], 2, sum) c("P", "E", "Qmm")], 2, sum)
TestedValues <- unlist(SeriesAggreg( TestedValues <- unlist(SeriesAggreg(TabSeries,
TabSeries, Format = "%Y",
Format = "%Y", YearFirstMonth = 9)[1, c("P", "E", "Qmm")])
ConvertFun = rep("sum", 3),
YearFirstMonth = 9
)[1, c("P", "E", "Qmm")])
expect_equal(GoodValues, TestedValues) 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", { test_that("Check SeriesAggreg.list 'DatesR' argument", {
InputsModel <- InputsModel <-
CreateInputsModel( CreateInputsModel(
...@@ -95,7 +102,7 @@ test_that("Check SeriesAggreg.list 'DatesR' argument", { ...@@ -95,7 +102,7 @@ test_that("Check SeriesAggreg.list 'DatesR' argument", {
# Wrong InputsModel$DatesR # Wrong InputsModel$DatesR
InputsModel$DatesR <- BasinObs$P InputsModel$DatesR <- BasinObs$P
expect_error(SeriesAggreg(InputsModel, "%Y%m"), regexp = "'POSIXt'") expect_error(SeriesAggreg(InputsModel, "%Y%m"), regexp = "'POSIXt'")
}) })
test_that("Check SeriesAggreg.list with embedded lists", { test_that("Check SeriesAggreg.list with embedded lists", {
...@@ -113,4 +120,47 @@ 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_equal(length(I2$ZLayers), 5)
expect_null(I2$LayerPrecip$DatesR) expect_null(I2$LayerPrecip$DatesR)
expect_equal(length(I2$DatesR), length(I2$LayerPrecip$L1)) 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))
})
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