In [1]:
from brightway2 import *
from bw2data import Database, get_activity
import numpy as np
import pandas as pd
In [2]:
projects.set_current('Import Quantis OFP - version 4')
In [3]:
bw2setup()
In [4]:
list(databases)
Out[4]:
try first sth from ecoinvent
In [6]:
act = Database("MeatDatasets").search('suckler average')[1]
act
Out[6]:
In [7]:
lca = LCA(
{act.key: 1},
method=('IPCC 2013', 'climate change', 'GWP 100a'),
)
lca.lci()
lca.lcia()
lca.score
Out[7]:
In [74]:
# help(lca.characterized_inventory)
# type(lca.characterized_inventory)
lca.characterized_inventory.shape
Out[74]:
In [8]:
from bw2analyzer import ContributionAnalysis
In [9]:
results = ContributionAnalysis().annotated_top_processes(lca, names=False)
results = [(x[0], x[1], get_activity(x[2]), x[2]) for x in results]
df = pd.DataFrame(results, columns=['lca_score', 'inventory_amount', 'activity', 'process_key'])
# print(df.activity.apply(type)) # peewee objects...
# print(df.activity.apply(len))
# For example
df.activity
Out[9]:
In [10]:
df = lca.to_dataframe()
df.head()
Out[10]:
In [11]:
lca.to_dataframe
Out[11]:
In [85]:
lca.characterized_inventory
Out[85]:
In [34]:
df.sort_values(by='Amount', ascending=False, inplace=True)
In [35]:
lca.top_emissions()
Out[35]:
In [39]:
c_an = ContributionAnalysis().annotated_top_emissions(lca, {'limit': 0, 'limit_type':'percent', 'total':None})
pd.DataFrame(c_an)
In [0]:
from bw2analyzer.report import SerializedLCAReport
test = SerializedLCAReport(
activity={act.key: 1},
method=('IPCC 2013', 'climate change', 'GWP 100a'),
iterations=10,
)
In [85]:
test.calculate()
In [0]:
test.report['monte carlo']['histogram']= list(test.report['monte carlo']['histogram'])
In [0]:
test.report['monte carlo']['smoothed'] = list(test.report['monte carlo']['smoothed'])
In [0]:
test.write()
In [0]:
test.report
In [0]:
In [0]:
In [0]:
sorted(str(get_activity(key)) for key, _ in Method(('IPCC 2013', 'climate change', 'GWP 100a')).load())
See all flows with their characterization factors
In [4]:
from brightway2 import *
# method = methods.random()
methods = Method(('IPCC 2013', 'climate change', 'GWP 100a')).load()
for key, cf in methods:
print(get_activity(key), cf)
In [0]:
In [0]:
In [0]:
In [0]:
In [0]:
In [0]:
In [0]:
In [0]:
In [0]:
In [0]:
In [0]:
In [0]: