knitr::opts_chunk$set(fig.width=12, fig.height=8, fig.path='images/',
                      echo=FALSE, warning=FALSE, message=FALSE, eval=TRUE)
load("data/flood_metadata.RData")
load("data/flood_data.RData")
source("global.R")
library(plot3D)

julian_normalized <- flood_metadata$median_julian / max(flood_metadata$median_julian, na.rm = TRUE)
flood_metadata$area_total[24] <- NA # Getting rid of station n24 which has a much bigger catchment than the others
area_normalized <- flood_metadata$area_total / max(flood_metadata$area_total, na.rm = TRUE)

initial_index <- seq(along = julian_normalized)
to_cluster <- na.omit(data.frame(julian_day = julian_normalized, area = area_normalized, index = initial_index))

set.seed(20)
stationsCluster <- kmeans(to_cluster[1:2], 3, nstart = 20)

st_selection_1 <- c()
st_selection_2 <- c()
st_selection_3 <- c()


for (i in seq(along = to_cluster$index)) {

if (stationsCluster$cluster[[i]] == 1) {st_selection_1[i] <- to_cluster$index[i]}
if (stationsCluster$cluster[[i]] == 2) {st_selection_2[i] <- to_cluster$index[i]}
if (stationsCluster$cluster[[i]] == 3) {st_selection_3[i] <- to_cluster$index[i]}

}

# st_selection_1 <- c(24,24)  # HACK as this station is alone in its cluster
st_selection_1 <- as.vector(na.omit(st_selection_1))
st_selection_2 <- as.vector(na.omit(st_selection_2))
st_selection_3 <- as.vector(na.omit(st_selection_3))


print("st_selection_1")
st_selection_1
print("st_selection_2")
st_selection_2
print("st_selection_3")
st_selection_3

## TO plot the clusters in 2D
plot(to_cluster[1:2], xlab("julian_day"), ylab("size"),
          col = stationsCluster$cluster,
          pch = 20, cex = 3)

QS

QS 2y

gof_type <- "QS"
returnPeriod <- 2

plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_1)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_2)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_3)

QS 10y

returnPeriod <- 10

plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_1)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_2)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_3)

QS 30y

returnPeriod <- 30

plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_1)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_2)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_3)

BS

BS 2y

gof_type <- "BS"
returnPeriod <- 2

plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_1)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_2)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_3)

BS 10y

returnPeriod <- 10

plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_1)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_2)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_3)

BS 30y

returnPeriod <- 30

plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_1)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_2)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_3)

Return levels

RL 10y

gof_type <- "r.levels"
returnPeriod <- 10

plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_1)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_2)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_3)

RL 100y

returnPeriod <- 100

plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_1)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_2)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_3)

RL 200y

returnPeriod <- 200

plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_1)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_2)
plot4server_rlevels_coeffvar_ave(gof_type, returnPeriod,30,150, st_selection_3)

KS

gof_type <- "KS"

plot4server_gof_averaged(gof_type, 30,150, st_selection_1)
plot4server_gof_averaged(gof_type, 30,150, st_selection_2)
plot4server_gof_averaged(gof_type, 30,150, st_selection_3)

AD

gof_type <- "AD"

plot4server_gof_averaged(gof_type, 30,150, st_selection_1)
plot4server_gof_averaged(gof_type, 30,150, st_selection_2)
plot4server_gof_averaged(gof_type, 30,150, st_selection_3)


NVE/FlomKart_ShinyApp documentation built on May 7, 2019, 6:03 p.m.