I am very new to bw2 and I am trying to make a simple LCA without using databases but just using a manually defined inventory and LCIA method. I used the values from the example in Chapter 11 of "The Computational Structure of Life Cycle Assessment" book.
I was able to create a inventory and run the LCI calculation:
t_db = Database("testdb")
t_db.write({
("testdb", "Electricity production"):{
'name':'Electricity production',
'unit': 'kWh',
'exchanges': [{
'input': ('testdb', 'Fuel production'),
'amount': 2,
'unit': 'kg',
'type': 'technosphere'
},{
'input': ('testdb', 'Carbon dioxide'),
'amount': 1,
'unit': 'kg',
'type': 'biosphere'
},{
'input': ('testdb', 'Sulphur dioxide'),
'amount': 0.1,
'unit': 'kg',
'type': 'biosphere'
},{
'input': ('testdb', 'Electricity production'), #important to write the same process name in output
'amount': 10,
'unit': 'kWh',
'type': 'production'
}]
},
('testdb', 'Fuel production'):{
'name': 'Fuel production',
'unit': 'kg',
'exchanges':[{
'input': ('testdb', 'Carbon dioxide'),
'amount': 10,
'unit': 'kg',
'type': 'biosphere'
},{
'input': ('testdb', 'Sulphur dioxide'),
'amount': 2,
'unit': 'kg',
'type': 'biosphere'
},{
'input': ('testdb', 'Crude oil'),
'amount': -50,
'unit': 'kg',
'type': 'biosphere'
},{
'input': ('testdb', 'Fuel production'),
'amount': 100,
'unit': 'kg',
'type': 'production'
}]
},
('testdb', 'Carbon dioxide'):{'name': 'Carbon dioxide', 'unit':'kg', 'type': 'biosphere'},
('testdb', 'Sulphur dioxide'):{'name': 'Sulphur dioxide', 'unit':'kg', 'type': 'biosphere'},
('testdb', 'Crude oil'):{'name': 'Crude oil', 'unit':'kg', 'type': 'biosphere'}
})
functional_unit = {t_db.get("Electricity production") : 1000}
lca = LCA(functional_unit)
lca.lci()
print(lca.inventory)
However, the problems start when I create the fictive LCIA method (with all CFs set to 1 for simplicity). This is the code I used but clearly it does not work. The key issue seems to be a failure to link the exchanges from the inventory to the LCIA method.
myLCIAdata = [[('biosphere', 'Carbon dioxide'), 1.0],
[('biosphere', 'Sulphur dioxide'), 1.0],
[('biosphere', 'Crude oil'), 1.0]]
method_key = ('simplemethod', 'imaginaryendpoint', 'imaginarymidpoint')
Method(method_key).validate(myLCIAdata) #returns "TRUE"
Method(method_key).register()
Method(method_key).write(myLCIAdata)
Method(method_key).load() #check everything works
lca = LCA(functional_unit, method_key) #run LCA calculations again with method
lca.characterized_inventory
The result is <3x2 sparse matrix of type '<class 'numpy.float64'>'
with 0 stored elements in Compressed Sparse Row format>
So an empty matrix. Any idea of what mistake I am making? Should I get an unique identifier for each exchange as in the existing databases? I have checked the bw2 tutorials, documentation, and previous questions on this site but can't find an answer. Thanks in advance.