plot.CalGR.R 3.13 KB
Newer Older
1
plot.CalGR <- function(x, which = c("perf", "hist", "time"), ...) {
unknown's avatar
unknown committed
2
3
4
5
  
  if (! any(class(x) %in% "CalGR")) {
    stop("Non convenient data for x argument. Must be of class \"CalGR\"")
  }
6
7
8
  if (! any(which %in% c("perf", "hist", "time"))) {
    stop("Non convenient data for which argument. Must be of class \"perf\", \"hist\" or \"time\"")
  }  
unknown's avatar
unknown committed
9
  
10
11
  nbParamX <- .TypeModelGR(x)$NbParam #as.numeric(gsub("\\D", "", x$TypeModel))
  nbParamC <- ifelse(.TypeModelGR(x)$CemaNeige, 2, 0)
unknown's avatar
unknown committed
12
13
14
  nbParam <- nbParamX + nbParamC
  nmParam <- c(sprintf("X%i", 1:nbParamX), sprintf("C%i", seq_len(nbParamC)))
  
15
  if (any(which[1L] %in%  c("perf"))) {
16
    plot(x$OutputsModel, Qobs = x$Qobs, ...)
17
18
19
  }
  
  if (any(which[1L] %in%  c("hist"))) {
unknown's avatar
unknown committed
20
21
22
23
24
25
26
27
28
29
30
31
32
    layout.list <- list(matrix(c(1:2), ncol = 2),
                        matrix(c(1:3, 3), ncol = 2),
                        matrix(NA),
                        matrix(c(1:5, 5), ncol = 3),
                        matrix(c(1:5, 0, 6, 6), ncol = 4),
                        matrix(c(1:7, 7), ncol = 4),
                        matrix(c(1:5, 0, 6:8, 8), ncol = 5),
                        matrix(c(1:9, 9), ncol = 5))
    layout.mat <- layout.list[[nbParam]]
    layout.w <- c(rep(1, ncol(layout.mat)-1), 2)
    layout.h <- rep(1, nrow(layout.mat))
    layout(mat = layout.mat, widths = layout.w, heights = layout.h)
  }
33
34
35
36
  # if (which[1L] %in%  c("both")) {
  #   layout.mat <- rbind(layout.mat, max(layout.mat)+1, max(layout.mat)+2)
  #   layout(mat = layout.mat, widths = layout.w, heights = layout.h)
  # }
unknown's avatar
unknown committed
37
38
  if (which[1L] %in%  c("time")) {
    layout(mat = matrix(1:2), widths = c(1, 2), heights = c(1, 2))
39
  }
unknown's avatar
unknown committed
40
  
41
  if (any(which[1L] %in%  c("hist"))) {
unknown's avatar
unknown committed
42
43
44
45
46
47
48
49
50
51
52
53
54
    
    par(mar = c(2.5, 2.5, 4.5, 1))
    for (i in seq_len(ncol(x$OutputsCalib$HistParamR))) {
      
      plot(x$OutputsCalib$HistParamR[, i], col = ifelse(grepl("X", nmParam[i]), "darkorchid3", "darkolivegreen3"),
           type = "b", pch = 19, cex = 0.8,
           xlab = "", ylab = "", main = nmParam[i])
    }
    plot(x$OutputsCalib$HistCrit, col = "tomato",
         type = "b", pch = 19, cex = 1.0,
         xlab = "", ylab = "", main = "Efficiency criteria\nduring the steepest-descent step")
  }
  
55
  if (any(which[1L] %in%  c("time"))) {
unknown's avatar
unknown committed
56
57
58
59
60
61
62
63
64
65
    data <- data.frame(DatesR = x$OutputsModel$DatesR,
                       Precip = x$OutputsModel$Precip,
                       Qobs   = x$Qobs,
                       Qsim   = x$OutputsModel$Qsim)
    
    par(mar = c(0.1, 4, 4, 1), xaxt = "n")
    plot(Precip ~ DatesR, data = data, type = "h", col = "royalblue",
         xlab = "", ylab = "Precip.", main = "", ylim = rev(range(data$Precip)))
    
    par(mar = c(5, 4, 0.1, 1), xaxt = "s")
66
    matplot(data$DatesR, data[, c("Qobs", "Qsim")], type = "l", col = c("black", "orangered"), lty = 1,
unknown's avatar
unknown committed
67
68
69
70
71
72
73
74
75
76
77
         xlab = "Time", ylab = "Flow", main = "", xaxt = "n")
    axis.POSIXct(side = 1, x = data$DatesR)
    
    # if (plot.na) {
    #   axis(side = 1, at = as.POSIXct(data$DatesR[is.na(data$Qobs)]),
    #        labels = FALSE, lwd.ticks = 3, col.ticks = col.na, tck = 0.025, lend = "butt")	
    #   
    #   legend("topright", legend = "NA", pch = 15, col = col.na, bty = "n", cex = 0.8)
    # }
  }
}