Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit 1714e46

Browse files
authored
Merge pull request #82 from lekoenig/fetch-nhdv2-attributes
Fetch nhdv2 attributes from ScienceBase
2 parents 9f1b5a3 + 7065cf3 commit 1714e46

File tree

3 files changed

+383
-182
lines changed

3 files changed

+383
-182
lines changed

1_fetch.R

+21-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ source("1_fetch/src/get_nhdplusv2.R")
77
source('1_fetch/src/download_tifs_annual.R')
88
source("1_fetch/src/get_gf.R")
99
source("1_fetch/src/fetch_sb_data.R")
10+
source("1_fetch/src/fetch_nhdv2_attributes_from_sb.R")
1011

1112
p1_targets_list <- list(
1213

@@ -178,7 +179,7 @@ p1_targets_list <- list(
178179
format = 'file'
179180
),
180181

181-
# Read in NLCD datasets and subet by comid in DRB
182+
# Read in NLCD datasets and subset by comid in DRB
182183
## Note that this returns a vector of dfs if more than one NLCD data is in the p1_NLCD_data_unzipped
183184
tar_target(
184185
p1_NLCD_data,
@@ -222,12 +223,28 @@ p1_targets_list <- list(
222223
format = 'file'
223224
),
224225

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
226229
tar_target(
227230
p1_vars_of_interest,
228231
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"
231248
),
232249

233250
# # download NADP data

0 commit comments

Comments
 (0)