-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_ecoinvent.py
executable file
·102 lines (82 loc) · 2.73 KB
/
import_ecoinvent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
import os
from os.path import join
import bw2data
from common import brightway_patch as brightway_patch
from common.import_ import (
DB_FILES_DIR,
import_simapro_csv,
setup_project,
)
CURRENT_FILE_DIR = os.path.dirname(os.path.realpath(__file__))
# Ecoinvent
EI391 = "./Ecoinvent3.9.1.CSV.zip"
EI310 = "./Ecoinvent3.10.CSV.zip"
WOOL = "./wool.CSV.zip"
EXCLUDED = [
"fix_localized_water_flows", # both agb and ef31 adapted have localized wf
"simapro-water",
]
# Patch for https://github.com/brightway-lca/brightway2-io/pull/283
def lower_formula_parameters(db):
"""lower formula parameters"""
for ds in db:
for k in ds.get("parameters", {}).keys():
if "formula" in ds["parameters"][k]:
ds["parameters"][k]["formula"] = ds["parameters"][k]["formula"].lower()
return db
def organic_cotton_irrigation(db):
"""add irrigation to the organic cotton"""
for ds in db:
if ds.get("simapro metadata", {}).get("Process identifier") in (
"MTE00149000081182217968", # EI 3.9.1
"EI3ARUNI000011519618166", # EI 3.10
):
# add: irrigation//[IN] market for irrigation;m3;0.75;Undefined;0;0;0;;
ds["exchanges"].append(
{
"amount": 0.75,
"categories": ("Materials/fuels",),
"comment": "",
"loc": 0.75,
"name": "irrigation//[IN] market for irrigation",
"negative": False,
"type": "technosphere",
"uncertainty type": 2,
"unit": "cubic meter",
}
)
return db
STRATEGIES = [organic_cotton_irrigation]
def main():
setup_project()
if (db := "Ecoinvent 3.9.1") not in bw2data.databases:
import_simapro_csv(
join(DB_FILES_DIR, EI391),
db,
first_strategies=STRATEGIES,
excluded_strategies=EXCLUDED,
)
else:
print(f"{db} already imported")
if (db := "Ecoinvent 3.10") not in bw2data.databases:
import_simapro_csv(
join(DB_FILES_DIR, EI310),
db,
first_strategies=STRATEGIES,
excluded_strategies=EXCLUDED,
)
else:
print(f"{db} already imported")
if (db := "Woolmark") not in bw2data.databases:
import_simapro_csv(
join(DB_FILES_DIR, WOOL),
db,
external_db="Ecoinvent 3.10", # wool is linked with EI 3.10
first_strategies=[lower_formula_parameters],
excluded_strategies=EXCLUDED,
)
else:
print(f"{db} already imported")
if __name__ == "__main__":
main()