From b03ad78cfb6b5c36a79fa2e13defcf1d6c070709 Mon Sep 17 00:00:00 2001 From: David Blodgett <dblodgett@usgs.gov> Date: Fri, 23 Apr 2021 10:10:49 -0500 Subject: [PATCH] get new nhdplus attributes checked into scripts --- workspace/003_enhd.Rmd | 12 +++++++++--- workspace/00_get_data.Rmd | 13 +++++++++++++ workspace/02_NHD_navigate.Rmd | 2 +- workspace/cache/data_paths.json | 3 ++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/workspace/003_enhd.Rmd b/workspace/003_enhd.Rmd index 104c410..7641b2c 100644 --- a/workspace/003_enhd.Rmd +++ b/workspace/003_enhd.Rmd @@ -12,6 +12,11 @@ Notes: This script updates the catchment topology of NHDPlusV2 with two data sou Most functionality is encapsulated in a `run_plus_attributes` function. ```{r} +# sbtools::item_file_download("5dcd5f96e4b069579760aedb", names = "enhd_nhdplusatts.csv", +# dest_dir = "cache") + +# To create this file, run the following. + library(dplyr) library(sf) @@ -21,8 +26,6 @@ enhd <- data.table::fread("data/ENHDPlusV2_us.txt", sep = ",", integer64 = "char enhd <- as.data.frame(enhd) -# enhd <- data.table::fread("data/e2nhdplusv2_us.csv", sep = ",", integer64 = "character") - nwm <- data.table::fread("data/NWM_v2_1_CONUS_Topology.csv") nwm <- as.data.frame(nwm) @@ -102,8 +105,11 @@ if(file.exists(lp_temp)) { saveRDS(lp, lp_temp) } -net_new <- run_plus_attributes(lp, net_new, "temp/enhd_nhdplusatts.csv", cores = 12) +net_new <- run_plus_attributes(lp, net_new, "cache/enhd_nhdplusatts.csv", cores = 12) +### ONLY RUN IF CHANGED ### +# sbtools::authenticate_sb() +# sbtools::item_replace_files("5dcd5f96e4b069579760aedb", "cache/enhd_nhdplusatts.csv") ``` diff --git a/workspace/00_get_data.Rmd b/workspace/00_get_data.Rmd index 43cd32c..c6ba586 100644 --- a/workspace/00_get_data.Rmd +++ b/workspace/00_get_data.Rmd @@ -441,6 +441,19 @@ out_list <- c(out_list, out) ``` +```{r nhdplus_attributes} + +out <- list(new_nhdp_atts = file.path("cache", (sb_f <- "enhd_nhdplusatts.csv"))) + +if(!file.exists(out$new_nhdp_atts)) { + sbtools::item_file_download("5dcd5f96e4b069579760aedb", + names = sb_f, + destinations = out) +} + +out_list <- c(out_list, out) +``` + ```{r} write_json(out_list, path = out_file, pretty = TRUE, auto_unbox = TRUE) rm(out_list) diff --git a/workspace/02_NHD_navigate.Rmd b/workspace/02_NHD_navigate.Rmd index fd65689..d9b2e67 100644 --- a/workspace/02_NHD_navigate.Rmd +++ b/workspace/02_NHD_navigate.Rmd @@ -42,7 +42,7 @@ if(needs_layer(nav_gpkg, temp_POIs)) { if (needs_layer(nav_gpkg, nhdflowline)){ # Subset NHD by VPU - nhd <- VPU_Subset(staged_nhd$flowline, VPU, new_atts = "temp/enhd_nhdplusatts.csv") + nhd <- VPU_Subset(staged_nhd$flowline, VPU, new_atts = data_paths$new_nhdp_atts) # Filter and write dendritic/non-coastal subset to gpkg # This will be iterated over to produce the final network after POIs identified diff --git a/workspace/cache/data_paths.json b/workspace/cache/data_paths.json index 6c0bdef..8421e20 100644 --- a/workspace/cache/data_paths.json +++ b/workspace/cache/data_paths.json @@ -167,5 +167,6 @@ "merit_catchments": "data/merged_AK_MERIT_Hydro/cat_pfaf_78_81_82_MERIT_Hydro_v07_Basins_v01.shp", "merit_rivers": "data/merged_AK_MERIT_Hydro/riv_pfaf_78_81_82_MERIT_Hydro_v07_Basins_v01.shp", "e2nhd_network": "data/e2nhdplusv2_us.csv", - "nwm_network": "data/NWM_v2_1_CONUS_Topology.csv" + "nwm_network": "data/NWM_v2_1_CONUS_Topology.csv", + "new_nhdp_atts": "cache/enhd_nhdplusatts.csv" } -- GitLab