{
"cells": [
{
"cell_type": "markdown",
"id": "d1b08680e689ca4",
"metadata": {},
"source": "# Generation of LCA impact scores"
},
{
"metadata": {},
"cell_type": "markdown",
"source": [
"This notebook aims to show how to generate Life-Cycle Assessment (LCA) impact scores to be used in EnergyScope. LCA impact scores can be used within modelling constraints, e.g., upper limit on life-cycle greenhouse gas emissions, or in the objective function, e.g., minimizing the total damage on human health. LCA impact scores are generated and integrated in EnergyScope using the Python package [_mescal_](https://mescal.readthedocs.io/en/latest/). The latter applies several transformations on LCA data to ensure the alignement between (your version of) EnergyScope and LCA models. For instance, _mescal_ performs double-counting removal (to avoid the overestimation of flows that are already represented in EnergyScope, e.g., energy flows), technological parameters harmonization (e.g., lifetime, efficiency, capacity factors), and normalization (to ease the solving process in EnergyScope).\n",
"\n",
"In this notebook, we illustrate the use of _mescal_ with the core model of EnergyScope. We employed a prospective LCA database from [_premise_](https://premise.readthedocs.io/en/latest/introduction.html) (i.e., TIAM-UCL with scenario SSP2-RCP2.6), but the overall methodology is agnostic to the used LCA database and even to the version of EnergyScope you are using. You should simply adapt the input data files accordingly, following the example ones from the core model.\n",
"\n",
"We show how to:\n",
"- create the ESM database (i.e., the database containing the datasets corresponding to the technologies and resources of the model) in your brightway2 project\n",
"- perform life-cycle impact assessment and contribution analyses\n",
"- create the .mod and .dat files for EnergyScope\n",
"- visualise the results using [_mescal_'s](https://mescal.readthedocs.io/en/latest/) visualisation features"
],
"id": "2ded8783dacccdbe"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "%pip install mescal == 1.2.3",
"id": "bebea3af369447c4"
},
{
"cell_type": "markdown",
"id": "fcea604216443279",
"metadata": {},
"source": [
"There is currently a dependency issue between energyscope library and mescal regarding numpy: energyscope requires numpy >= 2 while brightway2 (needed in mescal) requires numpy<2. However, you can keep numpy<2 in the present notebook as we do not use energyscope library."
]
},
{
"cell_type": "markdown",
"id": "2f11aaf838a61fdc",
"metadata": {},
"source": [
"## Project setup"
]
},
{
"cell_type": "markdown",
"id": "14b39fdaca68a810",
"metadata": {},
"source": [
"To be able to run the following script, you need to have already set up a Brightway2 project with ecoinvent and premise databases. You can refer to this [documentation](https://learn.brightway.dev/en/latest/content/chapters/BW2/BW2_introduction.html) to set up Brightway2 and this [notebook](https://github.com/polca/premise/blob/master/examples/examples.ipynb) to set up premise databases in your Brightway2 project."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "eeabdb27fe4d7bd1",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:30:17.442894Z",
"start_time": "2025-12-11T17:29:50.964049Z"
}
},
"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": 2,
"id": "8aa45e4eb65ea277",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:30:17.457915Z",
"start_time": "2025-12-11T17:30:17.447930Z"
}
},
"outputs": [],
"source": [
"location = 'BE' # Set the ecoinvent location code corresponding to your EnergyScope model here (e.g., 'BE' for Belgium)\n",
"year = 2050 # Set the year here (e.g., 2050)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d5f88f758c363df5",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:30:18.152485Z",
"start_time": "2025-12-11T17:30:18.144958Z"
}
},
"outputs": [],
"source": [
"# Set the name of your main LCI database (e.g., ecoinvent or premise database) here:\n",
"lca_db_name = f\"ecoinvent_cutoff_3.10.1_tiam-ucl_SSP2-RCP26_{year}\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f0ac5347fb1409f2",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:30:18.189274Z",
"start_time": "2025-12-11T17:30:18.180719Z"
}
},
"outputs": [],
"source": [
"# Set the name of the new database with the ESM results\n",
"esm_db_name = f'EnergyScope_{location}_{year}'"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "dd8a7f3a02721f53",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:30:18.205676Z",
"start_time": "2025-12-11T17:30:18.195315Z"
}
},
"outputs": [],
"source": [
"# Set the list of LCIA methods for which you want indicators (they must be registered in your brightway project)\n",
"lcia_methods=['IMPACT World+ Midpoint 2.1 for ecoinvent v3.10', 'IMPACT World+ Damage 2.1 for ecoinvent v3.10']"
]
},