diff --git a/workspace/R/02_POI_creation_functions.R b/workspace/R/02_POI_creation_functions.R index b478f58617b663f904d1f25df2ff83add2d50961..853779cf1ed73f09ba560dd763219ff530dee817 100644 --- a/workspace/R/02_POI_creation_functions.R +++ b/workspace/R/02_POI_creation_functions.R @@ -25,7 +25,8 @@ create_hu12_pois <- function(data, flowline, poi_name, vpu) { ungroup() # Create POIs - some r05 HUC12 POIs not in R05 NHD - POI_creation(st_drop_geometry(HUC12_COMIDs), filter(flowline, poi == 1), poi_name) + list(tmp_POIs = POI_creation(st_drop_geometry(HUC12_COMIDs), filter(flowline, poi == 1), poi_name), + HUC12_COMIDs = HUC12_COMIDs) } @@ -74,7 +75,7 @@ create_gage_pois <- function(gages, flowline, poi_name, vpu, tmp_POIs, "Gages_info", paste0("VPU ", vpu, "; low gage score")) } - c(gages_POIs, unassigned_gages = unassigned_gages) + list(tmp_POIs = tmp_POIs, events = events, unassigned_gages = unassigned_gages) } @@ -127,4 +128,59 @@ gage_POI_creation <- function(tmp_POIs, gages_info, nhd, combine_meters, reach_m return(list(events = events, tmp_POIs = tmp_POIs)) +} + +#' create thermo electric POIs +#' @param te_points point locations of thermo electric plants +#' @param te_attributes attributes for te_points +#' @param tmp_POIs pois from previous target +#' @param HUC12_COMIDs HUC12_COMIDs from hu12 poi step +#' @param flowline flowlines to attach pois to +#' @param poi_name name for poi set +#' @param vpu vpu that is being executed +#' +create_thermo_electric_pois <- function(te_points, te_attributes, tmp_POIs, HUC12_COMIDs, + flowline, poi_name, vpu) { + + if(vpu == "08"){ + flowline$VPUID <- "08" + } else { + flowline$VPUID <- substr(flowline$RPUID, 1, 2) + } + + # Read in Thermoelectric shapefile for 2015 estimates + TE_v1 <- te_points + # Read in Thermoelectric Plants csv for updated estimates + TE_v2 <- te_attributes %>% + mutate(Plant.Code = as.integer(Plant.Code)) + + # Bind hydrographic address information together and get final COMIDs + TE_COMIDs_full <- TE_v2 %>% + filter(water_source %in% c("sw_fresh", "gw_fresh", "gw_sw_mix")) %>% + left_join(select(st_drop_geometry(TE_v1), + Plant.Code = EIA_PLANT_, COMID), by = "Plant.Code") %>% + left_join(rename(st_drop_geometry(HUC12_COMIDs), huc12_comid = COMID), + by = c("huc_12" = "HUC12")) %>% + mutate(COMID = ifelse(is.na(COMID), huc12_comid, COMID)) %>% + select(-huc12_comid) + + # Prepare TE for POI Creation + TE_COMIDs <- TE_COMIDs_full %>% + inner_join(select(st_drop_geometry(flowline), COMID, VPUID), by = "COMID") %>% + filter(grepl(paste0("^", substr(vpu, 1, 2), ".*"), .data$VPUID), COMID > 0) %>% + switchDiv(., flowline) %>% + group_by(COMID) %>% + summarize(eia_id = paste0(unique(Plant.Code), collapse = " "), count = n()) %>% + ungroup() + + unassigned_plants <- filter(TE_COMIDs, !COMID %in% tmp_POIs$COMID) + + if(nrow(TE_COMIDs) > 0){ + # Derive TE POIs + tmp_POIs <- POI_creation(st_drop_geometry(TE_COMIDs), filter(flowline, poi == 1), poi_name) %>% + addType(., tmp_POIs, "TE", nexus = TRUE) + + } + + list(tmp_POIs = tmp_POIs, unassigned_plants = unassigned_plants) } \ No newline at end of file diff --git a/workspace/_targets/02_POI_creation_targets.R b/workspace/_targets/02_POI_creation_targets.R index 0a473db1cef133e0035c8369e55bb52aabf283b9..cc54ffc2ff24e0596de2e1d395e613625db5b1f2 100644 --- a/workspace/_targets/02_POI_creation_targets.R +++ b/workspace/_targets/02_POI_creation_targets.R @@ -33,6 +33,15 @@ list(tar_target(data_paths_file, "cache/data_paths.json", format = "file"), tar_target(gage_info_gpkg_file, gage_info_gpkg, format = "file"), tar_target(gage_pois, create_gage_pois(read_sf(gage_info_gpkg_file, "Gages"), - flowline, "Gages", vpu_codes, huc12_poi, + flowline, "Gages", vpu_codes, huc12_poi$tmp_POIs, min_da_km_gages, combine_meters, reach_meas_thresh), - pattern = map(flowline, huc12_poi, vpu_codes), deployment = "worker")) \ No newline at end of file + pattern = map(flowline, huc12_poi, vpu_codes), deployment = "worker"), + + tar_target(te_points_file, data_paths$TE_points_path, format = "file"), + tar_target(te_points, read_sf(te_points_file, "2015_TE_Model_Estimates_lat.long_COMIDs")), + tar_target(te_attributes_file, file.path(data_paths$TE_points_path, "1_model_inputs/te_plants.csv"), format = "file"), + tar_target(te_attributes, read.csv(te_attributes_file, colClasses = "character")), + tar_target(te_pois, create_thermo_electric_pois(te_points, te_attributes, + gage_pois$tmp_POIs, huc12_poi$HUC12_COMIDs, + flowline, "TE", vpu_codes), + pattern = map(gage_pois, huc12_poi, flowline, vpu_codes))) \ No newline at end of file