diff --git a/data-raw/explore-flow.Rmd b/data-raw/explore-flow.Rmd new file mode 100644 index 0000000..037f763 --- /dev/null +++ b/data-raw/explore-flow.Rmd @@ -0,0 +1,69 @@ +--- +title: "Explore Flow" +author: "Erin Cain" +date: "8/6/2021" +output: + html_document: + toc_depth: 2 + theme: flatly + code_folding: hide +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE, + fig.width=15, fig.height=8) +library(tidyverse) +library(ggplot2) +library(lubridate) +``` + +## Watershed Flow (cfs) + +```{r} +flow <- DSMflow::flows_cfs %>% + gather( watershed, cfs, -date) %>% + filter(!(watershed %in% c('Sutter Bypass', 'Yolo Bypass'))) + +for (w in DSMflow::watershed_ordering %>% pull(watershed)){ + watershed <- flow %>% + filter(watershed == w) %>% + summarise(watershed = w, + mean_flow = mean(cfs), + min_flow = min(cfs), + max_flow = max(cfs)) + + plot <- flow %>% + filter(watershed == w) %>% + ggplot(aes(date, cfs)) + + geom_line(color = 'blue') + + labs(title = w) + print(plot) + print(watershed) +} +``` + +## Proportion Diverted / Total Diverted +```{r} +total_diverted <- DSMflow::total_diverted +proportion_diverted <- DSMflow::proportion_diverted + +diversions <- expand_grid( + watershed = factor(DSMscenario::watershed_labels, + levels = DSMscenario::watershed_labels), + month = 1:12, + year = 1980:2000) %>% + arrange(year, month, watershed) %>% + mutate(total_diverted = as.vector(total_diverted), + proportion_diverted = as.vector(proportion_diverted)) + +diversions %>% + transmute(watershed, date = ymd(paste(year, month, 1)), total_diverted, proportion_diverted) %>% + filter(!(watershed %in% c('Sutter Bypass', 'Yolo Bypass'))) %>% + gather(version, cfs, -watershed, -date) %>% + ggplot(aes(date, cfs, color = version)) + + geom_line() + + facet_wrap(~watershed, scales = 'free') + + +``` + diff --git a/data-raw/explore-flow.html b/data-raw/explore-flow.html new file mode 100644 index 0000000..0fcb47c --- /dev/null +++ b/data-raw/explore-flow.html @@ -0,0 +1,445 @@ + + + + + + + + + + + + + + +Explore Flow + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+

Watershed Flow (cfs)

+
flow <- DSMflow::flows_cfs %>%
+  gather( watershed, cfs, -date) %>%
+  filter(!(watershed %in% c('Sutter Bypass', 'Yolo Bypass'))) 
+
+for (w in DSMflow::watershed_ordering %>% pull(watershed)){
+  watershed <- flow %>% 
+    filter(watershed == w) %>% 
+    summarise(watershed = w, 
+              mean_flow = mean(cfs), 
+              min_flow = min(cfs), 
+              max_flow = max(cfs))
+  
+  plot <- flow %>% 
+    filter(watershed == w) %>% 
+    ggplot(aes(date, cfs)) +
+    geom_line(color = 'blue') +
+    labs(title = w)
+  print(plot)
+  print(watershed)
+} 
+

+
## # A tibble: 1 x 4
+##   watershed              mean_flow min_flow max_flow
+##   <chr>                      <dbl>    <dbl>    <dbl>
+## 1 Upper Sacramento River     8510.     2923    58991
+

+
## # A tibble: 1 x 4
+##   watershed      mean_flow min_flow max_flow
+##   <chr>              <dbl>    <dbl>    <dbl>
+## 1 Antelope Creek      143.     15.1    1343.
+

+
## # A tibble: 1 x 4
+##   watershed    mean_flow min_flow max_flow
+##   <chr>            <dbl>    <dbl>    <dbl>
+## 1 Battle Creek      473.     115.    3146.
+

+
## # A tibble: 1 x 4
+##   watershed  mean_flow min_flow max_flow
+##   <chr>          <dbl>    <dbl>    <dbl>
+## 1 Bear Creek      65.1        0    1047.
+

+
## # A tibble: 1 x 4
+##   watershed       mean_flow min_flow max_flow
+##   <chr>               <dbl>    <dbl>    <dbl>
+## 1 Big Chico Creek      138.     10.2    1699.
+

+
## # A tibble: 1 x 4
+##   watershed   mean_flow min_flow max_flow
+##   <chr>           <dbl>    <dbl>    <dbl>
+## 1 Butte Creek      292.        0    3049.
+

+
## # A tibble: 1 x 4
+##   watershed   mean_flow min_flow max_flow
+##   <chr>           <dbl>    <dbl>    <dbl>
+## 1 Clear Creek      179.       50    2309.
+

+
## # A tibble: 1 x 4
+##   watershed        mean_flow min_flow max_flow
+##   <chr>                <dbl>    <dbl>    <dbl>
+## 1 Cottonwood Creek      857.       25    14781
+

+
## # A tibble: 1 x 4
+##   watershed mean_flow min_flow max_flow
+##   <chr>         <dbl>    <dbl>    <dbl>
+## 1 Cow Creek      642.      0.6    6302.
+

+
## # A tibble: 1 x 4
+##   watershed  mean_flow min_flow max_flow
+##   <chr>          <dbl>    <dbl>    <dbl>
+## 1 Deer Creek      358.     56.4    3023.
+

+
## # A tibble: 1 x 4
+##   watershed   mean_flow min_flow max_flow
+##   <chr>           <dbl>    <dbl>    <dbl>
+## 1 Elder Creek      96.4        0     1695
+

+
## # A tibble: 1 x 4
+##   watershed  mean_flow min_flow max_flow
+##   <chr>          <dbl>    <dbl>    <dbl>
+## 1 Mill Creek      303.     58.6    2071.
+

+
## # A tibble: 1 x 4
+##   watershed    mean_flow min_flow max_flow
+##   <chr>            <dbl>    <dbl>    <dbl>
+## 1 Paynes Creek      65.1        0    1047.
+

+
## # A tibble: 1 x 4
+##   watershed   mean_flow min_flow max_flow
+##   <chr>           <dbl>    <dbl>    <dbl>
+## 1 Stony Creek      342.        0    10065
+

+
## # A tibble: 1 x 4
+##   watershed    mean_flow min_flow max_flow
+##   <chr>            <dbl>    <dbl>    <dbl>
+## 1 Thomes Creek      298.        0    3597.
+
## # A tibble: 1 x 4
+##   watershed                  mean_flow min_flow max_flow
+##   <chr>                          <dbl>    <dbl>    <dbl>
+## 1 Upper-mid Sacramento River    12019.     3413   108026
+
## Warning in min(cfs): no non-missing arguments to min; returning Inf
+
## Warning in max(cfs): no non-missing arguments to max; returning -Inf
+

+
## # A tibble: 1 x 4
+##   watershed     mean_flow min_flow max_flow
+##   <chr>             <dbl>    <dbl>    <dbl>
+## 1 Sutter Bypass       NaN      Inf     -Inf
+

+
## # A tibble: 1 x 4
+##   watershed  mean_flow min_flow max_flow
+##   <chr>          <dbl>    <dbl>    <dbl>
+## 1 Bear River      492.      8.3    5426.
+

+
## # A tibble: 1 x 4
+##   watershed     mean_flow min_flow max_flow
+##   <chr>             <dbl>    <dbl>    <dbl>
+## 1 Feather River     4157.      750    45760
+
## # A tibble: 1 x 4
+##   watershed  mean_flow min_flow max_flow
+##   <chr>          <dbl>    <dbl>    <dbl>
+## 1 Yuba River     2030.        0    24928
+
## Warning in min(cfs): no non-missing arguments to min; returning Inf
+
+## Warning in min(cfs): no non-missing arguments to max; returning -Inf
+

+
## # A tibble: 1 x 4
+##   watershed                  mean_flow min_flow max_flow
+##   <chr>                          <dbl>    <dbl>    <dbl>
+## 1 Lower-mid Sacramento River       NaN      Inf     -Inf
+
## Warning in min(cfs): no non-missing arguments to min; returning Inf
+
+## Warning in min(cfs): no non-missing arguments to max; returning -Inf
+

+
## # A tibble: 1 x 4
+##   watershed   mean_flow min_flow max_flow
+##   <chr>           <dbl>    <dbl>    <dbl>
+## 1 Yolo Bypass       NaN      Inf     -Inf
+

+
## # A tibble: 1 x 4
+##   watershed      mean_flow min_flow max_flow
+##   <chr>              <dbl>    <dbl>    <dbl>
+## 1 American River     3248.      250    38199
+

+
## # A tibble: 1 x 4
+##   watershed              mean_flow min_flow max_flow
+##   <chr>                      <dbl>    <dbl>    <dbl>
+## 1 Lower Sacramento River    20472.     4339    80685
+

+
## # A tibble: 1 x 4
+##   watershed       mean_flow min_flow max_flow
+##   <chr>               <dbl>    <dbl>    <dbl>
+## 1 Calaveras River      200.        0    3865.
+

+
## # A tibble: 1 x 4
+##   watershed      mean_flow min_flow max_flow
+##   <chr>              <dbl>    <dbl>    <dbl>
+## 1 Cosumnes River      510.        0    7536.
+

+
## # A tibble: 1 x 4
+##   watershed       mean_flow min_flow max_flow
+##   <chr>               <dbl>    <dbl>    <dbl>
+## 1 Mokelumne River      675.      126     5695
+

+
## # A tibble: 1 x 4
+##   watershed    mean_flow min_flow max_flow
+##   <chr>            <dbl>    <dbl>    <dbl>
+## 1 Merced River      637.       15    12085
+

+
## # A tibble: 1 x 4
+##   watershed        mean_flow min_flow max_flow
+##   <chr>                <dbl>    <dbl>    <dbl>
+## 1 Stanislaus River      609.      150    7855.
+

+
## # A tibble: 1 x 4
+##   watershed      mean_flow min_flow max_flow
+##   <chr>              <dbl>    <dbl>    <dbl>
+## 1 Tuolumne River      902.       50    20982
+

+
## # A tibble: 1 x 4
+##   watershed         mean_flow min_flow max_flow
+##   <chr>                 <dbl>    <dbl>    <dbl>
+## 1 San Joaquin River     3060.      137    59524
+
+
+

Proportion Diverted / Total Diverted

+
total_diverted <- DSMflow::total_diverted
+proportion_diverted <- DSMflow::proportion_diverted
+
+diversions <- expand_grid(
+  watershed = factor(DSMscenario::watershed_labels, 
+                     levels = DSMscenario::watershed_labels),
+  month = 1:12,
+  year = 1980:2000) %>%
+  arrange(year, month, watershed) %>%
+  mutate(total_diverted = as.vector(total_diverted),
+         proportion_diverted = as.vector(proportion_diverted))
+
+diversions %>% 
+  transmute(watershed, date = ymd(paste(year, month, 1)), total_diverted, proportion_diverted) %>% 
+  filter(!(watershed %in% c('Sutter Bypass', 'Yolo Bypass'))) %>% 
+  gather(version, cfs, -watershed, -date)  %>% 
+  ggplot(aes(date, cfs, color = version)) +
+  geom_line() +
+  facet_wrap(~watershed, scales = 'free')
+

+
+ + + + +
+ + + + + + + + + + + + + + + +