Agribalyse is a French LCI database of agricultural products. It builds on top of ecoinvent 3.2. It was exported from SimaPro, so the names of ecoinvent processes are mangled, and need to be fixed back to standard ecoinvent.
This notebook uses Agribalyse 1.3.
In [1]:
from brightway2 import *
Create a new project for this notebook
In [2]:
projects.set_current("Agribalyse 1.3")
In [3]:
bw2setup()
In [4]:
path = '/d/documents/eaternity/data/3.3/datasets'
importer = SingleOutputEcospold2Importer(path, "ecoinvent 3.2 cutoff")
importer.apply_strategies()
importer.statistics()
Out[4]:
In [6]:
importer.write_database()
Out[6]:
In [8]:
fpath = '/d/documents/eaternity/data/agribalyse-csv-final_no-links_nov2016v3.csv'
# path = "/Users/cmutel/Documents/LCA Documents/Agribalyse/1.3/Agribalyse CSV FINAL_no links_Nov2016v3.CSV"
ag = SimaProCSVImporter(fpath, "Agribalyse 1.3")
In [0]:
[type(o) for o in ag]
In [11]:
ag.apply_strategies()
ag.statistics()
In [4]:
ag.migrate('simapro-ecoinvent-3.2')
In [5]:
ag.match_database("ecoinvent 3.2 cutoff", fields=('reference product', 'location', 'unit', 'name'))
In [3]:
ag.statistics()
Let's look at what we can't link. The easiest way is to export the unlinked exchanges to an Excel file.
In [2]:
ag.write_excel(TRUE)
You can also download this Excel file.
Brightway2-IO 0.5.7 includes a lot of fixes to import Agribalyse more cleanly: 2a5406a, 0154841, b2d5545, 99b07b9, 2129804, 5d6b936, and 5d0542a.
However, there are still a large number of biosphere flows not used in ecoinvent that we don't have in our biosphere3 database (and, consequently, in our LCIA methods). The best we can do is to import these flows into another biosphere database. If these flows are important to you, you should do further matching or modify the relevant LCIA methods to include them.
In [8]:
Database("Agribalyse 1.3 new biosphere").register()
ag.add_unlinked_flows_to_biosphere_database("Agribalyse 1.3 new biosphere")
We should now have no unlinked biosphere flows:
For some reason there are some links to market for transport, passenger car, medium size, diesel, EURO 4 and market for transport, passenger car, medium size, petrol, EURO 4 with units of meters (instead of person kilometers, as in ecoinvent). We can create a custom migration to handle these cases:
In [9]:
agribalyse_transport_data = {
'fields': ['name', 'unit'],
'data': [
(
('market for transport, passenger car, medium size, diesel, EURO 4', 'meter'),
{
'unit': 'kilometer',
'multiplier': 1e-3
}
),
(
('market for transport, passenger car, medium size, petrol, EURO 4', 'meter'),
{
'unit': 'kilometer',
'multiplier': 1e-3
}
)
]
}
Migration("agribalyse-transport").write(
agribalyse_transport_data,
description="Fix some transport unit conversions"
)
In [10]:
ag.migrate("agribalyse-transport")
Link to ecoinvent again, to fix our now linkable transport inputs.
In [11]:
ag.match_database("ecoinvent 3.2 cutoff", fields=('reference product', 'location', 'unit', 'name'))
In [12]:
ag.statistics()
Out[12]:
In [13]:
ag.add_unlinked_activities()
ag.statistics()
Out[13]:
In [14]:
ag.write_database()
Out[14]:
We need to do some basic validation to make sure we have meaningful results. Here I just do some basic testing, but you should validate against known scores if you are frequently using this database. The following code is rahter simple and is not a real validation check.
In [15]:
gwp = [x for x in methods if "IPCC 2013" in str(x)][0]
gwp
Out[15]:
In [16]:
db = Database("Agribalyse 1.3")
lca = LCA({db.random(): 1}, gwp)
lca.lci(factorize=True)
lca.lcia()
lca.score
Out[16]:
Let's calculate the LCIA scores of all activities in Agribalyse
In [17]:
import pyprind
scores = []
for act in pyprind.prog_bar(db):
lca.redo_lcia({act: 1})
scores.append(lca.score)
In [18]:
import numpy as np
scores = np.array(scores)
mask = scores == 0
print("Number of activities with zero GWP score: {} of {}".format(mask.sum(), len(db)))
In [19]:
%matplotlib notebook
In [20]:
import seaborn as sns
In [21]:
sns.distplot(np.log(scores[scores > 0]))
Out[21]:
We have imported the Agribalyse database. In the process of importing, we found and resolved several problems:
This was a bit of a pain, but this is the sad truth of LCA data compatibility - it currently isn't all that great.
In [0]: