-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresourceeff.rmd
255 lines (191 loc) · 8 KB
/
resourceeff.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
---
title: "resourceefficiency.rmd"
author: "Adrian Leip"
date: "Thursday, January 05, 2017"
output: html_document
---
Script calculating resource efficiency according to Heijungs and Suh (2002).
# Problem definition
## Processes
We assess a three-process life cycle:
- process 1: Feed production
- process 2: Livestock production
- process 3: Food production
```{r}
library("Matrix") # Matrix calculations
library("MASS") # Inverted matrix
processes<-c("feed","livestock","food")
```
All flows are expressed in kg of nitrogen.
### Feed production
- _Inputs_ to feed production are mineral fertilizer, crop residues, manure, and processing by-products.
- _Outputs_ to feed production are the feed (that is used in the livestock production stage/process), crop residues (recycled into the crop production process as a closed loop) and a crop-co-product which is exported from the system.
- Additionally, feed production generates _losses to the environment_.
### Livestock production
- _Inputs_ to the livestock production system is exclusively the feed produced in the crop productino process
- _Outputs_ are the livestock product which goes to the processing stage. A co-product is exported. Manure is used in the crop production process
- Additionally, _losses to the environment_ occur.
### Food production
- Only _input_ is the livestock product
- _Outputs_ are the main food product and a co-product which is recycled back to the crop production process
- Additionally, _losses to the environment_ occur.
## Economic flows
The following economic flows are differentiated:
1. Feed product #We start with the principal food-chain
2. Animal product
3. Food product
4. Feed co-product
5. Animal co-product
6. Crop residues production #Finally residues
7. Crop residues consumption
8. Recycled Manure
9. Recycled Food processing by-product
```{r}
products<-c("feed","anim","food","feedco","animco","cropreso","cropresi","manure","foodres")
#flagging flows from the process they are generated (0 for imports)
origin<-c(1,2,3,1,2,1,1,2,3)
```
In the default desing of the system, all residues are recycled in the system and none is wasted.
```{r}
waste<-c()
goods<-products[!products%in% waste]
print(goods)
```
## Environmental flows
We regard all environmental losses here independently of their nature.
Therefore, there is only one environmental flow:
9. Mineral fertilizer #After principal chain (other) inputs and co-products
10. Total N losses
```{r}
resources<-c("N fertilizer")
losses<-c("N losses")
interventions<-c(resource,losses)
```
# Technology matrix
The *Technology matrix _A_* gives the economic flows.
It has `r length(products)` rows and 'r length(processes)` columns.
# Intervention matrix
The *Intervention matrix _B_* gives the environmental flows.
```{r}
t1<-c( 50, 0, 0,40,0,10,-10,-10,-2)
# The vector is constructed such that consumption of recyling flows from other processes are not explicit to leave cross-dependencies flexible.
# They are indicated with NA.
# Required resources are coming from the resources (here mineral fertilizer)
# This does NOT affect the calculated NUE per process or the lifecycle NUE based on material flow analysis.
t1<-c( 50, 0, 0,40,0,10,-10, NA,NA)
t1<-c( 25, 0, 0,20,0, 5, -5, NA,NA)
t2<-c(-50, 20, 0, 0,5, 0, 0, 10, 0)
t3<-c( 0,-20,12.5, 0,0, 0, 0, 0, 2)
i1<-c(-100,22)
i1<-c(-112,22)
i1<-c(-56,11)
i2<-c( 0,15)
i3<-c( 0,5.5)
#Allocation factors
```
# Demand vector
There is demand only for food. Therefore, all for all ecnomic flows, which are not completely re-absorbed in the process, an additional process must be defined which consumes the product.
```{r}
f<-c(0,0,12.5) #Demand Vector required for main food chain
# Calculation requires a square Technology matrix
# Fill missing columns on the basis of existing data
#Matrix of flows which are 'too many' (not part of the main food chain)
Afull<-function(A){
n<-ncol(A)
m<-nrow(A)
grows2add<-m-n
g<-matrix(rep(0,ncol=(m-n)*(m-n)),ncol=(m-n),nrow=(m-n))
gtemp<-matrix(rep(0,ncol=(m-n)*n),ncol=(m-n),nrow=n)
fsum<-apply(A,1,sum)[(n+1):m]
for(i in 1:length(fsum)){g[i,i]<--fsum[i]}
g<-rbind(gtemp,g)
g<-cbind(A,g)
return(g)
}
fplus<-function(A,f){
g<-c(f,rep(0,nrow(A)-ncol(A)))
return(g)
}
```
# Scaling vector
```{r}
# Combine process vectors into Technology matrix, Intervention matrix, and the Process matrix
A<-cbind(t1,t2,t3)
A<-as.data.frame(A)
rownames(A)<-products
colnames(A)<-processes
B<-cbind(i1,i2,i3)
B<-as.data.frame(B)
rownames(B)<-intervention
colnames(B)<-processes
P<-rbind(A,B)
colnames(P)<-processes
nprod<-nrow(A)
nproc<-ncol(A)
nenv<-nrow(B)
# For the scaling factor only the main matrix counts
# Co-products or recycling doesn't change the relative quantitive of the processes required
# So far only P is scaled !
s<-as.vector(ginv(as.matrix(A[1:ncol(A),]))%*%f)
P[,]<-sapply(1:ncol(P),function(j) sapply(1:nrow(P),function(i) P[i,j]*s[j]))
```
# Fill recycling flows
Assumptions:
1. Each recycling flow is consumed by one process only (i.e. food processing residue is either used as feed or as fertilizer. If it is used for both purposes, then they should be two recycling flows defined.)
2. All recycling flows can be absorbed. If more is produced then the surplus must be shifted to 'export' or 'waste' (depending..) but this is not programmed yet.
3. The system draws on exactly ONE resource.If thereare more than one resource, then there must be rules how to account for accounting, but this has not been programmed yet.
```{r}
temp<-apply(P[1:nrow(A),]*recycling,1,sum,na.rm=T)
temp<-sapply(1:ncol(A),function(j)
sapply(1:nrow(A),function(i)
if(is.na(A[i,j])){-temp[i]}else{P[i,j]}))
tempdiff<-as.vector(apply(temp,2,sum))-as.vector(apply(P[1:nrow(A),],2,sum,na.rm=T))
P[1:nprod,]<-temp
P[nprod+length(resources),]<-P[nprod+length(resources),]-tempdiff
rm(temp,tempdiff)
```
# Nitrogen Use Efficiency for each process
NUE is calculated from the ratio of goods produced in a process to the sum of inputs. Here, NUE is calculated as a characteristicum of the process itself, thus no differentiation is made between different goods.
```{r}
goodstemp<-P[rownames(P)%in%goods,]
goodstemp[goodstemp<0]<-0
sumgoods<-apply(goodstemp[rownames(P)%in%goods,],2,sum)
goodstemp<-P[rownames(P)%in%goods,]
goodstemp[goodstemp>0]<-0
suminputs<--apply(goodstemp[rownames(P)%in%goods,],2,sum)
suminputs<-suminputs-P[rownames(P)%in%resources,]
nue<-sumgoods/suminputs
rm(goodstemp)
```
The NUE of the processes is `r print(nue)` for the processes `r print(processes)`
# Resource use per process
Total resource use is the sum of all inputs (goods and resources) which are not recycled in the process.
For this purpose a matrix need to be generates with rows/columns representing the processes. Each cell is the total net production/consumption of goods. Thereby products are aggregated according to their origin into 'feed products', 'livestock products', 'food products'.
According to Suh et al. (2011) each cell is obtained from
v - u - m + s
V: Production of product in process
u: Use of product in process
m: Import of product into process
s: Stock change [considered as good]
This is achieved by filtering for each product the flows originating from the corresponding process and summing by process:
```{r}
V<-matrix(rep(0,nproc**2),ncol=nproc,nrow=nproc)
V<-t(sapply(1:nproc,function(x) apply(P[1:nprod,][origin==x,],2,sum)))
print(V)
```
The inverse of this matrix is multiplied with the resource vector
```{r}
r<-as.vector(as.matrix(-P[rownames(P)%in%resources,]))
```
Finally, the resource-need vector for the processes is obtained according to equation (4) in Suh et a., (2011)
```{r}
rintensity<-t(r)%*%ginv(V)
```
According to Uwizeye et al. (2016), the life-cycle NUE is obtained as inverse of the resource-intensity of the last process
```{r}
lcanue<-1/rintensity[1,length(processes)]
```
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.