-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDEVTESTS.R
169 lines (116 loc) · 4.59 KB
/
DEVTESTS.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
library(fasstr)
library(tidyverse)
library(tidyhydat)
library(patchwork)
library(ggiraph)
d <- fill_missing_dates(station_number = "08HB048") %>%
add_date_variables(water_year_start = 1) %>%
add_daily_volume() %>%
add_daily_yield()
plot_flow_data_symbols(d, values = "Volume_m3")
plot_annual_symbols(d, plot_percent = FALSE)
plot_monthly_stats2(d)
plot_monthly_stats(d)
plot_annual_stats(d)
plot_data_screening(d, start_year = 1900, end_year = 2000)
plot_data_screening(d, start_year = 1900, end_year = 2000, plot_availability = FALSE)
## Problems with warnings on calculations:
calc_monthly_stats(d, allowed_missing = 100)
plot_monthly_stats2(d)
plot_flow_data(d)[[1]] %>%
plotly::ggplotly() %>%
config(modeBarButtonsToRemove = c("pan", "autoscale", "zoomIn2d", "zoomOut2d",
"hoverCompareCartesian", "hoverClosestCartesian"))
screen_data <- screen_flow_data(
data = d,
start_year = 1972,
end_year = 2019,
water_year_start = 1
)
g <- ggplot(data = screen_data, aes(x = Year, y = Maximum)) +
theme_bw() +
theme(
axis.title = element_text(size = 15),
plot.title = element_text(
size = 15,
hjust = 0.5
),
axis.text = element_text(size = 13)
) +
geom_line(colour = "dodgerblue4") +
geom_point(colour = "firebrick3", size = 2) +
labs(
x = "Year",
y = "Discharge (cms)",
title = "Annual Daily Maximum - Carnation creek at the mouth"
)
girafe(ggobj, g)
dts <- as.Date(c("1900-06-30", "1900-07-30", "1900-04-30"))
daily_stat <- plot_daily_stats(d, values = Yield_mm, ignore_missing = TRUE,
add_year = 2000, log_discharge = TRUE)[[1]]
g <- daily_stat
g <- convert_point_interactive(g)
g <- g + create_vline_interactive(daily_stat$data, stats = c("Day" = "Date",
"Median" = "Median",
"Mean" = "Mean",
"2000" = "RollingValue"))
girafe(ggobj = g)
plot_monthly_stats(d, percentiles = 50)[[1]] %>%
convert_point_interactive()
to_girafe(pmonthly)
plot_annual_normal_days(d, normal_percentiles = c(1,99))
plot_flow_data(d)[[1]] %>%
to_girafe()
dts <- as.Date(c("1900-06-30", "1900-07-30", "1900-04-30"))
plot_daily_stats(d, values = Yield_mm, ignore_missing = TRUE, add_year = 2000, log_discharge = TRUE)[[1]] +
geom_vline(xintercept = dts, colour = "grey20") +
annotate(geom = "text", x = dts, y = Inf, vjust = 2, hjust = 1.05, label = dts)
plot_longterm_daily_stats(d, values = Yield_mm, ignore_missing = TRUE, add_year = 2000, log_discharge = TRUE)[[1]] +
geom_vline(xintercept = dts, colour = "grey20") +
annotate(geom = "text", x = dts, y = Inf, vjust = 2, hjust = 1.05, label = dts)
plot_daily_stats(d, values = Yield_mm)[[1]]$mapping
mad <- calc_longterm_mean(d, percent_MAD = c(5, 10, 50, 99)) %>%
pivot_longer(-STATION_NUMBER, names_to = "type")
plot_daily_stats(d, values = Yield_mm, ignore_missing = TRUE, add_year = 2000, log_discharge = TRUE)[[1]] +
geom_hline(yintercept = mad$value, size = c(1, rep(0.5, nrow(mad) - 1))) +
geom_text(data = mad, aes(y = value, label = type),
x = c(Inf, rep(-Inf, nrow(mad) - 1)),
hjust = c(1.1, rep(-0.1, nrow(mad) -1)), vjust = -0.5)
calc_longterm_mean(d, percent_MAD = c(5, 10 ,50), complete_years = TRUE)
plot_annual_cumulative_stats(d, include_seasons = TRUE) %>%
wrap_plots(nrow = 2, byrow = FALSE, design = "AACC\nBBCC")
calc_annual_flow_timing(d)
plot_annual_flow_timing(d, values = Volume_m3)
calc_annual_lowflows(d)
plot_annual_lowflows(d, values = Volume_m3)[[1]] # Discharge
plot_annual_lowflows(d)[[2]] # DOY
calc_annual_peaks(d)
calc_annual_normal_days(d)
plot_annual_normal_days(d)
# Annual trends
at <- compute_annual_trends(d, zyp_method = "zhang")
to_ggiraph(at[[4]], type = "Annual Mean")
at$Annual_Trends_Data %>% filter(Statistic == "DoY_25pct_TotalQ")
at$Annual_Trends_Data
# Vol freq
v <- compute_annual_frequencies(d, roll_days = c(1, 3, 7, 9)) # uses compute_frequency_analysis
names(v)
v$Freq_Analysis_Data
v$Freq_Plot_Data
v$Freq_Plot
v$Freq_Fitting
v$Freq_Fitted_Quantiles
to_ggiraph(v$Freq_Plot, type = "flow")
# Single value
compute_frequency_quantile(d, roll_days = 7, return_period = 10)
tidyhydat::download_hydat()
v2 <- compute_hydat_peak_frequencies("08HB048")
compute_hydat_peak_frequencies("08HB048", fit_distr = "PIII")
# Just in case
# ggplotly_cust <- function(x, digits = 4) {
# opts <- options(digits = digits)
# p <- plotly::ggplotly(x) %>%
# plotly::config(modeBarButtons = list(list("toImage")))
# options(opts)
# p
# }