-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew_Spill_Count.Rmd
478 lines (373 loc) · 25.1 KB
/
New_Spill_Count.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
```{r}
#Spill redflags
Livneh_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/historical/Livneh/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]%>%
filter(between(as.Date(node), as.Date("1980-10-01"), as.Date("2010-09-30")))# %>%
# rename(node = node)
#CanESM2_RedFlag_Mer$CanESM2 <- rowSums(CanESM2_RedFlag_Mer[c(2,3)])
Livneh_Spill_Mer$GCM <- as.factor("Livneh (Historical)")
Livneh_Spill_Mer
CanESM2_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/gcms/CanESM2_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CanESM2_RedFlag_Mer$CanESM2 <- rowSums(CanESM2_RedFlag_Mer[c(2,3)])
CanESM2_Spill_Mer$GCM <- as.factor("CanESM2\u2020")
CanESM2_Spill_Mer
CNRM_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/gcms/CNRM-CM5_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CNRM_RedFlag_Mer$`CNRM-CM5` <- rowSums(CNRM_RedFlag_Mer[c(2,3)])
CNRM_Spill_Mer$GCM <- as.factor("CNRM-CM5\u2020")
CNRM_Spill_Mer
HadGEM2_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/gcms/HadGEM2-ES_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_Mer$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_Mer[c(2,3)])
HadGEM2_Spill_Mer$GCM <- as.factor("HadGEM2-ES\u2020")
HadGEM2_Spill_Mer
MIROC5_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/gcms/MIROC5_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_Mer$MIROC5 <- rowSums(MIROC5_RedFlag_Mer[c(2,3)])
MIROC5_Spill_Mer$GCM <- as.factor("MIROC5\u2020")
MIROC5_Spill_Mer
CCSM4_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/gcms/CCSM4_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CanESM2_RedFlag_Mer$CanESM2 <- rowSums(CanESM2_RedFlag_Mer[c(2,3)])
CCSM4_Spill_Mer$GCM <- as.factor("CCSM4")
CCSM4_Spill_Mer
CCMCC_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/gcms/CMCC-CMS_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CNRM_RedFlag_Mer$`CNRM-CM5` <- rowSums(CNRM_RedFlag_Mer[c(2,3)])
CCMCC_Spill_Mer$GCM <- as.factor("CMCC-CMS")
CCMCC_Spill_Mer
HadGEM_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/gcms/HadGEM2-CC_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_Mer$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_Mer[c(2,3)])
HadGEM_Spill_Mer$GCM <- as.factor("HadGEM2-CC")
HadGEM_Spill_Mer
GFDL_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/gcms/GFDL-CM3_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_Mer$MIROC5 <- rowSums(MIROC5_RedFlag_Mer[c(2,3)])
GFDL_Spill_Mer$GCM <- as.factor("GFDL-CM3")
GFDL_Spill_Mer
CESM1_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/gcms/CESM1-BGC_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_Mer$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_Mer[c(2,3)])
CESM1_Spill_Mer$GCM <- as.factor("CESM1-BGC")
CESM1_Spill_Mer
ACCESS_Spill_Mer <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/merced/gcms/ACCESS1-0_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_Mer$MIROC5 <- rowSums(MIROC5_RedFlag_Mer[c(2,3)])
ACCESS_Spill_Mer$GCM <- as.factor("ACCESS1-0")
ACCESS_Spill_Mer
```
```{r}
Spill_Mer1 <- rbind(CanESM2_Spill_Mer, CNRM_Spill_Mer,
HadGEM2_Spill_Mer, MIROC5_Spill_Mer, CCMCC_Spill_Mer,
ACCESS_Spill_Mer, CCSM4_Spill_Mer, CESM1_Spill_Mer,
GFDL_Spill_Mer, HadGEM_Spill_Mer)#%>%
# filter(between(as.Date(node, as.Date("2030-10-01"), as.Date("2060-09-30")))
Spill_Mer1 <- rbind(Livneh_Spill_Mer, Spill_Mer1) %>%
mutate(WaterYear = as.factor(water_year(node, origin= "usgs")),
Scenario = "RCP 8.5",
Basin = "Merced River")
Spill_Mer1
Spill_Mer <- melt(Spill_Mer1, id = c("node", "WaterYear", "GCM", "Scenario", "Basin")) #%>%
# mutate(value = round(value, digits = 1))
Spill_Mer
```
```{r}
#Spill redflags
Livneh_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/historical/Livneh/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]%>%
filter(between(as.Date(node), as.Date("1980-10-01"), as.Date("2010-09-30"))) %>%
rename(node = node)
#CanESM2_RedFlag_Tuo$CanESM2 <- rowSums(CanESM2_RedFlag_Tuo[c(2,3)])
Livneh_Spill_Tuo$GCM <- as.factor("Livneh (Historical)")
Livneh_Spill_Tuo
CanESM2_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/gcms/CanESM2_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CanESM2_RedFlag_Tuo$CanESM2 <- rowSums(CanESM2_RedFlag_Tuo[c(2,3)])
CanESM2_Spill_Tuo$GCM <- as.factor("CanESM2\u2020")
CanESM2_Spill_Tuo
CNRM_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/gcms/CNRM-CM5_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CNRM_RedFlag_Tuo$`CNRM-CM5` <- rowSums(CNRM_RedFlag_Tuo[c(2,3)])
CNRM_Spill_Tuo$GCM <- as.factor("CNRM-CM5\u2020")
CNRM_Spill_Tuo
HadGEM2_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/gcms/HadGEM2-ES_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_Tuo$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_Tuo[c(2,3)])
HadGEM2_Spill_Tuo$GCM <- as.factor("HadGEM2-ES\u2020")
HadGEM2_Spill_Tuo
MIROC5_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/gcms/MIROC5_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_Tuo$MIROC5 <- rowSums(MIROC5_RedFlag_Tuo[c(2,3)])
MIROC5_Spill_Tuo$GCM <- as.factor("MIROC5\u2020")
MIROC5_Spill_Tuo
CCSM4_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/gcms/CCSM4_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CanESM2_RedFlag_Tuo$CanESM2 <- rowSums(CanESM2_RedFlag_Tuo[c(2,3)])
CCSM4_Spill_Tuo$GCM <- as.factor("CCSM4")
CCSM4_Spill_Tuo
CCMCC_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/gcms/CMCC-CMS_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CNRM_RedFlag_Tuo$`CNRM-CM5` <- rowSums(CNRM_RedFlag_Tuo[c(2,3)])
CCMCC_Spill_Tuo$GCM <- as.factor("CMCC-CMS")
CCMCC_Spill_Tuo
HadGEM_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/gcms/HadGEM2-CC_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_Tuo$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_Tuo[c(2,3)])
HadGEM_Spill_Tuo$GCM <- as.factor("HadGEM2-CC")
HadGEM_Spill_Tuo
GFDL_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/gcms/GFDL-CM3_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_Tuo$MIROC5 <- rowSums(MIROC5_RedFlag_Tuo[c(2,3)])
GFDL_Spill_Tuo$GCM <- as.factor("GFDL-CM3")
GFDL_Spill_Tuo
CESM1_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/gcms/CESM1-BGC_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_Tuo$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_Tuo[c(2,3)])
CESM1_Spill_Tuo$GCM <- as.factor("CESM1-BGC")
CESM1_Spill_Tuo
ACCESS_Spill_Tuo <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-16/tuolumne/gcms/ACCESS1-0_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_Tuo$MIROC5 <- rowSums(MIROC5_RedFlag_Tuo[c(2,3)])
ACCESS_Spill_Tuo$GCM <- as.factor("ACCESS1-0")
ACCESS_Spill_Tuo
```
```{r}
Spill_Tuo1 <- rbind(CanESM2_Spill_Tuo, CNRM_Spill_Tuo,
HadGEM2_Spill_Tuo, MIROC5_Spill_Tuo, CCMCC_Spill_Tuo,
ACCESS_Spill_Tuo, CCSM4_Spill_Tuo, CESM1_Spill_Tuo,
GFDL_Spill_Tuo, HadGEM_Spill_Tuo)#%>%
# filter(between(as.Date(node, as.Date("2030-10-01"), as.Date("2060-09-30")))
Spill_Tuo1 <- rbind(Livneh_Spill_Tuo, Spill_Tuo1) %>%
mutate(WaterYear = as.factor(water_year(node, origin= "usgs")),
Scenario = "RCP 8.5",
Basin = "Tuolumne River")
Spill_Tuo1
Spill_Tuo <- melt(Spill_Tuo1, id = c("node", "WaterYear", "GCM", "Scenario", "Basin")) #%>%
# mutate(value = round(value, digits = 1))
Spill_Tuo
```
```{r}
#Spill redflags
Livneh_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/historical/Livneh/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]%>%
filter(between(as.Date(node), as.Date("1980-10-01"), as.Date("2010-09-30"))) %>%
rename(node = node)
#CanESM2_RedFlag_Stn$CanESM2 <- rowSums(CanESM2_RedFlag_Stn[c(2,3)])
Livneh_Spill_Stn$GCM <- as.factor("Livneh (Historical)")
Livneh_Spill_Stn
CanESM2_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/gcms/CanESM2_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CanESM2_RedFlag_Stn$CanESM2 <- rowSums(CanESM2_RedFlag_Stn[c(2,3)])
CanESM2_Spill_Stn$GCM <- as.factor("CanESM2\u2020")
CanESM2_Spill_Stn
CNRM_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/gcms/CNRM-CM5_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CNRM_RedFlag_Stn$`CNRM-CM5` <- rowSums(CNRM_RedFlag_Stn[c(2,3)])
CNRM_Spill_Stn$GCM <- as.factor("CNRM-CM5\u2020")
CNRM_Spill_Stn
HadGEM2_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/gcms/HadGEM2-ES_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_Stn$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_Stn[c(2,3)])
HadGEM2_Spill_Stn$GCM <- as.factor("HadGEM2-ES\u2020")
HadGEM2_Spill_Stn
MIROC5_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/gcms/MIROC5_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_Stn$MIROC5 <- rowSums(MIROC5_RedFlag_Stn[c(2,3)])
MIROC5_Spill_Stn$GCM <- as.factor("MIROC5\u2020")
MIROC5_Spill_Stn
CCSM4_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/gcms/CCSM4_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CanESM2_RedFlag_Stn$CanESM2 <- rowSums(CanESM2_RedFlag_Stn[c(2,3)])
CCSM4_Spill_Stn$GCM <- as.factor("CCSM4")
CCSM4_Spill_Stn
CCMCC_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/gcms/CMCC-CMS_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CNRM_RedFlag_Stn$`CNRM-CM5` <- rowSums(CNRM_RedFlag_Stn[c(2,3)])
CCMCC_Spill_Stn$GCM <- as.factor("CMCC-CMS")
CCMCC_Spill_Stn
HadGEM_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/gcms/HadGEM2-CC_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_Stn$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_Stn[c(2,3)])
HadGEM_Spill_Stn$GCM <- as.factor("HadGEM2-CC")
HadGEM_Spill_Stn
GFDL_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/gcms/GFDL-CM3_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_Stn$MIROC5 <- rowSums(MIROC5_RedFlag_Stn[c(2,3)])
GFDL_Spill_Stn$GCM <- as.factor("GFDL-CM3")
GFDL_Spill_Stn
CESM1_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/gcms/CESM1-BGC_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_Stn$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_Stn[c(2,3)])
CESM1_Spill_Stn$GCM <- as.factor("CESM1-BGC")
CESM1_Spill_Stn
ACCESS_Spill_Stn <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/stanislaus/gcms/ACCESS1-0_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_Stn$MIROC5 <- rowSums(MIROC5_RedFlag_Stn[c(2,3)])
ACCESS_Spill_Stn$GCM <- as.factor("ACCESS1-0")
ACCESS_Spill_Stn
```
```{r}
Spill_Stn1 <- rbind(CanESM2_Spill_Stn, CNRM_Spill_Stn,
HadGEM2_Spill_Stn, MIROC5_Spill_Stn, CCMCC_Spill_Stn,
ACCESS_Spill_Stn, CCSM4_Spill_Stn, CESM1_Spill_Stn,
GFDL_Spill_Stn, HadGEM_Spill_Stn)#%>%
# filter(between(as.Date(node, as.Date("2030-10-01"), as.Date("2060-09-30")))
Spill_Stn1 <- rbind(Livneh_Spill_Stn, Spill_Stn1) %>%
mutate(WaterYear = as.factor(water_year(node, origin= "usgs")),
Scenario = "RCP 8.5",
Basin = "Stanislaus River")
Spill_Stn1
Spill_Stn <- melt(Spill_Stn1, id = c("node", "WaterYear", "GCM", "Scenario", "Basin")) #%>%
# mutate(value = round(value, digits = 1))
Spill_Stn
```
```{r}
#Spill redflags
Livneh_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/historical/Livneh/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]%>%
filter(between(as.Date(node), as.Date("1980-10-01"), as.Date("2010-09-30"))) %>%
rename(node = node)
#CanESM2_RedFlag_USJ$CanESM2 <- rowSums(CanESM2_RedFlag_USJ[c(2,3)])
Livneh_Spill_USJ$GCM <- as.factor("Livneh (Historical)")
Livneh_Spill_USJ
CanESM2_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/gcms/CanESM2_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CanESM2_RedFlag_USJ$CanESM2 <- rowSums(CanESM2_RedFlag_USJ[c(2,3)])
CanESM2_Spill_USJ$GCM <- as.factor("CanESM2\u2020")
CanESM2_Spill_USJ
CNRM_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/gcms/CNRM-CM5_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CNRM_RedFlag_USJ$`CNRM-CM5` <- rowSums(CNRM_RedFlag_USJ[c(2,3)])
CNRM_Spill_USJ$GCM <- as.factor("CNRM-CM5\u2020")
CNRM_Spill_USJ
HadGEM2_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/gcms/HadGEM2-ES_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_USJ$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_USJ[c(2,3)])
HadGEM2_Spill_USJ$GCM <- as.factor("HadGEM2-ES\u2020")
HadGEM2_Spill_USJ
MIROC5_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/gcms/MIROC5_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_USJ$MIROC5 <- rowSums(MIROC5_RedFlag_USJ[c(2,3)])
MIROC5_Spill_USJ$GCM <- as.factor("MIROC5\u2020")
MIROC5_Spill_USJ
CCSM4_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/gcms/CCSM4_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CanESM2_RedFlag_USJ$CanESM2 <- rowSums(CanESM2_RedFlag_USJ[c(2,3)])
CCSM4_Spill_USJ$GCM <- as.factor("CCSM4")
CCSM4_Spill_USJ
CCMCC_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/gcms/CMCC-CMS_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#CNRM_RedFlag_USJ$`CNRM-CM5` <- rowSums(CNRM_RedFlag_USJ[c(2,3)])
CCMCC_Spill_USJ$GCM <- as.factor("CMCC-CMS")
CCMCC_Spill_USJ
HadGEM_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/gcms/HadGEM2-CC_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_USJ$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_USJ[c(2,3)])
HadGEM_Spill_USJ$GCM <- as.factor("HadGEM2-CC")
HadGEM_Spill_USJ
GFDL_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/gcms/GFDL-CM3_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_USJ$MIROC5 <- rowSums(MIROC5_RedFlag_USJ[c(2,3)])
GFDL_Spill_USJ$GCM <- as.factor("GFDL-CM3")
GFDL_Spill_USJ
CESM1_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/gcms/CESM1-BGC_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#HadGEM2_RedFlag_USJ$`HadGEM2-ES` <- rowSums(HadGEM2_RedFlag_USJ[c(2,3)])
CESM1_Spill_USJ$GCM <- as.factor("CESM1-BGC")
CESM1_Spill_USJ
ACCESS_Spill_USJ <- read_csv("C:/Users/gusta/Box/VICE Lab/RESEARCH/PROJECTS/CERC-WET/Task7_San_Joaquin_Model/pywr_models/results/Binary IFRs x Prices - 2021-03-29/upper_san_joaquin/gcms/ACCESS1-0_rcp85/UncontrolledSpill_Flow_mcm.csv")[-c(1:3), c(1,2)]
#MIROC5_RedFlag_USJ$MIROC5 <- rowSums(MIROC5_RedFlag_USJ[c(2,3)])
ACCESS_Spill_USJ$GCM <- as.factor("ACCESS1-0")
ACCESS_Spill_USJ
```
```{r}
Spill_USJ1 <- rbind(CanESM2_Spill_USJ, CNRM_Spill_USJ,
HadGEM2_Spill_USJ, MIROC5_Spill_USJ, CCMCC_Spill_USJ,
ACCESS_Spill_USJ, CCSM4_Spill_USJ, CESM1_Spill_USJ,
GFDL_Spill_USJ, HadGEM_Spill_USJ)#%>%
# filter(between(as.Date(node, as.Date("2030-10-01"), as.Date("2060-09-30")))
Spill_USJ1 <- rbind(Livneh_Spill_USJ, Spill_USJ1) %>%
mutate(WaterYear = as.factor(water_year(node, origin= "usgs")),
Scenario = "RCP 8.5",
Basin = "Upper San Joaquin River")
Spill_USJ1
Spill_USJ <- melt(Spill_USJ1, id = c("node", "WaterYear", "GCM", "Scenario", "Basin")) #%>%
# mutate(value = round(value, digits = 1))
Spill_USJ
```
```{r}
total_spill <- rbind(Spill_USJ, Spill_Stn, Spill_Mer, Spill_Tuo) %>%
mutate(value = as.numeric(value),
Count = ifelse(value > 0, 1,0))
total_spill
```
```{r}
spill_data <- total_spill %>%
group_by(Basin, GCM, WaterYear) %>%
summarize(Count = sum(Count))
write.csv(spill_data, "spill_per_climate.csv", row.names = FALSE)
```
```{r}
ggplot(total_spill) +
theme_bw(base_size=12, base_family='Times New Roman') +
geom_bar(aes(x= WaterYear, y=Count), stat = "identity") +
ggthemes::scale_color_colorblind() +
scale_y_continuous(expand = c(0, NA),
limits = c(0,NA), breaks = c(0, 40, 80, 120, 160)) +
scale_x_discrete(breaks = c("1980", "1986", "1991", "1996", "2001", "2006",
"2031", "2036", "2041", "2046", "2051", "2056"),
expand = c(0, NA))+
facet_wrap(GCM~Basin, scales = "free_x", ncol = 4) +
labs(#title = "Storage Below One Third of Reservoir Operating Capacity",
subtitle = "RCP 8.5 Scenario",
# subtitle = "CanESM2",
x = element_blank(),
y = "Spill occurrence (Days)") +
theme(#strip.text.x = element_blank(),
#legend.title = element_blank(),
#legend.position = "bottom",
# legend.direction = "horizontal",
# 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")) +
png("AllBasins_Spill_FacetWrap_RCP85_2009prices_.png", units ="in", width=8, height=8, res = 300)
```
```{r}
ggplot(total_spill) +
theme_bw(base_size=12, base_family='Times New Roman') +
geom_bar(aes(x= WaterYear, y=Count), stat = "identity") +
ggthemes::scale_color_colorblind() +
scale_y_continuous(expand = c(0, NA),
limits = c(0,NA), breaks = c(0, 40, 80, 120, 160)) +
scale_x_discrete(breaks = c("1981", "1991", "2001",
"2031", "2041","2051"),
expand = c(0, NA))+
facet_grid(GCM~Basin, scales = "free_x") +
labs(#title = "Storage Below One Third of Reservoir Operating Capacity",
subtitle = "RCP 8.5 Scenario",
# subtitle = "CanESM2",
x = element_blank(),
y = "Spill occurrence (Days)") +
theme(#strip.text.x = element_blank(),
#legend.title = element_blank(),
#legend.position = "bottom",
# legend.direction = "horizontal",
# 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")) +
png("AllBasins_Spill_FacetGrid.png", units ="in", width=10, height=10, res = 300)
```
```{r}
#Spill for each basin
Spill <- function (Data, Basins, Title, Subtitle) {
Data%>%
filter(Basin == Basins) %>%
# filter(GCM == "Livneh (Historical)" | GCM == "ACCESS1-0" | GCM == "CNRM-CM5") %>%
ggplot() +
theme_bw(base_size=12, base_family='Times New Roman') +
geom_bar(aes(x= WaterYear, y=Count), stat = "identity") +
ggthemes::scale_color_colorblind() +
scale_y_continuous(expand = c(0, NA),
limits = c(0,130), breaks = c(0, 20, 40, 60,
80, 100, 120, 140, 160)) +
scale_x_discrete(breaks = c("1981", "1986", "1991", "1996", "2001", "2006",
"2031", "2036", "2041", "2046", "2051", "2056"),
expand = c(0, NA))+
facet_wrap(~GCM, scales = "free_x", ncol = 1, strip.position = "left") +
labs(title = Title,
subtitle = Subtitle,
# subtitle = "CanESM2",
x = element_blank(),
y = "Spill Occurrence (Days)") +
theme(#legend.title = element_blank(),
#legend.position = "bottom",
# legend.direction = "horizontal",
# 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")) +
}
```
```{r}
Spill(total_spill, "Merced River", "Merced River", "ff - 2009 prices (RCP 8.5 Scenario)") +
png("Mer_Spill_ff_2009prices_RCP85_10GCMs_Report_2.png", units ="in", width=5, height=16, res = 300)
```
```{r}
Spill(total_spill, "Upper San Joaquin River", "Upper San Joaquin River", "ff - 2009 prices (RCP 8.5 Scenario)") +
png("USJ_Spill_ff_2009prices_RCP85_10GCMs_Report.png", units ="in", width=5, height=16, res = 300)
```
```{r}
Spill(total_spill, "Tuolumne River", "Tuolumne River", "ff - 2009 prices (RCP 8.5 Scenario)") +
png("Tuo_Spill_ff_2009prices_RCP85_10GCMs_Report.png", units ="in", width=5, height=16, res = 300)
```
```{r}
Spill(total_spill, "Stanislaus River", "Stanislaus River", "ff - 2009 prices (RCP 8.5 Scenario)") +
png("Stn_Spill_ff_2009prices_RCP85_10GCMs_Report.png", units ="in",width=5, height=16, res = 300)
```