forked from USGS-R/drb-inland-salinity-ml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_visualize.R
276 lines (260 loc) · 10.1 KB
/
3_visualize.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
source("3_visualize/src/plot_daily_data.R")
source("3_visualize/src/plot_inst_data.R")
source("3_visualize/src/map_SC_sites.R")
source("3_visualize/src/summarize_site_list.R")
source("3_visualize/src/summarize_timeseries.R")
source("3_visualize/src/plot_nhdv2_attr.R")
source("3_visualize/src/summarize_nhdv2_attr.R")
source("3_visualize/src/plot_ecdf.R")
p3_targets_list <- list(
# Plot daily data
# this is a 'local' target so making p3_daily_timeseries_ind_csv works
# see https://github.com/USGS-R/drb-inland-salinity-ml/issues/153
tar_target(
p3_daily_timeseries_png,
plot_daily_data(sprintf("3_visualize/out/daily_timeseries_png/daily_data_%s.png",
unique(p1_daily_data$site_no)),
p1_daily_data),
format = "file",
pattern = map(p1_daily_data),
repository = 'local'
),
# Plot instantaneous data (hourly averages)
# this is a 'local' target so making p3_inst_timeseries_ind_csv works
# see https://github.com/USGS-R/drb-inland-salinity-ml/issues/153
tar_target(
p3_hourly_timeseries_png,
plot_inst_data(sprintf("3_visualize/out/hourly_timeseries_png/hourly_data_%s.png",
unique(p2_inst_data_hourly$site_no)),
p2_inst_data_hourly),
format = "file",
pattern = map(p2_inst_data_hourly),
repository = 'local'
),
# Create and save log file containing data availability summary
tar_target(
p3_sitelist_summary_csv,
summarize_site_list(p2_site_list_nontidal_csv,p1_daily_data,p1_inst_data,
fileout = "3_visualize/log/sitelist_summary.csv"),
format = "file",
repository = 'local',
deployment = 'main'
),
# Create and save indicator file for NWIS daily data
tar_target(
p3_daily_timeseries_ind_csv,
command = save_target_ind_files("3_visualize/log/daily_timeseries_ind.csv",
names(p3_daily_timeseries_png)),
format = "file",
repository = 'local',
deployment = 'main'
),
# Create and save indicator file for NWIS instantaneous data
tar_target(
p3_inst_timeseries_ind_csv,
command = save_target_ind_files("3_visualize/log/inst_timeseries_ind.csv",
names(p3_hourly_timeseries_png)),
format = "file",
repository = 'local',
deployment = 'main'
),
# Create and save indicator file for WQP data
tar_target(
p3_wqp_ind_csv,
command = {
#forcing dependency to the target because the character string
#of the target name does not enforce it
force_dep <- p2_wqp_SC_data
save_target_ind_files("3_visualize/log/wqp_data_ind.csv", "p2_wqp_SC_data")
},
format = "file",
repository = 'local',
deployment = "main"
),
# Create and save summary log file for NWIS daily data
tar_target(
p3_daily_timeseries_summary_csv,
target_summary_stats(p1_daily_data, "Value",
"3_visualize/log/daily_timeseries_summary.csv"),
format = "file",
repository = 'local',
deployment = 'main'
),
# Create and save summary log file for NWIS instantaneous data
tar_target(
p3_inst_timeseries_summary_csv,
target_summary_stats(p1_inst_data, "Value_Inst",
"3_visualize/log/inst_timeseries_summary.csv"),
format = "file",
repository = 'local',
deployment = 'main'
),
# Render data summary report (note that tar_render returns a target with format="file")
# note - this is commented out b/c I'm getting an error
# see https://github.com/USGS-R/drb-inland-salinity-ml/issues/154
#tarchetypes::tar_render(p3_SC_report,
#"3_visualize/src/report-wqp-salinity-data.Rmd",
#output_dir = "3_visualize/out",
#deployment = 'main'
#),
# Plot distribution of NHDv2 attribute variables across the PRMS network
# see note at top of 1_fetch.R re why this is a 'local' target
tar_target(
p3_nhdv2_attr_png,
plot_nhdv2_attr(attr_data = p2_nhdv2_attr,
network_geometry = p1_reaches_sf,
file_path = "3_visualize/out/nhdv2_attr_png"),
format = "file",
repository = 'local'
),
# refined
# see note at top of 1_fetch.R re why this is a 'local' target
tar_target(
p3_nhdv2_attr_refined_png,
plot_nhdv2_attr(attr_data = p2_nhdv2_attr_refined %>% select(-hru_segment),
network_geometry = p1_reaches_sf,
file_path = "3_visualize/out/nhdv2_attr_png/refined"),
format = "file",
repository = 'local'
),
# Create and save a summary table that describes variation in the NHDv2 attribute variables across the PRMS network
tar_target(
p3_nhdv2_attr_summary_csv,
summarize_nhdv2_attr(p2_nhdv2_attr,"3_visualize/out/nhdv2_attr_summary.csv"),
format = "file",
repository = 'local'
),
# refined
tar_target(
p3_nhdv2_attr_summary_refined_csv,
summarize_nhdv2_attr(p2_nhdv2_attr_refined %>% select(-hru_segment),
"3_visualize/out/nhdv2_attr_summary_refined.csv"),
format = "file",
repository = 'local'
),
# Create and save a summary table that indicates the NA's among contributing
# NHDv2 catchments for each PRMS segment and attribute variable
tar_target(
p3_nhdv2_attr_missing_data_csv,
summarize_catchment_nhdv2_attr_missing(p2_nhdv2_attr_catchment,"3_visualize/out/nhdv2_attr_missing_data.csv"),
format = "file",
repository = 'local'
),
# Create a list of model results that will be passed to model performance
# plotting functions.
tar_target(
p3_model_results_random,
{
model_results_list <- list(static_dynamic = p4_pred_RF_static_dynamic_test$pred,
min_static_dynamic = p4_pred_RF_min_static_dynamic_test$pred,
dynamic = p4_pred_RF_dynamic_test$pred,
static = p4_pred_RF_static_test$pred,
min_static = p4_pred_RF_min_static_test$pred)
model_results <- purrr::map_df(model_results_list, ~as.data.frame(.x), .id = "model")
model_results
},
repository = "local"
),
tar_target(
p3_model_results_temporal,
{
model_results_list <- list(static_dynamic = p4_pred_RF_static_dynamic_temporal_test$pred,
min_static_dynamic = p4_pred_RF_min_static_dynamic_temporal_test$pred,
dynamic = p4_pred_RF_dynamic_temporal_test$pred)
model_results <- purrr::map_df(model_results_list, ~as.data.frame(.x), .id = "model")
model_results
},
repository = "local"
),
tar_target(
p3_model_results_spatial,
{
model_results_list <- list(static_dynamic = p4_pred_RF_static_dynamic_spatial_test$pred,
min_static_dynamic = p4_pred_RF_min_static_dynamic_spatial_test$pred,
dynamic = p4_pred_RF_dynamic_spatial_test$pred)
model_results <- purrr::map_df(model_results_list, ~as.data.frame(.x), .id = "model")
model_results
},
repository = "local"
),
#RGCN
tar_target(
p3_RGCN_model_results_temporal,
{
model_results_list <- list(static_dynamic = p4_RGCN_pred_obs_static_dynamic_temporal_test,
min_static_dynamic = p4_RGCN_pred_obs_min_static_dynamic_temporal_test,
dynamic = p4_RGCN_pred_obs_dynamic_temporal_test)
model_results <- purrr::map_df(model_results_list, ~as.data.frame(.x), .id = "model")
model_results
},
repository = "local"
),
tar_target(
p3_RGCN_model_results_spatial,
{
model_results_list <- list(static_dynamic = p4_RGCN_pred_obs_static_dynamic_spatial_test,
min_static_dynamic = p4_RGCN_pred_obs_min_static_dynamic_spatial_test,
dynamic = p4_RGCN_pred_obs_dynamic_spatial_test)
model_results <- purrr::map_df(model_results_list, ~as.data.frame(.x), .id = "model")
model_results
},
repository = "local"
),
# Plot empirical CDFs of model performance
tar_target(
p3_ecdf_all_reaches_random_png,
plot_ecdf(model_results = p3_model_results_random,
plot_type = "all_reaches",
fileout = "4_predict/out/random/ecdf_all_reaches_random.png",
log_x_axis = TRUE,
plot_points = FALSE,
plot_width_in = 6, plot_height_in = 4),
repository = "local",
format = "file"
),
tar_target(
p3_ecdf_all_reaches_temporal_png,
plot_ecdf(model_results = p3_model_results_temporal,
plot_type = "all_reaches",
fileout = "4_predict/out/temporal/ecdf_all_reaches_temporal.png",
log_x_axis = TRUE,
plot_points = FALSE,
plot_width_in = 6, plot_height_in = 4),
repository = "local",
format = "file"
),
tar_target(
p3_ecdf_all_reaches_spatial_png,
plot_ecdf(model_results = p3_model_results_spatial,
plot_type = "all_reaches",
fileout = "4_predict/out/spatial/ecdf_all_reaches_spatial.png",
log_x_axis = TRUE,
plot_points = FALSE,
plot_width_in = 6, plot_height_in = 4),
repository = "local",
format = "file"
),
#RGCN
tar_target(
p3_RGCN_ecdf_all_reaches_temporal_png,
plot_ecdf(model_results = p3_RGCN_model_results_temporal,
plot_type = "all_reaches",
fileout = "4_predict/out/temporal/RGCN_ecdf_all_reaches_temporal.png",
log_x_axis = TRUE,
plot_points = FALSE,
plot_width_in = 6, plot_height_in = 4),
repository = "local",
format = "file"
),
tar_target(
p3_RGCN_ecdf_all_reaches_spatial_png,
plot_ecdf(model_results = p3_RGCN_model_results_spatial,
plot_type = "all_reaches",
fileout = "4_predict/out/spatial/RGCN_ecdf_all_reaches_spatial.png",
log_x_axis = TRUE,
plot_points = FALSE,
plot_width_in = 6, plot_height_in = 4),
repository = "local",
format = "file"
)
)