-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFigures_Factsheet.Rmd
366 lines (296 loc) · 15.9 KB
/
Figures_Factsheet.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
---
title: "Figures for Factsheet Veilige en duurzame zonnepanelen impact voorspellen tijdens ontwerp"
author: "Joris T.K. Quik, Carlos Blanco, and Matthias Hof"
date: "15/08/2022"
output: html_document
editor_options:
chunk_output_type: console
---
#### Load required data, packages, and fuctions
```{r}
# input data
load("data/20220627RprobDynSB4_perov_tandem.RData")
# required packages
library(tidyr)
library(openxlsx)
library(ggplot2)
library(dplyr)
library(psych)
library(RColorBrewer)
# relevant functions
f_Soil.wetweight <- function(Conc.soil, # in kg/m3 soil or sediment
Fracw,
Fraca,
RHOsolid){
Conc.soil*1000/(Fracw*1000+(1-Fracw-Fraca)*RHOsolid) # in g/kg (wet) soil
}
f_Soil.dryweight <- function(Conc.soil, # in kg/m3 soil
Fracs,
RHOsolid){
Conc.soil*1000/(Fracs*RHOsolid) # in g/kg (dry) soil
}
f_wet2dryweight <- function(Conc.soil, # in g/kg (wet) soil/sediment
Fracs,
RHOsolid,
Fracw,
RHOw){
Conc.soil*(Fracw*RHOw/(Fracs*RHOsolid)+1) # in g/kg (dry) soil
}
cases <- expand.grid(Recycling=c("NR", "R"),substance=c("Ag","Cu", "Pb"),paneltype=c("Tandem"))
cases$casename <- paste(cases$substance,cases$Recycling,cases$paneltype,sep="_")
SB.scales <- c("LOC", "AM", "EU")
Substances <- as.character(unique(cases$substance))
```
#### Figure 3. "Emissie in de tijd naar het milieu van lood (Pb) afkomstig van C-Si/Lood-perovskiet tandem zonnepanelen op lokale schaal bij storten (EOL_R) of recycling (EOL_NR) als einde levensfase en emissie door uitloging tijdens gebruik."
```{r figure 3}
#initialize variables
emis.scens <- expand.grid("Scales"=SB.scales,"Substances"=Substances)
Emis_routes <- c("USE_s2", "USE_w0", "USE_w1", "EOL_a_NR", "EOL_a_R", "EOL_s2_NR","EOL_s2_R")
emis.stat.long3 <- data.frame()
## Makes a matrix with concentrations (year x MC run) from deSolve lists, for each compartment and scenario
for(s in 1:length(emis.scens[,1])){
Emis.loc_NR <- paste0("data/Emis PV data tandem perovskite/PV_emissions_Tandem_v0.1_",
emis.scens$Scales[s],"_NR_",
emis.scens$Substances[s],"_kg.xlsm")
Emis.loc_R <- paste0("data/Emis PV data tandem perovskite/PV_emissions_Tandem_v0.1_",
emis.scens$Scales[s],"_R_",
emis.scens$Substances[s],"_kg.xlsm")
emis.stat.long2 <- data.frame()
for(em in Emis_routes){
if(em=="USE_s2"){
Emis_data1 <- read.xlsx(Emis.loc_NR,
sheet = "PROB_Y_s (USE)",
colNames=TRUE)[,-1]
}else if(em=="USE_w0"){
Emis_data1 <- read.xlsx(Emis.loc_NR,
sheet = "PROB_Y_lw",
colNames=TRUE)[,-1]
}else if(em=="USE_w1"){
Emis_data1 <- read.xlsx(Emis.loc_NR,
sheet = "PROB_Y_fw",
colNames=TRUE)[,-1]
}else if(em=="EOL_a_NR"){
Emis_data1 <- read.xlsx(Emis.loc_NR,
sheet = "PROB_Y_a",
colNames=TRUE)[,-1]
}else if(em=="EOL_a_R"){
Emis_data1 <- read.xlsx(Emis.loc_R,
sheet = "PROB_Y_a",
colNames=TRUE)[,-1]
}else if(em=="EOL_s2_NR"){
Emis_data1 <- read.xlsx(Emis.loc_NR,
sheet = "PROB_Y_s (EOL)",
colNames=TRUE)[,-1]
}else if(em=="EOL_s2_R"){
Emis_data1 <- read.xlsx(Emis.loc_R,
sheet = "PROB_Y_s (EOL)",
colNames=TRUE)[,-1]
}else Emis_data1 <- NA
emm.mat.yr.df <- as.data.frame(Emis_data1)
# str(emm.mat.yr.df)
# str(Emis_data1)
## Reshapes dataframe and puts it in long form
data.long <- as.data.frame(emm.mat.yr.df) %>% gather(year, emmision, 1:100)
# str(data.long)
data.long$year <- as.integer(as.character(data.long$year))
#gets summary statistics for each year
sum.stat <- data.long %>%
group_by(year) %>%
summarize(geo.mean = geometric.mean(emmision), P25 = quantile(emmision, 0.25,na.rm = TRUE), P75 = quantile(emmision, 0.75,na.rm = TRUE))
sum.stat.long <- as.data.frame(sum.stat) %>% pivot_longer(c("P75","geo.mean", "P25"), names_to = "sum_stat", values_to = "emmision")
sum.stat.long$scale = (emis.scens$Scales[s])
sum.stat.long$substance = (emis.scens$Substance[s])
sum.stat.long$emission_rout = as.factor(em)
# str(sum.stat.long)
#stores values for this cycle (compartment x scenario)
emis.stat.long2 <- rbind(emis.stat.long2, sum.stat.long)
}
# str(emis.stat.long2)
emis.stat.long3 <- rbind(emis.stat.long3, emis.stat.long2)
}
emis.stat.long3$scenario <- paste0(emis.stat.long3$scale,"_",emis.stat.long3$substance)
##Plot
str(emis.stat.long3)
unique(emis.stat.long3$scale)
LOC_As <- emis.stat.long3[emis.stat.long3$scale=="LOC",]
LOC_As$use_eol <- as.character(LOC_As$emission_rout)
LOC_As$use_eol <- sub("_s2", "",LOC_As$use_eol)
LOC_As$use_eol <- sub("_w0", "",LOC_As$use_eol)
LOC_As$use_eol <- sub("_w1", "",LOC_As$use_eol)
LOC_As$use_eol <- sub("_a", "",LOC_As$use_eol)
# LOC_As$use_eol <- substr(as.character(LOC_As$emission_rout),1,3)
LOC_As2 <- LOC_As %>%
group_by(year,sum_stat,scale,substance,scenario,use_eol) %>%
summarise(emmision = sum(emmision))
LOC_As3 <- LOC_As2[LOC_As2$substance=="Pb",]
p <- ggplot(subset(LOC_As3, sum_stat %in% "geo.mean"), aes(x=year, y=emmision)) +
ylab('Emission (kg)') +
xlab('Time (years)')+
geom_ribbon(aes(ymin = subset(LOC_As3, sum_stat %in% "P25")$emmision,
ymax = subset(LOC_As3, sum_stat %in% "P75")$emmision),
fill = brewer.pal(7,"Blues")[2])+
geom_line(position = "identity", alpha = 1, colour=brewer.pal(7,"Blues")[7])
p1 <- p + facet_grid(vars(scenario), vars(use_eol), scales = "free")+ theme_bw() +scale_y_continuous(trans='log10')
ggsave(filename = paste0("emission_LOCAL_useeol_Pb_LOG_",cases$paneltype[1],"_v04.jpg"),
plot = p1,
device = "jpeg",
path = "figures",
scale = 1.5,
width = 16,
height = 7,
units = "cm",
dpi = 300)
```
### Figure 4. "Verwachte blootstellingsconcentraties van zilver (Ag) , koper (Cu), en lood (Pb) afkomstig uit lood perovskiet zonnepanelen in water (wL) en bodem (sL) op lokale schaal in een scenario zonder recycling van deze metalen."
```{r Figure 4}
# sb4n.loc <- "data/SimpleBox4DIRECT 07102021.xlsm"
#Get compartment volumes from @RISK input data
v_wL <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`v./.wL`[4:1003])
v_w1R <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`v./.w1R`[4:1003])
v_w1C <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`v./.w1C`[4:1003])
v_sL <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`v./.sL`[4:1003])
v_s2R <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`v./.s2R`[4:1003])
v_s2C <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`v./.s2C`[4:1003])
vols <- data.frame(v_wL, v_w1R, v_w1C,v_sL, v_s2R, v_s2C)
fracw_sL <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`FRACw.sL`[4:1003])
fracw_s2R <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`FRACw.s2R`[4:1003])
fracw_s2C <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`FRACw.s2C`[4:1003])
RHOSOLID <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`RHOsolid`[4:1003])
# fraca_sL <- as.double(read.xlsx(sb4n.loc,colNames=FALSE, namedRegion ="FRACa.sL") )
# fraca_s2R <- as.double(read.xlsx(sb4n.loc,colNames=FALSE, namedRegion ="FRACa.s2R"))
# fraca_s2C <- as.double( read.xlsx(sb4n.loc,colNames=FALSE, namedRegion ="FRACa.s2C"))
fracw_sdL <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`FRACw.sdL`[4:1003])
fracw_sd1R <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`FRACw.sd1R`[4:1003])
fracw_sd1C <- as.double(out.data2$`Ag_NR_Tandem`$addriskinput$`FRACw.sd1C`[4:1003])
FRACWs <- data.frame(fracw_sL, fracw_s2R, fracw_s2C)
# FRACAs <- data.frame(fraca_sL, fraca_s2R, fraca_s2C)
#initialize variables
sum.stat.long2 <- data.frame()
comp <- c("wL", "w1R", "w1C", "sL", "s2R", "s2C")
scen <- names(out.data2)
# for testing
c = "wL"
s = scen[2]
## Makes a matrix with concentrations (year x MC run) from deSolve lists, for each compartment and scenario
for(c in comp)
for(s in scen){
cv <- vols %>% select(matches(c))
mat.yr <- matrix(nrow=101, ncol=1000)
#new code to fill matrix, as previous one would not report on errors with DeSolve output... and skipped columns wihout valid data without warning, e.g. run 4 here.
for(r in 1:1000) {
#converts concentrations to ug/L for water and mg/kg for soil compartments
if (c %in% c("wL", "w1R", "w1C")){
try(mat.yr[,r] <- (out.data2[[s]][[r]][["SBout_kg"]][,c]/cv[r,1])*1e9/1000 ,silent = TRUE ) #divides mass by compartment volume in m3 and convert to ug/L
} else {
fracw <- FRACWs %>% select(matches(c))
# fraca <- FRACAs %>% select(matches(c))
try(mat.yr[,r] <- (f_Soil.dryweight(Conc.soil = c(out.data2[[s]][[r]][["SBout_kg"]][,c]/cv[r,1])*1e3, #*1e3 to convert from g to mg/kg dry weight, same unit as PNEC
Fracs = c(1-fracw[r,1]-0.2),
RHOsolid = RHOSOLID[r] ) ) ,silent = TRUE)
}
}
if(length(which(is.na(mat.yr),arr.ind = TRUE)[,2])>0){print("NA's found, please check, a Desolve SB run could have failed or a timestep failed")
# which(is.na(mat.yr))
which(is.na(mat.yr),arr.ind = TRUE)
print(paste0("NA's found in Runs: " ))
print(unique(which(is.na(mat.yr),arr.ind = TRUE)[,2]))
}
mat.yr.df <- as.data.frame(mat.yr)
# mat.yr.df <- mat.yr.df[-1]
## Reshapes dataframe and puts it in long form
mat.yr.df <-t(mat.yr.df) # 1 year is 1 column
colnames(mat.yr.df) <- seq(0, 100, by=1) #renames columns to year number
data.long <- as.data.frame(mat.yr.df) %>% gather(year, mass, 0:101)
data.long$year <- as.integer(as.character(data.long$year))
#gets summary statistics for each year
sum.stat <- data.long %>%
group_by(year) %>%
summarize(geo.mean = geometric.mean(mass), P5 = quantile(mass, 0.05,na.rm = TRUE), P95 = quantile(mass, 0.95,na.rm = TRUE))
sum.stat.long <- as.data.frame(sum.stat) %>% pivot_longer(c("P95","geo.mean", "P5"), names_to = "sum_stat", values_to = "PEC")
# sum.stat.long$Mass <- sum.stat.long$Mass
# names(sum.stat.long)[names(sum.stat.long) == "Mass"] <- "PEC"
sum.stat.long$scenario = s
sum.stat.long$compartment = c
#stores values for this cycle (compartment x scenario)
sum.stat.long2 <- rbind(sum.stat.long2, sum.stat.long)
}
}
unique(sum.stat.long2$scenario)
names(sum.stat.long2)
# dataframe with risk limits
risklimits <- expand.grid(scenario = unique(sum.stat.long2$scenario),
compartment = unique(sum.stat.long2$compartment))
risklimits$rlim [(risklimits$compartment == "wL" |
risklimits$compartment == "w1R" |
risklimits$compartment == "w1C") &
#grepl("Ag",risklimits$scenario)] <- 0.01 # Landoppervlaktewateren wettelijk JG-MKN (opgelost)
grepl("Ag",risklimits$scenario)] <- 0.04 #(µg/L) PNEC for freshwater aquatic organisms from REACH registration dossier
risklimits$rlim [(risklimits$compartment == "wL" |
risklimits$compartment == "w1R" |
risklimits$compartment == "w1C") &
#grepl("Cu",risklimits$scenario)] <- 2.4 # Landoppervlaktewateren wettelijk JG-MKN (opgelost)
grepl("Cu",risklimits$scenario)] <- 7.8 #(µg/L) PNEC for freshwater aquatic organisms from REACH registration dossier
risklimits$rlim [(risklimits$compartment == "wL" |
risklimits$compartment == "w1R" |
risklimits$compartment == "w1C") &
#grepl("Pb",risklimits$scenario)] <- 1.2 # Landoppervlaktewateren wettelijk JG-MKN (opgelost)
grepl("Pb",risklimits$scenario)] <- 2.4 #(µg/L) PNEC for freshwater aquatic organisms from REACH registration dossier
risklimits$unit [(risklimits$compartment == "wL" |
risklimits$compartment == "w1R" |
risklimits$compartment == "w1C") ] <- "microgram/liter"
risklimits$rlim [(risklimits$compartment == "sL" |
risklimits$compartment == "s2R" |
risklimits$compartment == "s2C") &
#grepl("Ag",risklimits$scenario)] <- 1e-4 # Grond VR (droge stof)
grepl("Ag",risklimits$scenario)] <- 1.41 #(mg/kg soil dw)PNEC for terrestrial organisms from REACH registration dossier
risklimits$rlim [(risklimits$compartment == "sL" |
risklimits$compartment == "s2R" |
risklimits$compartment == "s2C") &
#grepl("Cu",risklimits$scenario)] <- 54 # Maximale waarde bodemfunctieklasse wonen / Maximale waarden kwaliteitsklasse wonen (droge stof)
grepl("Cu",risklimits$scenario)] <- 65 #(mg/kg soil dw)PNEC for terrestrial organisms from REACH registration dossier
risklimits$rlim [(risklimits$compartment == "sL" |
risklimits$compartment == "s2R" |
risklimits$compartment == "s2C") &
#grepl("Pb",risklimits$scenario)] <- 210 # Maximale waarde bodemfunctieklasse wonen / Maximale waarden kwaliteitsklasse wonen (droge stof)
grepl("Pb",risklimits$scenario)] <- 212 #(mg/kg soil dw)PNEC for terrestrial organisms from REACH registration dossier
risklimits$unit [(risklimits$compartment == "sL" |
risklimits$compartment == "s2R" |
risklimits$compartment == "s2C") ] <- "mg/kg dw soil"
# sum.stat.Pb.Cu.Ag <- sum.stat.long2[(sum.stat.long2$scenario=="Pb_NR_Tandem" |
# sum.stat.long2$scenario=="Cu_NR_Tandem"|
# sum.stat.long2$scenario=="Ag_NR_Tandem")&
# (sum.stat.long2$compartment=="wL"),]
#
# risklimits.Pb.Cu.Ag <- risklimits[(risklimits$scenario=="Pb_NR_Tandem" |
# risklimits$scenario=="Cu_NR_Tandem"|
# risklimits$scenario=="Ag_NR_Tandem")&
# (risklimits$compartment=="wL"),]
sum.stat.Ag.Cu.Pb <- sum.stat.long2[(sum.stat.long2$scenario=="Ag_NR_Tandem" |
sum.stat.long2$scenario=="Cu_NR_Tandem"|
sum.stat.long2$scenario=="Pb_NR_Tandem")&
(sum.stat.long2$compartment=="wL"|
sum.stat.long2$compartment=="sL"),]
risklimits.Ag.Cu.Pb <- risklimits[(risklimits$scenario=="Ag_NR_Tandem" |
risklimits$scenario=="Cu_NR_Tandem"|
risklimits$scenario=="Pb_NR_Tandem")&
(risklimits$compartment=="wL"|
risklimits$compartment=="sL"),]
#make figure 4
p <- ggplot(subset(sum.stat.Ag.Cu.Pb, sum_stat %in% "geo.mean"), aes(x=year, y=PEC)) +
ylab('Concentration (ug/L or mg/kg dw)') +
xlab('Time (years)')+
geom_ribbon(aes(ymin = subset(sum.stat.Ag.Cu.Pb, sum_stat %in% "P5")$PEC,
ymax = subset(sum.stat.Ag.Cu.Pb, sum_stat %in% "P95")$PEC),
fill = brewer.pal(7,"Greens")[2])+
geom_line(position = "identity", alpha = 1, colour=brewer.pal(7,"Greens")[7])
p1 <- p + geom_hline(data = risklimits.Ag.Cu.Pb, aes(yintercept = rlim))
p3 <- p1 + facet_grid(vars(scenario),vars(compartment), scales = "free")+ theme_bw() +scale_y_continuous(trans='log10')+ylab('LOG-Concentration (ug/L or mg/kg dw)')
ggsave(filename = paste0("PEC_Ag_Cu_Pb_RLIM_v04.jpg"),
plot = last_plot(),
device = "jpeg",
path = "figures",
scale = 2,
width = 16,
height = 10,
units = "cm",
dpi = 300)