@@ -7,6 +7,7 @@ source("1_fetch/src/get_nhdplusv2.R")
7
7
source(' 1_fetch/src/download_tifs_annual.R' )
8
8
source(" 1_fetch/src/get_gf.R" )
9
9
source(" 1_fetch/src/fetch_sb_data.R" )
10
+ source(" 1_fetch/src/fetch_nhdv2_attributes_from_sb.R" )
10
11
11
12
p1_targets_list <- list (
12
13
@@ -178,7 +179,7 @@ p1_targets_list <- list(
178
179
format = ' file'
179
180
),
180
181
181
- # Read in NLCD datasets and subet by comid in DRB
182
+ # Read in NLCD datasets and subset by comid in DRB
182
183
# # Note that this returns a vector of dfs if more than one NLCD data is in the p1_NLCD_data_unzipped
183
184
tar_target(
184
185
p1_NLCD_data ,
@@ -222,12 +223,28 @@ p1_targets_list <- list(
222
223
format = ' file'
223
224
),
224
225
225
- # variables from the Wieczorek dataset that are of interest
226
+ # Variables from the Wieczorek dataset that are of interest
227
+ # use tar_group to define row groups based on ScienceBase ID; row groups facilitate
228
+ # branching over subsets of the VarsOfInterest table in downstream targets
226
229
tar_target(
227
230
p1_vars_of_interest ,
228
231
read_csv(p1_vars_of_interest_csv , show_col_types = FALSE ) %> %
229
- # Remove the NADP from this since we are loading that separately and no not need it in vars of interest
230
- filter(! Theme %in% c(' Chemical' , ' Land Cover' ))
232
+ # Parse sb_id from sb link
233
+ mutate(sb_id = str_extract(Science.Base.Link ," [^/]*$" )) %> %
234
+ # Omit NADP and LandCover rows since we are loading those separately
235
+ filter(! Theme %in% c(' Chemical' , ' Land Cover' )) %> %
236
+ group_by(sb_id ) %> %
237
+ tar_group(),
238
+ iteration = " group"
239
+ ),
240
+
241
+ # Map over variables of interest to download NHDv2 attribute data from ScienceBase
242
+ tar_target(
243
+ p1_vars_of_interest_downloaded_csvs ,
244
+ fetch_nhdv2_attributes_from_sb(vars_item = p1_vars_of_interest , save_dir = " 1_fetch/out" ,
245
+ comids = p1_nhdv2reaches_sf $ COMID , delete_local_copies = TRUE ),
246
+ pattern = map(p1_vars_of_interest ),
247
+ format = " file"
231
248
),
232
249
233
250
# # download NADP data
0 commit comments