Skip to content
Snippets Groups Projects
Commit a56db21d authored by Blodgett, David L.'s avatar Blodgett, David L.
Browse files

gagesiii to swim in gage_info

parent a4ebe425
No related branches found
No related tags found
1 merge request!110Updates to Alaska and ready for hyRefactor
......@@ -40,11 +40,11 @@ gages_ii_ref <- read_sf(data_paths$gagesii_lyr) %>%
st_drop_geometry()
```
Get data from Gages III
```{r gagesiii}
### read GagesIII data file from DBF file
allsites <- read.dbf(file.path(data_paths$gagesiii_points_path,
"GAGESIII_gages.dbf"),
Get data from SWIM
```{r swim}
### read swim data file from DBF file
allsites <- read.dbf(file.path(data_paths$SWIM_points_path,
"SWIM_gage_loc.dbf"),
as.is = TRUE)
allsites_dup <- group_by(allsites, Gage_no) %>%
......@@ -70,8 +70,8 @@ if(file.exists(tempf)) {
```
Provide some initial POR coverage for GAGES III
```{r analysis_gagesiii}
Provide some initial POR coverage for SWIM
```{r analysis_swim}
#Calculate number of days between begin date and end date
dailydata$TPdays <- difftime(dailydata$end_date,
dailydata$begin_date,
......@@ -111,10 +111,10 @@ dailydata <- dailydata %>%
dailydata$TPdays1 <- as.numeric(dailydata$TPdays1)
dailydata$missing_days<-as.numeric(dailydata$missing_days)
gagesiii_all <- full_join(siteinfo, dailydata, by = "site_no") %>%
swim_all <- full_join(siteinfo, dailydata, by = "site_no") %>%
left_join(gages_ii_ref, by = c("site_no" = "STAID"))
mapview(st_as_sf(gagesiii_all, coords = c("dec_long_va", "dec_lat_va"), crs = 4326), layer.name = "GAGES-III sites with daily Q")
mapview(st_as_sf(swim_all, coords = c("dec_long_va", "dec_lat_va"), crs = 4326), layer.name = "SWIM sites with daily Q")
```
Evaluate the NHDPlus GageLoc dataset
......@@ -123,7 +123,7 @@ Evaluate the NHDPlus GageLoc dataset
GageLocAll <- sf::read_sf(data_paths$nhdplus_gdb, "Gage")
#get rid of gages that are also in GagesIII
#get rid of gages that are also in SWIM
GageLoc<-anti_join(GageLocAll, gages, by = c("SOURCE_FEA"="Gage_no"))#16719 gages
tempf <- "temp/gages_gagloc_nwis_daily.rds"
......@@ -182,7 +182,7 @@ GLmdays_tojoin <- mostGLmdays %>%
GLmdays_tojoin$TPdays1<-as.numeric(GLmdays_tojoin$TPdays1)
GLmdays_tojoin$missing_days<-as.numeric(GLmdays_tojoin$missing_days)
#rearrange column order so the same as previous file with gages 3 data.
#rearrange column order so the same as previous file with SWIM data.
gageloc_all <- full_join(GLSI_tojoin, GLmdays_tojoin, by = "site_no") %>%
select(site_no, drain_area_va, contrib_drain_area_va, agency_cd, station_nm,
site_tp_cd, dec_lat_va, dec_long_va, coord_acy_cd, huc_cd,
......@@ -191,19 +191,19 @@ gageloc_all <- full_join(GLSI_tojoin, GLmdays_tojoin, by = "site_no") %>%
filter(!is.na(dec_lat_va)) %>%
left_join(gages_ii_ref, by = c("site_no" = "STAID"))
mapview(st_as_sf(gagesiii_all, coords = c("dec_long_va", "dec_lat_va"), crs = 4326), layer.name = "GAGES-III sites with daily Q") +
mapview(st_as_sf(filter(gageloc_all, !site_no %in% gagesiii_all$site_no),
mapview(st_as_sf(swim_all, coords = c("dec_long_va", "dec_lat_va"), crs = 4326), layer.name = "SWIM sites with daily Q") +
mapview(st_as_sf(filter(gageloc_all, !site_no %in% swim_all$site_no),
coords = c("dec_long_va", "dec_lat_va"), crs = 4326), layer.name = "GageLoc sites with daily Q", col.regions = "orange")
```
Retrieve streamgages that were a part of GFv1.1. This ensures all past locations used for modeling work are included in GFV2.0.
These will overlap with GAGES III and GageLoc but will sort out redundancy later
These will overlap with SWIM and GageLoc but will sort out redundancy later
```{r Gages_GFv1.1}
# Read in data layer, 373 non-EC gages
GFv11_gage <- readRDS(data_paths$GFv11_gages_lyr) %>%
filter(!Type_Gage %in% c(gageloc_all$site_no, gagesiii_all$site_no) &
filter(!Type_Gage %in% c(gageloc_all$site_no, swim_all$site_no) &
# Exclude GFv11 gages
nchar(NHD_Unit) < 4)
......@@ -265,7 +265,7 @@ Gv11mdays_tojoin <- mostGv11mdays %>%
Gv11mdays_tojoin$TPdays1 <- as.numeric(Gv11mdays_tojoin$TPdays1)
Gv11mdays_tojoin$missing_days <- as.numeric(Gv11mdays_tojoin$missing_days)
#rearrange column order so the same as previous file with gages 3 data.
#rearrange column order so the same as previous file with SWIM data.
gagev11_all <- full_join(Gv11SI_tojoin, Gv11mdays_tojoin, by = "site_no") %>%
select(site_no, drain_area_va, contrib_drain_area_va, agency_cd, station_nm,
site_tp_cd, dec_lat_va, dec_long_va, coord_acy_cd, huc_cd,
......@@ -281,10 +281,10 @@ mapview(st_as_sf(gagev11_all, coords = c("dec_long_va", "dec_lat_va"), crs = 432
```{r write}
write.dbf(as.data.frame(gagev11_all), "data/GFV11.dbf")
write.dbf(gageloc_all, "data/GageLocGFinfo.dbf")
write.dbf(gagesiii_all, "data/gages3GFinfo.dbf")
write.dbf(swim_all, "data/SWIMGFinfo.dbf")
### ONLY RUN IF CHANGED ###
# sbtools::authenticate_sb()
# sbtools::item_replace_files("5dcd5f96e4b069579760aedb", c("data/GageLocGFinfo.dbf",
# "data/gages3GFinfo.dbf"))
# "data/SWIMGFinfo.dbf"))
```
\ No newline at end of file
......@@ -71,7 +71,8 @@ if(!file.exists(SWIM_points_path)) {
g3gf <- "gages3GFinfo.dbf"
sbtools::item_file_download("5dcd5f96e4b069579760aedb", names = g3gf,
destinations = file.path(data_dir, g3gf))
destinations = file.path(data_dir, g3gf),
overwrite_file = TRUE)
}
out_list <- c(out_list, list(SWIM_points_path = SWIM_points_path))
......@@ -547,14 +548,14 @@ out_list <- c(out_list, out)
```{r Gages_II}
# Download the GFv1.1 geodatabase
if(!dir.exists(gagesiii_points_path))
dir.create(gagesiii_points_path, recursive = TRUE)
if(!dir.exists(SWIM_points_path))
dir.create(SWIM_points_path, recursive = TRUE)
g2_out <- list(gagesii_lyr = file.path(gagesiii_points_path, "gagesII_9322_point_shapefile.shp"))
g2_out <- list(gagesii_lyr = file.path(SWIM_points_path, "gagesII_9322_point_shapefile.shp"))
gagesII_url <- "https://water.usgs.gov/GIS/dsdl/gagesII_9322_point_shapefile.zip"
zip <- file.path(gagesiii_points_path, basename(gagesII_url))
zip <- file.path(SWIM_points_path, basename(gagesII_url))
if(!file.exists(g2_out$gagesii_lyr)) {
......
......@@ -101,7 +101,7 @@ retrieve_sb <- function(sbitem, out_dir){
{
out_file <- file.path(out_path, y$name)
download.file(y$downloadUri, out_file)
download.file(y$downloadUri, out_file, mode = "wb")
list(fname = y$name,
url = y$downloadUri)
......@@ -270,7 +270,7 @@ get_HUC12_Xwalk <- function(VPU, full_cats = FALSE, divides = FALSE, wbd = FALSE
# Convert area to squaker kilometers
mutate(intArea = as.numeric(st_area(.)) * 0.000001,
AreaHUC12 = ACRES * .00404686) %>%
rename(HUC_12_int = HUC_12.1)
rename(HUC_12_int = HUC_12)
return(list(cats_HUC12 = cats_HUC12, divides_HUC12 = divides_HUC12))
......
{
"data_dir": "data",
"hu12_points_path": "data/hu_outlets.gpkg",
"swim_points_path": "data/SWIM_gages",
"SWIM_points_path": "data/SWIM_gage_loc",
"TE_points_path": "data/TE_points",
"USGS_IT_path": "data/USGS_IT",
"NID_points_path": "data/NID_points",
......@@ -175,6 +175,6 @@
"new_nwm_nhdp_atts": "cache/nwm_enhd_nhdplusatts.csv",
"GFv11_gages_lyr": "data/GFv11/GFv11_gages.rds",
"GFv11_gdb": "data/GFv11/GFv1.1.gdb",
"gagesii_lyr": "data/GAGESIII_gages/gagesII_9322_point_shapefile.shp",
"gagesii_lyr": "data/SWIM_gage_loc/gagesII_9322_point_shapefile.shp",
"new_nhdp_rds": "data/NHDPlusNationalData/nhdplus_flowline_update.rds"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment