This notebook shows how to import a SimaPro CSV export that includes ecoinvent 2.2. We will use a custom strategy to remove the ecoinvent processes, and then link to the ecoinvent already present on our machine.
from brightway2 import *
Start a new project, and install base data
projects.set_current("simapro-ecoinvent-import")
bw2setup()
ei22 = SingleOutputEcospold1Importer(
"/Users/cmutel/Documents/LCA Documents/Ecoinvent/2.2/processes",
"ecoinvent 2.2"
)
ei22.apply_strategies()
ei22.write_database()
sp = SimaProCSVImporter("/Users/cmutel/Downloads/Furniture particle board and hardboard.CSV", "particle-board")
sp.statistics()
OK, the SimaPro export file has several cases where the parameter names were incorrect - SimaPro appears to ignore the difference between upper and lower case for parameter names, so for SimaPro "Foo" and "foo" are the same thing, which raises errors for our parameter parser. These have to be fixed manually in the CSV file. Basically, fix the errors that come up until the code runs without any errors.
sp = SimaProCSVImporter("/Users/cmutel/Downloads/Furniture particle board and hardboard-fixed.CSV", "particle-board")
sp.statistics()
To match against ecoinvent using the unit
field, we need to have everything in the right units. We accomplish this by applying a migration that converts units to ecoinvent defaults.
sp.migrate('default-units')
We are lucky in this case, as we know that the version of ecoinvent was not modified. If there were modifications, we would have to include the whole modified database. No software that I know of, including Brightway2, will keep a log of the modified processes after a database import, though this is certainly on our radar. But at least in this simple case, we can just delete the ecoinvent processes.
To do this, we use the most common technique in the IO library - matching based on a certain number of attributes. In this case, because we are importing from SimaPro, the categories will not match ecoinvent categories. However, at least for version 2.2, the names, units, and locations will (after we normalize things, and ignoring SimaPro changes to capitalization).
First, however, we need to apply some basic strategies.
sp.strategies[:5]
sp.apply_strategies(sp.strategies[:5])
Now we can try to find Ecoinvent datasets, and remove them:
from bw2io.utils import activity_hash
def match_by_activity_hash(data):
ei22 = Database("ecoinvent 2.2")
fields = ["name", "unit", "location"]
ei22_hashes = {activity_hash(ds, fields=fields) for ds in ei22}
assert len(ei22) == len(ei22_hashes)
return [obj for obj in data if activity_hash(obj, fields=fields) not in ei22_hashes]
sp.apply_strategy(match_by_activity_hash)
sp.statistics()
First, construct internal links within the database:
sp.apply_strategy(sp.strategies[5])
Next, link biosphere flows:
sp.apply_strategies(sp.strategies[6:])
Finally, link to ecoinvent 2.2:
sp.match_database("ecoinvent 2.2", ignore_categories=True)
sp.statistics()
This is fairly typical - there are some flows specific to SimaPro that we can't match perfectly yet. Let's look at what we still have to do:
for i, e in enumerate(sp.unlinked):
print(e['name'], e['unit'], e['categories'])
if i > 20:
break
Let's write an excel sheet and get a broader picture of what is left to do.
sp.write_excel()