-
Notifications
You must be signed in to change notification settings - Fork 0
/
climate_change_implications.R
298 lines (210 loc) · 13.2 KB
/
climate_change_implications.R
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
library(readr)
library(tidyverse)
library(reshape2)
setwd("C:/Users/falchetta/OneDrive - IIASA/Current papers/Groundwater_economic_feasibility/Groundwater-Cost/Groundwater-Cost")
rcp_ssp <- c("baseline", "245", "585")
water_sustainability_contraint <- c(F, T)
field_size_contraint <- c(T, F)
VAT_import_costs <- c(T,F)
instalments_business_model <- c(4,3,2,1) # 1. all upfront (system) costs 2. only pump + irr system unfront costs 3. only PV upfront costs 4. no upfront costs
no_battery <- c(T,F)
water_tank_storage <- c(T,F)
discount_rate = c(0.15, 0.075, 0.25, 0.4)
prices_sens <- c("median", "min", "max")
pvbatterycosts_sens <- c("baseline", "minus10pct", "minus25pct")
scenarios <- expand.grid(rcp_ssp, water_sustainability_contraint, field_size_contraint, VAT_import_costs, instalments_business_model, water_tank_storage, discount_rate, no_battery, stringsAsFactors = F)
colnames(scenarios) <- c("rcp_ssp", "water_sustainability_contraint", "field_size_contraint", "VAT_import_costs", "instalments_business_model", "water_tank_storage", "discount_rate", "no_battery")
####
baseline_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[1,], collapse="_"), ".Rds"))
s_245_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[2,], collapse="_"), ".Rds"))
s_585_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[3,], collapse="_"), ".Rds"))
baseline_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[4,], collapse="_"), ".Rds"))
s_245_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[5,], collapse="_"), ".Rds"))
s_585_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[6,], collapse="_"), ".Rds"))
# baseline_T <- subset(baseline_T, !is.na(baseline_T$profit_yearly))
# s_245_T <- subset(s_245_T, !is.na(s_245_T$profit_yearly))
# s_585_T <- subset(s_585_T, !is.na(s_585_T$profit_yearly))
#
# baseline_F <- subset(baseline_F, !is.na(baseline_F$profit_yearly))
# s_245_F <- subset(s_245_F, !is.na(s_245_F$profit_yearly))
# s_585_F <- subset(s_585_F, !is.na(s_585_F$profit_yearly))
#
summary(s_245_T$yearly_IRREQ) / summary(baseline_T$yearly_IRREQ) - 1
summary(s_585_T$yearly_IRREQ) / summary(baseline_T$yearly_IRREQ) - 1
i_n <- c(sum(baseline_T$yearly_IRREQ), sum(s_245_T$yearly_IRREQ), sum(s_585_T$yearly_IRREQ))
rcp_ssp <- c("Baseline", "SSP 245", "SSP 585")
t1 <- data.frame(rcp_ssp, i_n, stringsAsFactors = F)
t1$rcp_ssp <- factor(t1$rcp_ssp, levels = c("Baseline", "SSP 245", "SSP 585"))
uno <- ggplot(t1, aes(x=rcp_ssp, y=i_n/1e9, fill=rcp_ssp))+
theme_classic()+
geom_col()+
xlab("")+
ylab("Cubic km/yr.")+
ggsci::scale_fill_npg(name="Scenario")+
ggtitle("Rainfed crop evapotrans. needs in 2050")
#ggsave("//tsclient/D/OneDrive - IIASA/Conferences 2022/Scenarios Forum/LEAPRE submission/fig1.png", uno, scale = 1.5)
###
baseline_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[1,], collapse="_"), ".Rds"))
s_245_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[2,], collapse="_"), ".Rds"))
s_585_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[3,], collapse="_"), ".Rds"))
baseline_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[4,], collapse="_"), ".Rds"))
s_245_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[5,], collapse="_"), ".Rds"))
s_585_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[6,], collapse="_"), ".Rds"))
# baseline_T <- subset(baseline_T, !is.na(baseline_T$profit_yearly))
# s_245_T <- subset(s_245_T, !is.na(s_245_T$profit_yearly))
# s_585_T <- subset(s_585_T, !is.na(s_585_T$profit_yearly))
#
# baseline_F <- subset(baseline_F, !is.na(baseline_F$profit_yearly))
# s_245_F <- subset(s_245_F, !is.na(s_245_F$profit_yearly))
# s_585_F <- subset(s_585_F, !is.na(s_585_F$profit_yearly))
kwh_n <- c(sum(baseline_T$er_kwh_tt*baseline_T$npumps, na.rm=T), sum(s_245_T$er_kwh_tt*s_245_T$npumps, na.rm=T), sum(s_585_T$er_kwh_tt*s_585_T$npumps, na.rm=T), sum(baseline_F$er_kwh_tt*baseline_F$npumps, na.rm=T), sum(s_245_F$er_kwh_tt*s_245_F$npumps, na.rm=T), sum(s_585_F$er_kwh_tt*s_585_F$npumps, na.rm=T))
rcp_ssp <- c("Baseline", "SSP 245", "SSP 585", "Baseline", "SSP 245", "SSP 585")
scen <- c("Unbounded", "Unbounded", "Unbounded", "Env flows", "Env flows", "Env flows")
t1 <- data.frame(kwh_n, rcp_ssp, scen, stringsAsFactors = F)
t1$rcp_ssp <- factor(t1$rcp_ssp, levels = c("Baseline", "SSP 245", "SSP 585"))
due <- ggplot(t1, aes(x=rcp_ssp, y=kwh_n/1e9, fill=rcp_ssp))+
theme_classic()+
geom_col()+
facet_wrap(vars(scen))+
xlab("")+
ylab("TWh/year")+
ggsci::scale_fill_npg(name="Scenario")+
ggtitle("Solar pumping electricity demand in 2050")
#ggsave("//tsclient/D/OneDrive - IIASA/Conferences 2022/Scenarios Forum/LEAPRE submission/fig2.png", due, scale = 1.5)
#
###
baseline_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[1,], collapse="_"), ".Rds"))
s_245_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[2,], collapse="_"), ".Rds"))
s_585_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[3,], collapse="_"), ".Rds"))
baseline_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[4,], collapse="_"), ".Rds"))
s_245_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[5,], collapse="_"), ".Rds"))
s_585_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[6,], collapse="_"), ".Rds"))
baseline_T$which_pumping <- ifelse(is.na(baseline_T$profit_yearly), "Neither", baseline_T$which_pumping)
s_245_T$which_pumping <- ifelse(is.na(s_245_T$profit_yearly), "Neither", s_245_T$which_pumping)
s_585_T$which_pumping <- ifelse(is.na(s_585_T$profit_yearly), "Neither", s_585_T$which_pumping)
baseline_F$which_pumping <- ifelse(is.na(baseline_F$profit_yearly), "Neither", baseline_F$which_pumping)
s_245_F$which_pumping <- ifelse(is.na(s_245_F$profit_yearly), "Neither", s_245_F$which_pumping)
s_585_F$which_pumping <- ifelse(is.na(s_585_F$profit_yearly), "Neither", s_585_F$which_pumping)
s1 <- as.vector(table(baseline_T$which_pumping))
s2 <- as.vector(table(s_245_T$which_pumping))
s3 <- as.vector(table(s_585_T$which_pumping))
s4 <- as.vector(table(baseline_F$which_pumping))
s5 <- as.vector(table(s_245_F$which_pumping))
s6 <- as.vector(table(s_585_F$which_pumping))
shares <- as.data.frame(rbind(s1, s2, s3, s4, s5, s6))
rcp_ssp <- c("Baseline", "SSP 245", "SSP 585", "Baseline", "SSP 245", "SSP 585")
scen <- c("Unbounded", "Unbounded", "Unbounded", "Env flows", "Env flows", "Env flows")
shares$rcp_ssp <- rcp_ssp
shares$scen <- scen
rownames(shares) <- NULL
colnames(shares)[1:3] <- names(table(baseline_T$which_pumping))
shares$sum_cat <- rowSums(shares[,1:3])
shares <- reshape2::melt(shares, 4:6)
shares$rcp_ssp <- factor(shares$rcp_ssp, levels = c("Baseline", "SSP 245", "SSP 585"))
shares$variable <- factor(shares$variable, levels = rev(c("Neither", "Ground water pumping", "Surface water pumping")))
tre <- ggplot(shares, aes(x=rcp_ssp, y=value/sum_cat, fill=variable))+
theme_classic()+
geom_bar(stat = 'identity', position = 'stack') + facet_grid(~ scen)+
xlab("Climate change scenario")+
ylab("% of pumping water source")+
scale_fill_manual(name="Source", values=ggsci::pal_npg("nrc", alpha = .8)(9)[c(7, 9, 6)])+
ggtitle("Water source for solar pumps in 2050")+
scale_y_continuous(labels=scales::label_percent())
#ggsave("//tsclient/D/OneDrive - IIASA/Conferences 2022/Scenarios Forum/LEAPRE submission/fig3.png", tre, scale = 1.5)
###
baseline_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[1,], collapse="_"), ".Rds"))
s_245_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[2,], collapse="_"), ".Rds"))
s_585_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[3,], collapse="_"), ".Rds"))
baseline_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[4,], collapse="_"), ".Rds"))
s_245_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[5,], collapse="_"), ".Rds"))
s_585_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[6,], collapse="_"), ".Rds"))
baseline_F_wg <- dplyr::select(baseline_F, contains("monthly_unmet_IRRIG_share_") & !contains("surf") & !contains("avg"))
s_245_F_wg <- dplyr::select(s_245_F, contains("monthly_unmet_IRRIG_share_") & !contains("surf") & !contains("avg"))
s_585_F_wg <- dplyr::select(s_585_F, contains("monthly_unmet_IRRIG_share_") & !contains("surf") & !contains("avg"))
baseline_F_wg$geometry <- NULL
s_245_F_wg$geometry <- NULL
s_585_F_wg$geometry <- NULL
#
baseline_F_wd <- dplyr::select(baseline_F, contains("monthly_IRREQ") & !contains("surf") & !contains("avg"))
s_245_F_wd <- dplyr::select(s_245_F, contains("monthly_IRREQ") & !contains("surf") & !contains("avg"))
s_585_F_wd <- dplyr::select(s_585_F, contains("monthly_IRREQ") & !contains("surf") & !contains("avg"))
baseline_F_wd$geometry <- NULL
s_245_F_wd$geometry <- NULL
s_585_F_wd$geometry <- NULL
##
baseline_F_wg <- baseline_F_wg * baseline_F_wd
s_245_F_wg <- s_245_F_wg * s_245_F_wd
s_585_F_wg <- s_585_F_wg * s_585_F_wd
baseline_F_wg <- summarise_all(baseline_F_wg,.funs = "sum")
s_245_F_wg <- summarise_all(s_245_F_wg,.funs = "sum")
s_585_F_wg <- summarise_all(s_585_F_wg,.funs = "sum")
#
baseline_F_wg <- melt(baseline_F_wg)
baseline_F_wg$variable <- month.abb
baseline_F_wg$scen <- "Baseline"
s_245_F_wg <- melt(s_245_F_wg)
s_245_F_wg$variable <- month.abb
s_245_F_wg$scen <- "SSP 245"
s_585_F_wg <- melt(s_585_F_wg)
s_585_F_wg$variable <- month.abb
s_585_F_wg$scen <- "SSP 585"
all <- bind_rows(baseline_F_wg, s_245_F_wg, s_585_F_wg)
all$scen <- factor(all$scen, levels = c("Baseline", "SSP 245", "SSP 585"))
all$variable <- factor(all$variable, levels = month.abb)
all %>% group_by(scen) %>% dplyr::summarise(value=sum(value)/1e9)
all %>% filter(variable=="Aug") %>% group_by(scen) %>% dplyr::summarise(value=sum(value)/1e9)
quattro <- ggplot(all, aes(x=variable, y=value/1e9, colour=scen, group=scen))+
geom_line(show.legend=F)+
theme_classic()+
xlab("Month of the year")+
ylab("Km^3 groundwater requir.")+
ggsci::scale_colour_npg(name="Climate change scenario")+
ggtitle("Unmet groundwater demand in 2050")
#ggsave("//tsclient/D/OneDrive - IIASA/Conferences 2022/Scenarios Forum/LEAPRE submission/fig4.png", quattro, scale = 1.5)
######################
baseline_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[1,], collapse="_"), ".Rds"))
s_245_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[2,], collapse="_"), ".Rds"))
s_585_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[3,], collapse="_"), ".Rds"))
baseline_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[4,], collapse="_"), ".Rds"))
s_245_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[5,], collapse="_"), ".Rds"))
s_585_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[6,], collapse="_"), ".Rds"))
i_n <- c(sum(baseline_T$calories_gain_total[baseline_T$profit_yearly>0], na.rm=T), sum(s_245_T$calories_gain_total[s_245_T$profit_yearly>0], na.rm=T), sum(s_585_T$calories_gain_total[s_585_T$profit_yearly>0], na.rm=T))
rcp_ssp <- c("Baseline", "SSP 245", "SSP 585")
t1 <- data.frame(rcp_ssp, i_n, stringsAsFactors = F)
t1$rcp_ssp <- factor(t1$rcp_ssp, levels = c("Baseline", "SSP 245", "SSP 585"))
cinque <- ggplot(t1, aes(x=rcp_ssp, y=i_n/1e12, fill=rcp_ssp))+
theme_classic()+
geom_col()+
xlab("")+
ylab("Trillion calories")+
ggsci::scale_fill_npg(name="Scenario")+
ggtitle("Food growth potential from (economically \nfeasible) solar pumps adoption")
#
baseline_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[1,], collapse="_"), ".Rds"))
s_245_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[2,], collapse="_"), ".Rds"))
s_585_T <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[3,], collapse="_"), ".Rds"))
baseline_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[4,], collapse="_"), ".Rds"))
s_245_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[5,], collapse="_"), ".Rds"))
s_585_F <- read_rds(paste0("clusters_with_data_7_", paste(scenarios[6,], collapse="_"), ".Rds"))
i_n <- c(sum(baseline_T$A_total[baseline_T$profit_yearly>0], na.rm=T), sum(s_245_T$A_total[s_245_T$profit_yearly>0], na.rm=T), sum(s_585_T$A_total[s_585_T$profit_yearly>0], na.rm=T))
rcp_ssp <- c("Baseline", "SSP 245", "SSP 585")
t1 <- data.frame(rcp_ssp, i_n, stringsAsFactors = F)
t1$rcp_ssp <- factor(t1$rcp_ssp, levels = c("Baseline", "SSP 245", "SSP 585"))
sei <- ggplot(t1, aes(x=rcp_ssp, y=i_n/1e6, fill=rcp_ssp))+
theme_classic()+
geom_col()+
xlab("")+
ylab("Million of hectares equivalent")+
ggsci::scale_fill_npg(name="Scenario")+
ggtitle("Harvested area economically \nsuitable for solar irrigation")
library(patchwork)
m <- uno + tre + due + quattro + cinque + sei + patchwork::plot_annotation(tag_levels = 'A') + plot_layout(guides="collect", nrow=3) &
theme(legend.position = 'bottom',
legend.direction = 'horizontal')
m[[1]]$data
m[[2]]$data
m[[3]]$data
m[[4]]$data
m[[5]]$data
m[[6]]$data
ggsave("new_figures/fig_scens.png", m, scale = 1.25, height = 7, width = 7)