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
lakeperc_normalized <- flood_metadata$perc_lake / max(flood_metadata$perc_lake, na.rm = TRUE)

initial_index <- seq(along = julian_normalized)
to_cluster <- na.omit(data.frame(julian = julian_normalized, lake = lakeperc_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"), ylab("size"),
          col = stationsCluster$cluster,

          pch = 20, cex = 3)
legend("topright", inset = .05, c("Cluster 1","Cluster 2", "Cluster 3" ), cex = 1.2, bty = "n",
             col = c("black", "red","green"),lty = c(1, 1, 1),lwd=c(3, 3, 3), merge = TRUE, bg = "gray90")


# plot(to_cluster[1:2], xlab("julian"), ylab("size"),
# to_cluster[1:2][which(stationsCluster$cluster == 2),]
# 
# 
# legend("topright", inset = .05, c("Cluster 1","Cluster 2", "Cluster 3" ), col = stationsCluster$cluster, lty = c(1, 1, 1),lwd=c(3, 3, 3), merge = TRUE, bg = "gray90") 
# 
# 
#   d <- ggplot() + 
#     # scale_colour_manual(
#     # values = c("black", 
#     #            "red",
#     #            "blue")) + 
#     geom_point(data = to_cluster[1:2], aes(x = julian, y = lake, col = stationsCluster$cluster)) +
#     theme_bw()
# d

QS

gof_type <- "QS"
returnPeriod <- 2

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

BS

gof_type <- "BS"
returnPeriod <- 2

plot4server_QSBS_ave(gof_type, returnPeriod,30,150, st_selection_1)
plot4server_QSBS_ave(gof_type, returnPeriod,30,150, st_selection_2)
plot4server_QSBS_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.