I would like to know how to use the transverse_tagged_database method in brightway2. From the documentation is not entirely clear to me. Can we use for, example, to aggregat
The short answer is yes, aggregating impacts by ISIC code in your foreground product system model is exactly the kind of thing you can do using traverse_tagged_databases
.
The traverse_tagged_databases function takes advantage of the fact that you can add arbitrary key:value
pairs to activities in brightway to let you classify your the activities in your foreground model however you like.
For example, say your activities look like this:
('example_database', 'code_for_bread'):{
'name': 'Bread',
'code': 'code_for_bread',
'categories':[],
'exchanges':[...],
'location':'GLO'
'unit':'kg',
'database':'example_database',
'isic_code':'1071'
'isic_classifier':'Manufacture of bakery products'
},
You can tell traverse_tagged_databases
to go through your database looking for a given key (tag), for example 'isic_code'
, or 'isic_classifier'
and aggregate the impact based on these tags.
Say you were modelling a cheese sandwich, you could have the following ISIC codes in your model:
Sandwich: 1079 (Manufacture of other food products n.e.c.)
Bread: 1071 (Manufacture of bakery products)
Cheese: 1050 (Manufacture of dairy products)
Butter: 1050 (Manufacture of dairy products)
You can use traverse_tagged_databases
to see the total impact of dairy (cheese and butter) vs bakery (bread).
You use it in a similar way to the LCA
function, by specifying a functional unit as a dict
and the method as a tuple
, with an additional tag
argument. Like this:
fu = {('example_database', 'code_for_sandwich'):1}
m = ('IPCC 2013', 'climate change', 'GWP 100a')
result, tree = traverse_tagged_databases(fu, m, 'isic_classifier')
The function returns two objects (designated result
and tree
in the line above)
For this analysis, your result
will look something like this:
defaultdict(int,
{'Manufacture of other food products n.e.c.': 0,
'Manufacture of bakery products': 0.1875,
'Manufacture of dairy products': 0.55})
This is saying that dairy products in the foreground model have an aggregated impact of 0.55 kg CO2-eq, and bakery products have an aggregated impact of 0.1875 kg CO2-eq.
With a bit of post-processing you can turn this data into pie charts, stacked bar charts etc.
You also get a tree
, which looks like this:
[{'activity': 'Sandwich' (kg, GLO, []),
'amount': 1,
'tag': 'Manufacture of other food products n.e.c.',
'impact': 0,
'biosphere': [],
'technosphere': [{'activity': 'Bread' (kg, GLO, []),
'amount': 0.75,
'tag': 'Manufacture of bakery products',
'impact': 0,
'biosphere': [{'amount': 0.1875,
'impact': 0.1875,
'tag': 'Manufacture of bakery products'}],
'technosphere': []},
{'activity': 'Butter' (kg, GLO, []),
'amount': 0.05,
'tag': 'Manufacture of dairy products',
'impact': 0,
'biosphere': [{'amount': 0.05,
'impact': 0.05,
'tag': 'Manufacture of dairy products'}],
'technosphere': []},
{'activity': 'Cheese' (kg, GLO, []),
'amount': 0.25,
'tag': 'Manufacture of dairy products',
'impact': 0,
'biosphere': [{'amount': 0.5,
'impact': 0.5,
'tag': 'Manufacture of dairy products'}],
'technosphere': []}]}]
This can look a bit difficult to parse at first, but is essentially a set of nested dictionaries, starting with the root activity (the functional unit = Sandwich), showing techosphere
exchanges to other activities, and biosphere
exchanges to emissions.
The tree here looks like this (with the amount
s of each product in brackets)
Bread +----(0.75 kg)----------+
|
|
|
|
Cheese +----(0.20 kg)----------+------(1.00 kg)--------> Sandwich
|
|
|
|
Butter +----(0.05 kg)----------+
Again, with a bit of post-processing, you can turn this data into stuff like sankey diagrams, or the kind of impact tree diagram you get in SimaPro.