
{
"cell_type": "markdown",
"id": "245f23482a06045f",
"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": 6,
"id": "d9880509ae8f22bd",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:30:18.433747Z",
"start_time": "2025-12-11T17:30:18.221118Z"
}
},
"outputs": [],
"source": [
"# Set up your Brightway project\n",
"bd.projects.set_current('ecoinvent3.10.1') # put the name of your brightway project here"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "dbac8775081f3bf8",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:32:20.806146Z",
"start_time": "2025-12-11T17:30:18.448260Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Getting activity data\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 36014/36014 [00:00<00:00, 79358.33it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Adding exchange data to activities\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1182964/1182964 [01:12<00:00, 16415.79it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Filling out exchange data\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 36014/36014 [00:05<00:00, 6381.16it/s] \n",
"2025-12-11 12:31:58,132 - Database - INFO - Loaded ecoinvent_cutoff_3.10.1_tiam-ucl_SSP2-RCP26_2050 from brightway!\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"ecoinvent_cutoff_3.10.1_tiam-ucl_SSP2-RCP26_2050.pickle created!\n"
]
}
],
"source": [
"# Load the LCI database from your brightway project\n",
"lca_db = Database(lca_db_name, create_pickle=True)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "e95c9a3b6636145f",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:32:23.189871Z",
"start_time": "2025-12-11T17:32:21.436925Z"
}
},
"outputs": [],
"source": [
"# If necessary, add missing CPC categories to the database\n",
"lca_db.add_CPC_categories(overwrite_existing_CPC=True)"
]
},
{
"cell_type": "markdown",
"id": "e4b8f57e51fb06c1",
"metadata": {},
"source": [
"## Input data"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "4e5a3b74aa018cb9",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:32:23.221969Z",
"start_time": "2025-12-11T17:32:23.207639Z"
}
},
"outputs": [],
"source": "path_to_input_files = 'path/to/your/input/files/' # put here the path to the folder containing the input data files"
},
{
"cell_type": "markdown",
"id": "e8dc550a85181349",
"metadata": {},
"source": [
"Input data files can be retrieved from [mescal GitHub repository](https://github.com/matthieu-str/mescal/tree/master/dev/energyscope_data/core)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "1d458ca99528d5a0",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:32:23.553400Z",
"start_time": "2025-12-11T17:32:23.272081Z"
}
},
"outputs": [],
"source": [
"mapping = pd.read_csv(path_to_input_files+'mapping.csv')\n",
"unit_conversion = pd.read_excel(path_to_input_files+'unit_conversion.xlsx')\n",
"mapping_esm_flows_to_CPC = pd.read_csv(path_to_input_files+'mapping_esm_flows_to_CPC.csv')\n",
"model = pd.read_csv(path_to_input_files+'model.csv')\n",
"technology_compositions = pd.read_csv(path_to_input_files+'technology_compositions.csv')\n",
"technology_specifics = pd.read_csv(path_to_input_files+'technology_specifics.csv')\n",
"lifetime = pd.read_csv(path_to_input_files+'lifetime.csv')\n",
"efficiency = pd.read_csv(path_to_input_files+'efficiency.csv')\n",
"impact_abbrev = pd.read_csv(path_to_input_files+'impact_abbrev.csv')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "101fc41b7e28179a",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:32:23.645210Z",
"start_time": "2025-12-11T17:32:23.632960Z"
}
},
"outputs": [],
"source": [
"mapping.Database = lca_db_name # set the database name in the mapping file"
]
},