|
1 | 1 | # example workflow for StreamNetworkTools |
2 | | -remove.packages("StreamNetworkTools") |
3 | 2 |
|
4 | 3 | # install devtools if not already |
5 | | -#install.packages(devtools) |
| 4 | +# install.packages(devtools) |
6 | 5 | library("devtools") |
7 | | -#install StreamNetworkTools from github repository |
8 | | -#install_git("https://github.com/dkopp3/StreamNetworkTools_git.git", subdir = "StreamNetworkTools") |
| 6 | + |
| 7 | +# install StreamNetworkTools from github repository |
| 8 | +# install_git("https://github.com/dkopp3/StreamNetworkTools_git.git", subdir = "StreamNetworkTools") |
9 | 9 | library(StreamNetworkTools) |
10 | 10 |
|
11 | | -#check package help |
12 | | -help(package="StreamNetworkTools") |
| 11 | +#check SNT package help for avaialble functions |
| 12 | +help(package ="StreamNetworkTools") |
13 | 13 |
|
14 | 14 | # to begin download NHDPlusV2 data for Vector Processing Unit (VPU) of interest |
15 | 15 | # here we are using VPU 11 which includes Arkansas, Red and White River basins |
16 | 16 | # check function documentation for further details |
17 | 17 | # setwd to example folder - where NHDPlusV2 data will be downloaded |
18 | | -# this is mostly to keep myself organized |
| 18 | + |
19 | 19 | setwd("C:/Users/Darin/Dropbox/Dissertation/Chapter_2_StreamNetworkTools/StreamNetworkTools_git/Example_Data") |
20 | 20 |
|
21 | | -?net_nhdplus |
22 | | -net_nhdplus(nhdplus_path = getwd(), download = "http", |
23 | | - vpu = 11, files = ALL, zip_7 = "C:/Program Files/7-Zip") |
| 21 | +# check documentation |
| 22 | +# net_nhdplus |
| 23 | +# can download all available data for vpu but sppecified only files needed to run streamNetworkTools |
| 24 | +# this can be time consuming, be patient it only has to be done once |
| 25 | +# data for VPU is already present in example data folder |
| 26 | + |
| 27 | +#net_nhdplus(nhdplus_path = getwd(), download = "http", |
| 28 | + # vpu = 11, files = c("NHDPlusAttributes", "NHDSnapshot", |
| 29 | + # "NHDPlusCatchment", "VPUAttributeExtension", |
| 30 | + # "VogelExtension", "EROMExtension"), |
| 31 | + # zip_7 = "C:/Program Files/7-Zip") |
| 32 | + |
| 33 | +# can run with for loop to download all VPU in CONUS |
| 34 | +# recommend running overnight |
| 35 | + |
| 36 | +#vpus<- c("01","02","03N","03S","03W","04","05","06","07","08","09","10U", |
| 37 | + # "10L","11","12","13","14","15","16","17","18") |
| 38 | + |
| 39 | +# for (i in vpus){ |
| 40 | + # net_nhdplus(nhdplus_path = getwd(), download = "http", |
| 41 | + # vpu = i, files = c("NHDPlusAttributes", "NHDSnapshot", |
| 42 | + # "NHDPlusCatchment", "VPUAttributeExtension", |
| 43 | + # "VogelExtension", "EROMExtension"), |
| 44 | + # zip_7 = "C:/Program Files/7-Zip") |
| 45 | +#} |
| 46 | + |
| 47 | +# net_sample randomly selects comid's of specified stream order from a vector processing unit |
| 48 | +# below identifies 3, fifth order comid's from VPU 11 |
| 49 | + |
| 50 | +rmd_comid <- net_sample(nhdplus_path = getwd(), vpu = "11", ws_order = 5, n = 3) |
| 51 | +print(rmd_comid) |
| 52 | + |
| 53 | +# net_delin queries all COMID's upsteam comid's from root |
| 54 | +# inpput group_comids must be character |
| 55 | +rmd_netdelin <- net_delin(group_comid = as.character(rmd_comid), |
| 56 | + nhdplus_path = getwd(), |
| 57 | + vpu = "11") |
| 58 | +# output is list of 3 |
| 59 | +str(rmd_netdelin) |
| 60 | + |
| 61 | +# can write network as shapefile with |
| 62 | +library(sf) |
| 63 | +write_sf(rmd_netdelin$SF_Obj, paste(getwd(),"/rmd_netdelin.shp", sep = "")) |
| 64 | + |
| 65 | +# value added attribute queries for NHDPlusV2 |
| 66 | +# landcover percentage are for sub-catchments |
| 67 | +rmd_netlc <- net_lc(netdelin = rmd_netdelin, vpu = "11", nhdplus_path = getwd()) |
| 68 | +# field headings follow https://www.mrlc.gov/nlcd11_leg.php |
| 69 | +head(rmd_netlc) |
| 70 | + |
| 71 | +# climate variables follow world clim, bioclim variables and were calculated from 1971-2001 PRISM |
| 72 | +# where necessary units are in tempp in deg C and ppt in mm |
| 73 | +rmd_netclim <- net_clim (nhdplus_path = getwd(), vpu = "11", netdelin = rmd_netdelin) |
| 74 | +head(rmd_netclim) |
| 75 | + |
| 76 | +# flow variables were calculated using the Mean Annual and Mean Monthly EROM |
| 77 | +rmd_netflow <- net_flow(nhdplus_path = getwd(), vpu = "11", netdelin = rmd_netdelin) |
| 78 | +head(rmd_netflow) |
| 79 | + |
| 80 | +# network scale topology |
| 81 | +rmd_netclac <- net_calc(netdelin = rmd_netdelin, vpu = "11", nhdplus_path = getwd()) |
| 82 | +head(rmd_netclac) |
| 83 | + |
| 84 | +# net_hort M values are not included here |
| 85 | +rmd_nethort <- net_hort(netdelin = rmd_netdelin, vpu = "11", nhdplus_path = getwd()) |
| 86 | +str(rmd_nethort) |
24 | 87 |
|
| 88 | +# net sinu gives values for each reach (comid) within a network |
| 89 | +rmd_netsinu <- net_sinu (netdelin = rmd_netdelin, nhdplus_path = getwd(), vpu = "11") |
| 90 | +head(rmd_netsinu) |
25 | 91 |
|
| 92 | +# can be aggregated as a network mean |
| 93 | +mean.sinu <- aggregate(rmd_netsinu[,"sinuosity"], |
| 94 | + by = list(group.comid = rmd_netsinu[,"group.comid"]), |
| 95 | + mean) |
| 96 | +head(mean.sinu) |
26 | 97 |
|
| 98 | +# net_conflu resullts are given by each confluence |
| 99 | +# this takes a while - ended |
| 100 | +#rmd_netconflu <- net_conflu(netdelin = rmd_netdelin, |
| 101 | + # nhdplus_path = getwd(), |
| 102 | + # vpu = "11") |
0 commit comments