From 2f7c5399a9a97d0cffc8c6229779c36fa5153222 Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.priv> Date: Mon, 1 Apr 2019 16:42:03 +0200 Subject: [PATCH] v1.2.13.2 UPDATE: CreateRunOptions now check the compatibility between FUN_MOD, IniStates and IsHyst arguments --- DESCRIPTION | 2 +- NEWS.rmd | 2 +- R/CreateRunOptions.R | 35 ++++++++++++++++++++++++++--------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cd6ce9c6..5a01cea1 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.2.13.1 +Version: 1.2.13.2 Date: 2019-04-01 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), diff --git a/NEWS.rmd b/NEWS.rmd index ba7b0072..997d2e5f 100644 --- a/NEWS.rmd +++ b/NEWS.rmd @@ -13,7 +13,7 @@ output: -### 1.2.13.1 Release Notes (2019-04-01) +### 1.2.13.2 Release Notes (2019-04-01) diff --git a/R/CreateRunOptions.R b/R/CreateRunOptions.R index ac2c42f4..0dc15e76 100644 --- a/R/CreateRunOptions.R +++ b/R/CreateRunOptions.R @@ -139,10 +139,10 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP stop("'IndPeriod_WarmUp' should be of type integer") } if (identical(IndPeriod_WarmUp, as.integer(0)) & verbose) { - message(paste0(WTxt, ". No warm up period is used")) + message(paste0(WTxt, " No warm up period is used")) } if ((IndPeriod_Run[1] - 1) != tail(IndPeriod_WarmUp, 1) & !identical(IndPeriod_WarmUp, as.integer(0))) { - WTxt <- paste0(WTxt, ". Model warm up period is not directly before the model run period") + WTxt <- paste0(WTxt, " Model warm up period is not directly before the model run period") } } if (!is.null(WTxt) & warnings) { @@ -209,32 +209,49 @@ CreateRunOptions <- function(FUN_MOD, InputsModel, IndPeriod_WarmUp = NULL, IndP if (!is.null(IniStates)) { if (!inherits(IniStates, "IniStates")) { - stop("'IniStates' must be an object of class 'IniStates'\n") + stop("'IniStates' must be an object of class 'IniStates'") } if (sum(ObjectClass %in% class(IniStates)) < 2) { - stop(paste0("non convenient 'IniStates' for this 'FUN_MOD'\n")) + stop(paste0("non convenient 'IniStates' for the chosen 'FUN_MOD'")) } if (identical(FUN_MOD, RunModel_GR1A) & !is.null(IniStates)) { ## GR1A - stop(paste0("'IniStates' is not available for this 'FUN_MOD'\n")) + stop(paste0("'IniStates' is not available for the chosen 'FUN_MOD'")) } if ((identical(FUN_MOD, RunModel_GR5J) | identical(FUN_MOD, RunModel_CemaNeigeGR5J)) & !all(is.na(IniStates$UH$UH1))) { ## GR5J - stop(paste0("non convenient IniStates for this 'FUN_MOD.' In 'IniStates', 'UH1' has to be a vector of NA for GR5J")) + stop(paste0("non convenient 'IniStates' for the chosen 'FUN_MOD'.' In 'IniStates', 'UH1' has to be a vector of NA for GR5J")) } if ((identical(FUN_MOD, RunModel_GR6J) | identical(FUN_MOD, RunModel_CemaNeigeGR6J)) & is.na(IniStates$Store$Exp)) { ## GR6J - stop(paste0("non convenient IniStates for this 'FUN_MOD.' GR6J needs an exponential store value in 'IniStates'")) + stop(paste0("non convenient 'IniStates' for the chosen 'FUN_MOD'.' GR6J needs an exponential store value in 'IniStates'")) } if (!(identical(FUN_MOD, RunModel_GR6J) | identical(FUN_MOD, RunModel_CemaNeigeGR6J)) & !is.na(IniStates$Store$Exp)) { ## except GR6J - stop(paste0("non convenient IniStates for this 'FUN_MOD.' No exponential store value needed in 'IniStates'")) + stop(paste0("non convenient 'IniStates' for the chosen 'FUN_MOD'.' No exponential store value needed in 'IniStates'")) } # if (length(na.omit(unlist(IniStates))) != NState) { # stop(paste0("the length of IniStates must be ", NState, " for the chosen FUN_MOD")) # } + if ((!"CemaNeige" %in% ObjectClass & inherits(IniStates, "CemaNeige")) | + ( "CemaNeige" %in% ObjectClass & !inherits(IniStates, "CemaNeige"))) { + stop("'FUN_MOD' and 'IniStates' must be both of class 'CemaNeige'") + } + if (!"CemaNeige" %in% ObjectClass & "hysteresis" %in% ObjectClass) { + stop("'IsHyst' cannot be TRUE for the chosen 'FUN_MOD'") + } + if (( "hysteresis" %in% ObjectClass & !inherits(IniStates, "hysteresis")) | + (!"hysteresis" %in% ObjectClass & inherits(IniStates, "hysteresis"))) { + stop("'IsHyst' and 'IniStates' are not consistent on the use of the hysteresis") + } if (!"CemaNeige" %in% ObjectClass & any(is.na(IniStates$CemaNeigeLayers$G ))) { - IniStates$CemaNeigeLayers$G <- NULL + IniStates$CemaNeigeLayers$G <- NULL } if (!"CemaNeige" %in% ObjectClass & any(is.na(IniStates$CemaNeigeLayers$eTG))) { IniStates$CemaNeigeLayers$eTG <- NULL } + if (!"CemaNeige" %in% ObjectClass & any(is.na(IniStates$CemaNeigeLayers$Gthr))) { + IniStates$CemaNeigeLayers$Gthr <- NULL + } + if (!"CemaNeige" %in% ObjectClass & any(is.na(IniStates$CemaNeigeLayers$Glocmax))) { + IniStates$CemaNeigeLayers$Glocmax <- NULL + } IniStates$Store$Rest <- rep(NA, 4) IniStates <- unlist(IniStates) IniStates[is.na(IniStates)] <- 0 -- GitLab