From 36435a545f27fa1c36a7c9fe16133534425e264b Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.fr> Date: Sun, 5 Apr 2020 09:16:53 +0200 Subject: [PATCH] v1.6.0.0 NEW: add 3 arguments in CreateInputsModel in order to take into account semi-distribution in the models #39 --- DESCRIPTION | 4 ++-- NEWS.md | 9 +++++++++ R/CreateInputsModel.R | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e2b5370b..388a6b57 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.4.3.70 -Date: 2020-04-03 +Version: 1.6.0.0 +Date: 2020-04-05 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 3b2dcc21..6fe7a492 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,15 @@ +### 1.6.0.0 Release Notes (2020-04-05) + +#### New features +- Semi-distributed GR models. + + +____________________________________________________________________________________ + + ### 1.4.3.70 Release Notes (2020-04-03) #### CRAN-compatibility updates diff --git a/R/CreateInputsModel.R b/R/CreateInputsModel.R index 510ea517..0afb9f3e 100644 --- a/R/CreateInputsModel.R +++ b/R/CreateInputsModel.R @@ -4,6 +4,7 @@ CreateInputsModel <- function(FUN_MOD, PotEvap = NULL, TempMean = NULL, TempMin = NULL, TempMax = NULL, ZInputs = NULL, HypsoData = NULL, NLayers = 5, + Q_upstr = NULL, L_hyd = NULL, S_basin = NULL, verbose = TRUE) { @@ -183,6 +184,35 @@ CreateInputsModel <- function(FUN_MOD, } } + if (!is.null(Q_upstr) & !is.null(L_hyd) & !is.null(S_basin)) { + ObjectClass <- c(ObjectClass, "SD") + } + # olivier: add a check to avoid any missing argument: + # either we have the three of them (then it is SD) or none (then it is lumped) + + if("SD" %in% ObjectClass){ + if (!("daily" %in% ObjectClass) & !("hourly" %in% ObjectClass)){ + stop("Only daily and hourly time steps can be used in a semi-distributed mode") + } + if (!is.matrix(Q_upstr) | !is.matrix(L_hyd) | !is.matrix(S_basin)) { + stop("'Q_upstr', 'L_hyd' and 'S_basin' must be matrices of numeric values") + } + if (!is.numeric(Q_upstr) | !is.numeric(L_hyd) | !is.numeric(S_basin)) { + stop("'Q_upstr', 'L_hyd' and 'S_basin' must be matrices of numeric values") + } + if (ncol(Q_upstr) != ncol(L_hyd)){ + stop("'Q_upstr' and 'L_hyd' must have the same number of columns") + } + if (ncol(Q_upstr)+1 != ncol(S_basin)){ + stop("'S_basin' must have one column more than 'Q_upstr' and 'L_hyd'") + } + if (nrow(L_hyd) != 1 | nrow(S_basin) != 1){ + stop("'L_hyd' and 'S_basin' must have only one row") + } + if(any(is.na(Q_upstr))){ + stop("'Q_upstr' cannot contain any NA value") + } + } ##check_NA_values BOOL_NA <- rep(FALSE, length(DatesR)) @@ -296,6 +326,11 @@ CreateInputsModel <- function(FUN_MOD, LayerFracSolidPrecip = RESULT$LayerFracSolidPrecip, ZLayers = RESULT$ZLayers)) } + if("SD" %in% ObjectClass){ + InputsModel <- c(InputsModel, list(Q_upstr = Q_upstr, + L_hyd=L_hyd, + S_basin = S_basin)) + } class(InputsModel) <- c("InputsModel", ObjectClass) -- GitLab