Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Switch to brightway #822

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions data/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def spproject(activity):
return "ADEME UPR"
case "Woolmark":
return "Woolmark"
case "WFLDB":
return "World Food LCA Database"
case _:
return "AGB3.1.1 2023-03-06"

Expand Down
10 changes: 8 additions & 2 deletions data/common/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def compute_impacts(frozen_processes, default_db, impacts_py):
if not activity:
raise Exception(f"This process was not found in brightway: {process}")

results = compute_simapro_impacts(activity, main_method, impacts_py)
results = None # compute_simapro_impacts(activity, main_method, impacts_py)
# WARNING assume remote is in m3 or MJ (couldn't find unit from COM intf)
if process["unit"] == "kWh" and isinstance(results, dict):
results = {k: v * 3.6 for k, v in results.items()}
Expand Down Expand Up @@ -394,7 +394,13 @@ def find_id(dbname, activity):


def compute_simapro_impacts(activity, method, impacts_py):
strprocess = urllib.parse.quote(activity["name"], encoding=None, errors=None)
name = (
activity["name"]
if spproject(activity) != "World Food LCA Database"
# TODO this should probably done through disabling a strategy
else f"{activity['name']}/{activity['location']} U"
)
strprocess = urllib.parse.quote(name, encoding=None, errors=None)
project = urllib.parse.quote(spproject(activity), encoding=None, errors=None)
method = urllib.parse.quote(main_method, encoding=None, errors=None)
api_request = f"http://simapro.ecobalyse.fr:8000/impact?process={strprocess}&project={project}&method={method}"
Expand Down
2 changes: 1 addition & 1 deletion data/common/import_.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def import_simapro_csv(
zf.extractall(path=tempdir)
unzipped, _ = splitext(join(tempdir, basename(datapath)))

if "AGB" in datapath:
if "AGB3" in datapath:
print("### Patching Agribalyse...")
# `yield` is used as a variable in some Simapro parameters. bw2parameters cannot handle it:
# (sed is faster than Python)
Expand Down
10 changes: 10 additions & 0 deletions data/import_ecoinvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ def organic_cotton_irrigation(db):
STRATEGIES = [organic_cotton_irrigation]


def use_unit_processes(db):
"""the woolmark dataset comes with dependent processes which are set as system processes. EI3.10 has these processes but as unit processes. So we change the name such as the linking be done"""
for ds in db:
for exc in ds["exchanges"]:
if exc["name"].endswith("Cut-off, S"):
exc["name"].replace("Cut-off, S", "Cut-off, U")
return db


def main():
projects.set_current(PROJECT)
# projects.create_project(PROJECT, activate=True, exist_ok=True)
Expand Down Expand Up @@ -79,6 +88,7 @@ def main():
import_simapro_csv(
join("..", "..", "dbfiles", WOOL),
db,
first_strategies=[use_unit_processes],
external_db="Ecoinvent 3.10", # wool is linked with EI 3.10
excluded_strategies=EXCLUDED,
)
Expand Down
Loading