-
Notifications
You must be signed in to change notification settings - Fork 0
/
FinalConcentration.R
170 lines (146 loc) · 5.63 KB
/
FinalConcentration.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
setwd("~/Polybox/Projects/2018.10 Compost/Flows/20190530_Final_STAN_Jupyter/Concentration/")
SIM <- 100000
# load compost concentration data
load("~/Polybox/Projects/2018.10 Compost/Data/Schleiss/ConcentrationDistributions.Rdata")
## from
## Mandaliev, P.; Schleiss, K. Installations de Compostage et de Méthanisation
## Recensement En Suisse et Au Liechtenstein; 2016.
# 167 sites with 82093 t/a
# 131 sites with 290851 t/a
# 31 sites with 191666 t/a
# 39 sites with 691234 t/a
# create random vector with facility size (output produced in t/a)
facility.size <- sample(c(rep(492,167),
rep(2220,131),
rep(6183,31),
rep(17724,39)))*0.31
# total organic matter treated in Switzerland
total.OM <- sum(facility.size)
# concentration of plastic in processed organic waste
conc <- list("CompostAgriculture" = sample(Comp.Agri/100,
length(facility.size),
replace = T),
"CompostHorticulture" = sample(Comp.Gard/100,
length(facility.size),
replace = T),
"Digestate" = sample(Digestate/100,
length(facility.size),
replace = T))
# relative MP concentration
MP.conc <- sample(c(0.09, 0.02, 1.04, 0.16, 0.02, 0.10, 0.25)+1,SIM,replace = T)
Final.conc <- list()
for(k in 1:3){
# create an empty matrix
plast.mat <- matrix(0,SIM,length(facility.size))
# calculate the total amount of plastic while randomizing the concentration in each facilty
for(i in 1:SIM){
plast.mat[i,] <- sample(conc[[k]])*facility.size
}
# calculate total plastic in Switzerland
total.CH <- apply(plast.mat, 1, sum)
# total concentration
total.conc <- total.CH/total.OM #* MP.conc
# save data
write.csv(total.conc, file = paste0("TotalConcentration_",names(conc)[k],".csv"))
Final.conc[[names(conc)[k]]] <- total.conc
# plot
hist(total.conc*100, main = names(conc)[k], xlab = "Concentration (kg/kg)")
}
{
pdf(file = "ConcentrationVariability.pdf",
width = 9,
height = 3)
par(mfrow = c(1,3))
hist(Comp.Agri,
main = "Variability of the plastic content\nin compost for agriculture",
xlab = "Concentration (%)",
col = "limegreen",
freq = F)
legend("topright",
paste0(c("Mean", "SD", "Q75", "Q25"),
" = ",
round(c(mean(Comp.Agri),
sd(Comp.Agri),
quantile(Comp.Agri,probs = c(0.75, 0.25))), digits = 3),
"%"),
bty = "n")
box()
hist(Comp.Gard,
main = "Variability of the plastic content\nin compost for gardening and horticulture",
xlab = "Concentration (%)",
col = "cornflowerblue",
freq = F)
legend("topright",
paste0(c("Mean", "SD", "Q75", "Q25"),
" = ",
round(c(mean(Comp.Gard),
sd(Comp.Gard),
quantile(Comp.Gard,probs = c(0.75, 0.25))), digits = 3),
"%"),
bty = "n")
box()
hist(Digestate,
main = "Variability of the plastic content\nin solid digestate",
xlab = "Concentration (%)",
col = "tomato",
freq = F)
legend("topright",
paste0(c("Mean", "SD", "Q75", "Q25"),
" = ",
round(c(mean(Digestate),
sd(Digestate),
quantile(Digestate,probs = c(0.75, 0.25))), digits = 3),
"%"),
bty = "n")
box()
dev.off()
}
{
pdf(file = "SwissConcentration.pdf",
width = 9,
height = 3)
par(mfrow = c(1,3))
hist(Final.conc[["CompostAgriculture"]]*100,
main = "Swiss-wide plastic content in\ncompost for agriculture",
xlab = "Concentration (%)",
col = "limegreen",
freq = F)
legend("topright",
paste0(c("Mean", "SD", "Q75", "Q25"),
" = ",
round(c(mean(Final.conc[["CompostAgriculture"]]*100),
sd(Final.conc[["CompostAgriculture"]]*100),
quantile(Final.conc[["CompostAgriculture"]]*100,probs = c(0.75, 0.25))), digits = 3),
"%"),
bty = "n")
box()
hist(Final.conc[["CompostHorticulture"]]*100,
main = "Swiss-wide plastic content in\ncompost for gardening and horticulture",
xlab = "Concentration (%)",
col = "cornflowerblue",
freq = F)
legend("topright",
paste0(c("Mean", "SD", "Q75", "Q25"),
" = ",
round(c(mean(Final.conc[["CompostHorticulture"]]*100),
sd(Final.conc[["CompostHorticulture"]]*100),
quantile(Final.conc[["CompostHorticulture"]]*100,probs = c(0.75, 0.25))), digits = 3),
"%"),
bty = "n")
box()
hist(Final.conc[["Digestate"]]*100,
main = "Swiss-wide plastic content in\nsolid digestate",
xlab = "Concentration (%)",
col = "tomato",
freq = F)
legend("topright",
paste0(c("Mean", "SD", "Q75", "Q25"),
" = ",
round(c(mean(Final.conc[["Digestate"]]*100),
sd(Final.conc[["Digestate"]]*100),
quantile(Final.conc[["Digestate"]]*100,probs = c(0.75, 0.25))), digits = 3),
"%"),
bty = "n")
box()
dev.off()
}