From 207dd76021bf1b2e39c8df82b6342c171f983204 Mon Sep 17 00:00:00 2001
From: David Blodgett <dblodgett@usgs.gov>
Date: Mon, 25 Nov 2024 14:21:34 -0600
Subject: [PATCH] resolve minor issues

---
 workspace/02_NHD_navigate.Rmd      |  4 +++-
 workspace/03_hyRefactor_flines.Rmd |  5 -----
 workspace/05-2_NonDend.Rmd         | 12 ++++++------
 workspace/R/NHD_navigate.R         |  8 ++++----
 workspace/R/non_dend.R             |  4 ++--
 workspace/R/poi_move.R             |  2 ++
 workspace/R/user_vars.R            |  6 +++---
 7 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/workspace/02_NHD_navigate.Rmd b/workspace/02_NHD_navigate.Rmd
index fd0e904..6c1edc8 100644
--- a/workspace/02_NHD_navigate.Rmd
+++ b/workspace/02_NHD_navigate.Rmd
@@ -211,7 +211,7 @@ if(needs_layer(temp_gpkg, "WBs_layer_orig")){
   ref_WB <- WBs_VPU_all %>%
     group_by(wb_id, GNIS_NAME) %>%
     sfheaders::sf_remove_holes() %>%
-    summarize(do_union = T, member_comid = paste(COMID, collapse = ",")) %>%
+    summarize(do_union = TRUE, member_comid = paste(COMID, collapse = ",")) %>%
     st_make_valid() %>%
     ungroup() %>%
     mutate(area_sqkm = as.numeric(st_area(.)) / 1000000) %>%
@@ -236,6 +236,7 @@ if(!"Type_resops" %in% names(tmp_POIs)){
     mutate(member_comid = as.character(member_comid)) %>%
     distinct()
 
+  # TODO: get this file from data.json
   # ResOpsUS locations with attributes from the VPU NHDv2 wb set
   resops_wb_df <- read.csv("data/reservoir_data/istarf_xwalk_final_48_gfv11.csv") %>%
     # Subset to VPU, only one DAMID per waterbody
@@ -925,6 +926,7 @@ final_POIs_prec <- mutate(final_POIs, id = row_number(), moved = NA) %>%
   write_sf(nav_gpkg, nav_poi_layer)
 collapse <- TRUE
 
+# TODO: document what this is doing!
 source("R/poi_move.R")
 
 check_dups <- final_POIs %>%
diff --git a/workspace/03_hyRefactor_flines.Rmd b/workspace/03_hyRefactor_flines.Rmd
index d23d0b3..cabb6c3 100644
--- a/workspace/03_hyRefactor_flines.Rmd
+++ b/workspace/03_hyRefactor_flines.Rmd
@@ -177,11 +177,6 @@ if(needs_layer(out_refac_gpkg, outlets_layer)) {
       filter(member_COMID == max(member_COMID)) %>%
       select(hy_id = COMID, poi_id, member_COMID, reconciled_ID, type) 
   }
-
-  # final_outlets <-  outlets_ref_COMID %>%
-  #   st_as_sf() %>%
-  #   inner_join(select(lookup_table, member_COMID, reconciled_ID), 
-  #                     by = "member_COMID") 
   
   write_sf(outlets_ref_COMID, out_refac_gpkg, outlets_layer)
 } else {
diff --git a/workspace/05-2_NonDend.Rmd b/workspace/05-2_NonDend.Rmd
index 77f64e4..e700887 100644
--- a/workspace/05-2_NonDend.Rmd
+++ b/workspace/05-2_NonDend.Rmd
@@ -183,7 +183,7 @@ if(needs_layer(ND_gpkg, divides_nd)){
   if(debug) {
     protoHRUs <- divides_lu %>%
       group_by("POI_ID") %>%
-      summarize(do_union = T) %>%
+      summarize(do_union = TRUE) %>%
       sfheaders::sf_remove_holes(.) %>%
       st_make_valid()
     write_sf(protoHRUs, ND_gpkg, HRU_layer)
@@ -223,7 +223,7 @@ if(!"HUC_12" %in% unique(divides_lu$aggStep)){
     # HRU layer
     protoHRUs <- divides_lu %>%
       group_by(POI_ID) %>%
-      summarize(do_union = T) %>%
+      summarize(do_union = TRUE) %>%
       sfheaders::sf_remove_holes(.) %>%
       st_make_valid()
     write_sf(protoHRUs, ND_gpkg, HRU_layer)
@@ -259,7 +259,7 @@ if("Coastline" %in% unique(vpu_nhd$FTYPE)){
       # HRU layer
       protoHRUs <- divides_lu %>%
         group_by(POI_ID) %>%
-        summarize(do_union = T) %>%
+        summarize(do_union = TRUE) %>%
         sfheaders::sf_remove_holes(.) %>%
         st_make_valid()
       # Write out updates
@@ -370,7 +370,7 @@ if(needs_layer(ND_gpkg,  missing_cats)){
   # Prob HRU - filter(all_hrus, POI_ID == 140402000209)
   all_hrus <- filter(divides_lu, !is.na(POI_ID)) %>%
     group_by(POI_ID) %>%
-    summarize(do_union = T) %>%
+    summarize(do_union = TRUE) %>%
     sfheaders::sf_remove_holes(.) %>%
     nhdplusTools:::check_valid(.)
   
@@ -399,7 +399,7 @@ if(all(!is.na(noagg_divides$POI_ID_noagg))){
   # Prob HRU - filter(all_hrus, POI_ID == 140402000209)
   all_hrus <- filter(divides_lu, !is.na(POI_ID)) %>%
     group_by(POI_ID) %>%
-    summarize(do_union = T) %>%
+    summarize(do_union = TRUE) %>%
     sfheaders::sf_remove_holes(.) %>%
     nhdplusTools:::check_valid(.)
   
@@ -409,4 +409,4 @@ if(all(!is.na(noagg_divides$POI_ID_noagg))){
   print ("account for unaggregated divides")
 }
 
-```
\ No newline at end of file
+```
diff --git a/workspace/R/NHD_navigate.R b/workspace/R/NHD_navigate.R
index 7a4d3f9..3aaacd5 100644
--- a/workspace/R/NHD_navigate.R
+++ b/workspace/R/NHD_navigate.R
@@ -740,7 +740,7 @@ WB_event <- function(WBs, nhd_wb, type){
       arrange(desc(Hydroseq)) %>%
       group_by(LevelPathI) %>%
       # union together 
-      summarize(do_union = T) %>%
+      summarize(do_union = TRUE) %>%
       st_cast("LINESTRING")
     
     WBs_HR <- filter(WBs_layer, source == "HR ID AVAILABLE")
@@ -1288,7 +1288,7 @@ wb_inlet_collapse <- function(tmp_POIs, nhd, events){
     
     gage_reach <- gage_ds %>%
       group_by(REACHCODE) %>%
-      summarize(do_union = T,
+      summarize(do_union = TRUE,
                 total_length = sum(LENGTHKM))
     
     #print(nrow(gage_reach))
@@ -1433,7 +1433,7 @@ wb_poi_collapse <- function(tmp_POIs, nhd, events){
     
     gage_reach <- gage_ds %>%
       group_by(REACHCODE) %>%
-      summarize(do_union = T,
+      summarize(do_union = TRUE,
                 total_length = sum(LENGTHKM))
     
     #print(nrow(gage_reach))
@@ -1719,4 +1719,4 @@ cs_group <- function(a, athres) {
     result = c(result, group)
   }
   return (result)
-}
\ No newline at end of file
+}
diff --git a/workspace/R/non_dend.R b/workspace/R/non_dend.R
index 008afdd..090819d 100644
--- a/workspace/R/non_dend.R
+++ b/workspace/R/non_dend.R
@@ -10,7 +10,7 @@ dissolve_holes <- function(divides_poi){
   # HRU layer
   protoHRUs <- filter(divides_poi, !is.na(POI_ID)) %>%
     group_by(POI_ID) %>%
-    summarize(do_union = T) %>%
+    summarize(do_union = TRUE) %>%
     clean_geometry(., ID = "POI_ID")
   
   agg_noholes <- sfheaders::sf_remove_holes(protoHRUs) %>%
@@ -502,7 +502,7 @@ NHD_sinks <- function(divides_poi, area_thresh, HUC12_table, NHD_sinks){
     # Aggretate sink cats to HUC12 and add area
     sink_cats_agg <- filter(sink_cats, is.na(POI_ID)) %>%
       group_by(HUC_12_int)  %>%
-      summarize(do_union = T) %>%
+      summarize(do_union = TRUE) %>%
       mutate(agg_id = row_number())
   
     m_per_km <- 1000
diff --git a/workspace/R/poi_move.R b/workspace/R/poi_move.R
index 3edcde7..ebfdd7a 100644
--- a/workspace/R/poi_move.R
+++ b/workspace/R/poi_move.R
@@ -1,3 +1,5 @@
+## TODO: document this file!
+
 #  Load data
 if(collapse){
   
diff --git a/workspace/R/user_vars.R b/workspace/R/user_vars.R
index d721dbd..980c4ff 100644
--- a/workspace/R/user_vars.R
+++ b/workspace/R/user_vars.R
@@ -1,7 +1,7 @@
 if(Sys.getenv("sb_user") == "CHANGEME") stop("must set sb_user")
 
 # Path mods
-path_mod <- TRUE
+path_mod <- FALSE
 if (path_mod){
   # 7-zip
   old_path <- Sys.getenv("PATH")
@@ -9,11 +9,11 @@ if (path_mod){
   
   # Mapshaper
   old_path <- Sys.getenv("PATH") 
-  Sys.setenv(PATH = paste(old_path, "C:\\Users\\abock\\AppData\\Roaming\\npm", sep = ";"))
+  Sys.setenv(PATH = paste(old_path, paste0(Sys.getenv("USERPROFILE"), "AppData\\Roaming\\npm"), sep = ";"))
   
   # Whitebox Tools
   library(whitebox)
-  wbt_init(exe_path = "C:\\Users\\abock\\AppData\\Roaming\\R\\data\\R\\whitebox\\WBT\\whitebox_tools.exe")
+  wbt_init(exe_path = paste0(Sys.getenv("USERPROFILE"), "AppData\\Roaming\\R\\data\\R\\whitebox\\WBT\\whitebox_tools.exe"))
 }
 
 # CRS for projected and geographic reference systems
-- 
GitLab