Commit cba36bf1 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

v1.2.12.9 CLEAN check added in TransfoParam* funs

parent da3856fd
Package: airGR
Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.2.12.8
Version: 1.2.12.9
Date: 2019-03-29
Authors@R: c(
person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
......
......@@ -13,7 +13,7 @@ output:
### 1.2.12.8 Release Notes (2019-03-28)
### 1.2.12.9 Release Notes (2019-03-28)
......@@ -89,6 +89,8 @@ output:
- <code>plot.OutputsModel()</code> does not return a warning message anymore when <code>Qobs = NULL</code>.
- Inputs of <code>TransfoParam&#42;()</code> functions are now checked.
- The order of authors has been updated in the DESCRIPTION and the CITATION files.
____________________________________________________________________________________
......
......@@ -4,7 +4,7 @@ TransfoParam_CemaNeige <- function(ParamIn, Direction) {
NParam <- 2L
## check_arguments
## check arguments
isVecParamIn <- is.vector(ParamIn)
if (isVecParamIn) {
ParamIn <- matrix(ParamIn, nrow = 1)
......@@ -22,16 +22,18 @@ TransfoParam_CemaNeige <- function(ParamIn, Direction) {
## transformation
if (Direction == "TR") {
ParamOut <- ParamIn
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)
}
if (Direction == "RT") {
ParamOut <- ParamIn
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)
}
## check output
if (isVecParamIn) {
ParamOut <- as.vector(ParamOut)
}
......
......@@ -4,7 +4,7 @@ TransfoParam_CemaNeigeHyst <- function(ParamIn, Direction) {
NParam <- 4L
## check_arguments
## check arguments
isVecParamIn <- is.vector(ParamIn)
if (isVecParamIn) {
ParamIn <- matrix(ParamIn, nrow = 1)
......@@ -16,7 +16,7 @@ TransfoParam_CemaNeigeHyst <- function(ParamIn, Direction) {
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 linear hysteresis requires %i parameters", NParam))
stop(sprintf("the CemaNeige module with linear hysteresis requires %i parameters", NParam))
}
......@@ -36,6 +36,8 @@ TransfoParam_CemaNeigeHyst <- function(ParamIn, Direction) {
ParamOut[, 4] <- (ParamIn[, 4] - 0.5) * 19.98 ### Hyst CV
}
## check output
if (isVecParamIn) {
ParamOut <- as.vector(ParamOut)
}
......
TransfoParam_GR1A <- function(ParamIn, Direction) {
NParam <- 1
Bool <- is.matrix(ParamIn)
## number of model parameters
NParam <- 1L
NParam <- 2L
if (Bool == FALSE) {
ParamIn <- rbind(ParamIn)
}
## check arguments
isVecParamIn <- is.vector(ParamIn)
if (isVecParamIn) {
ParamIn <- matrix(ParamIn, nrow = 1)
}
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(paste("the GR1A model requires ", NParam, " parameters", sep = ""))
stop(sprintf("the GR1A model requires %i parameters", NParam))
}
## transformation
if (Direction == "TR") {
ParamOut <- (ParamIn + 10.0) / 8
}
......@@ -18,10 +29,12 @@ TransfoParam_GR1A <- function(ParamIn, Direction) {
ParamOut <- ParamIn * 8 - 10.0
}
if (Bool == FALSE) {
ParamOut <- ParamOut[1, ]
## check output
if (isVecParamIn) {
ParamOut <- as.vector(ParamOut)
}
return(ParamOut)
}
TransfoParam_GR2M <- function(ParamIn, Direction) {
NParam <- 2
Bool <- is.matrix(ParamIn)
## number of model parameters
NParam <- 2L
if (Bool == FALSE) {
ParamIn <- rbind(ParamIn)
## check arguments
isVecParamIn <- is.vector(ParamIn)
if (isVecParamIn) {
ParamIn <- matrix(ParamIn, nrow = 1)
}
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(paste("the GR2M model requires ", NParam, " parameters", sep = ""))
stop(sprintf("the GR2M model requires %i parameters", NParam))
}
## transformation
if (Direction == "TR") {
ParamOut <- ParamIn
ParamOut <- ParamIn
ParamOut[, 1] <- exp(ParamIn[, 1])
ParamOut[, 2] <- ParamIn[, 2] / 4 + 2.5
}
if (Direction == "RT") {
ParamOut <- ParamIn
ParamOut <- ParamIn
ParamOut[, 1] <- log(ParamIn[, 1])
ParamOut[, 2] <- (ParamIn[, 2] - 2.5) * 4
}
if (Bool == FALSE) {
ParamOut <- ParamOut[1, ]
## check output
if (isVecParamIn) {
ParamOut <- as.vector(ParamOut)
}
return(ParamOut)
}
TransfoParam_GR4H <- function(ParamIn,Direction){
TransfoParam_GR4H <- function(ParamIn, Direction) {
NParam <- 4;
Bool <- is.matrix(ParamIn);
if(Bool==FALSE){ ParamIn <- rbind(ParamIn); }
if(ncol(ParamIn)!=NParam){ stop(paste("the GR4H model requires ",NParam," parameters",sep="")) }
if(Direction=="TR"){
ParamOut <- ParamIn;
ParamOut[,1] <- exp(ParamIn[,1]); ### GR4H X1 (production store capacity)
ParamOut[,2] <- sinh(ParamIn[, 2] / 3); ### GR4H X2 (groundwater exchange coefficient)
ParamOut[,3] <- exp(ParamIn[,3]); ### GR4H X3 (routing store capacity)
ParamOut[,4] <- 480 + (480 - 0.5) * (ParamIn[,4] - 9.99) / 19.98; ### GR4H X4 (unit hydrograph time constant)
}
if(Direction=="RT"){
ParamOut <- ParamIn;
ParamOut[,1] <- log(ParamIn[,1]); ### GR4H X1 (production store capacity)
ParamOut[,2] <- 3 * asinh(ParamIn[,2]); ### GR4H X2 (groundwater exchange coefficient)
ParamOut[,3] <- log(ParamIn[,3]); ### GR4H X3 (routing store capacity)
ParamOut[,4] <- (ParamIn[,4] - 480) * 19.98 / (480 - 0.5) + 9.99; ### GR4H X4 (unit hydrograph time constant)
## number of model parameters
NParam <- 4L
## check arguments
isVecParamIn <- is.vector(ParamIn)
if (isVecParamIn) {
ParamIn <- matrix(ParamIn, nrow = 1)
}
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 GR4H model requires %i parameters", NParam))
}
## transformation
if (Direction == "TR") {
ParamOut <- ParamIn
ParamOut[, 1] <- exp(ParamIn[, 1]) ### GR4H X1 (production store capacity)
ParamOut[, 2] <- sinh(ParamIn[, 2] / 3) ### GR4H X2 (groundwater exchange coefficient)
ParamOut[, 3] <- exp(ParamIn[, 3]) ### GR4H X3 (routing store capacity)
ParamOut[, 4] <- 480 + (480 - 0.5) * (ParamIn[, 4] - 9.99) / 19.98 ### GR4H X4 (unit hydrograph time constant)
}
if (Direction == "RT") {
ParamOut <- ParamIn
ParamOut[, 1] <- log(ParamIn[, 1]) ### GR4H X1 (production store capacity)
ParamOut[, 2] <- 3 * asinh(ParamIn[, 2]) ### GR4H X2 (groundwater exchange coefficient)
ParamOut[, 3] <- log(ParamIn[, 3]) ### GR4H X3 (routing store capacity)
ParamOut[, 4] <- (ParamIn[, 4] - 480) * 19.98 / (480 - 0.5) + 9.99 ### GR4H X4 (unit hydrograph time constant)
}
if(Bool==FALSE){ ParamOut <- ParamOut[1,]; }
return(ParamOut);
## check output
if (isVecParamIn) {
ParamOut <- as.vector(ParamOut)
}
return(ParamOut)
}
TransfoParam_GR4J <- function(ParamIn,Direction){
TransfoParam_GR4J <- function(ParamIn, Direction) {
NParam <- 4;
Bool <- is.matrix(ParamIn);
if(Bool==FALSE){ ParamIn <- rbind(ParamIn); }
if(ncol(ParamIn)!=NParam){ stop(paste("the GR4J model requires ",NParam," parameters",sep="")) }
if(Direction=="TR"){
ParamOut <- ParamIn;
ParamOut[,1] <- exp(ParamIn[,1]); ### GR4J X1 (production store capacity)
ParamOut[,2] <- sinh(ParamIn[,2]); ### GR4J X2 (groundwater exchange coefficient)
ParamOut[,3] <- exp(ParamIn[,3]); ### GR4J X3 (routing store capacity)
ParamOut[,4] <- 20+19.5*(ParamIn[,4]-9.99)/19.98; ### GR4J X4 (unit hydrograph time constant)
}
if(Direction=="RT"){
ParamOut <- ParamIn;
ParamOut[,1] <- log(ParamIn[,1]); ### GR4J X1 (production store capacity)
ParamOut[,2] <- asinh(ParamIn[,2]); ### GR4J X2 (groundwater exchange coefficient)
ParamOut[,3] <- log(ParamIn[,3]); ### GR4J X3 (routing store capacity)
ParamOut[,4] <- 9.99+19.98*(ParamIn[,4]-20)/19.5; ### GR4J X4 (unit hydrograph time constant)
## number of model parameters
NParam <- 4L
## check arguments
isVecParamIn <- is.vector(ParamIn)
if (isVecParamIn) {
ParamIn <- matrix(ParamIn, nrow = 1)
}
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 GR4J model requires %i parameters", NParam))
}
## transformation
if (Direction == "TR") {
ParamOut <- ParamIn
ParamOut[, 1] <- exp(ParamIn[, 1]) ### GR4J X1 (production store capacity)
ParamOut[, 2] <- sinh(ParamIn[, 2]) ### GR4J X2 (groundwater exchange coefficient)
ParamOut[, 3] <- exp(ParamIn[, 3]) ### GR4J X3 (routing store capacity)
ParamOut[, 4] <- 20 + 19.5 * (ParamIn[, 4] - 9.99) / 19.98 ### GR4J X4 (unit hydrograph time constant)
}
if (Direction == "RT") {
ParamOut <- ParamIn
ParamOut[, 1] <- log(ParamIn[, 1]) ### GR4J X1 (production store capacity)
ParamOut[, 2] <- asinh(ParamIn[, 2]) ### GR4J X2 (groundwater exchange coefficient)
ParamOut[, 3] <- log(ParamIn[, 3]) ### GR4J X3 (routing store capacity)
ParamOut[, 4] <- 9.99 + 19.98 * (ParamIn[, 4] - 20) / 19.5 ### GR4J X4 (unit hydrograph time constant)
}
if(Bool==FALSE){ ParamOut <- ParamOut[1,]; }
return(ParamOut);
## check output
if (isVecParamIn) {
ParamOut <- as.vector(ParamOut)
}
return(ParamOut)
}
TransfoParam_GR5J <- function(ParamIn,Direction){
NParam <- 5;
Bool <- is.matrix(ParamIn);
if(Bool==FALSE){ ParamIn <- rbind(ParamIn); }
if(ncol(ParamIn)!=NParam){ stop(paste("the GR5J model requires ",NParam," parameters",sep="")) }
if(Direction=="TR"){
ParamOut <- ParamIn;
ParamOut[,1] <- exp(ParamIn[,1]); ### GR5J X1 (production store capacity)
ParamOut[,2] <- sinh(ParamIn[,2]); ### GR5J X2 (groundwater exchange coefficient 1)
ParamOut[,3] <- exp(ParamIn[,3]); ### GR5J X3 (routing store capacity)
ParamOut[,4] <- 20+19.5*(ParamIn[,4]-9.99)/19.98; ### GR5J X4 (unit hydrograph time constant)
ParamOut[,5] <- (ParamIn[,5] + 9.99) / 19.98; ### GR5J X5 (groundwater exchange coefficient 2)
}
if(Direction=="RT"){
ParamOut <- ParamIn;
ParamOut[,1] <- log(ParamIn[,1]); ### GR5J X1 (production store capacity)
ParamOut[,2] <- asinh(ParamIn[,2]); ### GR5J X2 (groundwater exchange coefficient 1)
ParamOut[,3] <- log(ParamIn[,3]); ### GR5J X3 (routing store capacity)
ParamOut[,4] <- 9.99+19.98*(ParamIn[,4]-20)/19.5; ### GR5J X4 (unit hydrograph time constant)
ParamOut[,5] <- ParamIn[,5] * 19.98 - 9.99; ### GR5J X5 (groundwater exchange coefficient 2)
TransfoParam_GR5J <- function(ParamIn, Direction) {
## number of model parameters
NParam <- 5L
## check arguments
isVecParamIn <- is.vector(ParamIn)
if (isVecParamIn) {
ParamIn <- matrix(ParamIn, nrow = 1)
}
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 GR4J model requires %i parameters", NParam))
}
## transformation
if (Direction == "TR") {
ParamOut <- ParamIn
ParamOut[, 1] <- exp(ParamIn[, 1]) ### GR5J X1 (production store capacity)
ParamOut[, 2] <- sinh(ParamIn[, 2]) ### GR5J X2 (groundwater exchange coefficient 1)
ParamOut[, 3] <- exp(ParamIn[, 3]) ### GR5J X3 (routing store capacity)
ParamOut[, 4] <- 20 + 19.5 * (ParamIn[, 4] - 9.99) / 19.98 ### GR5J X4 (unit hydrograph time constant)
ParamOut[, 5] <- (ParamIn[, 5] + 9.99) / 19.98 ### GR5J X5 (groundwater exchange coefficient 2)
}
if (Direction == "RT") {
ParamOut <- ParamIn
ParamOut[, 1] <- log(ParamIn[, 1]) ### GR5J X1 (production store capacity)
ParamOut[, 2] <- asinh(ParamIn[, 2]) ### GR5J X2 (groundwater exchange coefficient 1)
ParamOut[, 3] <- log(ParamIn[, 3]) ### GR5J X3 (routing store capacity)
ParamOut[, 4] <- 9.99 + 19.98 * (ParamIn[, 4] - 20) / 19.5 ### GR5J X4 (unit hydrograph time constant)
ParamOut[, 5] <- ParamIn[, 5] * 19.98 - 9.99 ### GR5J X5 (groundwater exchange coefficient 2)
}
if(Bool==FALSE){ ParamOut <- ParamOut[1,]; }
return(ParamOut);
## check output
if (isVecParamIn) {
ParamOut <- as.vector(ParamOut)
}
return(ParamOut)
}
TransfoParam_GR6J <- function(ParamIn, Direction) {
NParam <- 6
Bool <- is.matrix(ParamIn)
## number of model parameters
NParam <- 6L
if (Bool == FALSE) {
ParamIn <- rbind(ParamIn)
## check arguments
isVecParamIn <- is.vector(ParamIn)
if (isVecParamIn) {
ParamIn <- matrix(ParamIn, nrow = 1)
}
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 GR6J model requires %i parameters", NParam))
}
## transformation
if (Direction == "TR") {
ParamOut <- ParamIn
ParamOut[, 1] <- exp(ParamIn[, 1])
### GR6J X1 (production store capacity)
ParamOut[, 2] <- sinh(ParamIn[, 2])
### GR6J X2 (groundwater exchange coefficient 1)
ParamOut[, 3] <- exp(ParamIn[, 3])
### GR6J X3 (routing store capacity)
ParamOut[, 4] <- 20 + 19.5 * (ParamIn[, 4] - 9.99) / 19.98
### GR6J X4 (unit hydrograph time constant)
ParamOut[, 5] <- ParamIn[, 5] / 5.
### GR5J X5 (groundwater exchange coefficient 2)
ParamOut[, 6] <- exp(ParamIn[, 6])
### GR6J X6 (coefficient for emptying exponential store)
ParamOut <- ParamIn
ParamOut[, 1] <- exp(ParamIn[, 1]) ### GR6J X1 (production store capacity)
ParamOut[, 2] <- sinh(ParamIn[, 2]) ### GR6J X2 (groundwater exchange coefficient 1)
ParamOut[, 3] <- exp(ParamIn[, 3]) ### GR6J X3 (routing store capacity)
ParamOut[, 4] <- 20 + 19.5 * (ParamIn[, 4] - 9.99) / 19.98 ### GR6J X4 (unit hydrograph time constant)
ParamOut[, 5] <- ParamIn[, 5] / 5 ### GR6J X5 (groundwater exchange coefficient 2)
ParamOut[, 6] <- exp(ParamIn[, 6]) ### GR6J X6 (coefficient for emptying exponential store)
}
if (Direction == "RT") {
ParamOut <- ParamIn
ParamOut[, 1] <- log(ParamIn[, 1])
### GR6J X1 (production store capacity)
ParamOut[, 2] <- asinh(ParamIn[, 2])
### GR6J X2 (groundwater exchange coefficient 1)
ParamOut[, 3] <- log(ParamIn[, 3])
### GR6J X3 (routing store capacity)
ParamOut[, 4] <- 9.99 + 19.98 * (ParamIn[, 4] - 20) / 19.5
### GR6J X4 (unit hydrograph time constant)
ParamOut[, 5] <- ParamIn[, 5] * 5.
### GR5J X5 (groundwater exchange coefficient 2)
ParamOut[, 6] <- log(ParamIn[, 6])
### GR6J X6 (coefficient for emptying exponential store)
ParamOut <- ParamIn
ParamOut[, 1] <- log(ParamIn[, 1]) ### GR6J X1 (production store capacity)
ParamOut[, 2] <- asinh(ParamIn[, 2]) ### GR6J X2 (groundwater exchange coefficient 1)
ParamOut[, 3] <- log(ParamIn[, 3]) ### GR6J X3 (routing store capacity)
ParamOut[, 4] <- 9.99 + 19.98 * (ParamIn[, 4] - 20) / 19.5 ### GR6J X4 (unit hydrograph time constant)
ParamOut[, 5] <- ParamIn[, 5] * 5 ### GR6J X5 (groundwater exchange coefficient 2)
ParamOut[, 6] <- log(ParamIn[, 6]) ### GR6J X6 (coefficient for emptying exponential store)
}
if (Bool == FALSE) {
ParamOut <- ParamOut[1, ]
## check output
if (isVecParamIn) {
ParamOut <- as.vector(ParamOut)
}
return(ParamOut)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment