From b34b5d06c7d598cf55c61badca7e17efae0b02af Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.priv> Date: Fri, 15 Feb 2019 11:00:48 +0100 Subject: [PATCH] v1.2.2.0 NEW: add TransfoParam_CemaNeigeHyst fun to use hysteresis in CemaNeige #5252 --- DESCRIPTION | 4 +-- NEWS.rmd | 2 +- R/TransfoParam_CemaNeigeHyst.R | 46 ++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 R/TransfoParam_CemaNeigeHyst.R diff --git a/DESCRIPTION b/DESCRIPTION index 03632ab6..0eeed09a 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.2.1.1 -Date: 2019-01-30 +Version: 1.2.2.0 +Date: 2019-02-15 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), person("Charles", "Perrin", role = c("aut", "ths"), comment = c(ORCID = "0000-0001-8552-1881")), diff --git a/NEWS.rmd b/NEWS.rmd index 448d57e4..2c09db93 100644 --- a/NEWS.rmd +++ b/NEWS.rmd @@ -13,7 +13,7 @@ output: -### 1.2.1.1 Release Notes (2019-01-30) +### 1.2.2.0 Release Notes (2019-01-30) diff --git a/R/TransfoParam_CemaNeigeHyst.R b/R/TransfoParam_CemaNeigeHyst.R new file mode 100644 index 00000000..09a88934 --- /dev/null +++ b/R/TransfoParam_CemaNeigeHyst.R @@ -0,0 +1,46 @@ +TransfoParam_CemaNeigeHyst <- function(ParamIn, Direction) { + + + NParam <- 4L + + + ## check_arguments + Bool <- is.vector(ParamIn) + if (Bool) { + ParamIn <- matrix(ParamIn, nrow = 1) + warning("'ParamIn' automatically convert to 'matrix'") + } + if (!inherits(ParamIn, "matrix")) { + stop("'ParamIn' must be of class 'matrix'") + } + if (!inherits(Direction, "character") | length(Direction) != 1 | any(!Direction %in% c("RT", "TR"))) { + stop("'Direction' must be a character vector of length 1 equal to 'RT' or 'TR'") + } + if (ncol(ParamIn) != NParam) { + stop(sprintf( "the CemaNeige module with hysteresis requires %i parameters", NParam)) + } + + + if (Direction == "TR") { + ParamOut <- ParamIn + ParamOut[, 1] <- (ParamIn[, 1] + 9.99) / 19.98 ### CemaNeige X1 (weighting coefficient for snow pack thermal state) + ParamOut[, 2] <- exp(ParamIn[, 2]) / 200 ### CemaNeige X2 (degree-day melt coefficient) + ParamOut[, 3] <- (ParamIn[, 3] * 5) + 50 ### Hyst Gaccum + ParamOut[, 4] <- (ParamIn[, 4] / 19.98) + 0.5 ### Hyst CV + } + if (Direction == "RT") { + ParamOut <- ParamIn + ParamOut[, 1] <- ParamIn[, 1] * 19.98 - 9.99 ### CemaNeige X1 (weighting coefficient for snow pack thermal state) + ParamOut[, 2] <- log(ParamIn[, 2] * 200) ### CemaNeige X2 (degree-day melt coefficient) + ParamOut[, 3] <- (ParamIn[, 3] - 50) / 5 ### Hyst Gaccum + ParamOut[, 4] <- (ParamIn[, 4] - 0.5) * 19.98 ### Hyst CV + } + + if (Bool) { + ParamOut <- as.vector(ParamOut) + } + + return(ParamOut) + +} + -- GitLab