
{
"cell_type": "markdown",
"id": "f8ebfaf69faab385",
"metadata": {},
"source": [
"## Initialize the ESM class"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "bcd8ffd5d4feb008",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:32:23.715325Z",
"start_time": "2025-12-11T17:32:23.680702Z"
}
},
"outputs": [],
"source": [
"esm = ESM(\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=lca_db,\n",
" esm_db_name=esm_db_name,\n",
" esm_location=location,\n",
" technology_compositions=technology_compositions,\n",
" tech_specifics=technology_specifics,\n",
" lifetime=lifetime,\n",
" efficiency=efficiency,\n",
" regionalize_foregrounds=['Operation', 'Resource'], # types of LCI datasets that will be regionalized\n",
" locations_ranking=['BE', 'RER', 'WEU', 'CEU', 'GLO', 'RoW'], # order of preference for locations when regionalizing\n",
" results_path_file='lca_results/',\n",
" remove_double_counting_to=['Operation', 'Construction'], # we mention Construction as end-of-life flows from construction are extracted separately\n",
" extract_eol_from_construction=True,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "66c9aa4f81a11331",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:32:27.728004Z",
"start_time": "2025-12-11T17:32:23.762159Z"
}
},
"outputs": [],
"source": [
"# Update mapping dataframe with better locations\n",
"esm.change_location_mapping_file()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "9ea25487e86b9ae2",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:32:27.873255Z",
"start_time": "2025-12-11T17:32:27.790250Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-12-11 12:32:27,834 - Database - INFO - Mapping successfully linked to the database\n"
]
},
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"esm.main_database.test_mapping_file(esm.mapping) # test the mapping file"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "c65fffc9fc54f331",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:32:33.999808Z",
"start_time": "2025-12-11T17:32:33.975307Z"
}
},
"outputs": [],
"source": [
"esm.clean_inputs()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "d3d1853dc5aa35ba",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:32:34.890631Z",
"start_time": "2025-12-11T17:32:34.646152Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-12-11 12:32:34,659 - Mescal - WARNING - There are duplicates in the unit_conversion dataframe. Please check your inputs.\n",
"2025-12-11 12:32:34,738 - 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: ['CO2_ATM', 'CO2_CAPTURED', 'CO2_EMISSIONS', 'CO2_INDUSTRY', 'RES_GEO', 'RES_HYDRO', 'RES_SOLAR', 'RES_WIND']\n",
"2025-12-11 12:32:34,843 - 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: ['DEC_DIRECT_ELEC', 'DEC_SOLAR', 'DHN_DEEP_GEO', 'DHN_SOLAR', 'GEOTHERMAL', 'IND_DIRECT_ELEC']\n"
]
}
],
"source": [
"esm.check_inputs()"
]
},