Named Life Cycle Inventory

50 Views Asked by At

How do I get the named Life Cycle Inventory of an activity?

Let's say I'm calculating the Life Cycle Assessment of an activity:

act = [
       act for act in ei391cf
       if 'benzaldehyde production' == act['name']
       and 'RER' == act['location']
       ]

lca = bw.LCA(
    {act[0]: 1},
    ('ReCiPe 2016 v1.03, midpoint (H)',
     'water use', 'water consumption potential (WCP)')
    )

lca.lci()
lca.lcia()

... I understand that lca.biosphere_dict returns the biosphere flows of the Life Cycle Inventory. However, it only lists the codes of the biosphere flows rather than their names and categories. I could write my own function to determine the names and categories, but it must be such a basic task that I am sure there is a function for it.

In fact, I have come across get_labelled_inventory, but I can't get it to work.

I tried ba.lci.get_labeled_inventory(lca) but it just returns AttributeError: module 'bw2analyzer' has no attribute 'get_labeled_inventory'.

1

There are 1 best solutions below

1
On

First off, please always be careful with something like:

act = [
   act for act in ei391cf
   if 'benzaldehyde production' == act['name']
   and 'RER' == act['location']
   ]

You should at least check the length of this list with e.g. assert len(act) == 1. In Brightway 2.5 you can also do bw2data.get_node(name='benzaldehyde production', location='RER', database=ei391cf['name']).

In Brightway 2.5 you can do lca.to_dataframe(matrix_label='inventory') to get an annotated pandas Dataframe.

In Brightway 2, you can do something similar with (not tested code):

from functools import lru_cache
import bw2data as bd


@lru_cache(maxsize=16000):
def cached_lookup(key):
    return bd.get_activity(key)


inventory_results = []

for row, row_key in lca.biosphere_dict.items():
    for col, col_key in lca.activity_dict.items():
        if lca.inventory[row, col] != 0:
            inventory_results.append((
                abs(lca.inventory[row, col]), 
                lca.inventory[row, col], 
                cached_lookup(row_key),
                cached_lookup(col_key)
            ))

inventory_results.sort(reverse=True)