-
Bock, Andy authoredBock, Andy authored
config.R 4.62 KiB
library(nhdplusTools)
library(dplyr)
library(sf)
library(hyRefactor)
library(tidyr)
library(hyfabric)
library(mapview)
library(terra)
rpu_vpu <- readr::read_csv(system.file("extdata/rpu_vpu.csv", package = "hyfabric"),
show_col_types = FALSE)
rpu_vpu_out <- readr::read_csv("cache/rpu_vpu_out.csv",
col_types = c("c", "c", "i" , "i"), show_col_types = FALSE)
if(nchar(Sys.getenv("HYDREG")) > 1) {
VPU <- Sys.getenv("HYDREG")
}
if(!exists("rpu_code")) {
if(exists("VPU")) {
vpu <- VPU
rpu_codes <- rpu_vpu[rpu_vpu$vpuid %in% vpu, ]
rpu_code <- rpu_codes$rpuid[1]
} else {
vpu <- get_rpu_dependent_vars()
rpu_code <- vpu$r
vpu <- vpu$v
rpu_codes <- rpu_vpu[rpu_vpu$vpuid %in% vpu, ]
}
}
if(!exists("vpu")) {
vpu <- get_rpu_dependent_vars(rpu_code)$v
}
if(!nchar(out_agg_gpkg <- Sys.getenv("OUT_GPKG")) > 5)
out_agg_gpkg <- file.path("cache", paste0(rpu_code, "_aggregate.gpkg"))
if(!nchar(out_refac_gpkg <- Sys.getenv("OUT_REFACTOR_GPKG")) > 5)
out_refac_gpkg <- file.path("cache", paste0(rpu_code, "_refactor.gpkg"))
if(!nchar(cache_split <- Sys.getenv("CACHE_SPLIT")) > 5)
cache_split <- file.path("temp", paste0(rpu_code, ".rda"))
if(!nchar(lookup_table_file <- Sys.getenv("LOOKUP_TABLE")) > 5)
lookup_table_file <- file.path("cache", paste0(rpu_code, "_lookup.csv"))
if(!nchar(vpu_lookup_table_file <- Sys.getenv("VPU_LOOKUP_TABLE")) > 5)
vpu_lookup_table_file <- file.path("cache", paste0("lookup_", vpu, ".csv"))
options(scipen = 9999)
# Source Data
crs <- 5070
data_paths <- jsonlite::read_json(file.path("cache", "data_paths.json"))
nhdplus_path(data_paths$nhdplus_gdb)
suppressWarnings(staged_nhd <- stage_national_data())
# Defined and used broadly
nhd_flowline <- "reference_flowline"
nhd_catchment <- "reference_catchment"
nhd_outlet <- "nhd_outlet"
# Created and/or used during 02_Navigate
elev_diff <- 500 # Max difference in elevation within a single segment/POI
max_elev_TT_DA <- 10 # Min drainage area to consider for elevation/travel_time breaks
travt_diff <- 24 # Max number of hours between adjacent POIS
xwalk_layer <- paste0("HUC12_nhd") # HUC12 - nhdcat crosswalk, built in Nav for VPU 20
nav_poi_layer <- paste0("POIs_tmp_", vpu) # Rolling Nav POI layer added to/modified througout nav workflow
WBs_layer <- paste0("WB_", vpu) # Waterbodies within VPU
WB_events_layer <- paste0("WB_events_", vpu) # inlet and outlet events for NHDArea and HR waterbodies
poi_moved_layer <- paste0("POIs_mv_", vpu) # POIs moved from original COMID assignment
nsegments_layer <- paste0("nsegment_", vpu) # Minimally-sufficient network dissolved by POI_ID
pois_all_layer <- paste0("POIs_", vpu) # All POIs binded together
poi_xwalk_layer <- paste0("poi_xwalk_layer_", vpu) # POIs that changed COMIDS during the navigate part of the workflow
final_poi_layer <- "POIs"
# Settings for refactor workflow
split_meters <- 10000
combine_meters <- 1000
min_da_km <- 20
aggregate_da_thresh_sqkm <- 1
# parallel factor for catchment reconciliation.
para_reconcile <- 2
para_split_flines <- 2
keep_cat_points <- 1
# Created during refactor workflow
refactored_layer <- "collapsed"
reconciled_layer <- "refactored_flowpaths"
split_layer <- "split_events"
divide_layer <- "refactored_divides"
agg_fline_layer <- "aggregated_flowpaths"
agg_cats_layer <- "aggregated_divides"
outlets_layer <- "outlets"
mapped_outlets_layer <- "mapped_POIs"
lookup_table_refactor <- "lookup_table"
# output geopackage file names
nav_gpkg <- file.path("cache", paste0("reference_", vpu,".gpkg"))
temp_gpkg <- file.path("cache", paste0("nav_", vpu,".gpkg"))
rfc_gpkg <- file.path("cache", paste0("refactor_", vpu, ".gpkg"))
gf_gpkg <- file.path("cache", paste0("GF_", vpu, ".gpkg"))
gf_gpkg_conus <- "cache/reference_CONUS.gpkg"
# Defined during NonDend.Rmd
ND_gpkg <- file.path("temp", paste0("ND_", vpu,".gpkg"))
divides_xwalk <- paste0("divides_nhd")
HRU_layer <- paste0("all_cats")
divides_nd <- paste0("divides_nd")
missing_terms <- paste0("miss_terms")
missing_cats <- paste0("miss_cats")
# only used in HI?
inc_pois_layer <- paste0("inc_POIs_", vpu) # layer of POIs used to derive first cut of segments
# Defined at various points for HI workflow
#raw_wbd <- paste0("HU12_", VPU) # Raw HUC12
#gage_loc <- paste0("GageLoc_", VPU) # HI GageLoc
#TE <- paste0("TE_", VPU) # Thermo-electric
#NID_layer <- paste0("NID_", VPU) # Raw NID points
#gage_events_layer <- paste0("gage_events_", VPU) # gages with flowline index information for possible splitting
# not used?
# huc12_xWalk <- file.path(data_paths$nhdplus_dir, "CrosswalkTable_NHDplus_HU12.csv")
# HUC12 <- file.path(data_paths$nhdplus_dir, "HUC12.rds")