
{
"cell_type": "markdown",
"id": "c9db7257fddacfd5",
"metadata": {},
"source": [
"## Create the ESM database in your Brightway2 project"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "75c756c5daab291b",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:35:04.223789Z",
"start_time": "2025-12-11T17:32:45.278586Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-12-11 12:32:50,420 - Mescal - INFO - Starting to remove double-counted flows\n",
"100%|██████████| 109/109 [00:00<00:00, 703.93it/s]\n",
" 25%|██▌ | 19/75 [00:01<00:02, 20.73it/s]2025-12-11 12:33:03,241 - Mescal - WARNING - No location found in your ranking for (aluminium, primary, ingot, aluminium, ingot, primary, import from Rest of Europe) in the database ecoinvent_cutoff_3.10.1_tiam-ucl_SSP2-RCP26_2050. Have to keep the initial location: IAI Area, EU27 & EFTA\n",
"100%|██████████| 75/75 [00:04<00:00, 15.46it/s]\n",
"2025-12-11 12:33:06,928 - Mescal - INFO - Double-counting removal done in 16.5 seconds\n",
"2025-12-11 12:33:07,155 - Mescal - INFO - Starting to correct efficiency differences\n",
"2025-12-11 12:33:07,203 - Mescal - WARNING - No flow found for type(s) ['WET_BIOMASS'] in BIOMETHANATION. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,235 - Mescal - WARNING - No flow found for type(s) ['METHANOL', 'TRANSPORT_FUEL'] in BOAT_FREIGHT_METHANOL. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,251 - Mescal - WARNING - No flow found for type(s) ['GAS', 'TRANSPORT_FUEL'] in BOAT_FREIGHT_NG. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,378 - Mescal - WARNING - No flow found for type(s) ['GAS'] in CCGT. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,426 - Mescal - WARNING - No flow found for type(s) ['GAS'] in DEC_ADVCOGEN_GAS. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,474 - Mescal - WARNING - No flow found for type(s) ['WOOD'] in DEC_BOILER_WOOD. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,579 - Mescal - WARNING - No flow found for type(s) ['WOOD'] in DHN_BOILER_WOOD. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,595 - Mescal - WARNING - No flow found for type(s) ['WET_BIOMASS'] in DHN_COGEN_BIO_HYDROLYSIS. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,627 - Mescal - WARNING - No flow found for type(s) ['WASTE'] in DHN_COGEN_WASTE. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,647 - Mescal - WARNING - No flow found for type(s) ['WET_BIOMASS'] in DHN_COGEN_WET_BIOMASS. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,659 - Mescal - WARNING - No flow found for type(s) ['WOOD'] in DHN_COGEN_WOOD. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,691 - Mescal - WARNING - No flow found for type(s) ['WOOD'] in H2_BIOMASS. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,755 - Mescal - WARNING - No flow found for type(s) ['WASTE'] in IND_BOILER_WASTE. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,771 - Mescal - WARNING - No flow found for type(s) ['WOOD'] in IND_BOILER_WOOD. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,803 - Mescal - WARNING - No flow found for type(s) ['WASTE'] in IND_COGEN_WASTE. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,820 - Mescal - WARNING - No flow found for type(s) ['WOOD'] in IND_COGEN_WOOD. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,867 - Mescal - WARNING - No flow found for type(s) ['WOOD'] in PYROLYSIS_TO_LFO. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:07,915 - Mescal - WARNING - No flow found for type(s) ['METHANOL'] in TRUCK_METHANOL. The efficiency of this technology cannot be adjusted.\n",
"2025-12-11 12:33:08,417 - Mescal - WARNING - No flow of type TRANSPORT_FUEL has been removed in BOAT_FREIGHT_DIESEL.\n",
"2025-12-11 12:33:08,433 - Mescal - WARNING - Flow of type TRANSPORT_FUEL found for BOAT_FREIGHT_DIESEL in efficiency file, but not in model file.\n",
"2025-12-11 12:33:08,449 - Mescal - WARNING - Flow of type TRANSPORT_FUEL found for BOAT_FREIGHT_DIESEL in efficiency file, but not in unit conversion file.\n",
"2025-12-11 12:33:08,611 - Mescal - INFO - Efficiency differences corrected in 1.5 seconds\n",
"2025-12-11 12:33:09,525 - 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/11/2025 12:33:47\n",
" Finished: 12/11/2025 12:33:47\n",
" Total time elapsed: 00:00:00\n",
" CPU %: 93.10\n",
" Memory %: 2.17\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-12-11 12:35:03,989 - Database - INFO - EnergyScope_BE_2050 written to Brightway!\n",
"2025-12-11 12:35:04,113 - Mescal - INFO - Database written in 114.6 seconds\n"
]
}
],
"source": [
"esm.create_esm_database()"
]
},
{
"cell_type": "markdown",
"id": "58f3a7c6823168",
"metadata": {},
"source": [
"## Compute LCA impact scores and perform contribution analysis"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "46bd90d6d592470",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:37:50.552906Z",
"start_time": "2025-12-11T17:35:04.271993Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Getting activity data\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 410/410 [00:00, ?it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Adding exchange data to activities\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 8979/8979 [00:00<00:00, 18401.79it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Filling out exchange data\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 410/410 [00:01<00:00, 224.93it/s]\n",
"2025-12-11 12:35:06,646 - Database - INFO - Loaded EnergyScope_BE_2050 from brightway!\n",
"280it [02:20, 1.99it/s]\n"
]
}
],
"source": [
"impact_scores, contrib_analysis_res, _ = esm.compute_impact_scores(\n",
" methods=lcia_methods,\n",
" contribution_analysis='both',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "11fc82929ce22a20",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:37:52.479491Z",
"start_time": "2025-12-11T17:37:50.604093Z"
}
},
"outputs": [],
"source": [
"impact_scores.to_csv(esm.results_path_file+'impact_scores.csv', index=False)\n",
"contrib_analysis_res.to_csv(esm.results_path_file+'contribution_analysis.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "fbd355fb914a1b6d",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:37:59.239299Z",
"start_time": "2025-12-11T17:37:52.484153Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Getting activity data\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 410/410 [00:00, ?it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Adding exchange data to activities\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 8979/8979 [00:00<00:00, 24381.05it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Filling out exchange data\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 410/410 [00:02<00:00, 185.72it/s]\n",
"2025-12-11 12:37:55,149 - Database - INFO - Loaded EnergyScope_BE_2050 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/11/2025 12:37:56\n",
" Finished: 12/11/2025 12:37:56\n",
" Total time elapsed: 00:00:00\n",
" CPU %: 76.30\n",
" Memory %: 4.03\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2025-12-11 12:37:57,826 - Database - INFO - EnergyScope_BE_2050_direct_emissions written to Brightway!\n",
"75it [00:01, 74.15it/s]\n"
]
}
],
"source": [
"impact_scores_direct_emissions, _, _ = esm.compute_impact_scores(\n",
" methods=lcia_methods,\n",
" assessment_type='direct emissions', # specific metrics for direct emissions during operation\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "77f1c0457114ee15",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:37:59.409337Z",
"start_time": "2025-12-11T17:37:59.317311Z"
}
},
"outputs": [],
"source": [
"impact_scores_direct_emissions.to_csv(esm.results_path_file+'impact_scores_direct_emissions.csv', index=False)"
]
},
{
"cell_type": "markdown",
"id": "6d03e7a9f1b123bc",
"metadata": {},
"source": [
"## Create .dat and .mod files for AMPL integration"
]
},
{
"cell_type": "markdown",
"id": "1fa880cab925175e",
"metadata": {},
"source": [
"By default, the resulting .dat and .mod files are saved in the result directory specified in the ESM class initialization (here 'lca_results/')."
]
},