TODO
from brightway2 import *
Start a new project, and install base data
projects.set_current("student-project-SimaPro-import")
bw2setup()
Also want ecoinvent database
ei = SingleOutputEcospold2Importer(
"/Users/cmutel/Documents/LCA Documents/Ecoinvent/3.1/cutoff/datasets",
"ecoinvent 3.1 cutoff"
)
ei.apply_strategies()
ei.write_database()
fp = "data/caes.CSV"
sp = SimaProCSVImporter(fp, name="CAES")
sp.statistics()
The formula parser throws an error - it has a certain number of symbols already defined, and when one of those symbol names is used as a variable it raises an error. In this case, we already have $\pi$ defined, so we can manually delete it from the CSV file.
fp = "data/caes-no-pi.CSV"
sp = SimaProCSVImporter(fp, name="CAES")
sp.statistics()
sp.apply_strategies()
sp.statistics()
for exc in sp.unlinked:
print(exc['name'])
This is a two-step process. First, we have to change the names to ones that ecoinvent uses (no, there is not ecoinvent process Steel, chromium steel 18/8 {GLO}| market for | Alloc Def, U
!).
Then we can try to link against the Ecoinvent 3.1 database.
sp.migrate("simapro-ecoinvent-3")
Because we are importin from SimaPro, the categories are screwed up (i.e. ecoinvent categories aren't cleanly imported). Tell the matching algorithm to ignore categories and only use product, reference product, unit, and location.
import functools
from bw2io.strategies import link_iterable_by_fields
sp.apply_strategy(functools.partial(
link_iterable_by_fields,
other=Database("ecoinvent 3.1 cutoff"),
kind="technosphere",
fields=["reference product", "name", "unit", "location"]
))
sp.statistics()
for exc in sp.unlinked:
print(exc)
In this case, we are going to ignore these missing exchanges. We do this (naturally) through another strategy, thoough this one has a shortcut:
sp.drop_unlinked()
Oops, we got a complaint. But we proceed anyway:
sp.drop_unlinked(i_am_reckless=True)
Just to get a better view on what was imported
sp.write_excel()
sp.write_database()