Created
August 3, 2020 13:38
-
-
Save troyhill/dbdf81b2a755274a4a67fbb4b38bc01e to your computer and use it in GitHub Desktop.
Flow through S333 by headwater stage category, WY2006-2019
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### calculate total flow through S333 below and above 9.2' from WY 2006-2019. | |
if(!"devtools" %in% installed.packages()) install.packages("devtools", repos='http://cran.us.r-project.org') | |
if(!"SFNRC" %in% installed.packages()) devtools::install_github("troyhill/SFNRC") | |
library(SFNRC) | |
theme_set(theme_bw()) | |
# pull data --------------------------------------------------------------- | |
s333Flow <- getDBHYDROhydro(dbkey = 91487) # flow | |
s333stg1 <- getDBHYDROhydro(dbkey = "15616") # 1993-2012, ft NGVD29 | |
s333stg2 <- getDBHYDROhydro(dbkey = "AJ013") # 2012-2020, ft NGVD29 | |
s333stg <- rbind(s333stg1[-nrow(s333stg1), ], s333stg2) | |
names(s333stg)[ncol(s333stg)] <- "stage" | |
s333 <- join_all(list(s333Flow, s333stg[, c("date", "stage")]), by = "date") | |
s333$cat <- ifelse(s333$stage < 9.2, "below 9.2'", "at/above 9.2'") | |
s333$cat <- factor(s333$cat) | |
s333 <- seas(s333, timeCol = "date", waterYearBegin = "Nov", wetSeas = c("May", "Oct")) | |
s333 <- s333[!is.na(s333$day), ] | |
dd.flow.woNAs <- ddply(s333[(s333$waterYr < 2020) & (s333$waterYr > 2005), ], .(waterYr, cat), summarize, | |
kacft = sum(value*1.983, na.rm = TRUE) / 1e3 # 1 cfs = 1.983 acre-feet per day | |
) | |
ggplot(dd.flow.woNAs, aes(y = kacft, x = waterYr, fill = factor(cat))) + geom_col(position = position_dodge()) | |
### see the data: | |
dd.flow.woNAs | |
# write.csv(dd.flow.woNAs, "flow_by_stage_20200803.csv", row.names = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment