{ "cells": [ { "cell_type": "markdown", "id": "bac3505a5afe8971", "metadata": {}, "source": [ "# Advanced Tutorial\n", "*mescal* is a [Brightway](https://docs.brightway.dev/en/latest/)-powered Python package that helps you to integrate Life-Cycle Assessment (LCA) in your energy system model" ] }, { "cell_type": "markdown", "id": "7c15eb9c8df668d6", "metadata": {}, "source": [ "## Set up" ] }, { "cell_type": "code", "execution_count": 1, "id": "c1a2b2275a9ec01a", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:16:32.299329Z", "start_time": "2025-12-26T17:16:32.234771Z" } }, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "id": "ad6977f1e798f1ba", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:16:56.224368Z", "start_time": "2025-12-26T17:16:32.306331Z" } }, "outputs": [], "source": [ "# Import the required libraries\n", "from mescal import *\n", "import pandas as pd\n", "import bw2data as bd" ] }, { "cell_type": "code", "execution_count": 3, "id": "4cc6dc8c3e2d9486", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:16:58.370193Z", "start_time": "2025-12-26T17:16:57.030269Z" } }, "outputs": [], "source": [ "ecoinvent_version = '3.10.1' # choose the ecoinvent version you wish to use\n", "esm_location = 'CH' # choose the version of energyscope for which you want to generate metrics\n", "esm_year = 2050 # choose the year of the energyscope snapshot model or transition pathway time-step\n", "spatialized_database = True # set to True if you want to use your spatialized version of ecoinvent\n", "regionalize_foregrounds = ['Operation', 'Resource'] # set to 'all' if you want to regionalize the foreground inventories of all types of LCI datasets\n", "premise_iam = 'image' # choose the IAM to which the premise database is linked\n", "premise_ssp_rcp = 'SSP2-RCP26' # choose the SSP/RCP scenario to which the premise database is linked" ] }, { "cell_type": "code", "execution_count": 4, "id": "5ae4be2770b3170d", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:16:59.162041Z", "start_time": "2025-12-26T17:16:59.018261Z" } }, "outputs": [], "source": [ "# Set the name of your main LCI database (e.g., ecoinvent or premise database) here:\n", "name_premise_db = f\"ecoinvent_cutoff_{ecoinvent_version}_{premise_iam}_{premise_ssp_rcp}_{esm_year}\"\n", "name_biosphere_db = 'biosphere3'\n", "if spatialized_database:\n", " name_premise_db += ' regionalized'\n", " name_spatialized_biosphere_db = 'biosphere3_spatialized_flows'\n", "else:\n", " name_spatialized_biosphere_db = None" ] }, { "cell_type": "code", "execution_count": 5, "id": "69fe3b149b828ffd", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:16:59.311486Z", "start_time": "2025-12-26T17:16:59.181563Z" } }, "outputs": [], "source": [ "# Set the name of the new database with the ESM results\n", "esm_db_name = f'EnergyScope_{esm_location}_{esm_year}'" ] }, { "cell_type": "code", "execution_count": 6, "id": "1c3d17576915f094", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:16:59.505008Z", "start_time": "2025-12-26T17:16:59.333538Z" } }, "outputs": [], "source": [ "# Main version of ecoinvent (without .1 if any)\n", "ecoinvent_main_version = '.'.join(ecoinvent_version.split('.')[:2])" ] }, { "cell_type": "code", "execution_count": 7, "id": "5aae3d0d0ec618dd", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:16:59.635648Z", "start_time": "2025-12-26T17:16:59.527485Z" } }, "outputs": [], "source": [ "# Set the list of LCIA methods for which you want indicators (they must be registered in your brightway project)\n", "if spatialized_database:\n", " lcia_methods=[\n", " f'IMPACT World+ Midpoint 2.1_regionalized for ecoinvent v{ecoinvent_main_version}', \n", " f'IMPACT World+ Damage 2.1_regionalized for ecoinvent v{ecoinvent_main_version}',\n", " ]\n", "else:\n", " lcia_methods=[\n", " f'IMPACT World+ Midpoint 2.1 for ecoinvent v{ecoinvent_main_version}', \n", " f'IMPACT World+ Damage 2.1 for ecoinvent v{ecoinvent_main_version}', \n", " f'IMPACT World+ Footprint 2.1 for ecoinvent v{ecoinvent_main_version}', \n", " ]" ] }, { "cell_type": "markdown", "id": "e90719ecb37fefca", "metadata": {}, "source": [ "**Note**: you can download IMPACT World+ methods in your brightway project following this [notebook](https://github.com/matthieu-str/mescal/blob/master/dev/download_impact_world_plus.ipynb). Regionalized versions of ecoinvent and IMPACT World+ methods can be downloaded from this [repository](https://github.com/matthieu-str/Regiopremise)." ] }, { "cell_type": "code", "execution_count": 8, "id": "54ea776e842fae31", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:16:59.972526Z", "start_time": "2025-12-26T17:16:59.656046Z" } }, "outputs": [], "source": [ "# Set up your Brightway project\n", "bd.projects.set_current(f'ecoinvent{ecoinvent_version}') # put the name of your brightway project here" ] }, { "cell_type": "markdown", "id": "9e6d381be9e9eb6d", "metadata": {}, "source": [ "## Load databases" ] }, { "cell_type": "code", "execution_count": 9, "id": "f3ef8feb1e562ab3", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:08.352421Z", "start_time": "2025-12-26T17:16:59.994900Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-12-26 12:17:08,346 - Database - INFO - Loaded ecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 regionalized from pickle!\n" ] } ], "source": [ "premise_db = Database(name_premise_db, create_pickle=True)" ] }, { "cell_type": "code", "execution_count": 10, "id": "e771abcbdc25d432", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:14.952924Z", "start_time": "2025-12-26T17:17:08.386698Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Getting activity data\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 110559/110559 [00:01<00:00, 85887.84it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Adding exchange data to activities\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "0it [00:00, ?it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Filling out exchange data\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 110559/110559 [00:00<00:00, 3465962.51it/s]\n", "2025-12-26 12:17:14,936 - Database - INFO - Loaded biosphere3_spatialized_flows from brightway!\n" ] } ], "source": [ "if regionalize_foregrounds is not None and spatialized_database:\n", " spatialized_biosphere_db = Database(name_spatialized_biosphere_db)\n", "else:\n", " spatialized_biosphere_db = None" ] }, { "cell_type": "markdown", "id": "8325f04c8e08b23f", "metadata": {}, "source": [ "## Your data\n", "For mescal to understand the structure of your energy system model, you need to provide it with a set of dataframes." ] }, { "cell_type": "markdown", "id": "313875e4236bc644", "metadata": {}, "source": [ "### Mandatory dataframes" ] }, { "cell_type": "code", "execution_count": 11, "id": "6890050f93afe1d1", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:15.125387Z", "start_time": "2025-12-26T17:17:14.978789Z" } }, "outputs": [], "source": [ "mapping = pd.read_csv(f'../dev/energyscope_data/{esm_location}/mapping.csv')\n", "unit_conversion = pd.read_csv(f'../dev/energyscope_data/{esm_location}/unit_conversion.csv')\n", "mapping_esm_flows_to_CPC = pd.read_csv(f'../dev/energyscope_data/{esm_location}/mapping_esm_flows_to_CPC.csv')\n", "model = pd.read_csv(f'../dev/energyscope_data/{esm_location}/model.csv')" ] }, { "cell_type": "markdown", "id": "29846070143e8b95", "metadata": {}, "source": [ "A mapping between the energy technologies and resources of the energy system model, and Life-Cycle Inventories datasets (LCI) from an LCI database (e.g., ecoinvent). The mapping should be provided in a dataframe with the following columns:\n", "- `Name`: the name of the energy technology or resource in the energy model \n", "- `Type`: the type of the energy technology or resource (i.e., 'Construction', 'Decommission', 'Operation', 'Resource' or 'Flow')\n", "- `Product`: the name of the product of the energy technology or resource in the LCI database\n", "- `Activity`: the name of the activity of the energy technology or resource in the LCI database\n", "- `Location`: the name of the location of the energy technology or resource in the LCI database\n", "- `Unit`: (optional) the physical unit of the energy technology or resource in the LCI database\n", "- `Database`: the name of the database in your brightway project\n", "\n", "If you wish to change the version of ecoinvent used in your mapping file, you can follow this [notebook](https://github.com/matthieu-str/mescal/blob/master/dev/mapping_ecoinvent_version.ipynb). " ] }, { "cell_type": "code", "execution_count": 12, "id": "642b5fe1b99a6f7f", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:15.336074Z", "start_time": "2025-12-26T17:17:15.178750Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NameTypeProductActivityLocationDatabase
0ALKALINE_ELECTROLYSISOperationhydrogen, gaseous, 20 barhydrogen production, gaseous, 20 bar, from AEC...CHecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 ...
1ALKALINE_ELECTROLYSIS_PLANTConstructionelectrolyzer, 1MWe, AEC, Balance of Plantelectrolyzer production, 1MWe, AEC, Balance of...RERecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 ...
2ALKALINE_ELECTROLYSIS_PLANTDecommissionused fuel cell balance of plant, 1MWe, AECtreatment of fuel cell balance of plant, 1MWe,...RERecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 ...
3ALKALINE_ELECTROLYSIS_STACKConstructionelectrolyzer, 1MWe, AEC, Stackelectrolyzer production, 1MWe, AEC, StackRERecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 ...
4ALKALINE_ELECTROLYSIS_STACKDecommissionused fuel cell stack, 1MWe, AECtreatment of fuel cell stack, 1MWe, AECRERecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 ...
\n", "
" ], "text/plain": [ " Name Type \\\n", "0 ALKALINE_ELECTROLYSIS Operation \n", "1 ALKALINE_ELECTROLYSIS_PLANT Construction \n", "2 ALKALINE_ELECTROLYSIS_PLANT Decommission \n", "3 ALKALINE_ELECTROLYSIS_STACK Construction \n", "4 ALKALINE_ELECTROLYSIS_STACK Decommission \n", "\n", " Product \\\n", "0 hydrogen, gaseous, 20 bar \n", "1 electrolyzer, 1MWe, AEC, Balance of Plant \n", "2 used fuel cell balance of plant, 1MWe, AEC \n", "3 electrolyzer, 1MWe, AEC, Stack \n", "4 used fuel cell stack, 1MWe, AEC \n", "\n", " Activity Location \\\n", "0 hydrogen production, gaseous, 20 bar, from AEC... CH \n", "1 electrolyzer production, 1MWe, AEC, Balance of... RER \n", "2 treatment of fuel cell balance of plant, 1MWe,... RER \n", "3 electrolyzer production, 1MWe, AEC, Stack RER \n", "4 treatment of fuel cell stack, 1MWe, AEC RER \n", "\n", " Database \n", "0 ecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 ... \n", "1 ecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 ... \n", "2 ecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 ... \n", "3 ecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 ... \n", "4 ecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 ... " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mapping.head()" ] }, { "cell_type": "markdown", "id": "c63431e4a57bb29f", "metadata": {}, "source": [ "A set of unit conversion factors between the energy system model and the LCI database. The conversion factors should be provided in a dataframe with the following columns:\n", "- `Name`: the name of the energy technology or resource in the energy system model \n", "- `Type`: the type of the energy technology or resource (i.e., 'Construction', 'Decommission', 'Operation', 'Resource', or 'Other'). Other types can be added to fit your needs. The 'Other' category is meant for the unit conversion that are not specific to a technology or resource, but rather a generic type of product, e.g., conversion from kilogram to kilowatt hour for natural gas.\n", "- `Value`: the numerical value of the conversion factor that will multiply the impact scores. It actually denotes the conversion from Impact / LCA unit to Impact / ESM unit. \n", "- `ESM`: the unit of the energy technology or resource in the ESM\n", "- `LCA`: the target unit of the energy technology or resource in the LCA database\n", "- `Assumptions & Sources` (optional): additional information on the conversion factor.\n", "\n", "The `LCA` and `ESM` columns should respect the ecoinvent naming convention. You may use the `ecoinvent_unit_convention` function to convert the unit naming convention you've used to the one of ecoinvent." ] }, { "cell_type": "code", "execution_count": 13, "id": "40412ea78d6dc8af", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:15.590349Z", "start_time": "2025-12-26T17:17:15.419557Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NameTypeValueLCAESM
0ACETIC_ACIDResource0.247423kilogramkilowatt hour
1ACETONEResource0.121655kilogramkilowatt hour
2ALKALINE_ELECTROLYSISConstruction0.001556unitkilowatt
3ALKALINE_ELECTROLYSISDecommission0.001556unitkilowatt
4ALKALINE_ELECTROLYSISOperation0.030030kilogramkilowatt hour
\n", "
" ], "text/plain": [ " Name Type Value LCA ESM\n", "0 ACETIC_ACID Resource 0.247423 kilogram kilowatt hour\n", "1 ACETONE Resource 0.121655 kilogram kilowatt hour\n", "2 ALKALINE_ELECTROLYSIS Construction 0.001556 unit kilowatt\n", "3 ALKALINE_ELECTROLYSIS Decommission 0.001556 unit kilowatt\n", "4 ALKALINE_ELECTROLYSIS Operation 0.030030 kilogram kilowatt hour" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "unit_conversion.head()" ] }, { "cell_type": "markdown", "id": "b873476e1c532db4", "metadata": {}, "source": [ "A mapping between the energy system model flows and CPC categories. The mapping should be provided in a dataframe with the following columns:\n", "- `Flow`: the name of the flow in the ESM\n", "- `Description`: (optional) the description of the product\n", "- `CPC`: the list of names of corresponding CPC categories" ] }, { "cell_type": "code", "execution_count": 14, "id": "7254119105672bd2", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:15.895912Z", "start_time": "2025-12-26T17:17:15.685954Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FlowDescriptionCPC
0BENZENEBenzene['33100: Coke and semi-coke of coal, of lignit...
1BIO_DIESELBio-diesel['35491: Biodiesel']
2CO2_ACarbon dioxide (concentrated emissions)['34210b: Carbon dioxide and monoxide']
3CO2_CCarbon dioxide (captured)['34210b: Carbon dioxide and monoxide']
4CO2_CSCarbon dioxide (captured & stored)['34210b: Carbon dioxide and monoxide']
\n", "
" ], "text/plain": [ " Flow Description \\\n", "0 BENZENE Benzene \n", "1 BIO_DIESEL Bio-diesel \n", "2 CO2_A Carbon dioxide (concentrated emissions) \n", "3 CO2_C Carbon dioxide (captured) \n", "4 CO2_CS Carbon dioxide (captured & stored) \n", "\n", " CPC \n", "0 ['33100: Coke and semi-coke of coal, of lignit... \n", "1 ['35491: Biodiesel'] \n", "2 ['34210b: Carbon dioxide and monoxide'] \n", "3 ['34210b: Carbon dioxide and monoxide'] \n", "4 ['34210b: Carbon dioxide and monoxide'] " ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mapping_esm_flows_to_CPC.head()" ] }, { "cell_type": "markdown", "id": "639bfa05b6354e4b", "metadata": {}, "source": [ "The input and output flows of energy technologies. For a given technology, the inputs and outputs should be given with the same unit. Also, the main output flow should have 1 as an amount, i.e., all other flows as scaled with respect to the main output. It should be provided in a dataframe with the following columns:\n", "- `Name`: the name of the energy technology in the energy system model\n", "- `Flow`: the name of the input or output flow\n", "- `Amount`: the numerical value of the flow (negative if input, positive if output) " ] }, { "cell_type": "code", "execution_count": 15, "id": "176d23eb6579c212", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:16.193119Z", "start_time": "2025-12-26T17:17:16.060466Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NameFlowAmount
0ACETIC_ACIDACETIC_ACID1.00
1ACETONEACETONE1.00
2ALKALINE_ELECTROLYSISELECTRICITY_HV-1.72
3ALKALINE_ELECTROLYSISH2_MP1.00
4ALKALINE_ELECTROLYSISHEAT_LOW_T_DECEN0.26
\n", "
" ], "text/plain": [ " Name Flow Amount\n", "0 ACETIC_ACID ACETIC_ACID 1.00\n", "1 ACETONE ACETONE 1.00\n", "2 ALKALINE_ELECTROLYSIS ELECTRICITY_HV -1.72\n", "3 ALKALINE_ELECTROLYSIS H2_MP 1.00\n", "4 ALKALINE_ELECTROLYSIS HEAT_LOW_T_DECEN 0.26" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.head()" ] }, { "cell_type": "markdown", "id": "48478041736e84c0", "metadata": {}, "source": [ "### Optional dataframes" ] }, { "cell_type": "code", "execution_count": 16, "id": "dd4f202b4dbb9052", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:16.510236Z", "start_time": "2025-12-26T17:17:16.349776Z" } }, "outputs": [], "source": [ "technology_compositions = pd.read_csv(f'../dev/energyscope_data/{esm_location}/technology_compositions.csv')\n", "technology_specifics = pd.read_csv(f'../dev/energyscope_data/{esm_location}/technology_specifics.csv') \n", "lifetime = pd.read_csv(f'../dev/energyscope_data/{esm_location}/lifetime.csv')\n", "efficiency = pd.read_csv(f'../dev/energyscope_data/{esm_location}/efficiency.csv')\n", "mapping_product_to_CPC = pd.read_csv('../mescal/data/mapping_new_products_to_CPC.csv')\n", "impact_abbrev = pd.read_csv('../dev/lcia/impact_abbrev.csv')\n", "technologies_to_remove_from_layers = pd.read_csv(f'../dev/energyscope_data/{esm_location}/technologies_to_remove_from_layers.csv')\n", "new_end_use_types = pd.read_csv(f'../dev/energyscope_data/{esm_location}/new_end_use_types.csv')\n", "results_from_esm = pd.read_csv(f'../dev/energyscope_data/{esm_location}/results_ES.csv')" ] }, { "cell_type": "markdown", "id": "eee94b00d44a2efa", "metadata": {}, "source": [ "A set of composition of technologies, i.e., if one technology or resource in the energy model should be represented by a combination of LCI datasets. The composition should be provided in a dataframe with the following columns:\n", "- `Name`: the name of the main energy technology or resource in the energy model \n", "- `Components`: the list of names of subcomponents\n", "- `Type` (optional): to distinguish between 'Construction' and 'Decommission' components (if not provided, all components are considered as 'Construction' components)" ] }, { "cell_type": "code", "execution_count": 17, "id": "de810a82e99b68e", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:16.736561Z", "start_time": "2025-12-26T17:17:16.582459Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NameComponentsType
0AN_DIG_SI['AN_DIG_SI_PLANT', 'AN_DIG_SI_COGEN']Construction
1DEC_COGEN_GAS['DEC_COGEN_GAS_CHP', 'DEC_COGEN_GAS_HEAT', 'D...Construction
2DEC_COGEN_OIL['DEC_COGEN_OIL_BOILER', 'DEC_COGEN_OIL_TURBIN...Construction
3DEC_COGEN_WOOD['DEC_COGEN_WOOD_BOILER', 'DEC_COGEN_WOOD_TURB...Construction
4DHN_COGEN_GAS['DHN_COGEN_GAS_CHP', 'DHN_COGEN_GAS_HEAT', 'D...Construction
\n", "
" ], "text/plain": [ " Name Components \\\n", "0 AN_DIG_SI ['AN_DIG_SI_PLANT', 'AN_DIG_SI_COGEN'] \n", "1 DEC_COGEN_GAS ['DEC_COGEN_GAS_CHP', 'DEC_COGEN_GAS_HEAT', 'D... \n", "2 DEC_COGEN_OIL ['DEC_COGEN_OIL_BOILER', 'DEC_COGEN_OIL_TURBIN... \n", "3 DEC_COGEN_WOOD ['DEC_COGEN_WOOD_BOILER', 'DEC_COGEN_WOOD_TURB... \n", "4 DHN_COGEN_GAS ['DHN_COGEN_GAS_CHP', 'DHN_COGEN_GAS_HEAT', 'D... \n", "\n", " Type \n", "0 Construction \n", "1 Construction \n", "2 Construction \n", "3 Construction \n", "4 Construction " ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "technology_compositions.head()" ] }, { "cell_type": "markdown", "id": "7bdd1fc2ddf77780", "metadata": {}, "source": [ "A set of technologies with specific requirements. For instance, this stands for energy technologies without a construction phase, mobility technologies (if mismatch fuel in the LCI dataset), bio-processes (if mismatch fuel in the LCI dataset), etc. The requirements should be provided in a dataframe with the following columns:\n", "- `Name`: the name of the energy technology in the energy model\n", "- `Specifics`: the type of requirement. Can be '**Background search**' (i.e., double-counting removal is run n levels in the background, n being defined in Amount), '**Mobility**' (i.e., EUD types for which associated technologies are characterized as a mobility mean, to further add a FUEL layer), '**No background search**' (i.e., double-counting removal is not applied beyond the activity direct exchanges), '**No double-counting removal**' (i.e., the double-counting removal step is skipped), '**Process**' (i.e., the technology is characterized as an industrial bio-process, to further add a PROCESS_FUEL layer), '**DAC**' (for *premise* DAC technologies, to change the biogenic carbon flow into a fossil one), '**Biofuel**' (i.e., adapt direct emissions to the biofuel input: partially change fossil carbon emissions into biogenic ones), '**Import/Export**' (these activities will keep their original locations and will not be regionalized), '**Carbon flows**' (the direct carbon emissions of these activities will be multiplied by a factor), '**Add CC**' (add a carbon capture process to a technology, and modifies its direct carbon dioxide emissions according to the capture efficiency), '**Add CO2 (flow_type)**' (add a resource/emission flow of CO2 to an activity, flow_type can be 'fossil', 'non-fossil', 'from soil or biomass stock', 'in air', or 'non-fossil, resource correction').\n", "- `Amount`: the numerical value of the requirement (if relevant)" ] }, { "cell_type": "code", "execution_count": 18, "id": "6424ff1019091799", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:16.990669Z", "start_time": "2025-12-26T17:17:16.815022Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NameSpecificsAmountComment
0CO2_TO_JETFUELSBackground search0.0NaN
1CO2-To-DieselBackground search2.0NaN
2CROPS_TO_JETFUELSBackground search4.0NaN
3FTBackground search3.0NaN
4GASIFICATION_SNGBackground search3.0NaN
\n", "
" ], "text/plain": [ " Name Specifics Amount Comment \n", "0 CO2_TO_JETFUELS Background search 0.0 NaN\n", "1 CO2-To-Diesel Background search 2.0 NaN\n", "2 CROPS_TO_JETFUELS Background search 4.0 NaN\n", "3 FT Background search 3.0 NaN\n", "4 GASIFICATION_SNG Background search 3.0 NaN" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "technology_specifics.head()" ] }, { "cell_type": "markdown", "id": "326561ead79cf4c9", "metadata": {}, "source": [ "Energy technologies lifetimes in the ESM and the LCI database. For composition of technologies (if any), the main technology should not have a LCA lifetime (no LCI dataset is associated to it), while the sub-components should not have an ESM lifetime (they do not have a proper technology in the ESM). The lifetimes should be provided in a dataframe with the following columns:\n", "- `Name`: the name of the energy technology in the energy system model\n", "- `ESM`: the numerical value of the lifetime in the energy system model (if relevant)\n", "- `LCA`: the numerical value of the lifetime in the LCI database (if relevant)\n", "- `Comment`: (optional) additional information the `Amount` computation (if relevant)" ] }, { "cell_type": "code", "execution_count": 19, "id": "e268fad4190c4c8a", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:17.344431Z", "start_time": "2025-12-26T17:17:17.176981Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NameESMLCA
0ALKALINE_ELECTROLYSIS10.0NaN
1ALKALINE_ELECTROLYSIS_PLANTNaN20.0
2ALKALINE_ELECTROLYSIS_STACKNaN7.5
3AL_MAKING25.050.0
4AL_MAKING_HR25.050.0
\n", "
" ], "text/plain": [ " Name ESM LCA\n", "0 ALKALINE_ELECTROLYSIS 10.0 NaN\n", "1 ALKALINE_ELECTROLYSIS_PLANT NaN 20.0\n", "2 ALKALINE_ELECTROLYSIS_STACK NaN 7.5\n", "3 AL_MAKING 25.0 50.0\n", "4 AL_MAKING_HR 25.0 50.0" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lifetime.head()" ] }, { "cell_type": "markdown", "id": "be443561d3ffbf43", "metadata": {}, "source": [ "If you want to account for the possible efficiency differences between the ESM and the LCI datasets, you can provide a set of (technologies, flow) couples for which efficiency differences will be corrected by the scaling the elementary flows. Taking the example of the diesel car, the couple should be something like ('CAR_DIESEL', 'DIESEL'), the flow being the fuel of the technology responsible for direct emissions. Relevant biosphere flows will be the ratio between the LCA and ESM efficiencies. The (technology, flow) couples should be provided in a dataframe with the following columns:\n", "- `Name`: the name of the energy technology in the ESM\n", "- `Flow`: the name of the flow in the ESM\n", "- `Comment`: (optional) additional information on the set of `Flows`" ] }, { "cell_type": "code", "execution_count": 20, "id": "ebdf65eaa517f199", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:17.622460Z", "start_time": "2025-12-26T17:17:17.483515Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NameFlowComment
0AN_DIG['WET_BIOMASS']NaN
1AN_DIG_SI['WET_BIOMASS']NaN
2BUS_CNG_STOICH['NG_HP']NaN
3BUS_DIESEL['DIESEL']NaN
4BUS_FC_HYBRID_CH4['NG_HP']NaN
\n", "
" ], "text/plain": [ " Name Flow Comment\n", "0 AN_DIG ['WET_BIOMASS'] NaN\n", "1 AN_DIG_SI ['WET_BIOMASS'] NaN\n", "2 BUS_CNG_STOICH ['NG_HP'] NaN\n", "3 BUS_DIESEL ['DIESEL'] NaN\n", "4 BUS_FC_HYBRID_CH4 ['NG_HP'] NaN" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "efficiency.head()" ] }, { "cell_type": "markdown", "id": "330ee60ba864372a", "metadata": {}, "source": [ "In case you have a LCI database (partially) without CPC categories (which are necessary for the double-counting check), you can provide a mapping between the products and activities in the LCI database and the CPC categories. The mapping should be provided in a dataframe with the following columns:\n", "- `Name`: the full or partial name of the product or activity in the LCI database\n", "- `CPC`: the number and name of the corresponding CPC category\n", "- `Search type`: can be 'equals' if the `Name` entry is an exactly the name to look for, or 'contains' if it is contained in the full name\n", "- `Where`: can be 'Product' or 'Activity', whether the `Name` entry is meant for products or activities" ] }, { "cell_type": "code", "execution_count": 21, "id": "253e3eafb347c0af", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:17.942493Z", "start_time": "2025-12-26T17:17:17.794529Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NameCPCSearch typeWhere
0amine-based silica35310: Organic surface active agents, except soapequalsProduct
1biodiesel35491: BiodieselcontainsProduct
2biogas17200: Coal gas, water gas, producer gas and s...equalsProduct
3biomass, used as fuel31230: Wood in chips or particlesequalsProduct
4biomethane, from biogas upgrading, using amine...12020: Natural gas, liquefied or in the gaseou...equalsProduct
\n", "
" ], "text/plain": [ " Name \\\n", "0 amine-based silica \n", "1 biodiesel \n", "2 biogas \n", "3 biomass, used as fuel \n", "4 biomethane, from biogas upgrading, using amine... \n", "\n", " CPC Search type Where \n", "0 35310: Organic surface active agents, except soap equals Product \n", "1 35491: Biodiesel contains Product \n", "2 17200: Coal gas, water gas, producer gas and s... equals Product \n", "3 31230: Wood in chips or particles equals Product \n", "4 12020: Natural gas, liquefied or in the gaseou... equals Product " ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mapping_product_to_CPC.head()" ] }, { "cell_type": "markdown", "id": "b5da46d185c9766f", "metadata": {}, "source": [ "An abbreviation scheme for the impact categories you aim to work with, to ease the readability in the ESM. The one of IMPACT World+ is available in this [csv file](https://github.com/matthieu-str/mescal/blob/master/dev/lcia/impact_abbrev.csv). The abbreviations should be provided in a dataframe with the following columns:\n", "- `Impact_category`: the name of the impact category, expressed as a tuple following brightway convention\n", "- `Unit`: (optional) the unit of the impact category\n", "- `Abbrev`: the abbreviation of the impact category\n", "- `AoP`: the area of protection of the impact category. The normalization of indicators will be performed based of AoPs. If you do not have AoPs (e.g., midpoint-level indicators), set as many AoPs as you have impact categories." ] }, { "cell_type": "code", "execution_count": 22, "id": "a3da253e1403384a", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:18.233204Z", "start_time": "2025-12-26T17:17:18.102714Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Impact_categoryUnitAbbrevAoP
0('IMPACT World+ Damage 2.0.1', 'Ecosystem qual...PDF.m2.yrCCEQLEQ
1('IMPACT World+ Damage 2.0.1', 'Ecosystem qual...PDF.m2.yrCCEQSEQ
2('IMPACT World+ Damage 2.0.1', 'Ecosystem qual...PDF.m2.yrCCEQLBEQ
3('IMPACT World+ Damage 2.0.1', 'Ecosystem qual...PDF.m2.yrCCEQSBEQ
4('IMPACT World+ Damage 2.0.1', 'Human health',...DALYCCHHLHH
\n", "
" ], "text/plain": [ " Impact_category Unit Abbrev AoP\n", "0 ('IMPACT World+ Damage 2.0.1', 'Ecosystem qual... PDF.m2.yr CCEQL EQ\n", "1 ('IMPACT World+ Damage 2.0.1', 'Ecosystem qual... PDF.m2.yr CCEQS EQ\n", "2 ('IMPACT World+ Damage 2.0.1', 'Ecosystem qual... PDF.m2.yr CCEQLB EQ\n", "3 ('IMPACT World+ Damage 2.0.1', 'Ecosystem qual... PDF.m2.yr CCEQSB EQ\n", "4 ('IMPACT World+ Damage 2.0.1', 'Human health',... DALY CCHHL HH" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "impact_abbrev.head()" ] }, { "cell_type": "markdown", "id": "eb16bb1f7309ca37", "metadata": {}, "source": [ "In case you want to remove some energy technologies from energy layers in the results LCI datasets to be added to the LCI database, you can provide a list of technologies to remove. The list should be provided in a dataframe with the following columns:\n", "- `Layers`: name of the layer(s). A layer is basically an energy vector, which is an output for some energy technologies and an input for some others. \n", "- `Technologies`: the name of the energy technology to remove from the layer(s)\n", "- `Comment`: (optional) a comment on the removal" ] }, { "cell_type": "code", "execution_count": 23, "id": "846d3b9a433837cb", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:18.499412Z", "start_time": "2025-12-26T17:17:18.369759Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
LayersTechnologiesComment
0['ELECTRICITY_EHV', 'ELECTRICITY_HV']['TRAFO_HE','TRAFO_EH']The high and extra high voltage electricity ar...
1['ELECTRICITY_LV']['STO_ELEC']The storage technologies should be removed (pr...
2['NG_HP', 'NG_EHP']['NG_EXP_EH', 'NG_EXP_EH_COGEN', 'NG_COMP_HE',...The high and extra high pressure natural gas a...
3['H2_LP', 'H2_MP', 'H2_HP', 'H2_EHP']['H2_COMP_HE', 'H2_COMP_MH', 'H2_COMP_LM', 'H2...All pressure levels for hydrogen are merged in...
4['HEAT_HIGH_T', 'HEAT_LOW_T_DHN']['HT_LT']The high and low heat production at the DHN le...
\n", "
" ], "text/plain": [ " Layers \\\n", "0 ['ELECTRICITY_EHV', 'ELECTRICITY_HV'] \n", "1 ['ELECTRICITY_LV'] \n", "2 ['NG_HP', 'NG_EHP'] \n", "3 ['H2_LP', 'H2_MP', 'H2_HP', 'H2_EHP'] \n", "4 ['HEAT_HIGH_T', 'HEAT_LOW_T_DHN'] \n", "\n", " Technologies \\\n", "0 ['TRAFO_HE','TRAFO_EH'] \n", "1 ['STO_ELEC'] \n", "2 ['NG_EXP_EH', 'NG_EXP_EH_COGEN', 'NG_COMP_HE',... \n", "3 ['H2_COMP_HE', 'H2_COMP_MH', 'H2_COMP_LM', 'H2... \n", "4 ['HT_LT'] \n", "\n", " Comment \n", "0 The high and extra high voltage electricity ar... \n", "1 The storage technologies should be removed (pr... \n", "2 The high and extra high pressure natural gas a... \n", "3 All pressure levels for hydrogen are merged in... \n", "4 The high and low heat production at the DHN le... " ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "technologies_to_remove_from_layers.head()" ] }, { "cell_type": "markdown", "id": "c1f82852ad4b7e07", "metadata": {}, "source": [ "If you want to reformat your end-use types (e.g., output layer) in order to better fit the LCI database, you can provide a list of new end-use types. The list should be provided in a dataframe with the following columns:\n", "- `Name`: name of technologies for which the end-use type should be changed\n", "- `Search type`: whether the `Name` entry is an exactly the name to look for ('equals'), is contained in the full name ('contains'), or is the beginning of the full name ('startswith')\n", "- `Old`: the current end-use type\n", "- `New`: the new end-use type" ] }, { "cell_type": "code", "execution_count": 24, "id": "f6634cc71a6b13d", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:18.796559Z", "start_time": "2025-12-26T17:17:18.642164Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NameSearch typeOldNew
0BUSstartswithMOB_PUBLICMOB_PUBLIC_BUS
1SCHOOLBUSstartswithMOB_PUBLICMOB_PUBLIC_SCHOOLBUS
2COACHstartswithMOB_PUBLICMOB_PUBLIC_COACH
3TRAINstartswithMOB_PUBLICMOB_PUBLIC_TRAIN
4CARstartswithMOB_PRIVATEMOB_PRIVATE_CAR
\n", "
" ], "text/plain": [ " Name Search type Old New\n", "0 BUS startswith MOB_PUBLIC MOB_PUBLIC_BUS\n", "1 SCHOOLBUS startswith MOB_PUBLIC MOB_PUBLIC_SCHOOLBUS\n", "2 COACH startswith MOB_PUBLIC MOB_PUBLIC_COACH\n", "3 TRAIN startswith MOB_PUBLIC MOB_PUBLIC_TRAIN\n", "4 CAR startswith MOB_PRIVATE MOB_PRIVATE_CAR" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_end_use_types.head()" ] }, { "cell_type": "markdown", "id": "edecc3e872780922", "metadata": {}, "source": [ "If you want to inject the results of your ESM back in the LCI database, you should provide the results in a dataframe with the following columns:\n", "- `Name`: the name of the energy technology in the ESM\n", "- `Production`: the annual production value of the energy technology in the ESM. All values should be provided with the same unit.\n", "- `Capacity`: the installed capacity of the energy technology in the ESM. All values should be provided with the same unit.\n", "- `Year`: the year of the ESM snapshot or transition pathway time-step.\n", "- `Year_inst`: the year of installation of the energy technology. This is only required for `PathwayESM` if `operation_metrics_for_all_time_steps` is True." ] }, { "cell_type": "code", "execution_count": 25, "id": "39fc1572bfbdc36d", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:19.072893Z", "start_time": "2025-12-26T17:17:18.944505Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NameProductionCapacityYearYear_inst
0CAR_BEV_MEDRANGE_LOCAL44880.000005.12328820202020
1CAR_BEV_MEDRANGE_LONGD29920.000003.41552520202020
2CCGT_CC1622.231450.21786620202020
3COACH_EV17952.000002.04931520202020
4COMMUTER_RAIL_ELEC44880.000005.12328820202020
\n", "
" ], "text/plain": [ " Name Production Capacity Year Year_inst\n", "0 CAR_BEV_MEDRANGE_LOCAL 44880.00000 5.123288 2020 2020\n", "1 CAR_BEV_MEDRANGE_LONGD 29920.00000 3.415525 2020 2020\n", "2 CCGT_CC 1622.23145 0.217866 2020 2020\n", "3 COACH_EV 17952.00000 2.049315 2020 2020\n", "4 COMMUTER_RAIL_ELEC 44880.00000 5.123288 2020 2020" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results_from_esm.head()" ] }, { "cell_type": "markdown", "id": "9ab87522b2705c27", "metadata": {}, "source": [ "### Optional geographical data" ] }, { "cell_type": "code", "execution_count": 26, "id": "145d3b7fdc23fcc9", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:19.314010Z", "start_time": "2025-12-26T17:17:19.202653Z" } }, "outputs": [], "source": [ "# sufficient match within ecoinvent\n", "if esm_location == 'CA-QC':\n", " accepted_locations = ['CA-QC', 'CA']\n", "elif esm_location == 'CH':\n", " accepted_locations = ['CH']\n", "elif esm_location == 'core':\n", " accepted_locations = ['RER', 'WEU', 'EUR']\n", "else:\n", " accepted_locations = ['GLO', 'RoW']" ] }, { "cell_type": "code", "execution_count": 27, "id": "b27bcbc91b924324", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:19.474246Z", "start_time": "2025-12-26T17:17:19.325611Z" } }, "outputs": [], "source": [ "# Define the user-defined ranking\n", "if esm_location == 'CA-QC':\n", " my_ranking = [\n", " 'CA-QC', # Quebec\n", " 'CA', # Canada\n", " 'CAN', # Canada in IMAGE\n", " 'CAZ', # Canada - Australia - New Zealand in REMIND\n", " 'RNA', # North America\n", " 'US', # United States\n", " 'USA', # United States in REMIND and IMAGE\n", " 'GLO', # Global average \n", " 'RoW', # Rest of the world\n", " ]\n", "elif esm_location == 'CH':\n", " my_ranking = [\n", " 'CH',\n", " 'NEU',\n", " 'EUR',\n", " 'WEU',\n", " 'RER', \n", " 'IAI Area, EU27 & EFTA',\n", " 'GLO',\n", " 'RoW'\n", " ]\n", "elif esm_location == 'core':\n", " my_ranking = [\n", " 'RER',\n", " 'WEU',\n", " 'EUR',\n", " 'IAI Area, EU27 & EFTA',\n", " 'CH',\n", " 'BE',\n", " 'IT',\n", " 'GLO',\n", " 'RoW',\n", " ]\n", "else:\n", " my_ranking = [\n", " 'GLO',\n", " 'RoW',\n", " ]" ] }, { "cell_type": "markdown", "id": "93d4cc0ac977b2e1", "metadata": {}, "source": [ "## Create a new database with additional CPC categories (optional)\n", "In case you are working with a LCI database without CPC categories, you can create a new database with the CPC categories. The function `create_new_database_with_CPC_categories` takes as input the database with missing CPC categories, the name of the new database, and a mapping between the products and activities in the LCI database and the CPC categories. It creates a new database with the CPC categories. This step can take a few minutes depending on the size of the database." ] }, { "cell_type": "code", "execution_count": 28, "id": "4cd76ab14b74aed2", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:22.310254Z", "start_time": "2025-12-26T17:17:19.544867Z" } }, "outputs": [], "source": [ "# If necessary, add missing CPC categories to the database\n", "premise_db.add_CPC_categories(overwrite_existing_CPC=True)" ] }, { "cell_type": "markdown", "id": "c851693f8d9c7470", "metadata": {}, "source": [ "## Initialize the ESM database" ] }, { "cell_type": "code", "execution_count": 29, "id": "15dfcd77f62765b9", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:22.503682Z", "start_time": "2025-12-26T17:17:22.391836Z" } }, "outputs": [], "source": [ "mapping.Database = name_premise_db" ] }, { "cell_type": "code", "execution_count": 30, "id": "1a94b922a1fff43", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:22.633530Z", "start_time": "2025-12-26T17:17:22.508514Z" } }, "outputs": [], "source": [ "esm = ESM(\n", " # Mandatory inputs\n", " mapping=mapping,\n", " unit_conversion=unit_conversion,\n", " model=model,\n", " mapping_esm_flows_to_CPC_cat=mapping_esm_flows_to_CPC,\n", " main_database=premise_db,\n", " esm_db_name=esm_db_name,\n", " biosphere_db_name=name_biosphere_db,\n", " esm_location=esm_location if esm_location != 'core' else 'RER',\n", "\n", " # Optional inputs\n", " technology_compositions=technology_compositions,\n", " tech_specifics=technology_specifics,\n", " lifetime=lifetime,\n", " efficiency=efficiency,\n", " regionalize_foregrounds=regionalize_foregrounds,\n", " accepted_locations=accepted_locations,\n", " locations_ranking=my_ranking,\n", " spatialized_biosphere_db=spatialized_biosphere_db,\n", " results_path_file=f'results/energyscope_{esm_location}/{esm_year}/',\n", " remove_double_counting_to=['Operation', 'Construction'],\n", " extract_eol_from_construction=True,\n", " stop_background_search_when_first_flow_found=True,\n", ")" ] }, { "cell_type": "markdown", "id": "fdff9a72e4fbf70a", "metadata": {}, "source": [ "## Add or replace the location column based on a user-defined ranking (optional)\n", "Based on a user-defined ranking, the location column of the mapping dataframe can be updated. The function `change_location_mapping_file` takes as input the mapping dataframe, the user-defined ranking, and the base database. It returns the mapping dataframe with the location column updated." ] }, { "cell_type": "code", "execution_count": 31, "id": "cb4951f2d751a738", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:27.623120Z", "start_time": "2025-12-26T17:17:22.655217Z" } }, "outputs": [], "source": [ "# Update mapping dataframe with better locations\n", "esm.change_location_mapping_file()" ] }, { "cell_type": "code", "execution_count": 32, "id": "b0f1a09451388efa", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:27.824543Z", "start_time": "2025-12-26T17:17:27.644446Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-12-26 12:17:27,811 - Database - INFO - Mapping successfully linked to the database\n" ] }, { "data": { "text/plain": [ "[]" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "esm.main_database.test_mapping_file(esm.mapping)" ] }, { "cell_type": "markdown", "id": "9ccd735a29c943e1", "metadata": {}, "source": [ "## Perform basic tests on input data" ] }, { "cell_type": "code", "execution_count": 33, "id": "a5fad690e5cfe349", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:27.972680Z", "start_time": "2025-12-26T17:17:27.844180Z" } }, "outputs": [], "source": [ "esm.clean_inputs()" ] }, { "cell_type": "code", "execution_count": 34, "id": "22b602d98c6ca04", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:28.388515Z", "start_time": "2025-12-26T17:17:28.001533Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-12-26 12:17:28,178 - Mescal - WARNING - List of technologies or resources that are in the model file but not in the mapping file. Their impact scores will be set to the default value: ['CARBON_CAPTURE', 'CO2_CS', 'CO2_E', 'DEC_RENOVATION', 'DHN_RENOVATION', 'DIESEL_S', 'ELEC_S', 'GASOLINE_S', 'H2_S', 'HT_LT', 'LT_DEC_WH', 'LT_DHN_WH', 'NG_S', 'PLANE', 'RES_GEO', 'RES_HYDRO', 'RES_SOLAR', 'RES_WIND', 'STO_CO2', 'STO_DIE', 'STO_ELEC', 'STO_GASO', 'STO_H2', 'STO_NG']\n", "2025-12-26 12:17:28,195 - Mescal - WARNING - List of technologies or resources that are in the mapping file but not in the model file (this will not be a problem in the workflow): ['BATTERY', 'CAR_BEV_LOWRANGE', 'CAR_DME_D10_LOCAL', 'CAR_DME_D10_LONGD', 'DEC_TH_STORAGE', 'DHN_TH_STORAGE', 'EHP_H2_GRID', 'EHP_NG_GRID', 'EHV_GRID', 'HP_H2_GRID', 'HP_NG_GRID', 'HV_GRID', 'LP_H2_GRID', 'LP_NG_GRID', 'LV_GRID', 'MP_H2_GRID', 'MP_NG_GRID', 'MV_GRID']\n", "2025-12-26 12:17:28,320 - Mescal - WARNING - List of flows that are in the mapping file but not in the unit conversion file. It might be an issue if unit conversions are required during the efficiency correction step: ['ALUMINUM', 'FOOD', 'HEAT_LOW_T_DECEN', 'HEAT_LOW_T_DHN', 'MOB_FREIGHT_LCV', 'MOB_FREIGHT_SEMI', 'MOB_FREIGHT_TRAIN', 'MOB_FREIGHT_TRUCK', 'MOB_PRIVATE_CAR', 'MOB_PRIVATE_SUV', 'MOB_PUBLIC_BUS', 'MOB_PUBLIC_COACH', 'MOB_PUBLIC_TRAIN', 'PAPER', 'STEEL', 'XYLENE']\n", "2025-12-26 12:17:28,345 - Mescal - WARNING - Some technologies have no lifetime value for LCA in the lifetime file. Therefore, lifetime harmonization with the ESM will not be performed during the LCIA phase and capacity factor harmonization during the feedback of ESM results will not be performed either for those technologies: ['BATTERY', 'DEC_DIRECT_ELEC', 'DEC_SOLAR', 'DEEP_SALINE', 'DHN_DEEP_GEO', 'DIRECT_USAGE', 'DOGR', 'EHP_H2_GRID', 'ELEC_STO', 'EOR', 'GEOTHERMAL', 'H2_EXP_EH', 'H2_EXP_EH_COGEN', 'H2_EXP_HM', 'H2_EXP_HM_COGEN', 'H2_EXP_ML', 'H2_EXP_ML_COGEN', 'HP_H2_GRID', 'IND_DIRECT_ELEC', 'LP_H2_GRID', 'MINES_STORAGE', 'MP_H2_GRID', 'NG_COMP_HE', 'NG_COMP_LM', 'NG_COMP_MH', 'NG_EXP_EH', 'NG_EXP_EH_COGEN', 'NG_EXP_HM', 'NG_EXP_HM_COGEN', 'NG_EXP_ML', 'NG_EXP_ML_COGEN', 'TRAFO_EH', 'TRAFO_HE', 'TRAFO_HM', 'TRAFO_LM', 'TRAFO_MH', 'TRAFO_ML', 'UNMINEABLE_COAL_SEAM']\n", "2025-12-26 12:17:28,367 - Mescal - WARNING - List of technologies that are in the tech_specifics file but not in the mapping file (this will not be a problem in the workflow): ['MOB_AVIATION', 'MOB_FREIGHT_RAIL', 'MOB_FREIGHT_ROAD', 'MOB_PRIVATE_LOCAL', 'MOB_PRIVATE_LONGD', 'MOB_PUBLIC_LOCAL', 'MOB_PUBLIC_LONGD']\n" ] } ], "source": [ "esm.check_inputs()" ] }, { "cell_type": "markdown", "id": "4d25a01896041d53", "metadata": {}, "source": [ "## Create ESM database after double-counting removal, efficiency harmonization, and lifetime harmonization" ] }, { "cell_type": "code", "execution_count": 35, "id": "dcb433d280e724c4", "metadata": { "ExecuteTime": { "end_time": "2025-12-23T20:32:03.636854Z", "start_time": "2025-12-23T20:26:08.818569Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-12-23 15:26:47,629 - Mescal - INFO - Starting to remove double-counted flows\n", "100%|██████████| 215/215 [00:00<00:00, 731.76it/s]\n", "2025-12-23 15:26:53,584 - Mescal - WARNING - No location found in your ranking for (natural gas, liquefied, natural gas production, liquefied) in the database ecoinvent_cutoff_3.10.1_image_SSP2-RCP26_2050 regionalized. Have to keep the initial location: EG\n", "100%|██████████| 181/181 [01:48<00:00, 1.68it/s]\n", "2025-12-23 15:30:01,870 - Mescal - INFO - Double-counting removal done in 194.2 seconds\n", "2025-12-23 15:30:02,582 - Mescal - INFO - Starting to correct efficiency differences\n", "2025-12-23 15:30:03,021 - Mescal - WARNING - No flow found for type(s) ['NG_HP'] in BUS_FC_HYBRID_CH4. The efficiency of this technology cannot be adjusted.\n", "2025-12-23 15:30:03,353 - Mescal - WARNING - No flow found for type(s) ['NG_HP'] in CAR_FC_CH4_LOCAL. The efficiency of this technology cannot be adjusted.\n", "2025-12-23 15:30:03,433 - Mescal - WARNING - No flow found for type(s) ['NG_HP'] in CAR_FC_CH4_LONGD. The efficiency of this technology cannot be adjusted.\n", "2025-12-23 15:30:04,240 - Mescal - WARNING - No flow found for type(s) ['NG_HP'] in COACH_FC_HYBRID_CH4. The efficiency of this technology cannot be adjusted.\n", "2025-12-23 15:30:05,228 - Mescal - WARNING - No flow found for type(s) ['WASTE'] in DHN_COGEN_WASTE. The efficiency of this technology cannot be adjusted.\n", "2025-12-23 15:30:05,701 - Mescal - WARNING - No flow found for type(s) ['WASTE'] in IND_BOILER_WASTE. The efficiency of this technology cannot be adjusted.\n", "2025-12-23 15:30:05,844 - Mescal - WARNING - No flow found for type(s) ['WASTE'] in IND_COGEN_WASTE. The efficiency of this technology cannot be adjusted.\n", "2025-12-23 15:30:06,097 - Mescal - WARNING - No flow found for type(s) ['WOOD'] in PYROLYSIS. The efficiency of this technology cannot be adjusted.\n", "2025-12-23 15:30:06,297 - Mescal - WARNING - No flow found for type(s) ['NG_HP'] in TRAIN_FREIGHT_NG. The efficiency of this technology cannot be adjusted.\n", "2025-12-23 15:30:06,361 - Mescal - WARNING - No flow found for type(s) ['NG_HP'] in TRAIN_NG. The efficiency of this technology cannot be adjusted.\n", "2025-12-23 15:30:09,783 - Mescal - INFO - Efficiency differences corrected in 7.2 seconds\n", "2025-12-23 15:30:16,960 - Mescal - WARNING - Several names possible for the same type of flow in POLYPROPYLENE_PP: {'propylene', 'ethylene'}. Kept the first one.\n", "2025-12-23 15:30:18,367 - Mescal - INFO - Starting to write database\n", "Writing activities to SQLite3 database:\n", "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:00\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Title: Writing activities to SQLite3 database:\n", " Started: 12/23/2025 15:30:41\n", " Finished: 12/23/2025 15:30:42\n", " Total time elapsed: 00:00:00\n", " CPU %: 89.10\n", " Memory %: 7.13\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2025-12-23 15:31:59,168 - Database - INFO - EnergyScope_CH_2050_Test written to Brightway!\n", "2025-12-23 15:31:59,825 - Mescal - INFO - Database written in 101.5 seconds\n" ] } ], "source": [ "esm.create_esm_database()" ] }, { "cell_type": "markdown", "id": "6b4cb46fb46fc271", "metadata": {}, "source": [ "## Computing the LCA metrics" ] }, { "cell_type": "code", "execution_count": 36, "id": "e302b5dffde9e360", "metadata": { "ExecuteTime": { "end_time": "2025-12-23T20:33:36.541378Z", "start_time": "2025-12-23T20:32:03.699794Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Getting activity data\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 880/880 [00:00<00:00, 87082.40it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Adding exchange data to activities\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 14620/14620 [00:04<00:00, 3287.59it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Filling out exchange data\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 880/880 [00:01<00:00, 477.34it/s]\n", "2025-12-23 15:32:10,326 - Database - INFO - Loaded EnergyScope_CH_2050_Test from brightway!\n", "Writing activities to SQLite3 database:\n", "0% [##############################] 100% | ETA: 00:00:00\n", "Total time elapsed: 00:00:00\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Title: Writing activities to SQLite3 database:\n", " Started: 12/23/2025 15:32:33\n", " Finished: 12/23/2025 15:32:33\n", " Total time elapsed: 00:00:00\n", " CPU %: 78.70\n", " Memory %: 12.36\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2025-12-23 15:33:33,577 - Database - INFO - EnergyScope_CH_2050_Test_direct_emissions written to Brightway!\n", "181it [00:01, 116.03it/s]\n" ] } ], "source": [ "R_long_direct_emissions, _, _ = esm.compute_impact_scores(\n", " methods=lcia_methods,\n", " assessment_type='direct emissions',\n", " overwrite=True,\n", ")" ] }, { "cell_type": "code", "execution_count": 37, "id": "fea7a22995ed8628", "metadata": { "ExecuteTime": { "end_time": "2025-12-23T20:33:36.817643Z", "start_time": "2025-12-23T20:33:36.589998Z" } }, "outputs": [], "source": [ "R_long_direct_emissions.to_csv(f'results/energyscope_{esm_location}/{esm_year}/impact_scores_direct_emissions.csv', index=False)" ] }, { "cell_type": "code", "execution_count": 38, "id": "9fb9a39a727e6325", "metadata": { "ExecuteTime": { "end_time": "2025-12-23T20:33:36.957290Z", "start_time": "2025-12-23T20:33:36.829484Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Impact_categoryNew_codeValueNameTypeImpact_category (level 0)Impact_category (level 1)Impact_category (level 2)Impact_category_unitFunctional unit
0(IMPACT World+ Midpoint 2.1_regionalized for e...bhststsh7mmysi4fyiexddlpcxqvck5g0.0ALKALINE_ELECTROLYSISOperationIMPACT World+ Midpoint 2.1_regionalized for ec...MidpointClimate change, long termkg CO2 eq (long)kilowatt hour
1(IMPACT World+ Midpoint 2.1_regionalized for e...bhststsh7mmysi4fyiexddlpcxqvck5g0.0ALKALINE_ELECTROLYSISOperationIMPACT World+ Midpoint 2.1_regionalized for ec...MidpointClimate change, short termkg CO2 eq (short)kilowatt hour
2(IMPACT World+ Midpoint 2.1_regionalized for e...bhststsh7mmysi4fyiexddlpcxqvck5g0.0ALKALINE_ELECTROLYSISOperationIMPACT World+ Midpoint 2.1_regionalized for ec...MidpointFossil and nuclear energy useMJ deprivedkilowatt hour
3(IMPACT World+ Midpoint 2.1_regionalized for e...bhststsh7mmysi4fyiexddlpcxqvck5g0.0ALKALINE_ELECTROLYSISOperationIMPACT World+ Midpoint 2.1_regionalized for ec...MidpointFreshwater acidificationkg SO2 eqkilowatt hour
4(IMPACT World+ Midpoint 2.1_regionalized for e...bhststsh7mmysi4fyiexddlpcxqvck5g0.0ALKALINE_ELECTROLYSISOperationIMPACT World+ Midpoint 2.1_regionalized for ec...MidpointFreshwater ecotoxicityCTUekilowatt hour
\n", "
" ], "text/plain": [ " Impact_category \\\n", "0 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "1 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "2 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "3 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "4 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "\n", " New_code Value Name Type \\\n", "0 bhststsh7mmysi4fyiexddlpcxqvck5g 0.0 ALKALINE_ELECTROLYSIS Operation \n", "1 bhststsh7mmysi4fyiexddlpcxqvck5g 0.0 ALKALINE_ELECTROLYSIS Operation \n", "2 bhststsh7mmysi4fyiexddlpcxqvck5g 0.0 ALKALINE_ELECTROLYSIS Operation \n", "3 bhststsh7mmysi4fyiexddlpcxqvck5g 0.0 ALKALINE_ELECTROLYSIS Operation \n", "4 bhststsh7mmysi4fyiexddlpcxqvck5g 0.0 ALKALINE_ELECTROLYSIS Operation \n", "\n", " Impact_category (level 0) \\\n", "0 IMPACT World+ Midpoint 2.1_regionalized for ec... \n", "1 IMPACT World+ Midpoint 2.1_regionalized for ec... \n", "2 IMPACT World+ Midpoint 2.1_regionalized for ec... \n", "3 IMPACT World+ Midpoint 2.1_regionalized for ec... \n", "4 IMPACT World+ Midpoint 2.1_regionalized for ec... \n", "\n", " Impact_category (level 1) Impact_category (level 2) \\\n", "0 Midpoint Climate change, long term \n", "1 Midpoint Climate change, short term \n", "2 Midpoint Fossil and nuclear energy use \n", "3 Midpoint Freshwater acidification \n", "4 Midpoint Freshwater ecotoxicity \n", "\n", " Impact_category_unit Functional unit \n", "0 kg CO2 eq (long) kilowatt hour \n", "1 kg CO2 eq (short) kilowatt hour \n", "2 MJ deprived kilowatt hour \n", "3 kg SO2 eq kilowatt hour \n", "4 CTUe kilowatt hour " ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "R_long_direct_emissions.head()" ] }, { "cell_type": "code", "execution_count": 39, "id": "eec23a6fa77a5fb8", "metadata": { "ExecuteTime": { "end_time": "2025-12-23T20:39:39.104170Z", "start_time": "2025-12-23T20:33:37.102605Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Getting activity data\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 880/880 [00:00<00:00, 124271.49it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Adding exchange data to activities\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 14620/14620 [00:00<00:00, 35325.79it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Filling out exchange data\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 880/880 [00:01<00:00, 658.70it/s] \n", "2025-12-23 15:33:39,074 - Database - INFO - Loaded EnergyScope_CH_2050_Test from brightway!\n", "596it [05:54, 1.68it/s]\n" ] } ], "source": [ "R_long, contrib_analysis_res, _ = esm.compute_impact_scores(\n", " methods=lcia_methods,\n", " contribution_analysis='both',\n", ")" ] }, { "cell_type": "code", "execution_count": 40, "id": "287129cdf4552801", "metadata": { "ExecuteTime": { "end_time": "2025-12-23T20:39:42.904981Z", "start_time": "2025-12-23T20:39:39.309643Z" } }, "outputs": [], "source": [ "R_long.to_csv(f'results/energyscope_{esm_location}/{esm_year}/impact_scores.csv', index=False)\n", "contrib_analysis_res.to_csv(f'results/energyscope_{esm_location}/{esm_year}/contribution_analysis.csv', index=False)" ] }, { "cell_type": "code", "execution_count": 41, "id": "ca731ef9eda9ba66", "metadata": { "ExecuteTime": { "end_time": "2025-12-23T20:39:43.041752Z", "start_time": "2025-12-23T20:39:42.913480Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Impact_categoryNew_codeValueNameTypeImpact_category (level 0)Impact_category (level 1)Impact_category (level 2)Impact_category_unitFunctional unit
0(IMPACT World+ Midpoint 2.1_regionalized for e...djsx4kf89i179omk6lwr1hqptygdo6g2239.149972AL_MAKINGConstructionIMPACT World+ Midpoint 2.1_regionalized for ec...MidpointClimate change, long termkg CO2 eq (long)kilogram per hour
1(IMPACT World+ Midpoint 2.1_regionalized for e...djsx4kf89i179omk6lwr1hqptygdo6g2260.880150AL_MAKINGConstructionIMPACT World+ Midpoint 2.1_regionalized for ec...MidpointClimate change, short termkg CO2 eq (short)kilogram per hour
2(IMPACT World+ Midpoint 2.1_regionalized for e...djsx4kf89i179omk6lwr1hqptygdo6g23472.254845AL_MAKINGConstructionIMPACT World+ Midpoint 2.1_regionalized for ec...MidpointFossil and nuclear energy useMJ deprivedkilogram per hour
3(IMPACT World+ Midpoint 2.1_regionalized for e...djsx4kf89i179omk6lwr1hqptygdo6g21.672163AL_MAKINGConstructionIMPACT World+ Midpoint 2.1_regionalized for ec...MidpointFreshwater acidificationkg SO2 eqkilogram per hour
4(IMPACT World+ Midpoint 2.1_regionalized for e...djsx4kf89i179omk6lwr1hqptygdo6g2143450.673137AL_MAKINGConstructionIMPACT World+ Midpoint 2.1_regionalized for ec...MidpointFreshwater ecotoxicityCTUekilogram per hour
\n", "
" ], "text/plain": [ " Impact_category \\\n", "0 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "1 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "2 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "3 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "4 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "\n", " New_code Value Name Type \\\n", "0 djsx4kf89i179omk6lwr1hqptygdo6g2 239.149972 AL_MAKING Construction \n", "1 djsx4kf89i179omk6lwr1hqptygdo6g2 260.880150 AL_MAKING Construction \n", "2 djsx4kf89i179omk6lwr1hqptygdo6g2 3472.254845 AL_MAKING Construction \n", "3 djsx4kf89i179omk6lwr1hqptygdo6g2 1.672163 AL_MAKING Construction \n", "4 djsx4kf89i179omk6lwr1hqptygdo6g2 143450.673137 AL_MAKING Construction \n", "\n", " Impact_category (level 0) \\\n", "0 IMPACT World+ Midpoint 2.1_regionalized for ec... \n", "1 IMPACT World+ Midpoint 2.1_regionalized for ec... \n", "2 IMPACT World+ Midpoint 2.1_regionalized for ec... \n", "3 IMPACT World+ Midpoint 2.1_regionalized for ec... \n", "4 IMPACT World+ Midpoint 2.1_regionalized for ec... \n", "\n", " Impact_category (level 1) Impact_category (level 2) \\\n", "0 Midpoint Climate change, long term \n", "1 Midpoint Climate change, short term \n", "2 Midpoint Fossil and nuclear energy use \n", "3 Midpoint Freshwater acidification \n", "4 Midpoint Freshwater ecotoxicity \n", "\n", " Impact_category_unit Functional unit \n", "0 kg CO2 eq (long) kilogram per hour \n", "1 kg CO2 eq (short) kilogram per hour \n", "2 MJ deprived kilogram per hour \n", "3 kg SO2 eq kilogram per hour \n", "4 CTUe kilogram per hour " ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "R_long.head()" ] }, { "cell_type": "code", "execution_count": 42, "id": "66388d14aeabe646", "metadata": { "ExecuteTime": { "end_time": "2025-12-23T20:39:43.346917Z", "start_time": "2025-12-23T20:39:43.198323Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
scoreamountcodedatabaseimpact_categoryact_databaseact_codecontribution_typeact_nameact_type
0118.979814118.979814349b29d1-3e58-4c66-98b9-9d1a076efd2ebiosphere3(IMPACT World+ Midpoint 2.1_regionalized for e...EnergyScope_CH_2050_Testdjsx4kf89i179omk6lwr1hqptygdo6g2emissionsAL_MAKINGConstruction
161.12403561.124035f9749677-9c9f-4678-ab55-c607dfdc2cb9biosphere3(IMPACT World+ Midpoint 2.1_regionalized for e...EnergyScope_CH_2050_Testdjsx4kf89i179omk6lwr1hqptygdo6g2emissionsAL_MAKINGConstruction
245.52174145.521741aa7cac3a-3625-41d4-bc54-33e2cf11ec46biosphere3(IMPACT World+ Midpoint 2.1_regionalized for e...EnergyScope_CH_2050_Testdjsx4kf89i179omk6lwr1hqptygdo6g2emissionsAL_MAKINGConstruction
35.6703755.67037570ef743b-3ed5-4a6d-b192-fb6d62378555biosphere3(IMPACT World+ Midpoint 2.1_regionalized for e...EnergyScope_CH_2050_Testdjsx4kf89i179omk6lwr1hqptygdo6g2emissionsAL_MAKINGConstruction
42.5662302.566230ba2f3f82-c93a-47a5-822a-37ec97495275biosphere3(IMPACT World+ Midpoint 2.1_regionalized for e...EnergyScope_CH_2050_Testdjsx4kf89i179omk6lwr1hqptygdo6g2emissionsAL_MAKINGConstruction
\n", "
" ], "text/plain": [ " score amount code database \\\n", "0 118.979814 118.979814 349b29d1-3e58-4c66-98b9-9d1a076efd2e biosphere3 \n", "1 61.124035 61.124035 f9749677-9c9f-4678-ab55-c607dfdc2cb9 biosphere3 \n", "2 45.521741 45.521741 aa7cac3a-3625-41d4-bc54-33e2cf11ec46 biosphere3 \n", "3 5.670375 5.670375 70ef743b-3ed5-4a6d-b192-fb6d62378555 biosphere3 \n", "4 2.566230 2.566230 ba2f3f82-c93a-47a5-822a-37ec97495275 biosphere3 \n", "\n", " impact_category \\\n", "0 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "1 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "2 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "3 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "4 (IMPACT World+ Midpoint 2.1_regionalized for e... \n", "\n", " act_database act_code \\\n", "0 EnergyScope_CH_2050_Test djsx4kf89i179omk6lwr1hqptygdo6g2 \n", "1 EnergyScope_CH_2050_Test djsx4kf89i179omk6lwr1hqptygdo6g2 \n", "2 EnergyScope_CH_2050_Test djsx4kf89i179omk6lwr1hqptygdo6g2 \n", "3 EnergyScope_CH_2050_Test djsx4kf89i179omk6lwr1hqptygdo6g2 \n", "4 EnergyScope_CH_2050_Test djsx4kf89i179omk6lwr1hqptygdo6g2 \n", "\n", " contribution_type act_name act_type \n", "0 emissions AL_MAKING Construction \n", "1 emissions AL_MAKING Construction \n", "2 emissions AL_MAKING Construction \n", "3 emissions AL_MAKING Construction \n", "4 emissions AL_MAKING Construction " ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "contrib_analysis_res.head()" ] }, { "cell_type": "code", "execution_count": 48, "id": "de746fdfb70bc485", "metadata": { "ExecuteTime": { "end_time": "2025-12-23T21:02:48.263921Z", "start_time": "2025-12-23T20:39:56.096507Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Getting activity data\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 880/880 [00:00<00:00, 196621.96it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Adding exchange data to activities\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 14620/14620 [00:00<00:00, 18463.85it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Filling out exchange data\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 880/880 [00:00<00:00, 960.51it/s] \n", "2025-12-23 15:39:58,051 - Database - INFO - Loaded EnergyScope_CH_2050_Test from brightway!\n", "596it [22:28, 2.26s/it]\n" ] } ], "source": [ "_, contrib_analysis_processes_res, _ = esm.compute_impact_scores(\n", " methods=lcia_methods,\n", " contribution_analysis='processes',\n", " contribution_analysis_limit=100,\n", ")" ] }, { "cell_type": "code", "execution_count": 49, "id": "ca9be387f3cae20c", "metadata": { "ExecuteTime": { "end_time": "2025-12-23T21:03:13.477402Z", "start_time": "2025-12-23T21:02:48.366663Z" } }, "outputs": [], "source": [ "contrib_analysis_processes_res.to_csv(f'results/energyscope_{esm_location}/{esm_year}/contribution_analysis_processes.csv', index=False)" ] }, { "cell_type": "markdown", "id": "eced4286c9628abb", "metadata": {}, "source": [ "## Convert the results in an AMPL format" ] }, { "cell_type": "code", "execution_count": 35, "id": "34a01c8bb7ba33d7", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:17:34.391974Z", "start_time": "2025-12-26T17:17:28.408227Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\matth\\AppData\\Local\\Temp\\ipykernel_35040\\263815357.py:4: DtypeWarning: Columns (7) have mixed types. Specify dtype option on import or set low_memory=False.\n", " contrib_analysis_processes_res = pd.read_csv(f'results/energyscope_{esm_location}/{esm_year}/contribution_analysis_processes.csv')\n" ] } ], "source": [ "# To skip the previous steps\n", "R_long = pd.read_csv(f'results/energyscope_{esm_location}/{esm_year}/impact_scores.csv')\n", "R_long_direct_emissions = pd.read_csv(f'results/energyscope_{esm_location}/{esm_year}/impact_scores_direct_emissions.csv')\n", "contrib_analysis_processes_res = pd.read_csv(f'results/energyscope_{esm_location}/{esm_year}/contribution_analysis_processes.csv')" ] }, { "cell_type": "code", "execution_count": 52, "id": "6d4128137d2a0b5e", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:35:19.887855Z", "start_time": "2025-12-26T17:35:19.714718Z" } }, "outputs": [], "source": [ "# Tou can specify which specific LCIA methods or impact categories you wish to use using one of the three following options:\n", "# specific_lcia_methods = [f'IMPACT World+ Footprint 2.1 for ecoinvent v{ecoinvent_main_version}'] # selects the specific methods via their names\n", "# specific_lcia_categories = ['Total ecosystem quality', 'Total human health'] # selects the specific impact categories via their names \n", "specific_lcia_abbrev = ['TTHH', 'TTEQ', 'm_CCS'] # selects the specific impact categories via their abbreviations" ] }, { "cell_type": "code", "execution_count": 53, "id": "5a63cc009a68125f", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:35:20.264736Z", "start_time": "2025-12-26T17:35:20.086662Z" } }, "outputs": [], "source": [ "# Additional information that can be added at the beginning of the AMPL .mod and .dat files\n", "metadata = {\n", " 'ecoinvent_version': ecoinvent_version,\n", " 'year': esm_year,\n", " 'spatialized': spatialized_database,\n", " 'regionalized': regionalize_foregrounds,\n", " 'iam': premise_iam,\n", " 'ssp_rcp': premise_ssp_rcp,\n", " 'lcia_methods': lcia_methods,\n", "}" ] }, { "cell_type": "markdown", "id": "d3b36a88c73fce21", "metadata": {}, "source": [ "### Normalize LCA indicators and create the .dat file" ] }, { "cell_type": "code", "execution_count": 58, "id": "dd3b491c4e3d8ebb", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:39:59.519110Z", "start_time": "2025-12-26T17:39:59.144836Z" } }, "outputs": [], "source": [ "# Life-cycle impacts\n", "esm.normalize_lca_metrics(\n", " R=R_long,\n", " mip_gap=1e-6,\n", " lcia_methods=lcia_methods,\n", " specific_lcia_abbrev=specific_lcia_abbrev,\n", " impact_abbrev=impact_abbrev,\n", " path=f'results/energyscope_{esm_location}/{esm_year}/',\n", " metadata=metadata,\n", ")" ] }, { "cell_type": "code", "execution_count": 59, "id": "41a2a5e465273dab", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:41:21.673171Z", "start_time": "2025-12-26T17:41:21.127356Z" } }, "outputs": [], "source": [ "# Direct impacts\n", "esm.normalize_lca_metrics(\n", " R=R_long,\n", " R_direct=R_long_direct_emissions,\n", " mip_gap=1e-6,\n", " lcia_methods=lcia_methods,\n", " specific_lcia_abbrev=specific_lcia_abbrev,\n", " assessment_type='direct emissions',\n", " impact_abbrev=impact_abbrev,\n", " path=f'results/energyscope_{esm_location}/{esm_year}/',\n", " metadata=metadata,\n", " file_name='techs_lcia_direct',\n", ")" ] }, { "cell_type": "code", "execution_count": 60, "id": "21100d8825d72103", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:42:55.366879Z", "start_time": "2025-12-26T17:41:29.169506Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Getting activity data\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 880/880 [00:00<00:00, 48886.60it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Adding exchange data to activities\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 14620/14620 [00:01<00:00, 10273.36it/s]\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Filling out exchange data\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 880/880 [00:01<00:00, 489.38it/s] \n", "2025-12-26 12:41:32,926 - Database - INFO - Loaded EnergyScope_CH_2050_Test from brightway!\n" ] } ], "source": [ "# Territorial impacts\n", "esm.normalize_lca_metrics(\n", " R=R_long,\n", " contrib_processes=contrib_analysis_processes_res,\n", " mip_gap=1e-6,\n", " lcia_methods=lcia_methods,\n", " specific_lcia_abbrev=specific_lcia_abbrev,\n", " assessment_type='territorial emissions',\n", " impact_abbrev=impact_abbrev,\n", " path=f'results/energyscope_{esm_location}/{esm_year}/',\n", " metadata=metadata,\n", " file_name='techs_lcia_territorial',\n", ")" ] }, { "cell_type": "markdown", "id": "66b13911bb933dc5", "metadata": {}, "source": [ "### Create the .mod file" ] }, { "cell_type": "code", "execution_count": 61, "id": "d481ec84345d14d0", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:42:56.058482Z", "start_time": "2025-12-26T17:42:55.519925Z" } }, "outputs": [], "source": [ "# Life-cycle impacts\n", "esm.generate_mod_file_ampl(\n", " lcia_methods=lcia_methods,\n", " specific_lcia_abbrev=specific_lcia_abbrev,\n", " impact_abbrev=impact_abbrev,\n", " path=f'results/energyscope_{esm_location}/{esm_year}/',\n", " metadata=metadata,\n", " energyscope_version='core' if esm_location == 'core' else 'epfl',\n", ")" ] }, { "cell_type": "code", "execution_count": 62, "id": "f7e8ab19511f4a5f", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:42:56.323859Z", "start_time": "2025-12-26T17:42:56.124634Z" } }, "outputs": [], "source": [ "# Direct impacts\n", "esm.generate_mod_file_ampl(\n", " lcia_methods=lcia_methods,\n", " specific_lcia_abbrev=specific_lcia_abbrev,\n", " assessment_type='direct emissions',\n", " impact_abbrev=impact_abbrev,\n", " path=f'results/energyscope_{esm_location}/{esm_year}/',\n", " metadata=metadata,\n", " file_name='objectives_direct',\n", " energyscope_version='core' if esm_location == 'core' else 'epfl',\n", ")" ] }, { "cell_type": "code", "execution_count": 63, "id": "10d002f791d84f1c", "metadata": { "ExecuteTime": { "end_time": "2025-12-26T17:42:56.464116Z", "start_time": "2025-12-26T17:42:56.328867Z" } }, "outputs": [], "source": [ "# Territorial impacts\n", "esm.generate_mod_file_ampl(\n", " lcia_methods=lcia_methods,\n", " specific_lcia_abbrev=specific_lcia_abbrev,\n", " assessment_type='territorial emissions',\n", " impact_abbrev=impact_abbrev,\n", " path=f'results/energyscope_{esm_location}/{esm_year}/',\n", " metadata=metadata,\n", " file_name='objectives_territorial',\n", " energyscope_version='core' if esm_location == 'core' else 'epfl',\n", ")" ] }, { "cell_type": "markdown", "id": "9851a5bde60e6e51", "metadata": {}, "source": [ "## Integrate the ESM results back in the LCI database" ] }, { "cell_type": "code", "execution_count": null, "id": "4730e3ad33f56345", "metadata": {}, "outputs": [], "source": [ "esm.create_new_database_with_esm_results(\n", " esm_results=results_from_esm,\n", " new_end_use_types=new_end_use_types,\n", " tech_to_remove_layers=technologies_to_remove_from_layers,\n", " write_database=True,\n", " remove_background_construction_flows=True,\n", " harmonize_with_esm=False,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "d3a3766a8cb0cbe6", "metadata": {}, "outputs": [], "source": [ "esm.connect_esm_results_to_database(create_new_db=True)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }