TransfoParam_GR6J.R 1.56 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
TransfoParam_GR6J <- function(ParamIn, Direction) {
  
  NParam <- 6
  
  Bool <- is.matrix(ParamIn)
  
  if (Bool == FALSE) {
    ParamIn <- rbind(ParamIn)
  }
  if (ncol(ParamIn) != NParam) {
    stop(sprintf("the GR6J model requires %i parameters", NParam))
  }
  
  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)
  }
  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)
  }
  
  if (Bool == FALSE) {
    ParamOut <- ParamOut[1, ]
  }
  return(ParamOut)
  
Delaigue Olivier's avatar
Delaigue Olivier committed
52
}