This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path2_flow_metrics.R
254 lines (236 loc) · 10.9 KB
/
2_flow_metrics.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
source("2_flow_metrics/src/calc_HIT.R")
source("2_flow_metrics/src/calc_FDC.R")
#####################
##p2_only parameters
##statistics to compute within EflowStats
stats_HIT <- c("calc_magAverage", "calc_magLow", "calc_magHigh",
"calc_frequencyHigh", "calc_durationHigh", "calc_rateChange"
)
##EflowStats metrics to use
metrics <- c('ma1',
'ml17', 'ml18',
'mh20',
'fh2',
'dh1', 'dh6', 'dh15', 'dh16', 'dh23',
'ra1', 'ra2', 'ra3', 'ra4'
)
##metrics to normalize by drainage area
metrics_DA <- c('ma1', 'dh1', 'ra1', 'ra3')
##metric ml17 to normalize by *annual mean/drainage area
metrics_ml17 <- c('ml17')
##metrics to normalize by *median/drainage area
metrics_med_DA <- NULL
p2_targets_list<- list(
##compute all HIT metrics for screened sites list
tar_target(p2_HIT_metrics,
calc_HITmetrics(site_num = p1_screened_site_list,
clean_daily_flow = p1_clean_daily_flow,
yearType = yearType,
drainArea_tab = p1_drainage_area,
floodThreshold_tab = p1_flood_threshold,
stat_vec = stats_HIT,
save_metrics = metrics,
norm_DA = metrics_DA,
norm_med_DA = metrics_med_DA,
norm_ml17 = metrics_ml17,
out_format = 'pivot'),
map(p1_screened_site_list),
deployment = 'worker'
),
##compute additional FDC-based metrics for screened sites list
tar_target(p2_FDC_metrics,
calc_FDCmetrics(site_num = p1_screened_site_list,
clean_daily_flow = p1_clean_daily_flow,
yearType = yearType,
drainArea_tab = p1_drainage_area,
NE_probs = NE_quants,
seasonal = FALSE,
year_start = year_start,
out_format = 'pivot',
allow_event_overlap = TRUE),
map(p1_screened_site_list),
deployment = 'worker'
),
tar_target(p2_FDC_metrics_low,
calc_FDCmetrics(site_num = p1_screened_site_list,
clean_daily_flow = p1_clean_daily_flow,
yearType = yearType,
drainArea_tab = p1_drainage_area,
NE_probs = NE_quants_low,
seasonal = FALSE,
year_start = year_start,
out_format = 'pivot',
threshold_type = 'low',
allow_event_overlap = TRUE),
map(p1_screened_site_list),
deployment = 'worker'
),
##combined metrics tables
tar_target(p2_all_metrics,
inner_join(p2_FDC_metrics,p2_HIT_metrics)
),
#Metrics ml17 and 18 have NAs for some gages, so we will not predict them.
#also dropping 0.98, 0.99, and 0.995 metrics
tar_target(p2_all_metrics_predict,
p2_all_metrics %>%
select(-ml17, -ml18, -contains('0.98'),
-contains('0.99'), -contains('0.995'))
),
##list of all the metrics names - for dynamic branching
tar_target(p2_all_metrics_names,
colnames(p2_all_metrics)[-1]
),
tar_target(p2_all_metrics_names_predict,
colnames(p2_all_metrics_predict)[-1]
),
tar_target(p2_all_metrics_names_low,
colnames(p2_FDC_metrics_low)[
-c(1,
#Removing columns with NAs
grep(colnames(p2_FDC_metrics_low), pattern = 'q0.005'),
grep(colnames(p2_FDC_metrics_low), pattern = 'q0.01'))
]
),
tar_target(p2_FDC_metrics_names,
colnames(p2_FDC_metrics)[-1]
),
##Compute FDC-based metrics using non-overlapping event definitions
tar_target(p2_FDC_metrics_nonoverlapping,
calc_FDCmetrics(site_num = p1_screened_site_list,
clean_daily_flow = p1_clean_daily_flow,
yearType = yearType,
drainArea_tab = p1_drainage_area,
NE_probs = c(0.5, 0.75,0.95),
seasonal = FALSE,
year_start = year_start,
out_format = 'pivot',
allow_event_overlap = FALSE),
map(p1_screened_site_list),
deployment = 'worker'
),
tar_target(p2_FDC_metrics_low_nonoverlapping,
calc_FDCmetrics(site_num = p1_screened_site_list,
clean_daily_flow = p1_clean_daily_flow,
yearType = yearType,
drainArea_tab = p1_drainage_area,
NE_probs = c(0.5, 0.25,0.05),
seasonal = FALSE,
year_start = year_start,
out_format = 'pivot',
threshold_type = 'low',
allow_event_overlap = FALSE),
map(p1_screened_site_list),
deployment = 'worker'
),
#For these aggregated ranges of events, we would not be interested in the
# category above the second NE_quants (70-max in this case). Should remove
# that result from these targets.
tar_target(p2_FDC_metrics_nonoverlapping_agg5070,
calc_FDCmetrics(site_num = p1_screened_site_list,
clean_daily_flow = p1_clean_daily_flow,
yearType = yearType,
drainArea_tab = p1_drainage_area,
NE_probs = NE_quants[c(1,5)],
seasonal = FALSE,
year_start = year_start,
out_format = 'pivot',
allow_event_overlap = FALSE),
map(p1_screened_site_list),
deployment = 'worker'
),
tar_target(p2_FDC_metrics_nonoverlapping_agg7595,
calc_FDCmetrics(site_num = p1_screened_site_list,
clean_daily_flow = p1_clean_daily_flow,
yearType = yearType,
drainArea_tab = p1_drainage_area,
NE_probs = NE_quants[c(6,10)],
seasonal = FALSE,
year_start = year_start,
out_format = 'pivot',
allow_event_overlap = FALSE),
map(p1_screened_site_list),
deployment = 'worker'
),
##compute seasonal FDC-based metrics using water year seasons
tar_target(p2_FDC_metrics_season,
calc_FDCmetrics(site_num = p1_screened_site_list_season,
clean_daily_flow = p1_clean_daily_flow_season,
yearType = yearType,
drainArea_tab = NULL,
NE_probs = NE_quants,
seasonal = TRUE,
season_months = season_months,
stat_type = 'POR',
year_start = season_year_start,
out_format = 'pivot',
allow_event_overlap = TRUE),
map(p1_screened_site_list_season),
deployment = 'worker'
),
#Low flow
tar_target(p2_FDC_metrics_season_low,
calc_FDCmetrics(site_num = p1_screened_site_list_season,
clean_daily_flow = p1_clean_daily_flow_season,
yearType = yearType,
drainArea_tab = NULL,
NE_probs = NE_quants_low,
seasonal = TRUE,
season_months = season_months,
stat_type = 'POR',
year_start = season_year_start,
out_format = 'pivot',
threshold_type = 'low',
allow_event_overlap= TRUE),
map(p1_screened_site_list_season),
deployment = 'worker'
),
##compute seasonal FDC-based metrics using water year seasons and
##non-overlapping event definitions
tar_target(p2_FDC_metrics_season_nonoverlapping,
calc_FDCmetrics(site_num = p1_screened_site_list_season,
clean_daily_flow = p1_clean_daily_flow_season,
yearType = yearType,
drainArea_tab = NULL,
NE_probs = c(0.5,0.75,0.95),
seasonal = TRUE,
season_months = season_months,
stat_type = 'POR',
year_start = season_year_start,
out_format = 'pivot',
allow_event_overlap = FALSE),
map(p1_screened_site_list_season),
deployment = 'worker'
),
#Low flow
tar_target(p2_FDC_metrics_season_low_nonoverlapping,
calc_FDCmetrics(site_num = p1_screened_site_list_season,
clean_daily_flow = p1_clean_daily_flow_season,
yearType = yearType,
drainArea_tab = NULL,
NE_probs = c(0.5,0.25,0.05),
seasonal = TRUE,
season_months = season_months,
stat_type = 'POR',
year_start = season_year_start,
out_format = 'pivot',
threshold_type = 'low',
allow_event_overlap= FALSE),
map(p1_screened_site_list_season),
deployment = 'worker'
)
##compute seasonal FDC-based metrics using high flow seasons
# tar_target(p2_FDC_metrics_season_high,
# calc_FDCmetrics(site_num = p1_screened_site_list_season_high,
# clean_daily_flow = p1_clean_daily_flow_season_high,
# yearType = yearType,
# drainArea_tab = NULL,
# NE_probs = NE_quants,
# seasonal = TRUE,
# season_months = season_months_high,
# stat_type = 'POR',
# year_start = season_year_start_high,
# out_format = 'pivot'),
# map(p1_screened_site_list_season_high),
# deployment = 'worker'
# )
)