diff --git a/DESCRIPTION b/DESCRIPTION index 33863672b2605bf5d9b0db4960404bc041052b1b..3facf08453ca826b81967fee81a362d1448abbf3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ 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"), diff --git a/NEWS.md b/NEWS.md index bb266368a7502df97bc9525d3f4c593f56be260e..2b90594be7fe879c3122b69e438edd13598f0c0d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/Imax.R b/R/Imax.R index 3c6058f1b1c4945ee734b2a50a185c5ae3d9f8c5..59abad65dde473044233b1ae19261d540bfc8b56 100644 --- a/R/Imax.R +++ b/R/Imax.R @@ -1,17 +1,20 @@ -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)]) - + }