source("../../R/clean.R") source("../../R/shape.R") source("../../R/isolate.R") source("../../R/model.R") source("../../R/draw.R") source("../../R/util.R") load("../../data/hourly_rain.RData") load("../../data/hourly_flow.RData") # library(dplyr) library(zoo) library(lubridate) library(vars) library(imputeTS) library(stringr) library(tidyr) library(ggplot2); theme_set(theme_bw())
# convert hourly data to daily data rain_ <- hourly_rain %>% filter(station=="BUCKMN") %>% mutate(date=lubridate::date(datetime)) %>% group_by(date) %>% summarize(rain=sum(rainfall_in, na.rm=TRUE)) tmp <- hourly_flow %>% filter(str_detect(location, "Tow")) %>% mutate(date=date(datehour)) %>% filter(date>mdy("10/5/2018")) %>% filter(date<mdy("01/01/2020")) %>% na.omit(flow) %>% group_by(date) %>% summarize(df=sum(flow, na.rm=TRUE)) %>% left_join(rain_, by="date") date <- tmp$date flow <- tmp$df rain <- tmp$rain df <- data.frame(date=date, flow=flow, rain=rain)
df$scrub <- remove_outliers(df$flow)
df$gwi <- isolate_daily_gwi(df$date, df$scrub, df$rain) uh.3 <- shape_daily_hydrograph(df$date, df$gwi, df$rain, 14, 0.25, 1) df$gwi_model <- model_hydrograph(df$rain, uh.3) df$bsf <- df$scrub - df$gwi_model df$bsf_model <- isolate_daily_bsf(df$date, df$bsf, df$rain)
df$rdi <- df$scrub - df$bsf_model - df$gwi_model uh.2 <- shape_daily_hydrograph(df$date, df$rdi, df$rain, 7, 0.25, 10) df$rdi_model <- model_hydrograph(df$rain, uh.2)
df$model <- df$bsf + df$gwi + df$rdi df$residual <- df$model-df$scrub df$error <- df$residual/df$scrub draw_model_qaqc(df) plot(uh.2, type="n") lines(uh.2) lines(uh.3)
rain_ <- hourly_rain %>% filter(station=="BUCKMN") tmp <- hourly_flow %>% filter(str_detect(location, "Tow")) %>% mutate(date=date(datehour)) %>% filter(date>mdy("10/5/2018")) %>% filter(date<mdy("01/01/2020")) %>% left_join(rain_, by=c("datehour"="datetime")) %>% left_join(df, by="date") date <- tmp$datehour flow <- tmp$flow.x-tmp$gwi_model/1440*60-tmp$rdi_model/1440*60 rain <- tmp$rainfall_in hf <- data.frame(date=date, flow=flow, rain=rain) plot(date, flow, type="l", col=rgb(0.25,0.25,0.25,0.25)) abline(h=0) lines(date, rain*500, lwd=2, col="blue") # consider calculating GWI from night-time flow. # next step is to extract diurnal pattern
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.