pacotes <- c("raster", "dygraphs", "openair","EcoHydRology")

invisible(sapply(pacotes, FUN = require, character.only = TRUE, quietly = TRUE))
## 
## Attaching package: 'operators'
## 
## The following object is masked from 'package:dygraphs':
## 
##     %>%
## 
## The following object is masked from 'package:base':
## 
##     options
## 
## 
## DEoptim package
## Differential Evolution algorithm in R
## Authors: D. Ardia, K. Mullen, B. Peterson and J. Ulrich
sim.dir <- "~/ADBHM/pauliceia/simctl_roilan_marcelo/SOURCE/R_SCRIPTS/"
setwd(sim.dir )

    start.date <- as.POSIXct("2009-01-01 00:00:00", tz = "GMT")
    end.date <- as.POSIXct("2014-12-31 23:00:00", tz = "GMT")
        date <- seq.POSIXt(start.date, end.date, by = "hour" )

1 Condições iniciais

1.1 Rasters da bacia

# Só precisamos uma rodada para os raster de condições inicias

        
    list.Simulacoes <- basename(list.dirs(path = "../../run/",  full.names = F, recursive = F))
    sims <- as.numeric(gsub(pattern = "_",replacement = "",
                            x = substr(list.Simulacoes, start = 1,stop = 2)))
     list.Simulacoes <- list.Simulacoes[order(sims)]
        list.Simulacoes
##  [1] "1_0_1_0_1_0.5"   "2_1_1_0_1_0.5"   "3_2_1_0_1_0.5"  
##  [4] "4_3_1_0_1_0.5"   "5_0_11_0_1_0.5"  "6_1_11_0_1_0.5" 
##  [7] "7_2_11_0_1_0.5"  "8_3_11_0_1_0.5"  "9_0_26_0_1_0.5" 
## [10] "10_1_26_0_1_0.5" "11_2_26_0_1_0.5" "12_3_26_0_1_0.5"
     basin <- raster(paste("../../run/",list.Simulacoes[1],"/basin1.asc", sep = ""))
     # plot(basin)
     wsdem <- raster(paste("../../run/",list.Simulacoes[1],"/wsdem_pauliceia.asc", sep = ""))
     # plot(wsdem)
    sib2diag <- read.table(file = paste("../../run/",
                                        list.Simulacoes[1],
                                        "/sib2diag.txt", sep = ""), 
                        header = T)
     vars <- c("rn","ldwn","lupw","radswd","radswa","LE","ec","eg","H","G")
    torre <- sib2diag[c(T,F,F),vars]
    length(torre[,1]) == length(date)
## [1] TRUE
    torre$date <- date
      head(torre)
##           rn     ldwn     lupw   radswd   radswa       LE ec       eg
## 1  -31.07615 398.8981 430.0596 0.100000 0.085363 19.46067  0 19.46067
## 4  -29.48080 395.7124 425.2785 0.100000 0.085363 17.98696  0 17.98696
## 7  -28.94879 392.7964 421.8304 0.100000 0.085363 16.19161  0 16.19161
## 10 -27.57398 390.0948 417.7541 0.100000 0.085363 17.38367  0 17.38367
## 13 -29.04882 387.5692 416.7033 0.100000 0.085363 14.27821  0 14.27821
## 16 -36.30805 374.7288 413.3773 2.789559 2.340510 15.95515  0 15.95515
##             H          G                date
## 1   -8.555209  -3.230353 2009-01-01 00:00:00
## 4  -10.439493 -10.583304 2009-01-01 01:00:00
## 7  -11.012618 -15.328748 2009-01-01 02:00:00
## 10  -8.006154 -19.395637 2009-01-01 03:00:00
## 13 -12.342865 -21.588011 2009-01-01 04:00:00
## 16 -16.209661 -24.174086 2009-01-01 05:00:00
    center <- sib2diag[c(F,T,F),vars]
    center$date <- date
      head(center)  
##           rn     ldwn     lupw   radswd    radswa       LE ec       eg
## 2  -31.06573 398.8669 430.0181 0.100000 0.0853621 19.21301  0 19.21301
## 5  -29.46664 395.6815 425.2335 0.100000 0.0853621 17.82387  0 17.82387
## 8  -28.93696 392.7663 421.7885 0.100000 0.0853621 16.05640  0 16.05640
## 11 -27.63436 390.0651 417.7848 0.100000 0.0853621 17.10388  0 17.10388
## 14 -29.05959 387.5399 416.6849 0.100000 0.0853621 14.19649  0 14.19649
## 17 -36.29332 374.7217 413.3542 2.787854 2.3391252 15.83558  0 15.83558
##             H          G                date
## 2   -8.372032  -3.162889 2009-01-01 00:00:00
## 5  -10.329166 -10.469583 2009-01-01 01:00:00
## 8  -10.919917 -15.228049 2009-01-01 02:00:00
## 11  -8.066582 -19.243603 2009-01-01 03:00:00
## 14 -12.282153 -21.456825 2009-01-01 04:00:00
## 17 -16.111380 -24.046228 2009-01-01 05:00:00

1.2 Saldo de Radiação (Rn)

        selec <- "rn"
      Rn <- sapply(1:length(list.Simulacoes), 
                         function(i){
                            cat(i,"..")
                           read.table(file = paste("../../run/",
                                                   list.Simulacoes[i],
                                                   "/sib2diag.txt", sep = ""),
                                      header = T)[c(T,F,F),selec]    
                         }) 
## 1 ..2 ..3 ..4 ..5 ..6 ..7 ..8 ..9 ..10 ..11 ..12 ..
      str( Rn )
##  num [1:52584, 1:12] -31.1 -29.5 -28.9 -27.6 -29 ...
       Rn  <- as.data.frame( Rn )
      str( Rn )
## 'data.frame':    52584 obs. of  12 variables:
##  $ V1 : num  -31.1 -29.5 -28.9 -27.6 -29 ...
##  $ V2 : num  -27.5 -26.2 -25.6 -25.6 -25.8 ...
##  $ V3 : num  -29.8 -28.3 -26.9 -27.8 -28.9 ...
##  $ V4 : num  -27.5 -26.2 -25.6 -25.6 -25.8 ...
##  $ V5 : num  -31.1 -29.3 -26.4 -26.9 -27.7 ...
##  $ V6 : num  -27.5 -26.2 -25.6 -25.6 -25.8 ...
##  $ V7 : num  -29.8 -28.3 -26.9 -27.8 -28.5 ...
##  $ V8 : num  -27.5 -26.2 -25.6 -25.6 -25.8 ...
##  $ V9 : num  -31.1 -29.1 -26.9 -27.3 -27.6 ...
##  $ V10: num  -27.5 -26.2 -25.6 -25.6 -25.8 ...
##  $ V11: num  -29.8 -28.3 -26.9 -27.7 -28.3 ...
##  $ V12: num  -27.5 -26.2 -25.6 -25.6 -25.8 ...
      names( Rn ) <- gsub(pattern = "V",replacement = "", 
                         x = names( Rn ))
       Rn$date <- date

1.3 Fluxo de calor latente (LE)

        selec <- "LE"
      LE <- sapply(1:length(list.Simulacoes), 
                         function(i){
                            cat(i,"..")
                           read.table(file = paste("../../run/",
                                                   list.Simulacoes[i],
                                                   "/sib2diag.txt", sep = ""),
                                      header = T)[c(T,F,F),selec]    
                         }) 
## 1 ..2 ..3 ..4 ..5 ..6 ..7 ..8 ..9 ..10 ..11 ..12 ..
      str(LE)
##  num [1:52584, 1:12] 19.5 18 16.2 17.4 14.3 ...
      LE <- as.data.frame(LE)
      str(LE)
## 'data.frame':    52584 obs. of  12 variables:
##  $ V1 : num  19.5 18 16.2 17.4 14.3 ...
##  $ V2 : num  9.2441 2.1611 0.9841 0.1738 0.0524 ...
##  $ V3 : num  11.8 13.8 15 13.8 13.9 ...
##  $ V4 : num  9.2441 2.1611 0.9841 0.1738 0.0524 ...
##  $ V5 : num  19.5 17.7 18.1 13.7 12.5 ...
##  $ V6 : num  9.2441 2.1611 0.9841 0.1738 0.0524 ...
##  $ V7 : num  11.8 13.8 14.9 13.5 12.8 ...
##  $ V8 : num  9.2441 2.1611 0.9841 0.1738 0.0524 ...
##  $ V9 : num  19.5 17.5 16.6 13.3 12.6 ...
##  $ V10: num  9.2441 2.1612 0.9842 0.174 0.0524 ...
##  $ V11: num  11.8 13.8 14.8 13.1 12.3 ...
##  $ V12: num  9.2441 2.1612 0.9842 0.174 0.0524 ...
      names(LE) <- gsub(pattern = "V",replacement = "", 
                         x = names(LE))
      LE$date <- date

