-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCentroid_Timing_ Electricity.Rmd
846 lines (660 loc) · 42.9 KB
/
Centroid_Timing_ Electricity.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
---
title: "Centroid_Timing_Energy"
author: "Gustavo Facincani Dourado"
date: "6/25/2020"
output: html_document
---
```{r}
#Centroid Timing - RCP 8.5
CT <- function(x) {
read_csv(x, col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6,10)] %>%
filter(between(date, as.Date("2029-10-01"), as.Date("2060-09-30")))}
Livneh_Gen_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/merced/historical/Livneh/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10)] %>%
filter(between(node, as.Date("1950-10-01"), as.Date("2013-09-30")))
Livneh_Gen_Mer <- Livneh_Gen_Mer %>%
mutate(Total = rowSums(Livneh_Gen_Mer[c(2:4)]))
Livneh_Gen_Mer
CanES_Gen_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/merced/gcms/CanESM2_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10)]
CanES_Gen_Mer<- CanES_Gen_Mer %>%
mutate(Total = rowSums(CanES_Gen_Mer[c(2:4)]))
CanES_Gen_Mer
CNRM_Gen_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/merced/gcms/CNRM-CM5_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10)]
CNRM_Gen_Mer<- CNRM_Gen_Mer %>%
mutate(Total = rowSums(CNRM_Gen_Mer[c(2:4)]))
CNRM_Gen_Mer
HadGEM_Gen_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/merced/gcms/HadGEM2-ES_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10)]
HadGEM_Gen_Mer<- HadGEM_Gen_Mer %>%
mutate(Total = rowSums(HadGEM_Gen_Mer[c(2:4)]))
HadGEM_Gen_Mer
MIROC_Gen_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/merced/gcms/MIROC5_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10)]
MIROC_Gen_Mer<- MIROC_Gen_Mer %>%
mutate(Total = rowSums(MIROC_Gen_Mer[c(2:4)]))
MIROC_Gen_Mer
```
```{r}
Livneh_Gen_Mer4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/merced/historical/Livneh/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10)] %>%
filter(between(node, as.Date("1950-10-01"), as.Date("2013-09-30")))
Livneh_Gen_Mer4.5 <- Livneh_Gen_Mer4.5 %>%
mutate(Total = rowSums(Livneh_Gen_Mer4.5[c(2:4)]))
Livneh_Gen_Mer4.5
CanES_Gen_Mer4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/merced/gcms/CanESM2_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10)]
CanES_Gen_Mer4.5<- CanES_Gen_Mer4.5 %>%
mutate(Total = rowSums(CanES_Gen_Mer4.5[c(2:4)]))
CanES_Gen_Mer4.5
CNRM_Gen_Mer4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/merced/gcms/CNRM-CM5_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10)]
CNRM_Gen_Mer4.5<- CNRM_Gen_Mer4.5 %>%
mutate(Total = rowSums(CNRM_Gen_Mer4.5[c(2:4)]))
CNRM_Gen_Mer4.5
HadGEM_Gen_Mer4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/merced/gcms/HadGEM2-ES_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10)]
HadGEM_Gen_Mer4.5<- HadGEM_Gen_Mer4.5 %>%
mutate(Total = rowSums(HadGEM_Gen_Mer4.5[c(2:4)]))
HadGEM_Gen_Mer4.5
MIROC_Gen_Mer4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/merced/gcms/MIROC5_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10)]
MIROC_Gen_Mer4.5<- MIROC_Gen_Mer4.5 %>%
mutate(Total = rowSums(MIROC_Gen_Mer4.5[c(2:4)]))
MIROC_Gen_Mer4.5
```
```{r}
#Centroid timing of generation
#Function to calculate CT for generation
CT_Generation <- function(V, W, X, Y, Z) {
Liv <- calc_annual_flow_timing(V, dates = node, values =Total, water_year_start = 10, percent_total = 50) %>%
mutate(GCM = as.factor("Livneh (Historical)"))
Liv
Can <- calc_annual_flow_timing(W, dates = node, values = Total, water_year_start = 10, percent_total = 50) %>%
mutate(GCM = as.factor("CanESM2"))
Can
CNR <- calc_annual_flow_timing(X, dates = node, values =Total, water_year_start = 10, percent_total = 50) %>%
mutate(GCM = as.factor("CNRM-CM5"))
CNR
Had <- calc_annual_flow_timing(Y, dates = node, values = Total, water_year_start = 10, percent_total = 50) %>%
mutate(GCM = as.factor("HadGEM2-ES"))
Had
Mir <- calc_annual_flow_timing(Z, dates = node, values = Total, water_year_start = 10, percent_total = 50) %>%
mutate(GCM = as.factor("MIROC5"))
Mir
rbind(Liv, Can, CNR, Had, Mir)
}
```
CT_Gen_4.5 <- CT_Generation(Livneh_Gen_Mer4.5, CanES_Gen_Mer4.5, CNRM_Gen_Mer4.5, HadGEM_Gen_Mer4.5, MIROC_Gen_Mer4.5) %>%
mutate(Scenario = factor("RCP 4.5"))
CT_Gen_8.5 <- CT_Generation(Livneh_Gen_Mer, CanES_Gen_Mer, CNRM_Gen_Mer, HadGEM_Gen_Mer, MIROC_Gen_Mer) %>%
mutate(Scenario = factor("RCP 8.5"))
```{r}
#Centroid Timing - RCP 8.5
CT <- function(x) {
read_csv(x, col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6,10)] %>%
filter(between(date, as.Date("2029-10-01"), as.Date("2060-09-30")))}
Livneh_Gen_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/tuolumne/historical/Livneh/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14)] %>%
filter(between(node, as.Date("1950-10-01"), as.Date("2013-09-30")))
Livneh_Gen_Tuo <- Livneh_Gen_Tuo %>%
mutate(Total = rowSums(Livneh_Gen_Tuo[c(2:5)]))
Livneh_Gen_Tuo
CanES_Gen_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/tuolumne/gcms/CanESM2_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14)]
CanES_Gen_Tuo<- CanES_Gen_Tuo %>%
mutate(Total = rowSums(CanES_Gen_Tuo[c(2:5)]))
CanES_Gen_Tuo
CNRM_Gen_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/tuolumne/gcms/CNRM-CM5_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14)]
CNRM_Gen_Tuo<- CNRM_Gen_Tuo %>%
mutate(Total = rowSums(CNRM_Gen_Tuo[c(2:5)]))
CNRM_Gen_Tuo
HadGEM_Gen_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/tuolumne/gcms/HadGEM2-ES_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14)]
HadGEM_Gen_Tuo<- HadGEM_Gen_Tuo %>%
mutate(Total = rowSums(HadGEM_Gen_Tuo[c(2:5)]))
HadGEM_Gen_Tuo
MIROC_Gen_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/tuolumne/gcms/MIROC5_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14)]
MIROC_Gen_Tuo<- MIROC_Gen_Tuo %>%
mutate(Total = rowSums(MIROC_Gen_Tuo[c(2:5)]))
MIROC_Gen_Tuo
```
```{r}
Livneh_Gen_Tuo4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/tuolumne/historical/Livneh/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14)] %>%
filter(between(node, as.Date("1950-10-01"), as.Date("2013-09-30")))
Livneh_Gen_Tuo4.5 <- Livneh_Gen_Tuo4.5 %>%
mutate(Total = rowSums(Livneh_Gen_Tuo4.5[c(2:5)]))
Livneh_Gen_Tuo4.5
CanES_Gen_Tuo4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/tuolumne/gcms/CanESM2_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14)]
CanES_Gen_Tuo4.5<- CanES_Gen_Tuo4.5 %>%
mutate(Total = rowSums(CanES_Gen_Tuo4.5[c(2:5)]))
CanES_Gen_Tuo4.5
CNRM_Gen_Tuo4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/tuolumne/gcms/CNRM-CM5_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14)]
CNRM_Gen_Tuo4.5<- CNRM_Gen_Tuo4.5 %>%
mutate(Total = rowSums(CNRM_Gen_Tuo4.5[c(2:5)]))
CNRM_Gen_Tuo4.5
HadGEM_Gen_Tuo4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/tuolumne/gcms/HadGEM2-ES_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14)]
HadGEM_Gen_Tuo4.5<- HadGEM_Gen_Tuo4.5 %>%
mutate(Total = rowSums(HadGEM_Gen_Tuo4.5[c(2:5)]))
HadGEM_Gen_Tuo4.5
MIROC_Gen_Tuo4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/tuolumne/gcms/MIROC5_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14)]
MIROC_Gen_Tuo4.5<- MIROC_Gen_Tuo4.5 %>%
mutate(Total = rowSums(MIROC_Gen_Tuo4.5[c(2:5)]))
MIROC_Gen_Tuo4.5
```
CT_Gen_4.5 <- CT_Generation(Livneh_Gen_Tuo4.5, CanES_Gen_Tuo4.5, CNRM_Gen_Tuo4.5, HadGEM_Gen_Tuo4.5, MIROC_Gen_Tuo4.5) %>%
mutate(Scenario = factor("RCP 4.5"))
CT_Gen_8.5 <- CT_Generation(Livneh_Gen_Tuo, CanES_Gen_Tuo, CNRM_Gen_Tuo, HadGEM_Gen_Tuo, MIROC_Gen_Tuo) %>%
mutate(Scenario = factor("RCP 8.5"))
```{r}
#Centroid Timing - RCP 8.5
CT <- function(x) {
read_csv(x, col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6,10)] %>%
filter(between(date, as.Date("2029-10-01"), as.Date("2060-09-30")))}
Livneh_Gen_Stn <- 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", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42)] %>%
filter(between(node, as.Date("1950-10-01"), as.Date("2013-09-30")))
Livneh_Gen_Stn <- Livneh_Gen_Stn %>%
mutate(Total = rowSums(Livneh_Gen_Stn[c(2:12)]))
Livneh_Gen_Stn
CanES_Gen_Stn <- 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", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42)]
CanES_Gen_Stn<- CanES_Gen_Stn %>%
mutate(Total = rowSums(CanES_Gen_Stn[c(2:12)]))
CanES_Gen_Stn
CNRM_Gen_Stn <- 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", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42)]
CNRM_Gen_Stn<- CNRM_Gen_Stn %>%
mutate(Total = rowSums(CNRM_Gen_Stn[c(2:12)]))
CNRM_Gen_Stn
HadGEM_Gen_Stn <- 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", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42)]
HadGEM_Gen_Stn<- HadGEM_Gen_Stn %>%
mutate(Total = rowSums(HadGEM_Gen_Stn[c(2:12)]))
HadGEM_Gen_Stn
MIROC_Gen_Stn <- 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", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42)]
MIROC_Gen_Stn<- MIROC_Gen_Stn %>%
mutate(Total = rowSums(MIROC_Gen_Stn[c(2:12)]))
MIROC_Gen_Stn
```
```{r}
Livneh_Gen_Stn4.5 <- 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", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42)] %>%
filter(between(node, as.Date("1950-10-01"), as.Date("2013-09-30")))
Livneh_Gen_Stn4.5 <- Livneh_Gen_Stn4.5 %>%
mutate(Total = rowSums(Livneh_Gen_Stn4.5[c(2:12)]))
Livneh_Gen_Stn4.5
CanES_Gen_Stn4.5 <- 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", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42)]
CanES_Gen_Stn4.5<- CanES_Gen_Stn4.5 %>%
mutate(Total = rowSums(CanES_Gen_Stn4.5[c(2:12)]))
CanES_Gen_Stn4.5
CNRM_Gen_Stn4.5 <- 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", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42)]
CNRM_Gen_Stn4.5<- CNRM_Gen_Stn4.5 %>%
mutate(Total = rowSums(CNRM_Gen_Stn4.5[c(2:12)]))
CNRM_Gen_Stn4.5
HadGEM_Gen_Stn4.5 <- 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", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42)]
HadGEM_Gen_Stn4.5<- HadGEM_Gen_Stn4.5 %>%
mutate(Total = rowSums(HadGEM_Gen_Stn4.5[c(2:12)]))
HadGEM_Gen_Stn4.5
MIROC_Gen_Stn4.5 <- 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", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42)]
MIROC_Gen_Stn4.5<- MIROC_Gen_Stn4.5 %>%
mutate(Total = rowSums(MIROC_Gen_Stn4.5[c(2:12)]))
MIROC_Gen_Stn4.5
```
CT_Gen_4.5 <- CT_Generation(Livneh_Gen_Stn4.5, CanES_Gen_Stn4.5, CNRM_Gen_Stn4.5, HadGEM_Gen_Stn4.5, MIROC_Gen_Stn4.5) %>%
mutate(Scenario = factor("RCP 4.5"))
CT_Gen_8.5 <- CT_Generation(Livneh_Gen_Stn, CanES_Gen_Stn, CNRM_Gen_Stn, HadGEM_Gen_Stn, MIROC_Gen_Stn) %>%
mutate(Scenario = factor("RCP 8.5"))
```{r}
#Centroid Timing - RCP 8.5
CT <- function(x) {
read_csv(x, col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6,10)] %>%
filter(between(date, as.Date("2029-10-01"), as.Date("2060-09-30")))}
Livneh_Gen_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/upper_san_joaquin/historical/Livneh/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62)] %>%
filter(between(node, as.Date("1950-10-01"), as.Date("2013-09-30")))
Livneh_Gen_USJ <- Livneh_Gen_USJ %>%
mutate(Total = rowSums(Livneh_Gen_USJ[c(2:17)]))
Livneh_Gen_USJ
CanES_Gen_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/upper_san_joaquin/gcms/CanESM2_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62)]
CanES_Gen_USJ<- CanES_Gen_USJ %>%
mutate(Total = rowSums(CanES_Gen_USJ[c(2:17)]))
CanES_Gen_USJ
CNRM_Gen_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/upper_san_joaquin/gcms/CNRM-CM5_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62)]
CNRM_Gen_USJ<- CNRM_Gen_USJ %>%
mutate(Total = rowSums(CNRM_Gen_USJ[c(2:17)]))
CNRM_Gen_USJ
HadGEM_Gen_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/upper_san_joaquin/gcms/HadGEM2-ES_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62)]
HadGEM_Gen_USJ<- HadGEM_Gen_USJ %>%
mutate(Total = rowSums(HadGEM_Gen_USJ[c(2:17)]))
HadGEM_Gen_USJ
MIROC_Gen_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/upper_san_joaquin/gcms/MIROC5_rcp85/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62)]
MIROC_Gen_USJ<- MIROC_Gen_USJ %>%
mutate(Total = rowSums(MIROC_Gen_USJ[c(2:17)]))
MIROC_Gen_USJ
```
```{r}
Livneh_Gen_USJ4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/upper_san_joaquin/historical/Livneh/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62)] %>%
filter(between(node, as.Date("1950-10-01"), as.Date("2013-09-30")))
Livneh_Gen_USJ4.5 <- Livneh_Gen_USJ4.5 %>%
mutate(Total = rowSums(Livneh_Gen_USJ4.5[c(2:17)]))
Livneh_Gen_USJ4.5
CanES_Gen_USJ4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/upper_san_joaquin/gcms/CanESM2_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62)]
CanES_Gen_USJ4.5<- CanES_Gen_USJ4.5 %>%
mutate(Total = rowSums(CanES_Gen_USJ4.5[c(2:17)]))
CanES_Gen_USJ4.5
CNRM_Gen_USJ4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/upper_san_joaquin/gcms/CNRM-CM5_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62)]
CNRM_Gen_USJ4.5<- CNRM_Gen_USJ4.5 %>%
mutate(Total = rowSums(CNRM_Gen_USJ4.5[c(2:17)]))
CNRM_Gen_USJ4.5
HadGEM_Gen_USJ4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/upper_san_joaquin/gcms/HadGEM2-ES_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62)]
HadGEM_Gen_USJ4.5<- HadGEM_Gen_USJ4.5 %>%
mutate(Total = rowSums(HadGEM_Gen_USJ4.5[c(2:17)]))
HadGEM_Gen_USJ4.5
MIROC_Gen_USJ4.5 <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices/upper_san_joaquin/gcms/MIROC5_rcp45/Hydropower_Energy_MWh.csv", col_types = cols(node = col_date(), .default = col_double()))[-c(1:3), c(1,2,6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62)]
MIROC_Gen_USJ4.5<- MIROC_Gen_USJ4.5 %>%
mutate(Total = rowSums(MIROC_Gen_USJ4.5[c(2:17)]))
MIROC_Gen_USJ4.5
```
CT_Gen_4.5 <- CT_Generation(Livneh_Gen_USJ4.5, CanES_Gen_USJ4.5, CNRM_Gen_USJ4.5, HadGEM_Gen_USJ4.5, MIROC_Gen_USJ4.5) %>%
mutate(Scenario = factor("RCP 4.5"))
CT_Gen_8.5 <- CT_Generation(Livneh_Gen_USJ, CanES_Gen_USJ, CNRM_Gen_USJ, HadGEM_Gen_USJ, MIROC_Gen_USJ) %>%
mutate(Scenario = factor("RCP 8.5"))
```{r}
#bind RCPs separately and add basin name to divide basins by facets
#RCP 8.5
CT_Gen_8.5_Mer <- CT_Generation(Livneh_Gen_Mer, CanES_Gen_Mer, CNRM_Gen_Mer, HadGEM_Gen_Mer, MIROC_Gen_Mer) %>%
mutate(Basin = "Merced River")
CT_Gen_8.5_Tuo <- CT_Generation(Livneh_Gen_Tuo, CanES_Gen_Tuo, CNRM_Gen_Tuo, HadGEM_Gen_Tuo, MIROC_Gen_Tuo) %>%
mutate(Basin = "Tuolumne River")
CT_Gen_8.5_Stn <- CT_Generation(Livneh_Gen_Stn, CanES_Gen_Stn, CNRM_Gen_Stn, HadGEM_Gen_Stn, MIROC_Gen_Stn) %>%
mutate(Basin = "Stanislaus River")
CT_Gen_8.5_USJ <- CT_Generation(Livneh_Gen_USJ, CanES_Gen_USJ, CNRM_Gen_USJ, HadGEM_Gen_USJ, MIROC_Gen_Mer) %>%
mutate(Basin = "Upper San Joaquin River")
CT_Gen8.5 <- rbind(CT_Gen_8.5_Mer, CT_Gen_8.5_Stn, CT_Gen_8.5_Tuo, CT_Gen_8.5_USJ) %>%
mutate(Scenario = "RCP 8.5")
CT_Gen8.5$Basin <- factor(CT_Gen8.5$Basin, levels = c("Stanislaus River", "Tuolumne River", "Merced River", "Upper San Joaquin River"))
CT_Gen8.5
CT_Gen8.5$GCM <- factor(CT_Gen8.5$GCM, levels = c("Livneh (Historical)", "HadGEM2-ES", "CanESM2", "MIROC5", "CNRM-CM5"))
CT_Gen8.5
#RCP 4.5
CT_Gen_4.5_Mer4.5 <- CT_Generation(Livneh_Gen_Mer4.5, CanES_Gen_Mer4.5, CNRM_Gen_Mer4.5, HadGEM_Gen_Mer4.5, MIROC_Gen_Mer4.5) %>%
mutate(Basin = "Merced River")
CT_Gen_4.5_Tuo4.5 <- CT_Generation(Livneh_Gen_Tuo4.5, CanES_Gen_Tuo4.5, CNRM_Gen_Tuo4.5, HadGEM_Gen_Tuo4.5, MIROC_Gen_Tuo4.5) %>%
mutate(Basin = "Tuolumne River")
CT_Gen_4.5_Stn4.5 <- CT_Generation(Livneh_Gen_Stn4.5, CanES_Gen_Stn4.5, CNRM_Gen_Stn4.5, HadGEM_Gen_Stn4.5, MIROC_Gen_Stn4.5) %>%
mutate(Basin = "Stanislaus River")
CT_Gen_4.5_USJ4.5 <- CT_Generation(Livneh_Gen_USJ4.5, CanES_Gen_USJ4.5, CNRM_Gen_USJ4.5, HadGEM_Gen_USJ4.5, MIROC_Gen_Mer4.5) %>%
mutate(Basin = "Upper San Joaquin River")
CT_Gen4.5 <- rbind(CT_Gen_4.5_Mer4.5, CT_Gen_4.5_Stn4.5, CT_Gen_4.5_Tuo4.5, CT_Gen_4.5_USJ4.5) %>%
mutate(Scenario = "RCP 4.5")
CT_Gen4.5$GCM <- factor(CT_Gen4.5$GCM, levels = c("Livneh (Historical)", "HadGEM2-ES", "CanESM2", "MIROC5", "CNRM-CM5"))
CT_Gen4.5
```
```{r}
#bind them all into one object
CT_Gen <- rbind(CT_Gen4.5, CT_Gen8.5)
CT_Gen
CT_Gen$Scenario <- factor(CT_Gen$Scenario, levels = c("RCP 4.5", "RCP 8.5"))
CT_Gen$GCM <- factor(CT_Gen$GCM, levels = c("Livneh (Historical)", "HadGEM2-ES", "CanESM2", "MIROC5", "CNRM-CM5"))
```
#Scales Free RCP 8.5
ggplot(CT_Gen8.5, aes(x=DoY_50pct_TotalQ, y=..scaled.., group=GCM, color=GCM))+ # fill=GCM)) +
theme_bw(base_size=11, base_family='Times New Roman') + #change font to Times New Roman, 12pt
geom_density(adjust=1.5, alpha=.1, size = 1.1) +
geom_vline(data = plyr::ddply(CT_FNF4.5, c("GCM", "Basin"), summarise, GCM_mean=mean(DoY_50pct_TotalQ)), aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
#data=GCM.mean, aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
scale_color_manual(values = c("#5A5A5A", "#FF6103", "#FBB117", "#009E73", "#56B4E9")) +
# scale_fill_manual(values = c("#5A5A5A", "#E69F00", "#F0E442", "#009E73", "#56B4E9")) +
scale_y_continuous(expand = c(0, NA),
limits = c(0, 1.05),
breaks = c(0, 0.25, 0.50, 0.75, 1))+
scale_x_continuous(expand = c(0, NA),
# limits = c(93,280), #From Jan 1 to Jul 15
breaks = c(61, 92, 121, 151,
182, 212, 244, 273, 304),
labels = c("Dec 1","Jan 1","Feb 1", "Mar 1",
"Apr 1", "May 1", "Jun 1", "Jul 1", "Aug 1")) +
labs(color = "RCP 8.5",
linetype = FALSE,
title = "Electricity Generation (2009 prices)",
y = "Density",
x = "Centroid Time (Day)") +
theme(plot.margin = margin(c(1,8,1,1, "cm")), #add a margin to not cut the graph
# legend.title = element_blank(),
legend.position = "bottom",
legend.direction = "horizontal",
legend.box.margin = margin(t = -10),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
strip.background = element_blank(),
legend.text = element_text(size = 8),
legend.key.size = unit(0.75,"line"))+
facet_wrap(~Basin, ncol=1, scales = "free")+
png("AllBasins_Centroid_Timing_Electricity_Scalesfree.png", units ="in", width=5.5, height=6, res = 300)
#scales fixed RCP 8.5
ggplot(CT_Gen8.5, aes(x=DoY_50pct_TotalQ, y=..scaled.., group=GCM, color=GCM))+ # fill=GCM)) +
theme_bw(base_size=11, base_family='Times New Roman') + #change font to Times New Roman, 12pt
geom_density(adjust=1.5, alpha=.1, size = 1.1) +
geom_vline(data = plyr::ddply(CT_FNF4.5, c("GCM", "Basin"), summarise, GCM_mean=mean(DoY_50pct_TotalQ)), aes(xintercept=GCM_mean, color= GCM), linetype = "dashed", size=0.8) +
#data=GCM.mean, aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
scale_color_manual(values = c("#5A5A5A", "#FF6103", "#FBB117", "#009E73", "#56B4E9")) +
# scale_fill_manual(values = c("#5A5A5A", "#E69F00", "#F0E442", "#009E73", "#56B4E9")) +
scale_y_continuous(expand = c(0, NA),
limits = c(0, 1.05),
breaks = c(0, 0.25, 0.50, 0.75, 1))+
scale_x_continuous(expand = c(0, NA),
# limits = c(93,280), #From Jan 1 to Jul 15
breaks = c(61, 92, 121, 151,
182, 212, 244, 273, 304),
labels = c("Dec 1","Jan 1","Feb 1", "Mar 1",
"Apr 1", "May 1", "Jun 1", "Jul 1", "Aug 1")) +
labs(color = "RCP 8.5",
title = "Electricity Generation (2009 prices)",
y = "Density",
x = "Centroid Time (Day)") +
theme(plot.margin = margin(c(1,8,1,1, "cm")), #add a margin to not cut the graph
# legend.title = element_blank(),
legend.position = "bottom",
legend.direction = "horizontal",
legend.box.margin = margin(t = -10),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
strip.background = element_blank(),
legend.text = element_text(size = 8),
legend.key.size = unit(0.75,"line"))+
facet_wrap(~Basin, ncol=1, scales = "fixed")+
png("AllBasins_Centroid_Timing_Electricity_Scalesfixed.png", units ="in", width=5.5, height=6, res = 300)
#Scales free RCP 4.5
ggplot(CT_Gen4.5, aes(x=DoY_50pct_TotalQ, y=..scaled.., group=GCM, color=GCM))+ # fill=GCM)) +
theme_bw(base_size=11, base_family='Times New Roman') + #change font to Times New Roman, 12pt
geom_density(adjust=1.5, alpha=.1, size = 1.1) +
geom_vline(data = plyr::ddply(CT_FNF4.5, c("GCM", "Basin"), summarise, GCM_mean=mean(DoY_50pct_TotalQ)), aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
#data=GCM.mean, aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
scale_color_manual(values = c("#5A5A5A", "#FF6103", "#FBB117", "#009E73", "#56B4E9")) +
# scale_fill_manual(values = c("#5A5A5A", "#E69F00", "#F0E442", "#009E73", "#56B4E9")) +
scale_y_continuous(expand = c(0, NA),
limits = c(0, 1.05),
breaks = c(0, 0.25, 0.50, 0.75, 1))+
scale_x_continuous(expand = c(0, NA),
# limits = c(93,280), #From Jan 1 to Jul 15
breaks = c(61, 92, 121, 151,
182, 212, 244, 273, 304),
labels = c("Dec 1","Jan 1","Feb 1", "Mar 1",
"Apr 1", "May 1", "Jun 1", "Jul 1", "Aug 1")) +
labs(color = "RCP 4.5",
title = "Electricity Generation (2009 prices)",
y = "Density",
x = "Centroid Time (Day)") +
theme(plot.margin = margin(c(1,8,1,1, "cm")), #add a margin to not cut the graph
# legend.title = element_blank(),
legend.position = "bottom",
legend.direction = "horizontal",
legend.box.margin = margin(t = -10),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
strip.background = element_blank(),
legend.text = element_text(size = 8),
legend.key.size = unit(0.75,"line"))+
facet_wrap(~Basin, ncol=1, scales = "free")+
png("AllBasins_CT_Electricity_RCP45_Scalesfree2.png", units ="in", width=5.5, height=6, res = 300)
ggplot(CT_Gen4.5, aes(x=DoY_50pct_TotalQ, y=..scaled.., group=GCM, color=GCM))+ # fill=GCM)) +
theme_bw(base_size=11, base_family='Times New Roman') + #change font to Times New Roman, 12pt
geom_density(adjust=1.5, alpha=.1, size = 1.1) +
geom_vline(data = plyr::ddply(CT_FNF4.5, c("GCM", "Basin"), summarise, GCM_mean=mean(DoY_50pct_TotalQ)), aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
#data=GCM.mean, aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
scale_color_manual(values = c("#5A5A5A", "#FF6103", "#FBB117", "#009E73", "#56B4E9")) +
# scale_fill_manual(values = c("#5A5A5A", "#E69F00", "#F0E442", "#009E73", "#56B4E9")) +
scale_y_continuous(expand = c(0, NA),
limits = c(0, 1.05),
breaks = c(0, 0.25, 0.50, 0.75, 1))+
scale_x_continuous(expand = c(0, NA),
# limits = c(93,280), #From Jan 1 to Jul 15
breaks = c(61, 92, 121, 151,
182, 212, 244, 273, 304),
labels = c("Dec 1","Jan 1","Feb 1", "Mar 1",
"Apr 1", "May 1", "Jun 1", "Jul 1", "Aug 1")) +
labs(color = "RCP 4.5",
title = "Electricity Generation (2009 prices)",
y = "Density",
x = "Centroid Time (Day)") +
theme(plot.margin = margin(c(1,8,1,1, "cm")), #add a margin to not cut the graph
# legend.title = element_blank(),
legend.position = "bottom",
legend.direction = "horizontal",
legend.box.margin = margin(t = -10),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
strip.background = element_blank(),
legend.text = element_text(size = 8),
legend.key.size = unit(0.75,"line"))+
facet_wrap(~Basin, ncol=1, scales = "fixed")+
png("AllBasins_Centroid_Timing_Electricity_Scalesfixed2.png", units ="in", width=5.5, height=6, res = 300)
```{r}
#Density plot
Density_plot_Gen <- function(data, title, Legend) {
ggplot(data, aes(x=DoY_50pct_TotalQ, y=..scaled.., group=GCM, color=GCM))+ # fill=GCM)) +
theme_bw(base_size=11, base_family='Times New Roman') + #change font to Times New Roman, 12pt
geom_density(adjust=1.5, alpha=.1, size = 1.1) +
geom_vline(data = plyr::ddply(data, c("GCM", "Basin"), summarise, GCM_mean=mean(DoY_50pct_TotalQ)), aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
#data=GCM.mean, aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
scale_color_manual(values = c("#5A5A5A", "#FF6103", "#FBB117", "#009E73", "#56B4E9")) +
# scale_fill_manual(values = c("#5A5A5A", "#E69F00", "#F0E442", "#009E73", "#56B4E9")) +
scale_y_continuous(expand = c(0, NA),
limits = c(0, 1.05),
breaks = c(0, 0.25, 0.50, 0.75, 1))+
scale_x_continuous(expand = c(0, NA),
# limits = c(93,280), #From Jan 1 to Jul 15
breaks = c(61, 92, 121, 151,
182, 212, 244, 273, 304),
labels = c("Dec 1","Jan 1","Feb 1", "Mar 1",
"Apr 1", "May 1", "Jun 1", "Jul 1", "Aug 1")) +
labs(color = Legend,
linetype = FALSE,
title = "Electricity Generation (2009 prices)",
y = "Density",
x = "Centroid Timing (Day)") +
theme(plot.margin = margin(c(1,8,1,1, "cm")), #add a margin to not cut the graph
# legend.title = element_blank(),
legend.position = "bottom",
legend.direction = "horizontal",
legend.box.margin = margin(t = -10),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
strip.background = element_blank(),
legend.text = element_text(size = 8),
legend.key.size = unit(0.75,"line"))+
facet_wrap(~Basin, ncol=1, scales = "free")
#facet_wrap(~Scenario, ncol=1, scales = "free_y", strip.position = "left")
# panel.spacing.y = unit(0, "lines")+
#geom_text(note, #adding where to add text
# mapping = aes(x=x, y=y, label = label), size=3) + #, family= "Times New Roman")
}
```
```{r}
Density_plot_Gen(CT_Gen4.5, element_blank(), "RCP 4.5") +
png("AllBasins_CT_Timing_Electricity_RCP45_Scalesfree.png", units ="in", width=5.5, height=6, res = 300)
```
```{r}
Density_plot_Gen(CT_Gen8.5, element_blank(), "RCP 8.5") +
png("AllBasins_CT_Electricity_RCP85_Scalesfree2.png", units ="in", width=5.5, height=6, res = 300)
```
```{r}
#Density plot
Density_plot_Gen2 <- function(data, title, Legend) {
ggplot(data, aes(x=DoY_50pct_TotalQ, y=..scaled.., group=GCM, color=GCM))+ # fill=GCM)) +
theme_bw(base_size=11, base_family='Times New Roman') + #change font to Times New Roman, 12pt
geom_density(adjust=1.5, alpha=.1, size = 1.1) +
geom_vline(data = plyr::ddply(data, c("GCM", "Basin"), summarise, GCM_mean=mean(DoY_50pct_TotalQ)), aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
#data=GCM.mean, aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
scale_color_manual(values = c("#5A5A5A", "#FF6103", "#FBB117", "#009E73", "#56B4E9")) +
# scale_fill_manual(values = c("#5A5A5A", "#E69F00", "#F0E442", "#009E73", "#56B4E9")) +
scale_y_continuous(expand = c(0, NA),
limits = c(0, 1.05),
breaks = c(0, 0.25, 0.50, 0.75, 1))+
scale_x_continuous(expand = c(0, NA),
# limits = c(93,280), #From Jan 1 to Jul 15
breaks = c(61, 92, 121, 151,
182, 212, 244, 273, 304),
labels = c("Dec 1","Jan 1","Feb 1", "Mar 1",
"Apr 1", "May 1", "Jun 1", "Jul 1", "Aug 1")) +
labs(color = Legend,
linetype = FALSE,
title = "Electricity Generation (2009 prices)",
y = "Density",
x = "Centroid Timing (Day)") +
theme(plot.margin = margin(c(1,8,1,1, "cm")), #add a margin to not cut the graph
# legend.title = element_blank(),
legend.position = "bottom",
legend.direction = "horizontal",
legend.box.margin = margin(t = -10),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
strip.background = element_blank(),
legend.text = element_text(size = 8),
legend.key.size = unit(0.75,"line"))+
facet_wrap(~Basin, ncol=1, scales = "fixed")
#facet_wrap(~Scenario, ncol=1, scales = "free_y", strip.position = "left")
# panel.spacing.y = unit(0, "lines")+
#geom_text(note, #adding where to add text
# mapping = aes(x=x, y=y, label = label), size=3) + #, family= "Times New Roman")
}
```
```{r}
Density_plot_Gen2(CT_Gen4.5, element_blank(), "RCP 4.5") +
png("AllBasins_CT_Timing_Electricity_RCP45_Scalesfixed.png", units ="in", width=5.5, height=6, res = 300)
```
```{r}
Density_plot_Gen2(CT_Gen8.5, element_blank(), "RCP 8.5") +
png("AllBasins_CT_Electricity_RCP85_Scalesfixed.png", units ="in", width=6, height=6, res = 300)
```
```{r}
ggplot(CT_Gen4.5, aes(x=DoY_50pct_TotalQ, y=..scaled.., group=GCM, color=GCM))+ # fill=GCM)) +
theme_bw(base_size=12, base_family='Times New Roman') + #change font to Times New Roman, 12pt
geom_density(adjust=1.5, alpha=.1, size = 1.1) +
geom_vline(data = plyr::ddply(data, c("GCM", "Basin"), summarise, GCM_mean=mean(DoY_50pct_TotalQ)), aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
#data=GCM.mean, aes(xintercept=GCM_mean, color= GCM), linetype="dashed", size=1) +
scale_color_manual(values = c("#5A5A5A", "#FF6103", "#FBB117", "#009E73", "#56B4E9")) +
# scale_fill_manual(values = c("#5A5A5A", "#E69F00", "#F0E442", "#009E73", "#56B4E9")) +
scale_y_continuous(expand = c(0, NA),
limits = c(0, 1.05),
breaks = c(0, 0.25, 0.50, 0.75, 1))+
scale_x_continuous(expand = c(0, NA),
# limits = c(93,280), #From Jan 1 to Jul 15
breaks = c(61, 92, 121, 151,
182, 212, 244, 273, 304),
labels = c("Dec 1","Jan 1","Feb 1", "Mar 1",
"Apr 1", "May 1", "Jun 1", "Jul 1", "Aug 1")) +
labs(subtitle = "Electricity Generation (2009 prices)",
title = element_blank(),
y = "Density",
x = "Centroid Time (Day)") +
theme(plot.margin = margin(c(1,8,1,1, "cm")), #add a margin to not cut the graph
legend.title = element_blank(),
legend.position = "bottom",
legend.direction = "horizontal",
legend.box.margin = margin(t = -10),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
strip.background = element_blank(),
legend.text = element_text(size = 9),
legend.key.size = unit(0.75,"line"))+
facet_wrap(~Basin, ncol=1, scales = "fixed")
```
```{r}
#Black and white
CT_Generation <- function(data, title, subtitle) {
ggplot(data) +
theme_bw(base_size=11, base_family='Times New Roman') + #change font to Times New Roman, 12pt, Bold
geom_line(aes( x = Year, y = DoY_50pct_TotalQ, #color = GCM,
linetype = Scenario)) +
scale_y_continuous(expand = c(0, NA),
# limits = c(93,280), #From Jan 1 to Jul 15
breaks = c(31, 61, 93, 122, 152,
183, 213, 245, 274),
labels = c("Nov 1", "Dez 1", "Jan 1", "Feb 1",
"Mar 1", "Apr 1",
"May 1", "Jun 1", "Jul 1")) +
scale_x_continuous(breaks = c(1981, 1991, 2001, 2010, 2031, 2041, 2051, 2060),
expand = c(0, NA))+
stat_smooth(aes(x = Year, y = DoY_50pct_TotalQ, method = "loess",
linetype = Scenario), color = "#000000",se = FALSE) +
labs(title = title,
subtitle = subtitle,
x = element_blank(),
y = "Centroid Time (Days)") + #name of x axis
theme(plot.margin = margin(c(12,10,1,1, "cm")),
panel.spacing = unit(1.4, "lines"),
legend.position = "bottom",
legend.title = element_blank(),
legend.direction = "horizontal",
legend.box = "vertical",
legend.spacing.y = unit(-0.38, 'cm'),
legend.box.margin = margin(t = -17),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
strip.background = element_blank(),
panel.spacing.y = unit(0, "lines")) +
# guides(color=guide_legend("Climate Scenario"),
# linetype=guide_legend("Emission Scenario"))+
# guides(fill = guide_legend(nrow = 11)) +
facet_wrap(~GCM, ncol=5, scales= "free_x")
}
```
```{r}
CT_Generation(CT_MerGen, "Merced River", "Electricity Generation")+
png("Mer_CT_generation.png", units ="in", width=10, height=4, res = 300)
```
```{r}
CT_Generation(CT_TuoGen, "Tuolumne River", "Electricity Generation")+
png("Tuo_CT_generation.png", units ="in", width=10, height=4, res = 300)
```
```{r}
#Function for Black and White time series of CT
CentrTiming <- function(Data, Basins, Title) {
Data %>%
filter(Basin == Basins) %>%
ggplot() +
theme_bw(base_size=11, base_family='Times New Roman') + #change font to Times New Roman, 12pt, Bold
geom_line(aes( x = Year, y = DoY_50pct_TotalQ, #color = GCM,
linetype = Scenario)) +
scale_y_continuous(expand = c(0, NA),
# limits = c(93,280), #From Jan 1 to Jul 15
breaks = c(31, 61, 93, 122, 152,
183, 213, 245, 274),
labels = c("Nov 1", "Dez 1", "Jan 1", "Feb 1",
"Mar 1", "Apr 1",
"May 1", "Jun 1", "Jul 1")) +
scale_x_continuous(breaks = c(1981, 1991, 2001, 2010, 2031, 2041, 2051, 2060),
expand = c(0, NA))+
stat_smooth(aes(x = Year, y = DoY_50pct_TotalQ, method = "loess",
linetype = Scenario), color = "#000000",se = FALSE) +
labs(title = Title,
subtitle = "Electricity Generation (2009 prices)",
x = element_blank(),
y = "Centroid Time (Days)") + #name of x axis
theme(plot.margin = margin(c(12,10,1,1, "cm")),
panel.spacing = unit(1.4, "lines"),
legend.position = "bottom",
legend.title = element_blank(),
legend.direction = "horizontal",
legend.box = "vertical",
legend.spacing.y = unit(-0.38, 'cm'),
legend.box.margin = margin(t = -17),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
strip.placement = "outside",
strip.background = element_blank(),
panel.spacing.y = unit(0, "lines")) +
# guides(color=guide_legend("Climate Scenario"),
# linetype=guide_legend("Emission Scenario"))+
# guides(fill = guide_legend(nrow = 11)) +
facet_wrap(~GCM, ncol=5, scales= "free_x")
}
```
```{r}
CentrTiming(CT_Gen, "Tuolumne River", "Tuolumne River") +
png("Tuo_CT_generation.png", units ="in", width=10, height=4, res = 300)
```
```{r}
CentrTiming(CT_Gen, "Merced River", "Merced River") +
png("Mer_CT_generation.png", units ="in", width=10, height=4, res = 300)
```
```{r}
CentrTiming(CT_Gen, "Stanislaus River", "Stanislaus River") +
png("Stn_CT_generation.png", units ="in", width=10, height=4, res = 300)
```
```{r}
CentrTiming(CT_Gen, "Upper San Joaquin River", "Upper San Joaquin River") +
png("USJ_CT_generation.png", units ="in", width=10, height=4, res = 300)
```