diff --git a/data/Makefile b/data/Makefile index c40b89fb9..6b3a46b93 100644 --- a/data/Makefile +++ b/data/Makefile @@ -41,7 +41,7 @@ delete_method: @$(call DOCKER,python3 common/delete_methods.py) export_food: - @$(call DOCKER,bash -c "python3 food/export.py && npm run processes:build") + @$(call DOCKER,bash -c "python3 food/export.py") compare_food: @$(call DOCKER,python3 export.py compare) diff --git a/data/common/export.py b/data/common/export.py index 9c9f84a29..7327363e7 100644 --- a/data/common/export.py +++ b/data/common/export.py @@ -2,6 +2,8 @@ import functools import json import logging +from collections import OrderedDict +from copy import deepcopy import bw2data from bw2io.utils import activity_hash @@ -22,6 +24,17 @@ def spproject(activity): return "AGB3.1.1 2023-03-06" +def remove_detailed_impacts(processes): + result = list() + for process in processes: + new_process = OrderedDict(deepcopy(process)) + for k in new_process["impacts"].keys(): + if k not in ("pef", "ecs"): + new_process["impacts"][k] = 0 + result.append(new_process) + return result + + def export_json(data, filename): """ Export data to a JSON file, with added newline at the end. diff --git a/data/food/export.py b/data/food/export.py index 03018ee8f..3ceab8112 100644 --- a/data/food/export.py +++ b/data/food/export.py @@ -23,6 +23,7 @@ export_json, load_json, progress_bar, + remove_detailed_impacts, spproject, with_corrected_impacts, with_subimpacts, @@ -58,6 +59,7 @@ "UGB_FILE": f"{PROJECT_ROOT_DIR}/data/food/ecosystemic_services/ugb.csv", "INGREDIENTS_FILE": f"{PROJECT_ROOT_DIR}/public/data/food/ingredients.json", "PROCESSES_FILE": f"{ECOBALYSE_DATA_DIR}/data/food/processes_impacts.json", + "AGGREGATED": f"{PROJECT_ROOT_DIR}/public/data/food/processes.json", "LAND_OCCUPATION_METHOD": ("selected LCI results", "resource", "land occupation"), "GRAPH_FOLDER": f"{PROJECT_ROOT_DIR}/data/food/impact_comparison", } @@ -428,3 +430,7 @@ def csv_export_impact_comparison(compared_impacts): export_json(ingredients_animal_es, CONFIG["INGREDIENTS_FILE"]) display_changes("id", oldprocesses, processes_corrected_impacts) export_json(list(processes_corrected_impacts.values()), CONFIG["PROCESSES_FILE"]) + export_json( + remove_detailed_impacts(list(processes_corrected_impacts.values())), + CONFIG["AGGREGATED"], + )