From 4836d9d80184d6fe2177345481ae24f011609f61 Mon Sep 17 00:00:00 2001 From: Ann Willis Date: Thu, 8 Oct 2020 09:53:06 -0700 Subject: [PATCH 1/2] Renamed sites to correspond with monitoring site IDs. Changed catchment plot color for easier viewing. Started code to select streamlines showing the Little Shasta with no ditches/canals. --- code/get_flow_network.R | 28 ++++++++++++++++++---------- data/nhdplus_little_shasta.gpkg | Bin 311296 -> 311296 bytes 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/code/get_flow_network.R b/code/get_flow_network.R index d5d1494..2e50f71 100644 --- a/code/get_flow_network.R +++ b/code/get_flow_network.R @@ -11,17 +11,18 @@ library(sf) library(nhdplusTools) library(tidyverse) +library(mapview) # Identify the COMID ------------------------------------------------------ # comid for confluence segment Shasta-Little Shasta -peace <- st_sfc(st_point(c(-122.51016, 41.70364)), crs=4326) # peacemaker gage -uspt <- st_sfc(st_point(c(-122.34792, 41.73355)), crs=4326) # upstream gage +PMK <- st_sfc(st_point(c(-122.51016, 41.70364)), crs=4326) # peacemaker gage +LSR <- st_sfc(st_point(c(-122.34792, 41.73355)), crs=4326) # upstream gage -(peace_comid <- discover_nhdplus_id(point = peace)) -(uspt_comid <- discover_nhdplus_id(point = uspt)) +(PMK_comid <- discover_nhdplus_id(point = PMK)) +(LSR_comid <- discover_nhdplus_id(point = LSR)) -pts <- tibble("site"=c("peace","uspt"), "comid"=c(peace_comid, uspt_comid)) +pts <- tibble("site"=c("PMK","LSR"), "comid"=c(PMK_comid, LSR_comid)) # what sources of data? # discover_nldi_sources()$source @@ -91,22 +92,29 @@ sf::st_layers("data/nhdplus_little_shasta.gpkg") # QUICK PLOTS ------------------------------------------------------------- -library(mapview) -mapviewOptions(fgb=FALSE) +#mapviewOptions(fgb=FALSE) #This argument didn't mean anything when Ann ran the code # read data in: flowlines flowlines <- sf::read_sf("data/nhdplus_little_shasta.gpkg", "NHDFlowline_Network") catchment <- sf::read_sf("data/nhdplus_little_shasta.gpkg", "CatchmentSP") # quick plot -plot(catchment$geom, lwd = 4, border = "gray30") +plot(catchment$geom, lwd = 4, border = "maroon3") plot(sf::st_geometry(flowlines), lwd = 7, col = alpha("blue", 0.5), add=TRUE) plot(lshasta_ut$geometry, lwd = 1.2, col = "dodgerblue", add = TRUE) # mapview -mapview(catchment, color="gray50", col.regions="gray50", alpha.regions=0, alpha=0.5, lwd=2) + +lshasta_rawmap <- mapview(catchment, color="maroon3", col.regions="gray50", alpha.regions=0, alpha=0.5, lwd=2) + mapview(flowlines, zcol="ftype") + mapview(lshasta_ut, color="dodgerblue", lwd=0.75, alpha=0.9) -# so mainstem seems to be ok, but the associated tributaries are a jumble of diversions, canals, etc. +# so mainstem seems to be ok, but the associated tributaries are a jumble of diversions, canals, etc +# Also, catchment outline is incomplete. See map in Little Shasta Report, figure 1 for the HUC catchment + + +# Clean streamlines ------------------------------------------------------- + +library(mapedit) + +lshasta_network <- selectFeatures(lshasta_ut, map = lshasta_rawmap) diff --git a/data/nhdplus_little_shasta.gpkg b/data/nhdplus_little_shasta.gpkg index 256e056a726e874f26d33c278710bd006216bea1..07996493380fd4b4dd5047c41934a2e1e2da5693 100644 GIT binary patch delta 116 zcmZo@5N>D?o{+?3V7W2ny)KWTnU$fTm8q$og^Bs(c)e(ZfVr93D@x8K!g1Y#y2X5M~RpGA2B06YyK#Q*>R delta 116 zcmZo@5N>D?o{+@ke0XEZdtDv_BP$~lD??*F0|T?k@p{o<0ic+CtlhgIHU<%CiEX)m>@9MYT)n^1^CLm_sepjDGc>(}(;UPi* From c6404550bed5531c49b141fee4812e599bedf072 Mon Sep 17 00:00:00 2001 From: Ann Willis Date: Thu, 8 Oct 2020 15:35:26 -0700 Subject: [PATCH 2/2] Reviewed segments in the Little Shasta catchment and added attributes "channel_type" (natural, canal) and "altered" (altered, unaltered, NA). Saved out csv of comids for Little Shasta stream network. --- code/get_flow_network.R | 49 ++++++++++++++++++++++++++++---- data/lshasta_stream_network.csv | 38 +++++++++++++++++++++++++ data/nhdplus_little_shasta.gpkg | Bin 311296 -> 311296 bytes 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 data/lshasta_stream_network.csv diff --git a/code/get_flow_network.R b/code/get_flow_network.R index 2e50f71..239e646 100644 --- a/code/get_flow_network.R +++ b/code/get_flow_network.R @@ -12,6 +12,9 @@ library(sf) library(nhdplusTools) library(tidyverse) library(mapview) +library(mapedit) +library(leaflet) +library(leafpm) # Identify the COMID ------------------------------------------------------ @@ -104,17 +107,53 @@ plot(sf::st_geometry(flowlines), lwd = 7, col = alpha("blue", 0.5), add=TRUE) plot(lshasta_ut$geometry, lwd = 1.2, col = "dodgerblue", add = TRUE) # mapview -lshasta_rawmap <- mapview(catchment, color="maroon3", col.regions="gray50", alpha.regions=0, alpha=0.5, lwd=2) + +lshasta_rawmap <- mapview(catchment, color="maroon3", col.regions="gray50", alpha.regions=0, alpha=0.9, lwd=2) + mapview(flowlines, zcol="ftype") + - mapview(lshasta_ut, color="dodgerblue", lwd=0.75, alpha=0.9) - + mapview(lshasta_ut, color="dodgerblue", lwd=2, alpha=0.9) +lshasta_rawmap # so mainstem seems to be ok, but the associated tributaries are a jumble of diversions, canals, etc # Also, catchment outline is incomplete. See map in Little Shasta Report, figure 1 for the HUC catchment # Clean streamlines ------------------------------------------------------- -library(mapedit) +# First, create a list of all segments using their comids so we can add an attribute to them describing whether they are a stream channel (natural) or canal/ditch (canal) + +all_segments_w_sf <- rbind(lshasta_um,lshasta_ut) + +all_segments <- st_set_geometry(all_segments_w_sf,NULL) + +all_segments$channel_type <- with(all_segments, ifelse(type=="UM","natural","")) + +# Add another column to indicate whether the natural channel is altered (e.g., the runoff is natural, but it's been run into a ditch that's routed to the stream), unaltered (e.g., the natural channel), or NA (e.g., it's a canal) + +all_segments$altered <- with(all_segments, ifelse(type=="UM","unaltered","")) + +# Review each segment individually and update all_segments df + +natural_unaltered_segs <- as.character(c("3917194", "3917136", "3917138", "3917914", "3917916", "3917082", "3917114", "3917154", "3917156", "3917172", "3917164", "3917158", "3917160", "3917922", "3917364","3917372", "3917326", "3917330", "3917328", "3917374","3917392", "3917084", "3917084", "3917106", "3917130", "3917162", "3917176", "3917178", "3917198", "3917200", "3917244", "3917912", "3917918", "3917946", "3917948", "3917950")) + +natural_altered_segs <- as.character(c("948010089", "3917920")) + +canal_segs <- as.character(c("3917230", "3917954", "3918004", "3917382", "3917266", "3917222", "3917212", "3917214", "3917218", "3917228", "3917270", "3917250", "3917256", "3917268", "3917284", "3917282", "3917274", "3917278", "3917276", "3917958", "3917960", "3917384", "3917370", "3917376")) + +all_segments <- all_segments %>% + mutate(channel_type = case_when(nhdplus_comid %in% natural_unaltered_segs ~ "natural", + nhdplus_comid %in% natural_altered_segs ~ "natural", + nhdplus_comid %in% canal_segs ~ "canal")) + +all_segments <- all_segments %>% + mutate(altered = case_when(nhdplus_comid %in% natural_unaltered_segs ~ "unaltered", + nhdplus_comid %in% natural_altered_segs ~ "altered", + nhdplus_comid %in% canal_segs ~ "NA")) + +# filter all_segments df so that only natural channels w/in the Little Shasta watershed are included; UM segments are duplicated in the UT record, so filter out duplicate comids + +lshasta_stream_network <- all_segments %>% + filter(channel_type == "natural", type == "UT") + +#write out Little Shasta stream network as csv + +write_csv(lshasta_stream_network, path = "data/lshasta_stream_network.csv") -lshasta_network <- selectFeatures(lshasta_ut, map = lshasta_rawmap) diff --git a/data/lshasta_stream_network.csv b/data/lshasta_stream_network.csv new file mode 100644 index 0000000..ecd9ac4 --- /dev/null +++ b/data/lshasta_stream_network.csv @@ -0,0 +1,38 @@ +nhdplus_comid,type,channel_type,altered +3917946,UT,natural,unaltered +3917244,UT,natural,unaltered +3917950,UT,natural,unaltered +3917948,UT,natural,unaltered +3917200,UT,natural,unaltered +3917198,UT,natural,unaltered +948010089,UT,natural,altered +3917918,UT,natural,unaltered +3917920,UT,natural,altered +3917922,UT,natural,unaltered +3917364,UT,natural,unaltered +3917372,UT,natural,unaltered +3917176,UT,natural,unaltered +3917164,UT,natural,unaltered +3917160,UT,natural,unaltered +3917158,UT,natural,unaltered +3917178,UT,natural,unaltered +3917172,UT,natural,unaltered +3917374,UT,natural,unaltered +3917392,UT,natural,unaltered +3917912,UT,natural,unaltered +3917156,UT,natural,unaltered +3917328,UT,natural,unaltered +3917330,UT,natural,unaltered +3917162,UT,natural,unaltered +3917154,UT,natural,unaltered +3917326,UT,natural,unaltered +3917130,UT,natural,unaltered +3917114,UT,natural,unaltered +3917106,UT,natural,unaltered +3917916,UT,natural,unaltered +3917084,UT,natural,unaltered +3917082,UT,natural,unaltered +3917914,UT,natural,unaltered +3917194,UT,natural,unaltered +3917136,UT,natural,unaltered +3917138,UT,natural,unaltered diff --git a/data/nhdplus_little_shasta.gpkg b/data/nhdplus_little_shasta.gpkg index 07996493380fd4b4dd5047c41934a2e1e2da5693..f4d7b296d5bf2a134f2a002a43e82c520c8b1e11 100644 GIT binary patch delta 111 zcmZo@5N>D?-Vm(EV`N}uY-VL(u4ig$F*#l@8X;g}ZZP?nULZ`sOwYi;e6q5>B}~9T p&&D?-Vm(EV`ye&XlP|>s%K$hJ~>`58X;hAW;XelULZ`sM9