From 29cbbd1fba7e7d7f7e3213cf04d6e64ed699360b Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.fr> Date: Wed, 11 Dec 2019 16:07:10 +0100 Subject: [PATCH] v1.4.2.15 UPDATE: conditionnal test modified to take into that no IniResLevels is a vector of length 4 in CreateRunOptions #13 --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/CreateRunOptions.R | 64 +++++++++++++++++++++++++++++++------------- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 033ecb57..4d93f1c1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: airGR Type: Package Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling -Version: 1.4.2.14 +Version: 1.4.2.15 Date: 2019-12-11 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), diff --git a/NEWS.md b/NEWS.md index 72c11579..426274bb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ -### 1.4.2.14 Release Notes (2019-12-11) +### 1.4.2.15 Release Notes (2019-12-11) #### New features diff --git a/R/CreateRunOptions.R b/R/CreateRunOptions.R index 9322c37d..1c145a94 100644 --- a/R/CreateRunOptions.R +++ b/R/CreateRunOptions.R @@ -178,37 +178,65 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP ## check IniResLevels if ("GR" %in% ObjectClass & ("monthly" %in% ObjectClass | "daily" %in% ObjectClass | "hourly" %in% ObjectClass)) { if (!is.null(IniResLevels)) { - if (!is.vector(IniResLevels) | !is.numeric(IniResLevels) | any(is.na(IniResLevels))) { - stop("'IniResLevels' must be a vector of numeric values") + # if (!is.vector(IniResLevels) | !is.numeric(IniResLevels) | any(is.na(IniResLevels))) { + if (!is.vector(IniResLevels) | is.character(IniResLevels) | is.factor(IniResLevels) | length(IniResLevels) != 4) { + stop("'IniResLevels' must be a vector of 4 numeric values") } - if ((identical(FUN_MOD, RunModel_GR4H) | identical(FUN_MOD, RunModel_CemaNeigeGR4H) | - (identical(FUN_MOD, RunModel_GR5H) & !IsIntStore) | - identical(FUN_MOD, RunModel_GR4J) | identical(FUN_MOD, RunModel_CemaNeigeGR4J) | - identical(FUN_MOD, RunModel_GR5J) | identical(FUN_MOD, RunModel_CemaNeigeGR5J) | - identical(FUN_MOD, RunModel_GR2M)) & - length(IniResLevels) != 2) { - stop("the length of 'IniResLevels' must be 2 for the chosen 'FUN_MOD'") + # if ((identical(FUN_MOD, RunModel_GR4H) | identical(FUN_MOD, RunModel_CemaNeigeGR4H) | + # # (identical(FUN_MOD, RunModel_GR5H) & !IsIntStore) | + # identical(FUN_MOD, RunModel_GR5H) | + # identical(FUN_MOD, RunModel_GR4J) | identical(FUN_MOD, RunModel_CemaNeigeGR4J) | + # identical(FUN_MOD, RunModel_GR5J) | identical(FUN_MOD, RunModel_CemaNeigeGR5J) | + # identical(FUN_MOD, RunModel_GR2M)) & + # length(IniResLevels) != 2) { + # stop("the length of 'IniResLevels' must be 2 for the chosen 'FUN_MOD'") + # } + if (any(is.na(IniResLevels[1:2]))) { + stop("the first 2 values of 'IniResLevels' cannot be missing values for the chosen 'FUN_MOD'") } - if ((identical(FUN_MOD,RunModel_GR6J) | identical(FUN_MOD,RunModel_CemaNeigeGR6J) | - (identical(FUN_MOD, RunModel_GR5H) & IsIntStore)) & - length(IniResLevels) != 3) { - stop("the length of 'IniResLevels' must be 3 for the chosen 'FUN_MOD'") + # if ((identical(FUN_MOD,RunModel_GR6J) | identical(FUN_MOD,RunModel_CemaNeigeGR6J) | + # (identical(FUN_MOD, RunModel_GR5H) & IsIntStore)) & + # length(IniResLevels) != 3) { + # stop("the length of 'IniResLevels' must be 3 for the chosen 'FUN_MOD'") + # } + if ((identical(FUN_MOD,RunModel_GR6J) | identical(FUN_MOD,RunModel_CemaNeigeGR6J))) { + if (is.na(IniResLevels[3L])) { + stop("the third value of 'IniResLevels' cannot be a missing value for the chosen 'FUN_MOD'") + } + } else { + if (!is.na(IniResLevels[3L])) { + warning("the third value of 'IniResLevels' is set to NA value for the chosen 'FUN_MOD'. Only GR6J presents an exponential store") + IniResLevels[3L] <- NA + } } + if (identical(FUN_MOD,RunModel_GR5H)) { # | identical(FUN_MOD,RunModel_CemaNeigeGR5H) + if (IsIntStore & is.na(IniResLevels[4L])) { + stop("the fourth value of 'IniResLevels' cannot be a missing value for the chosen 'FUN_MOD' with a given value set for 'Imax") + } + if (!IsIntStore & !is.na(IniResLevels[4L])) { + warning("the fourth value of 'IniResLevels' is set to NA value for the chosen 'FUN_MOD'. Only GR5H uses with an 'Imax' value presents an interception store") + IniResLevels[4L] <- NA + } + } else { + if (!is.na(IniResLevels[4L])) { + warning("the fourth value of 'IniResLevels' is set to NA value for the chosen 'FUN_MOD'. Only GR5H uses with an 'Imax' value presents an interception store") + IniResLevels[4L] <- NA + } + } } else if (is.null(IniStates)) { + IniResLevels <- as.double(c(0.3, 0.5, NA, NA)) if (identical(FUN_MOD, RunModel_GR6J) | identical(FUN_MOD, RunModel_CemaNeigeGR6J)) { IniResLevels <- as.double(c(0.3, 0.5, 0, NA)) } # if ((identical(FUN_MOD, RunModel_GR5H) | identical(FUN_MOD, RunModel_CemaNeigeGR5H)) & IsIntStore) { if ((identical(FUN_MOD, RunModel_GR5H)) & IsIntStore) { - IniResLevels <- as.double(c(0.3, 0.5, NA, 0)) } # if (!identical(FUN_MOD, RunModel_GR6J) & !identical(FUN_MOD, RunModel_CemaNeigeGR6J) & # !identical(FUN_MOD, RunModel_GR5H) & !identical(FUN_MOD, RunModel_CemaNeigeGR5H)) { - if (!identical(FUN_MOD, RunModel_GR6J) & !identical(FUN_MOD, RunModel_CemaNeigeGR6J) & - !identical(FUN_MOD, RunModel_GR5H)) { - IniResLevels <- as.double(c(0.3, 0.5, NA, NA)) - } + # if (is.null(IniStates)) { + # IniResLevels <- as.double(c(0.3, 0.5, NA, NA)) + # } } } else { if (!is.null(IniResLevels)) { -- GitLab