-
Notifications
You must be signed in to change notification settings - Fork 0
/
New Melones Analysis.Rmd
1102 lines (880 loc) · 53.2 KB
/
New Melones Analysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "R Notebook"
output: html_notebook
---
```{r}
library(readr)
library(dplyr)
library(ggplot2)
library(extrafont)
library(lfstat)
```
```{r}
NM_hist_Gen <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/historical/Livneh/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "Livneh (Historical)",
Scenario = "RCP 4.5",
node = as.Date(node),
`New Melones PH` = as.numeric(`New Melones PH`),
WaterYear = water_year(node, origin = "usgs"))
NM_hist_Gen
NM_Can_Gen <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CanESM2_rcp45/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CanESM2",
Scenario = "RCP 4.5")
NM_Mir_Gen <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/MIROC5_rcp45/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "MIROC5",
Scenario = "RCP 4.5")
NM_Mir_Gen
NM_CNR_Gen <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CNRM-CM5_rcp45/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CNRM-CM5",
Scenario = "RCP 4.5")
NM_CNR_Gen
NM_Had_Gen <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-ES_rcp45/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "HadGEM2-ES",
Scenario = "RCP 4.5")
NM_Had_Gen
```
```{r}
#RCP 8.5
NM_hist_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/historical/Livneh/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "Livneh (Historical)",
Scenario = "RCP 8.5",
node = as.Date(node),
`New Melones PH` = as.numeric(`New Melones PH`),
WaterYear = water_year(node, origin = "usgs"))
NM_hist_Gen2
NM_Can_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CanESM2_rcp85/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CanESM2",
Scenario = "RCP 8.5")
NM_Can_Gen2
NM_Mir_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/MIROC5_rcp85/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "MIROC5",
Scenario = "RCP 8.5")
NM_Mir_Gen2
NM_CNR_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CNRM-CM5_rcp85/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CNRM-CM5",
Scenario = "RCP 8.5")
NM_CNR_Gen2
NM_Had_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-ES_rcp85/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "HadGEM2-ES",
Scenario = "RCP 8.5")
NM_Had_Gen2
NM_CCSM4_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CCSM4_rcp85/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CCSM4",
Scenario = "RCP 8.5")
NM_CCSM4_Gen2
NM_GFDL_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/GFDL-CM3_rcp85/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "GFDL-CM3",
Scenario = "RCP 8.5")
NM_GFDL_Gen2
NM_HadGEMCC_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-CC_rcp85/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "HadGEM2-CC",
Scenario = "RCP 8.5")
NM_HadGEMCC_Gen2
NM_CMCC_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CMCC-CMS_rcp85/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CMCC-CMS",
Scenario = "RCP 8.5")
NM_CMCC_Gen2
NM_ACCESS1_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/ACCESS1-0_rcp85/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "ACCESS1-0",
Scenario = "RCP 8.5")
NM_ACCESS1_Gen2
NM_CESM1_Gen2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CESM1-BGC_rcp85/Hydropower_Energy_MWh.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CESM1-BGC",
Scenario = "RCP 8.5")
NM_CESM1_Gen2
```
```{r}
library(lfstat)
New_Mel1 <- rbind(NM_Can_Gen, NM_Can_Gen2, NM_Mir_Gen,
NM_Mir_Gen2, NM_Had_Gen, NM_Had_Gen2, NM_CNR_Gen, NM_CNR_Gen2,
NM_HadGEMCC_Gen2, NM_CMCC_Gen2, NM_ACCESS1_Gen2, NM_CESM1_Gen2, NM_GFDL_Gen2, NM_CCSM4_Gen2) %>%
mutate(`New Melones PH` = as.numeric(`New Melones PH`),
node = as.Date(node),
WaterYear = water_year(node, origin = "usgs")) %>%
filter(WaterYear %in% (2040:2059))
New_Mel1
New_Mel <- rbind(NM_hist_Gen2, New_Mel1)
New_Mel2 <- New_Mel %>%
mutate(WaterYear = water_year(node, origin = "usgs")) %>%
mutate(Month = as.factor(format(as.Date(node, format = "%B"), "%b"))) %>%
# filter(WaterYear %in% (2040:2059)) %>%
group_by(WaterYear, Model, Scenario) %>%
summarize(Generation = sum(`New Melones PH`)) %>%
ungroup() %>%
group_by(Scenario, Model) %>%
summarize(Generation = mean(Generation))
New_Mel2
New_Mel_GenWY <- New_Mel %>%
mutate(WaterYear = water_year(node, origin = "usgs"),
Month = as.factor(format(as.Date(node, format = "%B"), "%b"))) %>%
group_by(WaterYear, Model, Scenario, Month) %>%
summarize(Generation = sum(`New Melones PH`))
New_Mel_GenWY
New_Mel_Gen_Ensem <- New_Mel1 %>%
mutate(Month = as.factor(format(as.Date(node, format = "%B"), "%b"))) %>%
group_by(WaterYear, Month, Scenario, Model) %>%
summarize(Generation = sum(`New Melones PH`)) %>%
ungroup() %>%
group_by(WaterYear, Scenario, Month) %>%
summarize(Generation = mean(Generation)) %>%
mutate(Model = "Ensemble")
New_Mel_Gen_Ensem
New_Mel_GenWY2 <- rbind(New_Mel_Gen_Ensem, New_Mel_GenWY)%>%
filter(!Scenario == "RCP 4.5")
New_Mel_GenWY2
New_Mel_GenWY2$Model <- factor(New_Mel_GenWY2$Model, levels = c("Livneh (Historical)","MIROC5", "ACCESS1-0", "GFDL‐CM3","CMCC-CMS", "HadGEM2-ES", "CCSM4", "CESM1-BGC", "HadGEM2‐CC","CanESM2", "CNRM-CM5", "Ensemble"))
New_Mel_Genannual <- New_Mel_GenWY2 %>%
group_by(Model, WaterYear) %>%
summarize(Generation = sum(Generation))
New_Mel_Genannual
New_Mel_Genannual_Livneh <- New_Mel_Genannual %>%
filter(Model == "Livneh (Historical)") %>%
summarize(Generation = mean(Generation))
New_Mel_Genannual_Livneh
New_Mel_Genannual2 <- New_Mel_Genannual %>%
filter(!Model == "Livneh (Historical)") %>%
mutate(AbsoluteDiff = (Generation-as.numeric(paste(New_Mel_Genannual_Livneh[2]))),
RelativeDiff = (Generation-as.numeric(paste(New_Mel_Genannual_Livneh[2])))/as.numeric(paste(New_Mel_Genannual_Livneh[2]))*100)
New_Mel_Genannual2
```
```{r}
Figure_Annual(New_Mel_Genannual2, New_Mel_Genannual2$RelativeDiff, Delta~"Hydropower Generation (%)", "Hydropower_Percent", "Figure 3. Relative change in annual hydropower generation compared to historical (1951-2013)")
Figure_Annual_abs(New_Mel_Genannual2, New_Mel_Genannual2$AbsoluteDiff, Delta~"Hydropower Generation (GWh/year)", "Hydropower_abs", "Figure 2. Absolute change in annual hydropower generation compared to historical (1951-2013)")
Figure_Monthly(New_Mel_GenWY2, New_Mel_GenWY2$Generation, "", "Hydropower Generation (GWh/month)", "Hydropower", "Figure 1. Monthly hydropower generation by the New Melones Powerhouse")
```
```{r}
NM_hist_IFR <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/historical/Livneh/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "Livneh (Historical)",
Scenario = "RCP 4.5",
`IFR bl Goodwin Reservoir` = as.numeric(`IFR bl Goodwin Reservoir`),
node = as.Date(node))
NM_hist_IFR
NM_Can_IFR <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CanESM2_rcp45/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "CanESM2",
Scenario = "RCP 4.5")
NM_Mir_IFR <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/MIROC5_rcp45/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "MIROC5",
Scenario = "RCP 4.5")
NM_Mir_IFR
NM_CNR_IFR <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CNRM-CM5_rcp45/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "CNRM-CM5",
Scenario = "RCP 4.5")
NM_CNR_IFR
NM_Had_IFR <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-ES_rcp45/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "HadGEM2-ES",
Scenario = "RCP 4.5")
NM_Had_IFR
```
```{r}
#RCP 8.5
NM_hist_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/historical/Livneh/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "Livneh (Historical)",
Scenario = "RCP 8.5",
`IFR bl Goodwin Reservoir` = as.numeric(`IFR bl Goodwin Reservoir`),
node = as.Date(node),
WaterYear = water_year(node, origin = "usgs"))
NM_hist_IFR2
NM_Can_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CanESM2_rcp85/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "CanESM2",
Scenario = "RCP 8.5")
NM_Can_IFR2
NM_Mir_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/MIROC5_rcp85/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "MIROC5",
Scenario = "RCP 8.5")
NM_Mir_IFR2
NM_CNR_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CNRM-CM5_rcp85/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "CNRM-CM5",
Scenario = "RCP 8.5")
NM_CNR_IFR2
NM_Had_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-ES_rcp85/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "HadGEM2-ES",
Scenario = "RCP 8.5")
NM_Had_IFR2
NM_CCSM4_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CCSM4_rcp85/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "CCSM4",
Scenario = "RCP 8.5")
NM_CCSM4_IFR2
NM_GFDL_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/GFDL-CM3_rcp85/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "GFDL-CM3",
Scenario = "RCP 8.5")
NM_GFDL_IFR2
NM_HadGEMCC_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-CC_rcp85/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "HadGEM2-CC",
Scenario = "RCP 8.5")
NM_HadGEMCC_IFR2
NM_CMCC_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CMCC-CMS_rcp85/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "CMCC-CMS",
Scenario = "RCP 8.5")
NM_CMCC_IFR2
NM_ACCESS1_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/ACCESS1-0_rcp85/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "ACCESS1-0",
Scenario = "RCP 8.5")
NM_ACCESS1_IFR2
NM_CESM1_IFR2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CESM1-BGC_rcp85/InstreamFlowRequirement_Requirement_mcm.csv")[-c(1:3), c(1,14)] %>%
mutate(Model = "CESM1-BGC",
Scenario = "RCP 8.5")
NM_CESM1_IFR2
```
```{r}
library(lfstat)
New_Mel_IFR1 <- rbind(NM_Can_IFR, NM_Can_IFR2, NM_Mir_IFR,
NM_Mir_IFR2, NM_Had_IFR, NM_Had_IFR2, NM_CNR_IFR, NM_CNR_IFR2,
NM_HadGEMCC_IFR2, NM_CMCC_IFR2, NM_ACCESS1_IFR2, NM_CESM1_IFR2, NM_GFDL_IFR2, NM_CCSM4_IFR2) %>%
mutate(`IFR bl Goodwin Reservoir` = as.numeric(`IFR bl Goodwin Reservoir`),
node = as.Date(node),
WaterYear = water_year(node, origin = "usgs")) %>%
filter(WaterYear %in% (2040:2059))
New_Mel_IFR1
New_Mel_IFR <- rbind(New_Mel_IFR1, NM_hist_IFR2)
New_Mel_IFR2 <- New_Mel_IFR %>%
mutate(Month = as.factor(format(as.Date(node, format = "%B"), "%b"))) %>%
group_by(WaterYear, Model, Scenario)%>%
summarize(IFR = sum(`IFR bl Goodwin Reservoir`)) %>%
ungroup() %>%
group_by(Scenario, Model) %>%
summarize(IFR = mean(IFR))
New_Mel_IFR2
New_Mel_IFRWY <- New_Mel_IFR %>%
mutate(Month = as.factor(format(as.Date(node, format = "%B"), "%b"))) %>%
group_by(WaterYear, Model, Scenario, Month) %>%
summarize(IFR = sum(`IFR bl Goodwin Reservoir`))
New_Mel_IFRWY
New_Mel_IFR_Ensem <- New_Mel_IFR1 %>%
mutate(Month = as.factor(format(as.Date(node, format = "%B"), "%b"))) %>%
group_by(WaterYear, Month, Scenario, Model) %>%
summarize(IFR = sum(`IFR bl Goodwin Reservoir`)) %>%
ungroup() %>%
group_by(WaterYear, Scenario, Month) %>%
summarize(IFR = mean(IFR)) %>%
mutate(Model = "Ensemble")
New_Mel_IFR_Ensem
New_Mel_IFRWY2 <- rbind(New_Mel_IFR_Ensem, New_Mel_IFRWY)%>%
filter(!Scenario == "RCP 4.5")
New_Mel_IFRWY2
New_Mel_IFRWY2$Model <- factor(New_Mel_IFRWY2$Model, levels = c("Livneh (Historical)","MIROC5", "ACCESS1-0", "GFDL‐CM3","CMCC-CMS", "HadGEM2-ES", "CCSM4", "CESM1-BGC", "HadGEM2‐CC","CanESM2", "CNRM-CM5", "Ensemble"))
New_Mel_IFRannual <- New_Mel_IFRWY2 %>%
group_by(Model, WaterYear) %>%
summarize(IFR = sum(IFR))
New_Mel_IFRannual
New_Mel_IFRannual_Livneh <- New_Mel_IFRannual %>%
filter(Model == "Livneh (Historical)") %>%
summarize(IFR = mean(IFR))
New_Mel_IFRannual_Livneh
New_Mel_IFRannual2 <- New_Mel_IFRannual %>%
filter(!Model == "Livneh (Historical)") %>%
mutate(AbsoluteDiff = (IFR-as.numeric(paste(New_Mel_IFRannual_Livneh[2]))),
RelativeDiff = (IFR-as.numeric(paste(New_Mel_IFRannual_Livneh[2])))/as.numeric(paste(New_Mel_IFRannual_Livneh[2]))*100)
New_Mel_IFRannual2
```
```{r}
Figure_Annual(New_Mel_IFRannual2, New_Mel_IFRannual2$RelativeDiff, Delta~"Minimum Flow Requirement (%)", "IFR_Perc", "Figure 6. Relative change in annual minimum instream flow requirement compared to historical (1951-2013)")
Figure_Annual_abs(New_Mel_IFRannual2, New_Mel_IFRannual2$AbsoluteDiff, Delta~"Minimum Flow Requirement (acre-feet/year)", Delta~"Minimum Flow Requirement (mcm/year)", "IFR_abs", "Figure 5. Absolute change in annual minimum instream flow requirement compared to historical (1951-2013)")
Figure_Monthly(New_Mel_IFRWY2, New_Mel_IFRWY2$IFR, "Minimum Flow Requirement (acre-feet/month)", "Minimum Flow Requirement (mcm/month)", "IFR", "Figure 4. Monthly minimum instream flow requirement below Goodwin Dam")
```
```{r}
NM_hist_Out <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/historical/Livneh/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "Livneh (Historical)",
Scenario = "RCP 4.5")
NM_hist_Out
NM_Can_Out <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CanESM2_rcp45/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "CanESM2",
Scenario = "RCP 4.5")
NM_Mir_Out <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/MIROC5_rcp45/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "MIROC5",
Scenario = "RCP 4.5")
NM_Mir_Out
NM_CNR_Out <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CNRM-CM5_rcp45/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "CNRM-CM5",
Scenario = "RCP 4.5")
NM_CNR_Out
NM_Had_Out <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-ES_rcp45/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "HadGEM2-ES",
Scenario = "RCP 4.5")
NM_Had_Out
```
```{r}
#RCP 8.5
NM_hist_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/historical/Livneh/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "Livneh (Historical)",
Scenario = "RCP 8.5",
WaterYear = water_year(node, origin = "usgs"))
NM_hist_Out2
NM_Can_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CanESM2_rcp85/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "CanESM2",
Scenario = "RCP 8.5")
NM_Can_Out2
NM_Mir_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/MIROC5_rcp85/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "MIROC5",
Scenario = "RCP 8.5")
NM_Mir_Out2
NM_CNR_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CNRM-CM5_rcp85/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "CNRM-CM5",
Scenario = "RCP 8.5")
NM_CNR_Out2
NM_Had_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-ES_rcp85/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "HadGEM2-ES",
Scenario = "RCP 8.5")
NM_Had_Out2
NM_CCSM4_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CCSM4_rcp85/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "CCSM4",
Scenario = "RCP 8.5")
NM_CCSM4_Out2
NM_GFDL_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/GFDL-CM3_rcp85/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "GFDL-CM3",
Scenario = "RCP 8.5")
NM_GFDL_Out2
NM_HadGEMCC_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-CC_rcp85/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "HadGEM2-CC",
Scenario = "RCP 8.5")
NM_HadGEMCC_Out2
NM_CMCC_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CMCC-CMS_rcp85/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "CMCC-CMS",
Scenario = "RCP 8.5")
NM_CMCC_Out2
NM_ACCESS1_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/ACCESS1-0_rcp85/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "ACCESS1-0",
Scenario = "RCP 8.5")
NM_ACCESS1_Out2
NM_CESM1_Out2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CESM1-BGC_rcp85/Output_Flow_mcm.csv")[-c(1:3), c(1,2,6,10,14)] %>%
mutate(Model = "CESM1-BGC",
Scenario = "RCP 8.5")
NM_CESM1_Out2
```
```{r}
library(lfstat)
New_Mel_Out1 <- rbind(NM_Can_Out, NM_Can_Out2, NM_Mir_Out,
NM_Mir_Out2, NM_Had_Out, NM_Had_Out2, NM_CNR_Out, NM_CNR_Out2,
NM_HadGEMCC_Out2, NM_CMCC_Out2, NM_ACCESS1_Out2, NM_CESM1_Out2, NM_GFDL_Out2, NM_CCSM4_Out2) %>%
mutate(Outflow = as.numeric(`Stanislaus River Outflow`),#+as.numeric(`Phoenix Canal Outflow`),
Irrigation = as.numeric(`Oakdale Irrigation District`)+as.numeric(`South San Joaquin Irrigation District`),
node = as.Date(node),
WaterYear = water_year(node, origin = "usgs")) %>%
filter(WaterYear %in% (2040:2059))
New_Mel_Out1
NM_hist_Out3 <- NM_hist_Out2 %>%
mutate(Outflow = as.numeric(`Stanislaus River Outflow`),#+as.numeric(`Phoenix Canal Outflow`),
Irrigation = as.numeric(`Oakdale Irrigation District`)+as.numeric(`South San Joaquin Irrigation District`),
node = as.Date(node))
NM_hist_Out2
New_Mel_Out <- rbind(NM_hist_Out3, New_Mel_Out1)
New_Mel_Out2 <- New_Mel_Out %>%
#mutate(WaterYear = water_year(node, origin = "usgs")) %>%
# filter(WaterYear %in% (2040:2059)) %>%
group_by(WaterYear, Model, Scenario) %>%
summarize(Irrigation = sum(Irrigation),
Outflow = sum(Outflow)) %>%
ungroup() %>%
group_by(Scenario, Model) %>%
summarize(Irrigation = mean(Irrigation),
Outflow = mean(Outflow))
New_Mel_Out2
New_Mel_OutWY <- New_Mel_Out %>%
mutate(Month = as.factor(format(as.Date(node, format = "%B"), "%b"))) %>%
group_by(WaterYear, Month, Model, Scenario) %>%
summarize(Irrigation = sum(Irrigation),
Outflow = sum(Outflow))
New_Mel_OutWY
New_Mel_Out_Ensem <- New_Mel_Out1 %>%
mutate(Month = as.factor(format(as.Date(node, format = "%B"), "%b"))) %>%
group_by(WaterYear, Month, Scenario, Model) %>%
summarize(Irrigation = sum(Irrigation),
Outflow = sum(Outflow)) %>%
ungroup() %>%
group_by(WaterYear, Scenario, Month) %>%
summarize(Irrigation = mean(Irrigation),
Outflow = mean(Outflow)) %>%
mutate(Model = "Ensemble")
New_Mel_Out_Ensem
New_Mel_OutWY2 <- rbind(New_Mel_Out_Ensem, New_Mel_OutWY)%>%
filter(!Scenario == "RCP 4.5")
New_Mel_OutWY2
New_Mel_OutWY2$Model <- factor(New_Mel_OutWY2$Model, levels = c("Livneh (Historical)","MIROC5", "ACCESS1-0", "GFDL‐CM3","CMCC-CMS", "HadGEM2-ES", "CCSM4", "CESM1-BGC", "HadGEM2‐CC","CanESM2", "CNRM-CM5", "Ensemble"))
New_Mel_Outannual <- New_Mel_OutWY2 %>%
group_by(Model, WaterYear) %>%
summarize(Irrigation = sum(Irrigation),
Outflow = sum(Outflow))
New_Mel_Outannual
New_Mel_Outannual_Livneh <- New_Mel_Outannual %>%
filter(Model == "Livneh (Historical)") %>%
summarize(Irrigation = mean(Irrigation),
Outflow = mean(Outflow))
New_Mel_Outannual_Livneh
New_Mel_Irrigannual2 <- New_Mel_Outannual %>%
filter(!Model == "Livneh (Historical)") %>%
mutate(AbsoluteDiff = (Irrigation-as.numeric(paste(New_Mel_Outannual_Livneh[2]))),
RelativeDiff = (Irrigation-as.numeric(paste(New_Mel_Outannual_Livneh[2])))/as.numeric(paste(New_Mel_Outannual_Livneh[2]))*100)
New_Mel_Irrigannual2
New_Mel_Outannual2 <- New_Mel_Outannual %>%
filter(!Model == "Livneh (Historical)") %>%
mutate(AbsoluteDiff = (Outflow-as.numeric(paste(New_Mel_Outannual_Livneh[3]))),
RelativeDiff = (Outflow-as.numeric(paste(New_Mel_Outannual_Livneh[3])))/as.numeric(paste(New_Mel_Outannual_Livneh[3]))*100)
New_Mel_Outannual2
```
```{r}
Figure_Annual(New_Mel_Irrigannual2, New_Mel_Irrigannual2$RelativeDiff, Delta~"Irrigation Deliveries (%)", "Irrigation_Percent", "Figure 12. Relative change in annual irrigation deliveries compared to historical (1951-2013)")
Figure_Annual_abs(New_Mel_Irrigannual2, New_Mel_Irrigannual2$AbsoluteDiff, Delta~"Irrigation deliveries (acre-feet/year)", Delta~"Irrigation deliveries (mcm/year)", "Irrigation_abs", "Figure 11. Absolute change in annual irrigation deliveries compared to historical (1951-2013)")
Figure_Monthly(New_Mel_OutWY2, New_Mel_OutWY2$Irrigation, Delta~"Irrigation deliveries (acre-feet/month)", Delta~"Irrigation deliveries (mcm/month)", "Irrigation", "Figure 10. Monthly deliveries to Oakdale and South San Joaquin Irrigation Districts")
Figure_Annual(New_Mel_Outannual2, New_Mel_Outannual2$RelativeDiff, Delta~"River Outflow (%)", "outflow_Percent", "Figure 9. Relative change in annual river outflow compared to historical (1951-2013)")
Figure_Annual_abs(New_Mel_Outannual2, New_Mel_Outannual2$AbsoluteDiff, Delta~"River Outflow (acre-feet/year)", Delta~"River Outflow (mcm/year)", "outflow_abs", "Figure 8. Absolute change in annual river outflow compared to historical (1951-2013)")
Figure_Monthly(New_Mel_OutWY2, New_Mel_OutWY2$Outflow, "River Outflow (acre-feet/month)", "River Outflow (mcm/month)", "outflow", "Figure 7. Monthly Stanislaus river outflow")
```
```{r}
NM_hist_PH <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/historical/Livneh/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "Livneh (Historical)",
Scenario = "RCP 4.5",
`New Melones PH` = as.numeric(`New Melones PH`),
node = as.Date(node))
NM_hist_PH
NM_Can_PH <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CanESM2_rcp45/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CanESM2",
Scenario = "RCP 4.5")
NM_Mir_PH <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/MIROC5_rcp45/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "MIROC5",
Scenario = "RCP 4.5")
NM_Mir_PH
NM_CNR_PH <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CNRM-CM5_rcp45/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CNRM-CM5",
Scenario = "RCP 4.5")
NM_CNR_PH
NM_Had_PH <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-ES_rcp45/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "HadGEM2-ES",
Scenario = "RCP 4.5")
NM_Had_PH
```
```{r}
#RCP 8.5
NM_hist_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/historical/Livneh/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "Livneh (Historical)",
Scenario = "RCP 8.5",
`New Melones PH` = as.numeric(`New Melones PH`),
node = as.Date(node),
WaterYear = water_year(node, origin = "usgs"))
NM_hist_PH2
NM_Can_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CanESM2_rcp85/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CanESM2",
Scenario = "RCP 8.5")
NM_Can_PH2
NM_Mir_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/MIROC5_rcp85/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "MIROC5",
Scenario = "RCP 8.5")
NM_Mir_PH2
NM_CNR_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CNRM-CM5_rcp85/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CNRM-CM5",
Scenario = "RCP 8.5")
NM_CNR_PH2
NM_Had_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-ES_rcp85/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "HadGEM2-ES",
Scenario = "RCP 8.5")
NM_Had_PH2
NM_CCSM4_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CCSM4_rcp85/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CCSM4",
Scenario = "RCP 8.5")
NM_CCSM4_PH2
NM_GFDL_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/GFDL-CM3_rcp85/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "GFDL-CM3",
Scenario = "RCP 8.5")
NM_GFDL_PH2
NM_HadGEMCC_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/HadGEM2-CC_rcp85/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "HadGEM2-CC",
Scenario = "RCP 8.5")
NM_HadGEMCC_PH2
NM_CMCC_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CMCC-CMS_rcp85/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CMCC-CMS",
Scenario = "RCP 8.5")
NM_CMCC_PH2
NM_ACCESS1_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/ACCESS1-0_rcp85/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "ACCESS1-0",
Scenario = "RCP 8.5")
NM_ACCESS1_PH2
NM_CESM1_PH2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/stanislaus/gcms/CESM1-BGC_rcp85/Hydropower_Flow_mcm.csv")[-c(1:3), c(1,18)] %>%
mutate(Model = "CESM1-BGC",
Scenario = "RCP 8.5")
NM_CESM1_PH2
```
```{r}
library(lfstat)
New_Mel_PH1 <- rbind(NM_Can_PH, NM_Can_PH2, NM_Mir_PH,
NM_Mir_PH2, NM_Had_PH, NM_Had_PH2, NM_CNR_PH, NM_CNR_PH2,
NM_HadGEMCC_PH2, NM_CMCC_PH2, NM_ACCESS1_PH2, NM_CESM1_PH2, NM_GFDL_PH2, NM_CCSM4_PH2) %>%
mutate(PH = as.numeric(`New Melones PH`),#+as.numeric(`Phoenix Canal PH`),
#Irrigation = as.numeric(`New Melones PH`),
node = as.Date(node),
WaterYear = water_year(node, origin = "usgs")) %>%
filter(WaterYear %in% (2040:2059))
New_Mel_PH1
NM_hist_PH3 <- NM_hist_PH2 %>%
mutate(PH = as.numeric(`New Melones PH`),#+as.numeric(`Phoenix Canal PH`),
#Irrigation = as.numeric(`New Melones PH`),
node = as.Date(node))
NM_hist_PH2
New_Mel_PH <- rbind(NM_hist_PH3, New_Mel_PH1)
New_Mel_PH2 <- New_Mel_PH %>%
group_by(WaterYear, Model, Scenario) %>%
summarize(PH = sum(PH)) %>%
ungroup() %>%
group_by(Scenario, Model) %>%
summarize(PH = mean(PH))
New_Mel_PH2
New_Mel_PHWY <- New_Mel_PH %>%
mutate(Month = as.factor(format(as.Date(node, format = "%B"), "%b"))) %>%
group_by(WaterYear, Month, Model, Scenario) %>%
summarize(PH = sum(PH))
New_Mel_PHWY
New_Mel_PH_Ensem <- New_Mel_PH1 %>%
mutate(Month = as.factor(format(as.Date(node, format = "%B"), "%b"))) %>%
group_by(WaterYear, Month, Scenario, Model) %>%
summarize(PH = sum(PH)) %>%
ungroup() %>%
group_by(WaterYear, Month, Scenario) %>%
summarize(PH = mean(PH)) %>%
mutate(Model = "Ensemble")
New_Mel_PH_Ensem
New_Mel_PHWY <- rbind(New_Mel_PH_Ensem, New_Mel_PHWY)%>%
filter(!Scenario == "RCP 4.5")
New_Mel_PHWY
New_Mel_PHWY$Model <- factor(New_Mel_PHWY$Model, levels = c("Livneh (Historical)","MIROC5", "ACCESS1-0", "GFDL‐CM3","CMCC-CMS", "HadGEM2-ES", "CCSM4", "CESM1-BGC", "HadGEM2‐CC","CanESM2", "CNRM-CM5", "Ensemble"))
New_Mel_PHannual <- New_Mel_PHWY %>%
group_by(Model, WaterYear) %>%
summarize(PH = sum(PH))
New_Mel_PHannual
New_Mel_PHannual_Livneh <- New_Mel_PHannual %>%
filter(Model == "Livneh (Historical)") %>%
summarize(PH = mean(PH))
New_Mel_PHannual_Livneh
New_Mel_PHannual2 <- New_Mel_PHannual %>%
filter(!Model == "Livneh (Historical)") %>%
mutate(AbsoluteDiff = (PH-as.numeric(paste(New_Mel_PHannual_Livneh[2]))),
RelativeDiff = (PH-as.numeric(paste(New_Mel_PHannual_Livneh[2])))/as.numeric(paste(New_Mel_PHannual_Livneh[2]))*100)
New_Mel_PHannual2
```
```{r}
Figure_Annual_abs <- function(data, yaxis, yaxis2, ylabel, figurename, heading){
data %>%
ggplot(.) +
theme_bw(base_size=12, base_family='Times New Roman') + #change font to Times New Roman, 12pt, Bold
geom_hline(yintercept=0)+
geom_violin(aes( x = Model, y = yaxis, fill = Model),draw_quantiles = c(0.25, 0.5, 0.75)) + #plot monthly observed data in greenish blue
scale_y_continuous(#limits = c(0, NA),
#expand = c(0, NA),
labels=scales::comma,
sec.axis = sec_axis( trans=~./1233.48185, name= yaxis2)
) +
# scale_x_discrete(limits=c("Oct","Nov","Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"))+
scale_fill_manual(values = c("#A50026", "#d1190f", "#db4821", "chocolate1", "gold1", "cadetblue2", "deepskyblue2", "dodgerblue2", "#4575B4", "#313695", "white")) +
labs(fill = "RCP 8.5",
title = heading,
# subtitle = title,
x = element_blank(),
y = ylabel)+ #Delta~"Hydropower Flow (mcm/year)") + #name of x axis
theme(legend.position = "bottom",
legend.direction = "horizontal",
legend.box.margin = margin(t = -14.5),
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
plot.title = element_text(hjust = 0.5, size = 11),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
legend.key.size = unit(0.75,"line"),
strip.background = element_blank(),
panel.spacing.y = unit(0, "lines")) +
guides(fill=guide_legend(nrow=2)) +
ggsave(paste("Changes_Stanislaus_annual_",figurename,".png", sep=""), units ="in", width=7.5, height=4, dpi = 300) }
```
```{r}
Figure_Annual <- function(data, yaxis, ylabel, figurename, heading){
data %>%
ggplot(.) +
theme_bw(base_size=12, base_family='Times New Roman') + #change font to Times New Roman, 12pt, Bold
geom_hline(yintercept=0)+
geom_violin(aes( x = Model, y = yaxis, fill = Model),draw_quantiles = c(0.25, 0.5, 0.75)) + #plot monthly observed data in greenish blue
scale_y_continuous(#limits = c(0, NA),
#expand = c(0, NA),
labels=scales::comma) +
# scale_x_discrete(limits=c("Oct","Nov","Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"))+
scale_fill_manual(values = c("#A50026", "#d1190f", "#db4821", "chocolate1", "gold1", "cadetblue2", "deepskyblue2", "dodgerblue2", "#4575B4", "#313695", "white")) +
labs(fill = "RCP 8.5",
title = heading,
# subtitle = "New Melones Reservoir",
x = element_blank(),
y = ylabel)+ #Delta~"Hydropower Flow (mcm/year)") + #name of x axis
theme(legend.position = "bottom",
legend.direction = "horizontal",
legend.box.margin = margin(t = -14.5),
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
plot.title = element_text(hjust = 0.5, size = 11),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
legend.key.size = unit(0.75,"line"),
strip.background = element_blank(),
panel.spacing.y = unit(0, "lines")) +
guides(fill=guide_legend(nrow=2)) +
ggsave(paste("Changes_Stanislaus_annual_",figurename,".png", sep=""), units ="in", width=7.5, height=4, dpi = 300) }
```
```{r}
Figure_Monthly <- function(data, yaxis, yaxis2, ylabel, figurename, heading){
data %>%
ggplot(.) +
theme_bw(base_size=12, base_family='Times New Roman') + #change font to Times New Roman, 12pt, Bold
geom_boxplot(aes( x = Month, y = yaxis, fill = Model), outlier.alpha = 0.3) + #plot monthly observed data in greenish blue
#geom_line(aes(x = node, y = value)) +
scale_y_log10(#limits = c(0, NA),
# expand = c(0, NA),
labels=scales::comma,
sec.axis = sec_axis( trans=~./1233.48185, name= yaxis2)
) +
scale_x_discrete(limits=c("Oct","Nov","Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep"))+
scale_fill_manual(values = c("#5A5A5A", "#A50026", "#D73027", "#F46D43", "chocolate1", "gold1", "cadetblue2", "deepskyblue2", "dodgerblue2", "#4575B4", "#313695", "white")) +
labs(fill = "RCP 8.5",
title = heading,
# subtitle = "Merced River",
x = element_blank(),
y = ylabel)+# "Hydropower Flow (mcm/month)") + #name of x axis
theme(legend.position = "bottom",
legend.direction = "horizontal",
legend.box.margin = margin(t = -17),
plot.title = element_text(hjust = 0.5, size = 11),
strip.placement = "outside",
strip.background = element_blank(),
panel.spacing.y = unit(0, "lines")) +
guides(fill=guide_legend(nrow=2))+
#scale_y_log10()+
ggsave(paste("Changes_Stanislaus_monthly_",figurename,".png",sep=""), units ="in", width=8.5, height=5, dpi = 300)}
```
```{r}
Allocation <- readxl::read_xlsx("C:/Users/gusta/Desktop/PhD/CERCWET/New Melones Analysis - AGU (version 1).xlsx", sheet = "Water2") %>%
mutate(Model = as.factor(Model),
Scenario = as.factor(Scenario),
Allocation = as.factor(Allocation))
Allocation
```
```{r}
#library(relayer)
Allocation$Model <-factor(Allocation$Model, levels=c("ACCESS1-0", "CMCC-CMS", "MIROC5", "GFDL-CM3", "CCSM4", "HadGEM2-ES", "HadGEM2-CC", "CanESM2", "CESM1-BGC", "CNRM-CM5")) #unique(interaction(Allocation$Scenario, Allocation$Model))
#Allocation$Scenarios <-factor(interaction(Allocation$Scenario, Allocation$Model), levels=c("Title 1","RCP 4.5.CanESM2","RCP 4.5.HadGEM2-ES","RCP 4.5.CNRM-CM5", "RCP 4.5.MIROC5", " ", "Title 2", "RCP 8.5.CanESM2","RCP 8.5.HadGEM2-ES","RCP 8.5.CNRM-CM5", "RCP 8.5.MIROC5")) #unique(interaction(Allocation$Scenario, Allocation$Model))
dat_text <- data.frame(x = c(1.1, 2, 2.8, 4, 5, 6, 6.9, 8),
y = c(6, 6, 6, 6, 6, 6, 6, 6),
label = c("MIROC5", "","HadGEM2-ES","", "CanESM2","", "CNRM-CM5", ""),
Allocation = c("Stanislaus River Outflow", "Stanislaus River Outflow", "Stanislaus River Outflow", "Stanislaus River Outflow", "Stanislaus River Outflow", "Stanislaus River Outflow", "Stanislaus River Outflow", "Stanislaus River Outflow")
)
Allocation %>%
filter(!Model == "Livneh (Historical)") %>%
ggplot(., aes(x= Model, y=`Difference %`)) +
geom_bar(stat = "identity", aes(fill=Model), colour="black", legend = FALSE) +
scale_fill_manual(#values = c("red","yellow2","cyan3", "dodgerblue2", "red3", "gold2", "cyan4", "dodgerblue4"))+
labels = c(" ", " ", " ", " ", " ", " "," "," "," "),
values = c("#A50026", "#D73027", "#F46D43", "chocolate1", "gold1", "cadetblue2", "deepskyblue2", "dodgerblue2", "#4575B4", "#313695"))+#"red","red4","yellow2","gold2", "cyan3", "cyan4", "dodgerblue2", "dodgerblue4"))+
theme_bw(base_size=13, base_family='Times New Roman') +
geom_hline(yintercept = 0) + labs(y="Relative change (%)")+
# geom_text(x=1.5, y=-30, label="MIROC5") +
theme(plot.title = element_text(hjust = 0.5),
axis.title.x=element_blank(),
axis.text.x=element_text(),
axis.ticks.x=element_blank(),
legend.position = "none",#"bottom",
# legend.key.size = unit(0.9, 'lines'),
# axis.text.x = element_text(angle = 45, hjust = 1),
strip.placement = "outside",
strip.background = element_blank(),
panel.spacing.y = unit(1, "lines"))+
# legend.title=element_text(size=11))+
# guides(fill=guide_legend(nrow=2))+#"RCP 4.5\nRCP 8.5")) +
facet_wrap(~Allocation,
ncol = 1,
# labeller = as_labeller(c(`Hydropower Flow` = expression(Delta)~"Hydropower Flow", `Irrigation Districts` = expression(Delta)~"Irrigation Districts", `Stanislaus River Outflow` = expression(Delta)~"Stanislaus River Outflow")),
strip.position = "top")+
# coord_cartesian(clip = "off")+
# geom_text(
# data = dat_text,
# mapping = aes(x = x, y = y, label = label, family = "Times New Roman"), size = 3.8,
# hjust = -0.1,
#vjust = +4.5)
ggsave("Changes_Stanislaus2.png", units ="in", width=10, height=5.8, dpi = 300)
```
```{r}
Allocation2 <- readxl::read_xlsx("C:/Users/gusta/Desktop/PhD/CERCWET/New Melones Analysis - AGU (version 1).xlsx", sheet = "Others") %>%
mutate(Model = as.factor(Model),
Scenario = as.factor(Scenario),
Allocation = as.factor(Allocation))
Allocation2
```
```{r}
Allocation2 %>%
# filter(!Allocation == "Hydropower Flow") %>%
ggplot(., aes(fill=Allocation, y = Proportion, x=forcats::fct_rev(factor(interaction(Scenario,Model))))) + #fct_rev reverts the order
#theme_bw(base_size=12, base_family='Times New Roman') +
geom_bar(stat="identity", position = position_fill(reverse = TRUE))+
# geom_bar(color = "black", position = "stack", stat = "count") +
#geom_bar(color = "black", position = "dodge", stat = "count") +
#geom_bar(aes(y = (..count..)/sum(..count..)))+
scale_y_continuous(labels=scales::percent, #reverts the colors
expand = c(0,NA)) +
scale_fill_manual(values = c("cyan3", "dodgerblue2", "blue"))+
#"Critical", "Dry", "Below Normal", "Above Normal", "Wet")) +
labs(title = "Water Allocation in the Stanislaus",
x = element_blank(),
y = element_blank()) + #name of x axis
#scale_x_discrete(limits=c("Critical", "Dry", "Below Normal", "Above Normal", "Wet"),
# labels =c("Critical", "Dry", "Below Normal", "Above Normal", "Wet"))+
#"C", "D", "BN", "AN", "W")) +
# scale_y_continuous(expand = c(0, 0), limits = c(0,25)) +
theme_bw(base_size=12, base_family='Times New Roman') + #change font to Times New Roman, 12pt, Bold
#facet_wrap(~ Scenario, ncol=2, labeller = labeller(Scenario = c(`RCP4.5` = "RCP 4.5 Scenario", `RCP8.5` = "RCP 8.5 Scenario"))) +
theme(plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(hjust = +0.5),
strip.placement = "outside",
legend.key.size = unit(0.75,"line"),
legend.position = "bottom",
strip.background = element_blank(),
plot.margin=unit(c(1,1,1.5,1.2),"cm"),
panel.margin = unit(1.5, "lines"),
legend.title = "element_blank"(),
legend.box.margin = margin(t = -17))+
coord_flip(clip = 'off')
```
```{r}
#library(relayer)
Allocation2$Model <-factor(Allocation$Model, levels=c("ACCESS1-0", "CMCC-CMS", "MIROC5", "GFDL-CM3", "CCSM4", "HadGEM2-ES", "HadGEM2-CC", "CanESM2", "CESM1-BGC", "CNRM-CM5")) #unique(interaction(Allocation$Scenario, Allocation$Model))
Allocation2 %>%
ggplot(., aes(x= Model, y=`Difference %`)) +
geom_bar(stat = "identity", aes(fill=Model), colour="black", legend = FALSE) +
scale_fill_manual(#values = c("red","yellow2","cyan3", "dodgerblue2", "red3", "gold2", "cyan4", "dodgerblue4"))+
labels = c(" ", " ", " ", " ", " ", " "," "," "," "),
values = c("#A50026", "#D73027", "#F46D43", "chocolate1", "gold1", "cadetblue2", "deepskyblue2", "dodgerblue2", "#4575B4", "#313695"))+#"red","red4","yellow2","gold2", "cyan3", "cyan4", "dodgerblue2", "dodgerblue4"))+
theme_bw(base_size=13, base_family='Times New Roman') +
geom_hline(yintercept = 0) + labs(y="Relative change (%)")+
# geom_text(x=1.5, y=-30, label="MIROC5") +
theme(plot.title = element_text(hjust = 0.5),
axis.title.x=element_blank(),
axis.text.x=element_text(),
axis.ticks.x=element_blank(),
legend.position = "none",#"bottom",
# legend.key.size = unit(0.9, 'lines'),
# axis.text.x = element_text(angle = 45, hjust = 1),
strip.placement = "outside",
strip.background = element_blank(),
panel.spacing.y = unit(1, "lines"))+
# legend.title=element_text(size=11))+
# guides(fill=guide_legend(nrow=2))+#"RCP 4.5\nRCP 8.5")) +
facet_wrap(~Allocation,
ncol = 1,
# labeller = as_labeller(c(`Hydropower Flow` = expression(Delta)~"Hydropower Flow", `Irrigation Districts` = expression(Delta)~"Irrigation Districts", `Stanislaus River Outflow` = expression(Delta)~"Stanislaus River Outflow")),
strip.position = "top")+
# coord_cartesian(clip = "off")+
# geom_text(
# data = dat_text,
# mapping = aes(x = x, y = y, label = label, family = "Times New Roman"), size = 3.8,
# hjust = -0.1,
#vjust = +4.5)
ggsave("Changes_Stanislaus.png", units ="in", width=10, height=5.8, dpi = 300)
```
```{r}
FNF <- readxl::read_xlsx("C:/Users/gusta/Desktop/PhD/CERCWET/New Melones Analysis - AGU (version 1).xlsx", sheet = "FNF2") %>%
mutate(Model = as.factor(Model))
# Scenario = as.factor(Scenario))
# Allocation = as.factor(Allocation))
FNF
```
```{r}
#RCP 8.5
NM_hist_FNF2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/data/Stanislaus River/hydrology/historical/Livneh/preprocessed/full_natural_flow_monthly_mcm.csv") %>%
mutate(Model = "Livneh (Historical)",
Scenario = "RCP 8.5",
# node = as.Date(date),
#`New Melones PH` = as.numeric(`New Melones PH`),
WaterYear = water_year(date, origin = "usgs"))
NM_hist_FNF2
NM_Can_FNF2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/data/Stanislaus River/hydrology/gcms/CanESM2_rcp85/preprocessed/full_natural_flow_monthly_mcm.csv") %>%
mutate(Model = "CanESM2",
Scenario = "RCP 8.5")
NM_Can_FNF2
NM_Mir_FNF2 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/data/Stanislaus River/hydrology/gcms/MIROC5_rcp85/preprocessed/full_natural_flow_monthly_mcm.csv") %>%
mutate(Model = "MIROC5",
Scenario = "RCP 8.5")
NM_Mir_FNF2