2

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.

1 Answers1

2

You are very close. In defining your CFs, you do the following:

myLCIAdata = [[('biosphere', 'Carbon dioxide'), 1.0], 
              [('biosphere', 'Sulphur dioxide'), 1.0],
              [('biosphere', 'Crude oil'), 1.0]]

Taking the first line, this would mean that in the database biosphere, there would be a flow with the code Carbon dioxide. But you don't have a biosphere database, you put everything into a database named testdb:

    ('testdb', 'Carbon dioxide'):{'name': 'Carbon dioxide', 'unit':'kg', 'type': 'biosphere'},

So either use the right database name in the list of characterization factors, or create a separate biosphere database called biosphere.

Note also that instead of this:

method_key = ('simplemethod', 'imaginaryendpoint', 'imaginarymidpoint')
Method(method_key).validate(myLCIAdata) #returns "TRUE"
Method(method_key).register() 
Method(method_key).write(myLCIAdata)

You should do this:

method_key = ('simplemethod', 'imaginaryendpoint', 'imaginarymidpoint')
my_method = Method(method_key)
my_method.validate(myLCIAdata)
my_method.register() 
my_method.write(myLCIAdata)

(Your code isn't broken, but could be more elegant).

Chris Mutel
  • 2,549
  • 1
  • 14
  • 9
  • Thank you. I see the mistake, I was confused by the "biosphere" part in the LCIA method definition, I thought it was the type of flow instead it refers to the database. I modified the code as: `myLCIAdata = [[('testdb', 'Carbon dioxide'), 1.0] ... ` , added `lca.lcia()`, and it worked. (Got the elegance point, thanks for the suggestion). – Massimo Pizzol Jan 04 '17 at 20:14