1.4 Fluxo de calor sensível (H)

# Calor sensível na torre
        selec <- "H"
      H <- sapply(1:length(list.Simulacoes), 
                         function(i){
                            cat(i,"..")
                           read.table(file = paste("../../run/",
                                                   list.Simulacoes[i],
                                                   "/sib2diag.txt", sep = ""),
                                      header = T)[c(T,F,F),selec]    
                         }) 
## 1 ..2 ..3 ..4 ..5 ..6 ..7 ..8 ..9 ..10 ..11 ..12 ..
      str(H)
##  num [1:52584, 1:12] -8.56 -10.44 -11.01 -8.01 -12.34 ...
      H <- as.data.frame(H)
      str(H)
## 'data.frame':    52584 obs. of  12 variables:
##  $ V1 : num  -8.56 -10.44 -11.01 -8.01 -12.34 ...
##  $ V2 : num  4.781 -0.303 -0.679 -1.046 -1.523 ...
##  $ V3 : num  -2.3 -7.39 -7.1 -10.72 -12.14 ...
##  $ V4 : num  4.781 -0.303 -0.679 -1.046 -1.523 ...
##  $ V5 : num  -8.56 -10.36 -6.28 -10.01 -11.48 ...
##  $ V6 : num  4.781 -0.303 -0.679 -1.046 -1.523 ...
##  $ V7 : num  -2.3 -7.39 -7.13 -10.62 -11.43 ...
##  $ V8 : num  4.781 -0.303 -0.679 -1.046 -1.523 ...
##  $ V9 : num  -8.56 -10.29 -8 -11.22 -11.17 ...
##  $ V10: num  4.781 -0.303 -0.679 -1.046 -1.523 ...
##  $ V11: num  -2.3 -7.39 -7.16 -10.48 -11.11 ...
##  $ V12: num  4.781 -0.303 -0.679 -1.046 -1.523 ...
      names(H) <- gsub(pattern = "V",replacement = "", 
                         x = names(H))
      H$date <- date
    # Arquivo que contém a descripção das configurações
    rodadas <- read.table("../../run/.rodadas", header = F)
      rodadas <- rodadas[order(rodadas$V1),]
# Plotando com a distribuição PRatio
     vars <-  which(rodadas[,2] == 3) 
    timePlot( Rn , vars,  
             group = F, stack = F, lty = 1,
             name.pol = c(paste("Ks", as.character(rodadas[vars,3]*3.3))),
             ylab = "Radiação neta", xlab = "Data",
             main = "Radiação neta [W/m²], distribuição PRatio"
    )
    timePlot(LE, vars,  
             group = F, stack = F, lty = 1,
             name.pol = c(paste("Ks", as.character(rodadas[vars,3]*3.3))),
             ylab = "Fluxo de calor latente", xlab = "Data",
             main = "Fluxo de calor latente [W/m²], distribuição PRatio"
    ) 
    timePlot(H, vars,  
             group = F, stack = F, lty = 1,
             name.pol = c(paste("Ks", as.character(rodadas[vars,3]*3.3))),
             ylab = "Fluxo de calor sensível", xlab = "Data",
             main = "Fluxo de calor sensível [W/m²], distribuição PRatio"
    )     
# Plotando Com a distribuição da precipitação a media horária em 24 horas
     vars <-  which(rodadas[,2] == 2) 
    timePlot( Rn , vars,  
             group = F, stack = F, lty = 1,
             name.pol = c(paste("Ks", as.character(rodadas[vars,3]*3.3))),
             ylab = "Radiação neta", xlab = "Data",
             main = "Radiação neta [W/m²], distribuição 24 horas"
    )
    timePlot(LE, vars,  
             group = F, stack = F, lty = 1,
             name.pol = c(paste("Ks", as.character(rodadas[vars,3]*3.3))),
             ylab = "Fluxo de calor latente", xlab = "Data",
             main = "Fluxo de calor latente [W/m²], distribuição 24 horas"
    ) 
    timePlot(H, vars,  
             group = F, stack = F, lty = 1,
             name.pol = c(paste("Ks", as.character(rodadas[vars,3]*3.3))),
             ylab = "Fluxo de calor sensível", xlab = "Data",
             main = "Fluxo de calor sensível [W/m²], distribuição 24 horas"
    )