{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Run EnergyScope with LCA impact scores"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this notebook, we show how to use LCA data in EnergyScope. We use the core model of EnergyScope as an illustrative example.\n",
    "Before following this tutorial, make sure you have followed the \"Generation of LCA impact scores\" tutorial to generate the .dat and .mod files of LCA parameters and constraints to be used in EnergyScope.\n",
    "\n",
    "We show how to:\n",
    "- easily add the LCA .mod and .dat files to the core version\n",
    "- run the model\n",
    "- format the results\n",
    "- visualise the results using [_mescal_'s](https://mescal.readthedocs.io/en/latest/) visualisation features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install mescal==1.2.4\n",
    "%pip install energyscope==2.1.2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once you have generated your set of LCA metrics, you are ready to run EnergyScope with LCA variables as objective function or constraints."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Import packages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:12:00.651643Z",
     "start_time": "2026-02-20T15:11:42.216022Z"
    }
   },
   "outputs": [],
   "source": [
    "from energyscope.models import core, Model\n",
    "from energyscope.energyscope import Energyscope\n",
    "from mescal import Plot\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:12:00.678770Z",
     "start_time": "2026-02-20T15:12:00.670799Z"
    }
   },
   "outputs": [],
   "source": [
    "INPUT_DATA_FOLDER = 'path/to/your/input/files/'  # put the path of your data folder here\n",
    "LCA_RESULTS_FOLDER = 'path/to/your/lca/results/files/'  # put the path of your LCA results folder here\n",
    "license_uuid = 'xxx'  # put your AMPL licence UUID here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:12:01.490182Z",
     "start_time": "2026-02-20T15:12:01.388010Z"
    }
   },
   "outputs": [],
   "source": [
    "lifetime = pd.read_csv(INPUT_DATA_FOLDER+'lifetime.csv')\n",
    "impact_scores_lca = pd.read_csv(LCA_RESULTS_FOLDER+'impact_scores.csv')  # LCA impact scores\n",
    "impact_scores_direct = pd.read_csv(LCA_RESULTS_FOLDER+'impact_scores_direct_emissions.csv')  # Impact scores for direct emissions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Run EnergyScope"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:12:01.591070Z",
     "start_time": "2026-02-20T15:12:01.583369Z"
    }
   },
   "outputs": [],
   "source": [
    "LCA_model = Model([\n",
    "    ('mod', LCA_RESULTS_FOLDER+'objectives_lca.mod'),\n",
    "    # ('mod', LCA_RESULTS_FOLDER+'objectives_lca_direct.mod'),\n",
    "    ('dat', LCA_RESULTS_FOLDER+'techs_lca.dat'),\n",
    "    # ('dat', LCA_RESULTS_FOLDER+'techs_lca_direct.dat'),\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:12:01.628294Z",
     "start_time": "2026-02-20T15:12:01.618387Z"
    }
   },
   "outputs": [],
   "source": [
    "core = core.__add__(LCA_model)  # add the LCA model to the core model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Make sure to replace the license UUID with your own, you can access it directly from the [AMPL portal](https://portal.ampl.com/user/ampl/license/list). If you don't have an account please create one, and favor your academic address to get access to the free academic license."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:12:01.670934Z",
     "start_time": "2026-02-20T15:12:01.661769Z"
    }
   },
   "outputs": [],
   "source": [
    "energyscope_lca = Energyscope(\n",
    "    model=core,\n",
    "    solver_options={'solver': 'gurobi','gurobi_options':'outlev=1 NumericFocus=2 method=2'},\n",
    "    modules=['gurobi'],\n",
    "    license_uuid=license_uuid,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:14:55.875561Z",
     "start_time": "2026-02-20T15:12:01.729642Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gurobi 11.0.0: Set parameter LogToConsole to value 1\n",
      "  tech:outlev = 1\n",
      "Set parameter NumericFocus to value 2\n",
      "  alg:numericfocus = 2\n",
      "Set parameter Method to value 2\n",
      "  alg:method = 2\n",
      "Set parameter InfUnbdInfo to value 1\n",
      "Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.5.0 23F79)\n",
      "\n",
      "CPU model: Apple M2 Pro\n",
      "Thread count: 10 physical cores, 10 logical processors, using up to 10 threads\n",
      "\n",
      "Optimize a model with 491079 rows, 268733 columns and 1576042 nonzeros\n",
      "Model fingerprint: 0x489b5254\n",
      "Coefficient statistics:\n",
      "  Matrix range     [1e-06, 7e+04]\n",
      "  Objective range  [1e+00, 1e+00]\n",
      "  Bounds range     [2e-02, 6e+01]\n",
      "  RHS range        [1e+00, 4e+04]\n",
      "Presolve removed 243247 rows and 128451 columns\n",
      "Presolve time: 1.11s\n",
      "Presolved: 247832 rows, 140282 columns, 798471 nonzeros\n",
      "\n",
      "Elapsed ordering time = 5s\n",
      "Ordering time: 5.65s\n",
      "\n",
      "Barrier statistics:\n",
      " Dense cols : 98\n",
      " AA' NZ     : 3.806e+06\n",
      " Factor NZ  : 1.871e+07 (roughly 300 MB of memory)\n",
      " Factor Ops : 7.223e+09 (less than 1 second per iteration)\n",
      " Threads    : 10\n",
      "\n",
      "                  Objective                Residual\n",
      "Iter       Primal          Dual         Primal    Dual     Compl     Time\n",
      "   0   1.26214894e+07 -1.08114072e+06  1.99e+05 7.82e-14  1.00e+06     8s\n",
      "   1   1.35339311e+07 -2.45874867e+06  1.48e+05 8.36e+02  9.01e+05     8s\n",
      "   2   1.38220425e+07 -4.82323219e+06  1.43e+05 8.19e+02  8.29e+05     9s\n",
      "   3   1.55994536e+07 -5.80812720e+07  9.43e+04 6.18e+02  6.47e+05    10s\n",
      "   4   1.69376975e+07 -8.75794573e+07  6.41e+04 2.55e+02  2.99e+05    10s\n",
      "   5   1.67070071e+07 -9.53004389e+07  4.38e+04 8.43e+01  1.23e+05    11s\n",
      "   6   1.49631224e+07 -9.21859993e+07  2.77e+04 2.79e+01  5.37e+04    11s\n",
      "   7   1.24321302e+07 -9.04378015e+07  1.43e+04 1.76e+01  3.09e+04    11s\n",
      "   8   1.17871098e+07 -8.62747350e+07  1.17e+04 1.15e+01  2.23e+04    12s\n",
      "   9   9.83264710e+06 -8.06615974e+07  5.15e+03 5.91e+00  1.11e+04    12s\n",
      "  10   8.27717146e+06 -7.19404442e+07  1.52e+03 2.11e+00  3.83e+03    13s\n",
      "  11   7.07560975e+06 -4.98458760e+07  5.99e+02 4.49e-01  1.06e+03    13s\n",
      "  12   4.69555157e+06 -2.83726138e+07  1.19e+02 1.45e-01  3.27e+02    14s\n",
      "  13   2.73919161e+06 -8.60861758e+06  2.36e+01 3.31e-02  8.11e+01    14s\n",
      "  14   1.58495883e+06 -5.04289313e+06  9.81e+00 1.89e-02  4.50e+01    15s\n",
      "  15   1.15002761e+06 -3.73458586e+06  5.92e+00 1.38e-02  3.26e+01    15s\n",
      "  16   1.00327382e+06 -2.27155989e+06  4.78e+00 8.30e-03  2.07e+01    15s\n",
      "  17   6.05300251e+05 -1.23203779e+06  2.28e+00 4.45e-03  1.13e+01    16s\n",
      "  18   4.64584361e+05 -6.32348880e+05  1.58e+00 2.30e-03  6.34e+00    16s\n",
      "  19   3.55194859e+05 -5.01622560e+05  1.08e+00 1.88e-03  5.02e+00    17s\n",
      "  20   2.94192951e+05 -3.71479342e+05  7.98e-01 1.44e-03  3.88e+00    17s\n",
      "  21   2.02704421e+05 -3.00907689e+05  4.08e-01 1.18e-03  3.00e+00    17s\n",
      "  22   1.67462697e+05 -1.68280621e+05  2.63e-01 6.95e-04  1.92e+00    18s\n",
      "  23   1.16017225e+05 -7.11479718e+04  6.35e-02 3.46e-04  1.04e+00    18s\n",
      "  24   1.05167669e+05 -3.62786352e+04  2.30e-02 2.23e-04  7.56e-01    18s\n",
      "  25   1.01090645e+05 -2.44646310e+04  1.27e-02 1.82e-04  6.60e-01    19s\n",
      "  26   9.11274044e+04 -9.36211225e+03  1.07e-02 1.30e-04  5.18e-01    19s\n",
      "  27   8.07349691e+04  2.69477488e+03  8.50e-03 9.13e-05  3.95e-01    20s\n",
      "  28   7.16514186e+04  1.64619174e+04  6.44e-03 5.70e-05  2.76e-01    20s\n",
      "  29   6.10425774e+04  2.63738488e+04  3.78e-03 3.10e-05  1.74e-01    21s\n",
      "  30   5.53785573e+04  3.41295145e+04  2.51e-03 1.81e-05  1.03e-01    21s\n",
      "  31   5.16638429e+04  3.70952997e+04  1.75e-03 1.40e-05  7.05e-02    21s\n",
      "  32   4.97160337e+04  3.87140228e+04  1.34e-03 1.14e-05  5.27e-02    22s\n",
      "  33   4.85231204e+04  3.98536285e+04  1.10e-03 8.79e-06  4.07e-02    22s\n",
      "  34   4.79416363e+04  4.02236940e+04  9.73e-04 7.78e-06  3.61e-02    22s\n",
      "  35   4.77836802e+04  4.05966990e+04  9.42e-04 6.74e-06  3.31e-02    23s\n",
      "  36   4.74617778e+04  4.10556830e+04  8.75e-04 5.49e-06  2.89e-02    23s\n",
      "  37   4.65818999e+04  4.14538277e+04  7.01e-04 4.24e-06  2.30e-02    23s\n",
      "  38   4.60620737e+04  4.16875188e+04  6.00e-04 3.52e-06  1.95e-02    24s\n",
      "  39   4.56003673e+04  4.20036758e+04  5.14e-04 2.62e-06  1.58e-02    24s\n",
      "  40   4.51788339e+04  4.22294120e+04  4.33e-04 1.99e-06  1.28e-02    25s\n",
      "  41   4.49533642e+04  4.23101110e+04  3.89e-04 1.77e-06  1.15e-02    25s\n",
      "  42   4.45119295e+04  4.24128387e+04  3.06e-04 1.48e-06  9.21e-03    26s\n",
      "  43   4.40936860e+04  4.25302794e+04  2.28e-04 1.12e-06  6.88e-03    26s\n",
      "  44   4.37293726e+04  4.26569933e+04  1.57e-04 7.37e-07  4.67e-03    27s\n",
      "  45   4.35295399e+04  4.27327619e+04  1.18e-04 5.05e-07  3.42e-03    27s\n",
      "  46   4.32563072e+04  4.27846262e+04  6.58e-05 3.32e-07  2.04e-03    28s\n",
      "  47   4.31874802e+04  4.28275410e+04  5.29e-05 1.93e-07  1.50e-03    29s\n",
      "  48   4.31408174e+04  4.28390582e+04  4.43e-05 1.53e-07  1.24e-03    29s\n",
      "  49   4.31149968e+04  4.28486203e+04  3.96e-05 1.21e-07  1.08e-03    29s\n",
      "  50   4.30727773e+04  4.28537318e+04  3.20e-05 1.04e-07  8.91e-04    30s\n",
      "  51   4.30174189e+04  4.28618969e+04  2.21e-05 7.55e-08  6.30e-04    31s\n",
      "  52   4.29811217e+04  4.28680043e+04  1.63e-05 5.30e-08  4.55e-04    33s\n",
      "  53   4.29621596e+04  4.28738129e+04  1.31e-05 3.13e-08  3.47e-04    33s\n",
      "  54   4.29403716e+04  4.28761294e+04  9.32e-06 2.40e-08  2.52e-04    34s\n",
      "  55   4.29298139e+04  4.28773018e+04  7.62e-06 1.94e-08  2.05e-04    35s\n",
      "  56   4.29251256e+04  4.28778535e+04  6.80e-06 1.77e-08  1.84e-04    36s\n",
      "  57   4.29217064e+04  4.28786685e+04  6.23e-06 1.46e-08  1.67e-04    37s\n",
      "  58   4.29166251e+04  4.28787407e+04  5.43e-06 1.42e-08  1.47e-04    38s\n",
      "  59   4.29109658e+04  4.28801101e+04  4.46e-06 1.01e-08  1.19e-04    39s\n",
      "  60   4.29047023e+04  4.28808103e+04  3.40e-06 8.05e-09  9.18e-05    40s\n",
      "  61   4.29007751e+04  4.28810904e+04  2.77e-06 7.19e-09  7.57e-05    42s\n",
      "  62   4.28978158e+04  4.28815872e+04  2.28e-06 5.68e-09  6.22e-05    43s\n",
      "  63   4.28958179e+04  4.28817601e+04  1.96e-06 5.01e-09  5.38e-05    44s\n",
      "  64   4.28949524e+04  4.28819003e+04  1.81e-06 4.68e-09  5.00e-05    44s\n",
      "  65   4.28904490e+04  4.28823731e+04  1.07e-06 3.38e-09  3.10e-05    45s\n",
      "  66   4.28879606e+04  4.28828284e+04  6.59e-07 2.12e-09  1.97e-05    46s\n",
      "  67   4.28871286e+04  4.28830120e+04  5.26e-07 1.62e-09  1.57e-05    47s\n",
      "  68   4.28867831e+04  4.28830540e+04  4.69e-07 1.52e-09  1.43e-05    48s\n",
      "  69   4.28863795e+04  4.28832572e+04  4.05e-07 1.11e-09  1.19e-05    49s\n",
      "  70   4.28860712e+04  4.28833410e+04  3.54e-07 9.48e-10  1.04e-05    50s\n",
      "  71   4.28856095e+04  4.28834629e+04  2.78e-07 7.07e-10  8.14e-06    50s\n",
      "  72   4.28853010e+04  4.28835296e+04  2.31e-07 5.67e-10  6.71e-06    51s\n",
      "  73   4.28850324e+04  4.28835725e+04  1.88e-07 4.87e-10  5.53e-06    52s\n",
      "  74   4.28847724e+04  4.28836136e+04  1.47e-07 4.03e-10  4.40e-06    52s\n",
      "  75   4.28845461e+04  4.28837236e+04  1.11e-07 1.44e-10  3.08e-06    53s\n",
      "  76   4.28843701e+04  4.28837595e+04  8.38e-08 8.27e-11  2.28e-06    54s\n",
      "  77   4.28842334e+04  4.28837720e+04  6.21e-08 6.53e-11  1.72e-06    55s\n",
      "  78   4.28841378e+04  4.28837761e+04  4.78e-08 5.88e-11  1.35e-06    56s\n",
      "  79   4.28840293e+04  4.28838001e+04  3.11e-08 1.36e-11  8.49e-07    56s\n",
      "  80   4.28838919e+04  4.28838121e+04  1.02e-08 1.14e-12  2.95e-07    57s\n",
      "  81   4.28838632e+04  4.28838158e+04  6.14e-09 1.56e-12  1.75e-07    57s\n",
      "  82   4.28838236e+04  4.28838169e+04  6.79e-09 2.39e-12  2.49e-08    57s\n",
      "  83   4.28838184e+04  4.28838176e+04  1.00e-09 3.98e-12  2.80e-09    58s\n",
      "  84   4.28838178e+04  4.28838177e+04  8.06e-10 7.28e-12  2.82e-10    58s\n",
      "\n",
      "Barrier solved model in 84 iterations and 57.89 seconds (74.59 work units)\n",
      "Optimal objective 4.28838178e+04\n",
      "\n",
      "Crossover log...\n",
      "\n",
      "   53749 DPushes remaining with DInf 0.0000000e+00                58s\n",
      "    5830 DPushes remaining with DInf 0.0000000e+00                60s\n",
      "       0 DPushes remaining with DInf 0.0000000e+00                65s\n",
      "\n",
      "    3062 PPushes remaining with PInf 2.7143602e-02                65s\n",
      "    2641 PPushes remaining with PInf 1.5617888e-02                65s\n",
      "       0 PPushes remaining with PInf 0.0000000e+00                66s\n",
      "\n",
      "  Push phase complete: Pinf 0.0000000e+00, Dinf 8.0106546e+01     66s\n",
      "\n",
      "Iteration    Objective       Primal Inf.    Dual Inf.      Time\n",
      "   39744    4.2883818e+04   0.000000e+00   8.010655e+01     66s\n",
      "Extra simplex iterations after uncrush: 1\n",
      "   39962    4.2883818e+04   0.000000e+00   0.000000e+00     67s\n",
      "\n",
      "Solved in 39962 iterations and 67.15 seconds (86.38 work units)\n",
      "Optimal objective  4.288381774e+04\n",
      "\bGurobi 11.0.0: optimal solution; objective 42883.81774\n",
      "39962 simplex iteration(s)\n",
      "84 barrier iteration(s)\n"
     ]
    }
   ],
   "source": [
    "results_tc = energyscope_lca.calc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:18:05.809261Z",
     "start_time": "2026-02-20T15:18:05.789832Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TotalLCIA</th>\n",
       "      <th>Run</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>TTEQ</th>\n",
       "      <td>1480.600133</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TTHH</th>\n",
       "      <td>1137.142874</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        TotalLCIA  Run\n",
       "TTEQ  1480.600133    0\n",
       "TTHH  1137.142874    0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results_tc.variables['TotalLCIA']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You might want to change the objective function with an environmental objective, such as the life-cycle greenhouse gas emissions, or the total damage on human health/ecosystem quality. Alternatively, you can also add a constraint on the total life-cycle impact, to be lower than a certain threshold."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:19:22.795844Z",
     "start_time": "2026-02-20T15:19:22.788504Z"
    }
   },
   "outputs": [],
   "source": [
    "# To change the objective function\n",
    "# energyscope_lca.es_model.eval(\"\"\"\n",
    "# drop obj;\n",
    "# minimize new_obj: TotalLCIA_TTHH;\n",
    "# \"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:20:01.704945Z",
     "start_time": "2026-02-20T15:20:01.694141Z"
    }
   },
   "outputs": [],
   "source": [
    "# To add upper limits on environmental impacts\n",
    "reduction_target = 0.5  # for instance, 50% reduction target of damages\n",
    "scenario_file_path = LCA_RESULTS_FOLDER + 'scenario.dat'\n",
    "with open(scenario_file_path, 'w', encoding='utf-8', newline='\\n') as f:\n",
    "    f.write(f\"let limit_lcia['TTHH'] := {reduction_target} * {results_tc.variables['TotalLCIA'].loc['TTHH'].iloc[0]};\\n\")\n",
    "    f.write(f\"let limit_lcia['TTEQ'] := {reduction_target} * {results_tc.variables['TotalLCIA'].loc['TTEQ'].iloc[0]};\\n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:21:36.040537Z",
     "start_time": "2026-02-20T15:21:36.032563Z"
    }
   },
   "outputs": [],
   "source": [
    "core = core.__add__(Model([('dat', scenario_file_path)]))  # add the scenario file to the core model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:25:26.999072Z",
     "start_time": "2026-02-20T15:25:26.925190Z"
    }
   },
   "outputs": [],
   "source": [
    "energyscope_lca = Energyscope(\n",
    "    model=core,\n",
    "    solver_options={'solver': 'gurobi', 'gurobi_options':'outlev=1 NumericFocus=2 method=2'},\n",
    "    modules=['gurobi'],\n",
    "    license_uuid=license_uuid,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:28:36.227754Z",
     "start_time": "2026-02-20T15:25:28.108283Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gurobi 11.0.0: Set parameter LogToConsole to value 1\n",
      "  tech:outlev = 1\n",
      "Set parameter NumericFocus to value 2\n",
      "  alg:numericfocus = 2\n",
      "Set parameter Method to value 2\n",
      "  alg:method = 2\n",
      "Set parameter InfUnbdInfo to value 1\n",
      "Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (mac64[arm] - Darwin 23.5.0 23F79)\n",
      "\n",
      "CPU model: Apple M2 Pro\n",
      "Thread count: 10 physical cores, 10 logical processors, using up to 10 threads\n",
      "\n",
      "Optimize a model with 491079 rows, 268733 columns and 1576042 nonzeros\n",
      "Model fingerprint: 0xdcb6a7e9\n",
      "Coefficient statistics:\n",
      "  Matrix range     [1e-06, 7e+04]\n",
      "  Objective range  [1e+00, 1e+00]\n",
      "  Bounds range     [2e-02, 7e+02]\n",
      "  RHS range        [1e+00, 4e+04]\n",
      "Presolve removed 243244 rows and 128162 columns\n",
      "Presolve time: 1.09s\n",
      "Presolved: 247835 rows, 140571 columns, 825165 nonzeros\n",
      "\n",
      "Ordering time: 3.75s\n",
      "\n",
      "Barrier statistics:\n",
      " Dense cols : 98\n",
      " AA' NZ     : 3.844e+06\n",
      " Factor NZ  : 1.872e+07 (roughly 300 MB of memory)\n",
      " Factor Ops : 7.224e+09 (less than 1 second per iteration)\n",
      " Threads    : 10\n",
      "\n",
      "                  Objective                Residual\n",
      "Iter       Primal          Dual         Primal    Dual     Compl     Time\n",
      "   0   2.53843025e+06 -2.99215692e+05  3.27e+06 3.55e-14  1.00e+06     6s\n",
      "   1   3.04076457e+06 -7.18144107e+05  2.82e+06 8.33e+02  9.89e+05     6s\n",
      "   2   3.18107906e+06 -3.60235627e+06  2.48e+06 6.92e+02  7.95e+05     6s\n",
      "   3   4.56493266e+06 -1.18222818e+07  1.98e+06 5.19e+02  6.15e+05     7s\n",
      "   4   5.54382554e+06 -2.08075497e+07  9.34e+05 3.58e+02  4.06e+05     7s\n",
      "   5   5.47355389e+06 -3.09204199e+07  4.47e+05 1.57e+02  1.83e+05     8s\n",
      "   6   4.57233413e+06 -3.60665673e+07  2.64e+05 8.59e+01  1.02e+05     8s\n",
      "   7   3.83989050e+06 -4.28818121e+07  1.81e+05 5.05e+01  6.35e+04     8s\n",
      "   8   2.96318349e+06 -4.36282973e+07  1.14e+05 4.50e+01  5.32e+04     9s\n",
      "   9   2.36873470e+06 -5.37880547e+07  7.84e+04 2.54e+01  3.30e+04     9s\n",
      "  10   1.93445861e+06 -5.87250366e+07  5.74e+04 1.93e+01  2.50e+04     9s\n",
      "  11   1.80936991e+06 -5.98724256e+07  5.11e+04 1.58e+01  2.03e+04     9s\n",
      "  12   1.60562656e+06 -6.31849344e+07  3.95e+04 1.06e+01  1.49e+04    10s\n",
      "  13   1.47890144e+06 -5.97169202e+07  2.86e+04 7.98e+00  1.10e+04    10s\n",
      "  14   1.54082883e+06 -5.44646230e+07  2.31e+04 6.59e+00  8.84e+03    11s\n",
      "  15   1.70192735e+06 -5.14513691e+07  1.84e+04 6.16e+00  7.95e+03    11s\n",
      "  16   2.64073408e+06 -3.61262867e+07  9.28e+03 3.60e+00  4.69e+03    12s\n",
      "  17   3.22595919e+06 -2.47893877e+07  4.72e+03 2.06e+00  2.75e+03    12s\n",
      "  18   3.36953008e+06 -1.90952308e+07  3.12e+03 1.20e+00  1.64e+03    13s\n",
      "  19   3.46994899e+06 -1.77935448e+07  1.79e+03 1.05e+00  1.41e+03    13s\n",
      "  20   3.48520576e+06 -1.13073450e+07  1.33e+03 4.62e-01  6.56e+02    13s\n",
      "  21   3.30532899e+06 -5.78248305e+06  5.72e+02 1.72e-01  2.52e+02    13s\n",
      "  22   2.86627597e+06 -2.39424076e+06  2.40e+02 5.81e-02  9.02e+01    14s\n",
      "  23   2.00349506e+06 -1.41483522e+06  1.09e+02 3.27e-02  4.95e+01    14s\n",
      "  24   1.17009444e+06 -5.01615907e+05  3.23e+01 1.00e-02  1.69e+01    14s\n",
      "  25   6.39351203e+05 -2.74630866e+05  1.29e+01 5.12e-03  8.62e+00    15s\n",
      "  26   3.91972204e+05 -1.93791942e+05  6.91e+00 3.08e-03  5.15e+00    15s\n",
      "  27   3.63207139e+05 -1.25667056e+05  6.39e+00 1.74e-03  3.45e+00    15s\n",
      "  28   3.59261701e+05 -1.05506447e+05  6.20e+00 1.48e-03  3.11e+00    16s\n",
      "  29   2.51020289e+05 -8.13710586e+04  3.88e+00 1.17e-03  2.28e+00    16s\n",
      "  30   2.01903969e+05 -6.02203511e+04  3.01e+00 9.11e-04  1.77e+00    16s\n",
      "  31   1.76234214e+05 -3.68403815e+04  2.42e+00 7.25e-04  1.42e+00    17s\n",
      "  32   1.61180575e+05 -4.70450996e+03  1.77e+00 5.16e-04  1.06e+00    17s\n",
      "  33   1.47262965e+05  8.09243903e+03  1.46e+00 4.32e-04  8.83e-01    18s\n",
      "  34   1.26371833e+05  2.26577691e+04  9.82e-01 3.35e-04  6.64e-01    18s\n",
      "  35   1.19276413e+05  3.71262364e+04  8.59e-01 2.38e-04  5.05e-01    19s\n",
      "  36   1.10073313e+05  4.55089831e+04  7.10e-01 1.77e-04  3.94e-01    19s\n",
      "  37   1.01343133e+05  4.94201905e+04  5.83e-01 1.42e-04  3.25e-01    20s\n",
      "  38   9.34773402e+04  5.14798974e+04  4.84e-01 1.20e-04  2.77e-01    21s\n",
      "  39   8.92751601e+04  5.27248989e+04  4.31e-01 1.10e-04  2.48e-01    22s\n",
      "  40   8.35868864e+04  5.34854887e+04  3.44e-01 9.65e-05  2.12e-01    22s\n",
      "  41   7.83983589e+04  5.51154446e+04  2.56e-01 7.37e-05  1.63e-01    23s\n",
      "  42   7.46263093e+04  5.65402182e+04  2.00e-01 5.31e-05  1.22e-01    23s\n",
      "  43   7.09943711e+04  5.74514802e+04  1.47e-01 3.84e-05  9.00e-02    24s\n",
      "  44   6.97634736e+04  5.79259480e+04  1.30e-01 3.16e-05  7.67e-02    25s\n",
      "  45   6.87002534e+04  5.82711939e+04  1.16e-01 2.63e-05  6.61e-02    25s\n",
      "  46   6.76451941e+04  5.85570027e+04  1.02e-01 2.10e-05  5.56e-02    26s\n",
      "  47   6.70852871e+04  5.87171482e+04  9.53e-02 1.79e-05  4.98e-02    26s\n",
      "  48   6.68973058e+04  5.87808962e+04  9.28e-02 1.68e-05  4.77e-02    27s\n",
      "  49   6.57836808e+04  5.89188917e+04  7.89e-02 1.41e-05  4.04e-02    27s\n",
      "  50   6.46067235e+04  5.90295130e+04  6.41e-02 1.19e-05  3.34e-02    28s\n",
      "  51   6.35207274e+04  5.91090125e+04  5.03e-02 1.03e-05  2.73e-02    28s\n",
      "  52   6.28148607e+04  5.92760786e+04  4.06e-02 7.10e-06  2.06e-02    29s\n",
      "  53   6.18438911e+04  5.93640618e+04  2.72e-02 5.54e-06  1.50e-02    29s\n",
      "  54   6.12747598e+04  5.94494550e+04  1.95e-02 4.25e-06  1.12e-02    30s\n",
      "  55   6.07002614e+04  5.95266244e+04  1.15e-02 3.20e-06  7.63e-03    31s\n",
      "  56   6.05388849e+04  5.95731258e+04  9.36e-03 2.54e-06  6.15e-03    31s\n",
      "  57   6.03611503e+04  5.96082897e+04  6.94e-03 2.07e-06  4.86e-03    32s\n",
      "  58   6.02612497e+04  5.96747256e+04  5.51e-03 1.28e-06  3.43e-03    32s\n",
      "  59   6.02110801e+04  5.97017132e+04  4.76e-03 1.07e-06  2.92e-03    33s\n",
      "  60   6.01656906e+04  5.97281576e+04  4.15e-03 8.43e-07  2.43e-03    33s\n",
      "  61   6.01295901e+04  5.97474492e+04  3.65e-03 6.75e-07  2.05e-03    34s\n",
      "  62   6.00592385e+04  5.97539844e+04  2.68e-03 6.21e-07  1.70e-03    34s\n",
      "  63   6.00274421e+04  5.97714957e+04  2.25e-03 4.92e-07  1.39e-03    35s\n",
      "  64   6.00063199e+04  5.97832268e+04  1.96e-03 4.04e-07  1.18e-03    35s\n",
      "  65   5.99869217e+04  5.97951690e+04  1.70e-03 3.28e-07  9.91e-04    36s\n",
      "  66   5.99728583e+04  5.98009488e+04  1.51e-03 2.91e-07  8.82e-04    37s\n",
      "  67   5.99554247e+04  5.98085292e+04  1.29e-03 2.38e-07  7.40e-04    37s\n",
      "  68   5.99346101e+04  5.98180026e+04  1.01e-03 1.79e-07  5.74e-04    37s\n",
      "  69   5.99303783e+04  5.98212785e+04  9.52e-04 1.59e-07  5.29e-04    38s\n",
      "  70   5.99240814e+04  5.98273948e+04  8.73e-04 1.24e-07  4.54e-04    39s\n",
      "  71   5.99089482e+04  5.98292787e+04  6.79e-04 1.14e-07  3.80e-04    39s\n",
      "  72   5.99062123e+04  5.98312079e+04  6.48e-04 1.01e-07  3.52e-04    40s\n",
      "  73   5.98943187e+04  5.98321969e+04  5.07e-04 9.46e-08  2.97e-04    41s\n",
      "  74   5.98856417e+04  5.98347163e+04  4.05e-04 7.83e-08  2.42e-04    41s\n",
      "  75   5.98818806e+04  5.98376863e+04  3.59e-04 6.16e-08  2.05e-04    42s\n",
      "  76   5.98727580e+04  5.98398429e+04  2.50e-04 5.00e-08  1.54e-04    43s\n",
      "  77   5.98701402e+04  5.98411146e+04  2.19e-04 4.34e-08  1.35e-04    43s\n",
      "  78   5.98682990e+04  5.98425256e+04  1.98e-04 3.58e-08  1.17e-04    44s\n",
      "  79   5.98627424e+04  5.98440672e+04  1.32e-04 2.85e-08  8.58e-05    45s\n",
      "  80   5.98591239e+04  5.98456393e+04  9.12e-05 2.12e-08  6.18e-05    46s\n",
      "  81   5.98584576e+04  5.98460685e+04  8.42e-05 1.91e-08  5.65e-05    47s\n",
      "  82   5.98577825e+04  5.98474989e+04  7.70e-05 1.28e-08  4.50e-05    49s\n",
      "  83   5.98533242e+04  5.98488364e+04  2.84e-05 6.45e-09  1.99e-05    51s\n",
      "  84   5.98518840e+04  5.98493358e+04  1.41e-05 4.31e-09  1.16e-05    52s\n",
      "  85   5.98516221e+04  5.98493826e+04  1.15e-05 4.10e-09  1.03e-05    53s\n",
      "  86   5.98514260e+04  5.98495159e+04  9.66e-06 3.56e-09  8.81e-06    54s\n",
      "  87   5.98513880e+04  5.98496263e+04  9.30e-06 3.12e-09  8.04e-06    55s\n",
      "  88   5.98512869e+04  5.98496390e+04  8.33e-06 3.07e-09  7.59e-06    55s\n",
      "  89   5.98512330e+04  5.98496906e+04  7.80e-06 2.84e-09  7.09e-06    56s\n",
      "  90   5.98511585e+04  5.98498498e+04  7.05e-06 2.18e-09  5.90e-06    57s\n",
      "  91   5.98510341e+04  5.98499731e+04  5.81e-06 1.68e-09  4.73e-06    57s\n",
      "  92   5.98509843e+04  5.98499917e+04  5.34e-06 1.61e-09  4.45e-06    58s\n",
      "  93   5.98509258e+04  5.98500172e+04  4.78e-06 1.51e-09  4.09e-06    59s\n",
      "  94   5.98506864e+04  5.98500758e+04  2.44e-06 1.28e-09  2.88e-06    59s\n",
      "  95   5.98505216e+04  5.98502473e+04  8.96e-07 6.20e-10  1.31e-06    60s\n",
      "  96   5.98504547e+04  5.98503186e+04  3.22e-07 3.45e-10  6.69e-07    62s\n",
      "  97   5.98504496e+04  5.98503280e+04  2.82e-07 3.09e-10  5.98e-07    62s\n",
      "  98   5.98504415e+04  5.98503416e+04  2.19e-07 2.58e-10  4.93e-07    63s\n",
      "  99   5.98504310e+04  5.98503926e+04  1.42e-07 5.76e-11  1.69e-07    63s\n",
      " 100   5.98504127e+04  5.98504074e+04  2.12e-08 6.47e-12  2.26e-08    64s\n",
      " 101   5.98504097e+04  5.98504091e+04  2.00e-09 8.79e-13  2.38e-09    64s\n",
      " 102   5.98504094e+04  5.98504093e+04  2.58e-10 2.13e-12  2.39e-10    65s\n",
      "\n",
      "Barrier solved model in 102 iterations and 65.29 seconds (92.79 work units)\n",
      "Optimal objective 5.98504094e+04\n",
      "\n",
      "Crossover log...\n",
      "\n",
      "   42281 DPushes remaining with DInf 2.6466504e-02                66s\n",
      "    2272 DPushes remaining with DInf 0.0000000e+00                70s\n",
      "       0 DPushes remaining with DInf 0.0000000e+00                75s\n",
      "\n",
      "    3459 PPushes remaining with PInf 3.2086930e-05                75s\n",
      "    2433 PPushes remaining with PInf 1.8013505e-03                75s\n",
      "       0 PPushes remaining with PInf 0.0000000e+00                76s\n",
      "\n",
      "  Push phase complete: Pinf 0.0000000e+00, Dinf 6.0393358e-01     76s\n",
      "\n",
      "Iteration    Objective       Primal Inf.    Dual Inf.      Time\n",
      "   27352    5.9850411e+04   0.000000e+00   6.039336e-01     76s\n",
      "   27374    5.9850409e+04   0.000000e+00   0.000000e+00     76s\n",
      "\n",
      "Solved in 27374 iterations and 76.18 seconds (109.67 work units)\n",
      "Optimal objective  5.985040933e+04\n",
      "\bGurobi 11.0.0: optimal solution; objective 59850.40933\n",
      "27374 simplex iteration(s)\n",
      "102 barrier iteration(s)\n"
     ]
    }
   ],
   "source": [
    "results_lca = energyscope_lca.calc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:28:36.893633Z",
     "start_time": "2026-02-20T15:28:36.873267Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TotalLCIA</th>\n",
       "      <th>Run</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>TTEQ</th>\n",
       "      <td>740.300067</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TTHH</th>\n",
       "      <td>423.584077</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       TotalLCIA  Run\n",
       "TTEQ  740.300067    0\n",
       "TTHH  423.584077    0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results_lca.variables['TotalLCIA']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Formatting the results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:29:52.769168Z",
     "start_time": "2026-02-20T15:29:52.755788Z"
    }
   },
   "outputs": [],
   "source": [
    "results = results_lca  # choose among results_tc and results_lca"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:29:53.757002Z",
     "start_time": "2026-02-20T15:29:53.674711Z"
    }
   },
   "outputs": [],
   "source": [
    "df_annual_prod = pd.merge(results.variables['F_t'].reset_index(), results.parameters['t_op'].reset_index(), left_on=['index1', 'index2'], right_on=['index0', 'index1'], suffixes=('', '_'))\n",
    "df_annual_prod['Annual_Prod'] = df_annual_prod['F_t'] * df_annual_prod['t_op']\n",
    "df_annual_prod = df_annual_prod.groupby(['index0', 'Run'])['Annual_Prod'].sum().reset_index()\n",
    "df_installed_cap = results.variables['F'].reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:29:54.277639Z",
     "start_time": "2026-02-20T15:29:54.265039Z"
    }
   },
   "outputs": [],
   "source": [
    "df_annual_res = df_annual_prod[df_annual_prod.index0.isin(list(results.sets['RESOURCES'].RESOURCES))].rename(columns={'index0':'index', 'Annual_Prod':'Annual_Res'})\n",
    "df_annual_prod = df_annual_prod[~df_annual_prod.index0.isin(list(results.sets['RESOURCES'].RESOURCES))].rename(columns={'index0':'index'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:29:54.847841Z",
     "start_time": "2026-02-20T15:29:54.812210Z"
    }
   },
   "outputs": [],
   "source": [
    "esm_results_tech = pd.merge(\n",
    "    df_annual_prod,\n",
    "    df_installed_cap,\n",
    "    on=['index', 'Run']\n",
    ").rename(columns={'index':'Name', 'Annual_Prod': 'Production', 'F': 'Capacity'})\n",
    "esm_results_res = df_annual_res.rename(columns={'index': 'Name', 'Annual_Res': 'Import'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:29:55.391716Z",
     "start_time": "2026-02-20T15:29:55.375274Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Run</th>\n",
       "      <th>Production</th>\n",
       "      <th>Capacity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ATM_CCS</td>\n",
       "      <td>0</td>\n",
       "      <td>249.819476</td>\n",
       "      <td>1.642478</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>BEV_BATT</td>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>91.160423</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>BOAT_FREIGHT_NG</td>\n",
       "      <td>0</td>\n",
       "      <td>966.908558</td>\n",
       "      <td>30.521103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>BUS_COACH_HYDIESEL</td>\n",
       "      <td>0</td>\n",
       "      <td>551.338240</td>\n",
       "      <td>6.381230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>CAR_BEV</td>\n",
       "      <td>0</td>\n",
       "      <td>2756.691201</td>\n",
       "      <td>191.436889</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Name  Run   Production    Capacity\n",
       "2              ATM_CCS    0   249.819476    1.642478\n",
       "4             BEV_BATT    0     0.000000   91.160423\n",
       "10     BOAT_FREIGHT_NG    0   966.908558   30.521103\n",
       "14  BUS_COACH_HYDIESEL    0   551.338240    6.381230\n",
       "15             CAR_BEV    0  2756.691201  191.436889"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esm_results_tech = esm_results_tech[esm_results_tech.Capacity != 0]\n",
    "esm_results_tech.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:29:55.624055Z",
     "start_time": "2026-02-20T15:29:55.606652Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Run</th>\n",
       "      <th>Import</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>BIODIESEL</td>\n",
       "      <td>0</td>\n",
       "      <td>110.267648</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>CO2_ATM</td>\n",
       "      <td>0</td>\n",
       "      <td>249.819476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>CO2_EMISSIONS</td>\n",
       "      <td>0</td>\n",
       "      <td>435.516977</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>ELEC_EXPORT</td>\n",
       "      <td>0</td>\n",
       "      <td>671.424283</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>H2_RE</td>\n",
       "      <td>0</td>\n",
       "      <td>6180.293383</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             Name  Run       Import\n",
       "7       BIODIESEL    0   110.267648\n",
       "29        CO2_ATM    0   249.819476\n",
       "31  CO2_EMISSIONS    0   435.516977\n",
       "64    ELEC_EXPORT    0   671.424283\n",
       "76          H2_RE    0  6180.293383"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esm_results_res = esm_results_res[esm_results_res.Import != 0]\n",
    "esm_results_res.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:29:56.603858Z",
     "start_time": "2026-02-20T15:29:56.590135Z"
    }
   },
   "outputs": [],
   "source": [
    "esm_results_tech.to_csv(LCA_RESULTS_FOLDER+'esm_results_tech.csv', index=False)\n",
    "esm_results_res.to_csv(LCA_RESULTS_FOLDER+'esm_results_res.csv', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualise the results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:41:13.172101Z",
     "start_time": "2026-02-20T15:41:13.163264Z"
    }
   },
   "outputs": [],
   "source": [
    "plot = Plot(\n",
    "    df_impact_scores=impact_scores_lca,\n",
    "    esm_results_tech=esm_results_tech[~esm_results_tech.Name.isin(['ATM_CCS'])],  # negative impacts are not displayed in the following plots\n",
    "    esm_results_res=esm_results_res,\n",
    "    lifetime=lifetime,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:41:14.286493Z",
     "start_time": "2026-02-20T15:41:14.126058Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "customdata": [
          [
           "95.21 %"
          ],
          [
           "95.22 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "Construction",
         "marker": {
          "color": "#636efa",
          "pattern": {
           "shape": ""
          }
         },
         "name": "Construction",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "3l31uIjNV0A64G9nVc5XQA==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "0.85 %"
          ],
          [
           "1.17 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "Decommission",
         "marker": {
          "color": "#EF553B",
          "pattern": {
           "shape": ""
          }
         },
         "name": "Decommission",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "Pdkh2pUR6z+zxM9dh6jyPw==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "2.61 %"
          ],
          [
           "3.01 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "Operation",
         "marker": {
          "color": "#00cc96",
          "pattern": {
           "shape": ""
          }
         },
         "name": "Operation",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "qYULFm3oBEAja/L57QsIQA==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "1.33 %"
          ],
          [
           "0.60 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "Resource",
         "marker": {
          "color": "#ab63fa",
          "pattern": {
           "shape": ""
          }
         },
         "name": "Resource",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "npCAqSxE9T94raakhVTjPw==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        }
       ],
       "layout": {
        "barmode": "stack",
        "legend": {
         "title": {
          "text": "Type"
         },
         "tracegroupgap": 0
        },
        "margin": {
         "t": 60
        },
        "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"
           }
          ],
          "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"
           }
          ],
          "scattermap": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermap"
           }
          ],
          "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
          }
         }
        },
        "xaxis": {
         "anchor": "y",
         "domain": [
          0,
          1
         ],
         "title": {
          "text": "Normalized impacts"
         }
        },
        "yaxis": {
         "anchor": "x",
         "domain": [
          0,
          1
         ],
         "title": {
          "text": "Impact categories"
         }
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot.plot_results(\n",
    "    impact_categories_list=[\n",
    "        (\n",
    "        'IMPACT World+ Damage 2.1 for ecoinvent v3.10',\n",
    "        'Ecosystem quality',\n",
    "        'Total ecosystem quality',\n",
    "        ),\n",
    "        (\n",
    "        'IMPACT World+ Damage 2.1 for ecoinvent v3.10',\n",
    "        'Human health',\n",
    "        'Total human health',\n",
    "        ),\n",
    "    ],\n",
    "    normalized=True,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2026-02-20T15:41:27.708582Z",
     "start_time": "2026-02-20T15:41:27.576315Z"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "customdata": [
          [
           "1.60 %"
          ],
          [
           "1.18 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "BUS_COACH_HYDIESEL",
         "marker": {
          "color": "#636efa",
          "pattern": {
           "shape": ""
          }
         },
         "name": "BUS_COACH_HYDIESEL",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "8Qnzcp6g+T+A9AEIjezyPw==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "46.43 %"
          ],
          [
           "49.41 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "CAR_BEV",
         "marker": {
          "color": "#EF553B",
          "pattern": {
           "shape": ""
          }
         },
         "name": "CAR_BEV",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "xQsv/Is2R0A1iv+nJ7RIQA==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "1.12 %"
          ],
          [
           "1.51 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "DEC_ADVCOGEN_GAS",
         "marker": {
          "color": "#00cc96",
          "pattern": {
           "shape": ""
          }
         },
         "name": "DEC_ADVCOGEN_GAS",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "ekyfuTf58T8CLRC++yz4Pw==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "4.09 %"
          ],
          [
           "2.82 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "DEC_ADVCOGEN_H2",
         "marker": {
          "color": "#ab63fa",
          "pattern": {
           "shape": ""
          }
         },
         "name": "DEC_ADVCOGEN_H2",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "CBGOOwhdEEBdKjGm5JAGQA==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "1.47 %"
          ],
          [
           "0.86 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "H2_RE",
         "marker": {
          "color": "#FFA15A",
          "pattern": {
           "shape": ""
          }
         },
         "name": "H2_RE",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "v0pySAyO9z9G7FUsnKzrPw==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "3.98 %"
          ],
          [
           "4.42 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "OTHER",
         "marker": {
          "color": "#19d3f3",
          "pattern": {
           "shape": ""
          }
         },
         "name": "OTHER",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "KSxifirQD0Bs1GSqPbERQA==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "15.59 %"
          ],
          [
           "15.58 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "PV",
         "marker": {
          "color": "#FF6692",
          "pattern": {
           "shape": ""
          }
         },
         "name": "PV",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "u40cfH8tL0DTxzaxsScvQA==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "2.46 %"
          ],
          [
           "2.23 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "SYN_METHANATION",
         "marker": {
          "color": "#B6E880",
          "pattern": {
           "shape": ""
          }
         },
         "name": "SYN_METHANATION",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "w7BfBVSuA0Bb9mdaeNkBQA==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "18.47 %"
          ],
          [
           "16.80 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "TRUCK_ELEC",
         "marker": {
          "color": "#FF97FF",
          "pattern": {
           "shape": ""
          }
         },
         "name": "TRUCK_ELEC",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "jxg9tGx4MkB2F5Rh7s0wQA==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "2.17 %"
          ],
          [
           "2.48 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "WIND_OFFSHORE",
         "marker": {
          "color": "#FECB52",
          "pattern": {
           "shape": ""
          }
         },
         "name": "WIND_OFFSHORE",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "W+6cpVNhAUBqKf78zt4DQA==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        },
        {
         "customdata": [
          [
           "2.62 %"
          ],
          [
           "2.69 %"
          ]
         ],
         "hovertemplate": "<br><b>Impact category</b>: %{y}</br><b>Normalized impacts</b>: %{customdata}</br>",
         "insidetextanchor": "middle",
         "legendgroup": "WIND_ONSHORE",
         "marker": {
          "color": "#636efa",
          "pattern": {
           "shape": ""
          }
         },
         "name": "WIND_ONSHORE",
         "orientation": "h",
         "showlegend": true,
         "textposition": "auto",
         "texttemplate": "%{x:.2s}",
         "type": "bar",
         "x": {
          "bdata": "cwq3zwjwBEDpAgzuuIsFQA==",
          "dtype": "f8"
         },
         "xaxis": "x",
         "y": [
          "Total ecosystem quality",
          "Total human health"
         ],
         "yaxis": "y"
        }
       ],
       "layout": {
        "barmode": "stack",
        "legend": {
         "title": {
          "text": "Name"
         },
         "tracegroupgap": 0
        },
        "margin": {
         "t": 60
        },
        "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"
           }
          ],
          "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"
           }
          ],
          "scattermap": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermap"
           }
          ],
          "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
          }
         }
        },
        "xaxis": {
         "anchor": "y",
         "domain": [
          0,
          1
         ],
         "title": {
          "text": "Normalized impacts"
         }
        },
        "yaxis": {
         "anchor": "x",
         "domain": [
          0,
          1
         ],
         "title": {
          "text": "Impact categories"
         }
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot.plot_results(\n",
    "    impact_categories_list=[\n",
    "        (\n",
    "        'IMPACT World+ Damage 2.1 for ecoinvent v3.10',\n",
    "        'Ecosystem quality',\n",
    "        'Total ecosystem quality',\n",
    "        ),\n",
    "        (\n",
    "        'IMPACT World+ Damage 2.1 for ecoinvent v3.10',\n",
    "        'Human health',\n",
    "        'Total human health',\n",
    "        ),\n",
    "    ],\n",
    "    normalized=True,\n",
    "    split_by='Name',\n",
    "    N_highest_contributors=10,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Due to IAM projections (in the present case, scenario SSP2-RCP26 run in TIAM-UCL) in the LCA database, some important changes occur in LCA datasets. For instance, diesel production has switched to biodiesel (from used cooking oil with CCS). Consequently, CO2 emissions from diesel combustion are biogenic (i.e., their characterization factor is 0) and the impact of TRUCK_DIESEL mostly comes from its construction."
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": [
    {
     "file_id": "1iXiT1Y7Ld9Cy9BVn8DyUan3JyaPru8sB",
     "timestamp": 1760451064422
    }
   ]
  },
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
