#Packages needed for this project
library(tidyverse)
library(here)
Read in the data frame.
df <- read_csv(here('hydrology/src_classes_spring_2022/data/channel_df.csv'))
Let’s plot the raw data
df %>%
ggplot(aes(x = Width_m, y = Channel_height_m, color = Location)) +
geom_point() +
geom_line()
Now lets invert the channel height.
df %>%
mutate(invert_height = 1 - Channel_height_m) %>%
ggplot(aes(x = Width_m, y = invert_height, color = Location)) +
geom_point() +
geom_line()
That is starting to look OK. Now let’s add the water level.
df <- df %>%
mutate(invert_height = 1 - Channel_height_m, new_water = Water_level_m + invert_height)
df %>%
ggplot() +
geom_point(aes(x = Width_m, y = invert_height, color = Location), alpha = 0.5, size = 3) +
geom_line(aes(x = Width_m, y = invert_height, color = Location)) +
geom_line(aes(x = Width_m, y = new_water), color = "blue", size = 1.5) +
geom_point(aes(x = Width_m, y = new_water), color = "blue", alpha = 0.5, size = 3)+
ylab("Height (m)") +
xlab("Width (m)") +
theme_linedraw() +
theme(legend.title = element_blank())
And to calculate the area of the channel. The first part is the linear interpolation.You will note that cor_d does have one negative value. You could remove that with a filter.
seq <- seq(from = 0.02, to = 0.17, length.out = 61)
df <- cbind(df, seq) %>%
mutate(cor_d = Channel_height_m - seq)
df <- df %>%
mutate(area_m2 = (lead(Width_m) - lag(Width_m)) / 2 *cor_d)
total_area <- sum(df$area_m2, na.rm = TRUE)
We could also calculate the wetted area, mean BF-depth, etc. I don’t have the notes on location of BF, so I’ll just do wetted area.
df <- df %>%
mutate(wetted_area_m2 = (lead(Width_m) - lag(Width_m)) / 2 *
Water_level_m)
total_wetted_area <- sum(df$wetted_area_m2, na.rm = TRUE)
Here we can do some bankfull calculations. Left bankfull (LBF) was at 1.3 and RBF was at 28.5.
bf_df <- df %>%
filter(Width_m %in% c(1.5:28.5)) %>%
select(-Water_level_m, -new_water, -invert_height)
seq_bf <- seq(from = 0.14, to = 0.25, length.out = 28)
bf_df <- cbind(bf_df, seq_bf) %>%
mutate(cor_d_bf = Channel_height_m - seq_bf)
bf_df$cor_d_bf[bf_df$cor_d_bf < 0] <- 0
mean_bf_d <- mean(bf_df$cor_d_bf)
bf_df <- bf_df %>%
mutate(bf_area_m2 = (lead(Width_m) - lag(Width_m)) / 2 *cor_d_bf)
tot_bf_area <- sum(bf_df$bf_area_m2, na.rm = TRUE)
bf_df$bf_area_m2[bf_df$bf_area_m2 < 0] <- 0