-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_modna-output_weekly_dis.R
83 lines (67 loc) · 2.89 KB
/
graph_modna-output_weekly_dis.R
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
library(tidyverse)
library(lubridate)
library(stringi)
detach("package:hydroGOF", unload=TRUE)
path <- "/home/christoph/Dokumente/BOKU/Masterarbeit/master/daten/output" #stimmt der pfAD?
if( .Platform$OS.type == "windows" )
path <- "C:/Users/Russ/Desktop/master/daten/output"
setwd(path)
file <- "tt2summary.txt"
### to get r to read in files with in the form of
### dmmyyy AND ddmmyyy we have to do smt like this:
discharge <- read_table(file, col_names = T,
cols(TTMMYYYY = "c",
.default=col_double()))
stri_sub(discharge$TTMMYYYY,-6,0) <- "-"
stri_sub(discharge$TTMMYYYY,-4,0) <- "-"
discharge$TTMMYYYY <- as.Date(discharge$TTMMYYYY, "%d-%m-%Y")
# now the dates are correctly read in
#calculate qsim and select output which is interesting for us
discharge <- discharge %>% mutate(qsim=linout + cascout) %>%
select(., TTMMYYYY,Qobs,qsim,linout,cascout)
### calculate weekly discharge
# dplyr and pipe ftw!
weekly_dis <- discharge %>%
group_by(week = week(TTMMYYYY))%>%
summarise(
Qobs = mean(Qobs),
qsim = mean(qsim),
linout = mean(linout),
cascout = mean(cascout))
library(hydroGOF)
nse <- NSE(weekly_dis$qsim,weekly_dis$Qobs)
kge <- KGE(weekly_dis$qsim,weekly_dis$Qobs)
Q <- ggplot(data= weekly_dis)+
geom_line( aes(x=week, y=Qobs, color = "Qobs"))+
geom_line( aes(x=week, y=qsim, color = "Qsim"))+
# geom_line( aes(x=week, y=linout, color = "lin"))+
# geom_line( aes(x=week, y=cascout, color = "casc"))+
xlab("Date")+
ylab("mean weekly discharge [mm]")+
annotate("text", x=40, y=10,label="nse= ")+
annotate("text", x=45.5, y=10,label=as.character(round(nse,2)))+
annotate("text", x=40, y=9,label="kge= ")+
annotate("text", x=45.5, y=9,label=as.character(round(kge,2)))+
scale_color_manual(values=c("Qobs"="#00BFC4", "Qsim"="#C77CFF",
"lin"="#7CAE00", "casc"="#F8766D"))
Q
# setwd("C:/Users/Russ/Desktop/master/plotfiles_weekly")
# file = paste(format(Sys.time(), "%Y-%m-%d_%H-%M"),"_Q_weekly",".png",sep="")
# ggsave(file, height = 3.368173, width = 4.27, units = "in")
#
# ##to trace my changes copy inputfile.txt to directories of plots
#
# file <- list.files("C:/Users/Russ/Desktop/master/daten/input/",
# "inputmodna.txt", full.names = TRUE)
# file.copy(file,"C:/Users/Russ/Desktop/master/plotfiles_weekly")
#
# ##rename files
#
# # in plotfiles_weekly
# file.rename("inputmodna.txt",paste(format(Sys.time(), "%Y-%m-%d_%H-%M"),
# "_inputmodna", ".txt", sep = ""))
#sources:
#copy files: https://stackoverflow.com/questions/2384517/using-r-to-copy-files#2384621
#rename files: https://stackoverflow.com/questions/10758965/how-do-i-rename-files-using-r
#scale_color_manual:https://stackoverflow.com/a/40181166
#weekly data: https://stackoverflow.com/questions/40554231/dplyr-lubridate-how-to-aggregate-a-dataframe-by-week#comment68346741_40554231