
{
"cell_type": "markdown",
"id": "a3b657694fdbdedb",
"metadata": {},
"source": [
"We can select a few impact categories that we want to integrate in the model. Here, we select only two categories: TTHH (Total human health) and TTEQ (Total ecosystem quality). The abbreviations are defined in the impact_abbrev.csv file."
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "3b0704db53479201",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:37:59.483676Z",
"start_time": "2025-12-11T17:37:59.471922Z"
}
},
"outputs": [],
"source": [
"specific_lca_abbrev = ['TTHH', 'TTEQ']"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "aa368a78d038e1ac",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:37:59.752084Z",
"start_time": "2025-12-11T17:37:59.601886Z"
}
},
"outputs": [],
"source": [
"esm.normalize_lca_metrics(\n",
" R=impact_scores,\n",
" mip_gap=1e-6,\n",
" lcia_methods=lcia_methods,\n",
" specific_lcia_abbrev=specific_lca_abbrev,\n",
" impact_abbrev=impact_abbrev,\n",
" file_name='techs_lca',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "3102580ffc4b4b83",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:37:59.827299Z",
"start_time": "2025-12-11T17:37:59.760007Z"
}
},
"outputs": [],
"source": [
"# specific for direct emissions metrics\n",
"esm.normalize_lca_metrics(\n",
" R=impact_scores,\n",
" R_direct=impact_scores_direct_emissions, # thus we specify this\n",
" mip_gap=1e-6,\n",
" lcia_methods=lcia_methods,\n",
" specific_lcia_abbrev=specific_lca_abbrev,\n",
" assessment_type='direct emissions', # and this\n",
" impact_abbrev=impact_abbrev,\n",
" file_name='techs_lca_direct',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "a34e6131b95e82fa",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:37:59.917605Z",
"start_time": "2025-12-11T17:37:59.887398Z"
}
},
"outputs": [],
"source": [
"esm.generate_mod_file_ampl(\n",
" lcia_methods=lcia_methods,\n",
" impact_abbrev=impact_abbrev,\n",
" specific_lcia_abbrev=specific_lca_abbrev,\n",
" file_name='objectives_lca',\n",
" energyscope_version='core',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "306505769420cc0a",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:38:00.021973Z",
"start_time": "2025-12-11T17:37:59.990089Z"
}
},
"outputs": [],
"source": [
"# specific for direct emissions metrics\n",
"esm.generate_mod_file_ampl(\n",
" lcia_methods=lcia_methods,\n",
" specific_lcia_abbrev=specific_lca_abbrev,\n",
" assessment_type='direct emissions', # specify this\n",
" impact_abbrev=impact_abbrev,\n",
" file_name='objectives_lca_direct',\n",
" energyscope_version='core',\n",
")"
]
},