Search code examples
brightway

Brightway2 - How can I get my impact results for technosphere and biosphere flows like it is shown in the Sankey Diagramm in the Activity Browser?


I just started with Brightway2 and the Activity Browser and I created a simple project in the Activity Browser which I am using now in my python IDE to understand how it all works. Now I'm wondering how I can get the individual impact data for the technosphere/biosphere flow I used for my activity like it is shown in the Sankey Diagramm of the Activity Browser.

My code looks like this:

#importing some packages 
from brightway2 import *
import bw2io
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

#current project is defined
projects.set_current("test LCA")
bw2io.bw2setup()

#selecting databases for this project    
test=Database("test")

#see which databases are already loaded
print(databases.list)

#selecting method
EF30 = [method for method in methods if 'EF v3.0' in str(method) and not 'no LT' in str(method)and not 'EN' in str(method)]

#look for activities in database
print(test.search("*"))
#defining the activity in the database
activity = [act for act in test]       


act_df = pd.DataFrame()
act_df['Database Process'] = test
act_df['Amount'] = 1
act_df.reset_index()

#Loop through all activities in the dataframe and all methods (impact categories) defined to calculate the impacts
for index in act_df.index:
    lca = LCA({act_df['Database Process'][index]: act_df['Amount'][index]})
    lca.lci()
    for method in EF30:
        lca.switch_method(method)
        lca.lcia()
       
        impact_cat = str(method[1])
        impact_unit = str(methods[method]['unit'])
        header = impact_cat,'({})'.format(impact_unit)
        act_df.loc[index, " ".join(header)] = lca.score
        
act_df_transposed=act_df.transpose()

#write data in Excel
act_df_transposed.to_excel("test.xlsx")


print('DONE!')

I already looked at the technosphere and biosphere matrixes but didn't really understand what it is telling me.


Solution

  • There isn't a builtin Sankey visualization in Brightway, but you can try https://github.com/romainsacchi/polyviz.