Commit a46e9773 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

v1.6.9.28 fix: stop Imax when IndPeriod_Run doesn't select 24 hours by day

Refs #92
Showing with 46 additions and 24 deletions
+46 -24
Package: airGR
Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.6.9.27
Date: 2021-01-18
Version: 1.6.9.28
Date: 2021-01-25
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"),
......
......@@ -2,6 +2,15 @@
### Unreleased
#### Major user-visible changes
- `Imax()` now returns an error message when `IndPeriod_Run` doesn't select 24 hours by day). ([#92](https://gitlab.irstea.fr/HYCAR-Hydro/airgr/-/issues/92))
____________________________________________________________________________________
### 1.6.9.27 Release Notes (2021-01-18)
#### New features
......
Imax <- function(InputsModel,
IndPeriod_Run,
Imax <- function(InputsModel,
IndPeriod_Run,
TestedValues = seq(from = 0.1, to = 3, by = 0.1)) {
##_____Arguments_check_____________________________________________________________________
## ---------- check arguments
## InputsModel
if (!inherits(InputsModel, "InputsModel")) {
stop("'InputsModel' must be of class 'InputsModel'")
}
}
if (!inherits(InputsModel, "hourly")) {
stop("'InputsModel' must be of class 'hourly'")
}
##check_IndPeriod_Run
}
## IndPeriod_Run
if (!is.vector(IndPeriod_Run)) {
stop("'IndPeriod_Run' must be a vector of numeric values")
}
......@@ -21,26 +24,36 @@ Imax <- function(InputsModel,
if (!identical(as.integer(IndPeriod_Run), IndPeriod_Run[1]:IndPeriod_Run[length(IndPeriod_Run)])) {
stop("'IndPeriod_Run' must be a continuous sequence of integers")
}
##TestedValues
## TestedValues
if (!(is.numeric(TestedValues))) {
stop("'TestedValues' must be 'numeric'")
}
##aggregate data at the daily time step
TabSeries <- data.frame(DatesR = InputsModel$DatesR[IndPeriod_Run],
Precip = InputsModel$Precip[IndPeriod_Run],
## ---------- hourly inputs aggregation
## aggregate data at the daily time step
TabSeries <- data.frame(DatesR = InputsModel$DatesR[IndPeriod_Run],
Precip = InputsModel$Precip[IndPeriod_Run],
PotEvap = InputsModel$PotEvap[IndPeriod_Run])
daily_data <- SeriesAggreg(TabSeries, Format = "%Y%m%d",
daily_data <- SeriesAggreg(TabSeries, Format = "%Y%m%d",
ConvertFun = c("sum", "sum"))
##calculate total interception of daily GR models on the period
## ---------- calculate interception
## calculate total interception of daily GR models on the period
cum_daily <- sum(pmin(daily_data$Precip, daily_data$PotEvap))
##calculate total interception of the GR5H interception store on the period
if (anyNA(cum_daily)) {
stop("'IndPeriod_Run' must be set to select 24 hours by day")
}
## calculate total interception of the GR5H interception store on the period
## and compute difference with daily values
differences <- array(NA, c(length(TestedValues)))
print(differences)
for (Imax in TestedValues) {
C0 <- 0
cum_hourly <- 0
......@@ -52,8 +65,8 @@ Imax <- function(InputsModel,
}
differences[which(Imax == TestedValues)] <- abs(cum_hourly - cum_daily)
}
##return the Imax value that minimises the difference
## return the Imax value that minimises the difference
return(TestedValues[which.min(differences)])
}
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