
{
"cell_type": "markdown",
"id": "ebc2d2e10668ac66",
"metadata": {},
"source": [
"## Visualize the LCA impact scores"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "e5201366cd6d4326",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:38:00.115684Z",
"start_time": "2025-12-11T17:38:00.080111Z"
}
},
"outputs": [],
"source": [
"plot = Plot(\n",
" df_impact_scores=impact_scores,\n",
" lifetime=lifetime, # used to visualise infrastructure impacts per kW.year\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "2f89d33b3744b531",
"metadata": {
"ExecuteTime": {
"end_time": "2025-12-11T17:38:09.021455Z",
"start_time": "2025-12-11T17:38:00.170908Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "
Technology: %{x}Value: %{y:.2e} kg CO2 eq (short)/kWh",
"name": "Operation",
"type": "bar",
"x": [
"CCGT",
"COAL_IGCC",
"NUCLEAR",
"PV",
"WIND_ONSHORE"
],
"xaxis": "x",
"y": [
0.36861552691277943,
0.5640359762632728,
5.293331209955286E-4,
8.661252321281242E-7,
1.1767216933954002E-4
],
"yaxis": "y"
},
{
"hovertemplate": "
Technology: %{x}Value: %{y:.2e} kg CO2 eq (short)/kW/year",
"name": "Construction",
"type": "bar",
"x": [
"CCGT",
"COAL_IGCC",
"NUCLEAR",
"PV",
"WIND_ONSHORE"
],
"xaxis": "x2",
"y": [
3.269182861127532,
9.305924608703423,
4.602803998740713,
13.418789008072192,
18.167718346897196
],
"yaxis": "y2"
}
],
"layout": {
"annotations": [
{
"font": {
"size": 16
},
"showarrow": false,
"text": "Operation",
"x": 0.225,
"xanchor": "center",
"xref": "paper",
"y": 1,
"yanchor": "bottom",
"yref": "paper"
},
{
"font": {
"size": 16
},
"showarrow": false,
"text": "Construction",
"x": 0.775,
"xanchor": "center",
"xref": "paper",
"y": 1,
"yanchor": "bottom",
"yref": "paper"
}
],
"showlegend": false,
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#2a3f5f"
},
"error_y": {
"color": "#2a3f5f"
},
"marker": {
"line": {
"color": "white",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "white",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "#C8D4E3",
"linecolor": "#C8D4E3",
"minorgridcolor": "#C8D4E3",
"startlinecolor": "#2a3f5f"
},
"baxis": {
"endlinecolor": "#2a3f5f",
"gridcolor": "#C8D4E3",
"linecolor": "#C8D4E3",
"minorgridcolor": "#C8D4E3",
"startlinecolor": "#2a3f5f"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"heatmapgl": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmapgl"
}
],
"histogram": [
{
"marker": {
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"fillpattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergl"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#EBF0F8"
},
"line": {
"color": "white"
}
},
"header": {
"fill": {
"color": "#C8D4E3"
},
"line": {
"color": "white"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#2a3f5f",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"font": {
"color": "#2a3f5f"
},
"geo": {
"bgcolor": "white",
"lakecolor": "white",
"landcolor": "white",
"showlakes": true,
"showland": true,
"subunitcolor": "#C8D4E3"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "light"
},
"paper_bgcolor": "white",
"plot_bgcolor": "white",
"polar": {
"angularaxis": {
"gridcolor": "#EBF0F8",
"linecolor": "#EBF0F8",
"ticks": ""
},
"bgcolor": "white",
"radialaxis": {
"gridcolor": "#EBF0F8",
"linecolor": "#EBF0F8",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "white",
"gridcolor": "#DFE8F3",
"gridwidth": 2,
"linecolor": "#EBF0F8",
"showbackground": true,
"ticks": "",
"zerolinecolor": "#EBF0F8"
},
"yaxis": {
"backgroundcolor": "white",
"gridcolor": "#DFE8F3",
"gridwidth": 2,
"linecolor": "#EBF0F8",
"showbackground": true,
"ticks": "",
"zerolinecolor": "#EBF0F8"
},
"zaxis": {
"backgroundcolor": "white",
"gridcolor": "#DFE8F3",
"gridwidth": 2,
"linecolor": "#EBF0F8",
"showbackground": true,
"ticks": "",
"zerolinecolor": "#EBF0F8"
}
},
"shapedefaults": {
"line": {
"color": "#2a3f5f"
}
},
"ternary": {
"aaxis": {
"gridcolor": "#DFE8F3",
"linecolor": "#A2B1C6",
"ticks": ""
},
"baxis": {
"gridcolor": "#DFE8F3",
"linecolor": "#A2B1C6",
"ticks": ""
},
"bgcolor": "white",
"caxis": {
"gridcolor": "#DFE8F3",
"linecolor": "#A2B1C6",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"xaxis": {
"automargin": true,
"gridcolor": "#EBF0F8",
"linecolor": "#EBF0F8",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "#EBF0F8",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "#EBF0F8",
"linecolor": "#EBF0F8",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "#EBF0F8",
"zerolinewidth": 2
}
}
},
"title": {
"text": "LCA Indicators of electricity production technologies for Climate change, short term"
},
"xaxis": {
"anchor": "y",
"domain": [
0,
0.45
]
},
"xaxis2": {
"anchor": "y2",
"domain": [
0.55,
1
]
},
"yaxis": {
"anchor": "x",
"domain": [
0,
1
],
"title": {
"text": "Climate change, short term [kg CO2 eq (short)/kWh]"
}
},
"yaxis2": {
"anchor": "x2",
"domain": [
0,
1
],
"title": {
"text": "Climate change, short term [kg CO2 eq (short)/kW/year]"
}
}
}
},
"text/html": [
"