{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Workflow for a multi-regional energy system\n",
    "\n",
    "In this application of the FINE framework, a multi-regional energy system is modeled and optimized.\n",
    "\n",
    "All classes which are available to the user are utilized and examples of the selection of different parameters within these classes are given.\n",
    "\n",
    "The workflow is structures as follows:\n",
    "1. Required packages are imported and the input data path is set\n",
    "2. An energy system model instance is created\n",
    "3. Commodity sources are added to the energy system model\n",
    "4. Commodity conversion components are added to the energy system model\n",
    "5. Commodity storages are added to the energy system model\n",
    "6. Commodity transmission components are added to the energy system model\n",
    "7. Commodity sinks are added to the energy system model\n",
    "8. The energy system model is optimized\n",
    "9. Selected optimization results are presented\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. Import required packages and set input data path\n",
    "\n",
    "The FINE framework is imported which provides the required classes and functions for modeling the energy system."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import FINE as fn\n",
    "import matplotlib.pyplot as plt\n",
    "from getData import getData\n",
    "import pandas as pd\n",
    "import os\n",
    "\n",
    "cwd = os.getcwd()\n",
    "data = getData()\n",
    "\n",
    "%matplotlib inline  \n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. Create an energy system model instance \n",
    "\n",
    "The structure of the energy system model is given by the considered locations, commodities, the number of time steps as well as the hours per time step.\n",
    "\n",
    "The commodities are specified by a unit (i.e. 'GW_electric', 'GW_H2lowerHeatingValue', 'Mio. t CO2/h') which can be given as an energy or mass unit per hour. Furthermore, the cost unit and length unit are specified."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "locations = {'cluster_0', 'cluster_1', 'cluster_2', 'cluster_3', 'cluster_4', 'cluster_5', 'cluster_6', 'cluster_7'}\n",
    "commodityUnitDict = {'electricity': r'GW$_{el}$', 'methane': r'GW$_{CH_{4},LHV}$', 'biogas': r'GW$_{biogas,LHV}$',\n",
    "                     'CO2': r'Mio. t$_{CO_2}$/h', 'hydrogen': r'GW$_{H_{2},LHV}$'}\n",
    "commodities = {'electricity', 'hydrogen', 'methane', 'biogas', 'CO2'}\n",
    "numberOfTimeSteps=8760\n",
    "hoursPerTimeStep=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM = fn.EnergySystemModel(locations=locations, commodities=commodities, numberOfTimeSteps=8760,\n",
    "                           commodityUnitsDict=commodityUnitDict,\n",
    "                           hoursPerTimeStep=1, costUnit='1e9 Euro', lengthUnit='km', verboseLogLevel=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "CO2_reductionTarget = 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3. Add commodity sources to the energy system model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.1. Electricity sources"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Wind onshore"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Source(esM=esM, name='Wind (onshore)', commodity='electricity', hasCapacityVariable=True,\n",
    "                  operationRateMax=data['Wind (onshore), operationRateMax'],\n",
    "                  capacityMax=data['Wind (onshore), capacityMax'],\n",
    "                  investPerCapacity=1.1, opexPerCapacity=1.1*0.02, interestRate=0.08,\n",
    "                  economicLifetime=20))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Full load hours:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "cluster_0    1572.003960\n",
       "cluster_1    2350.292663\n",
       "cluster_2    2374.507270\n",
       "cluster_3    2186.572278\n",
       "cluster_4    1572.650655\n",
       "cluster_5    1767.840650\n",
       "cluster_6    2719.564564\n",
       "cluster_7    1553.045964\n",
       "dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Wind (onshore), operationRateMax'].sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Wind offshore"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Source(esM=esM, name='Wind (offshore)', commodity='electricity', hasCapacityVariable=True,\n",
    "                  operationRateMax=data['Wind (offshore), operationRateMax'],\n",
    "                  capacityMax=data['Wind (offshore), capacityMax'],\n",
    "                  investPerCapacity=2.3, opexPerCapacity=2.3*0.02, interestRate=0.08,\n",
    "                  economicLifetime=20))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Full load hours:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "cluster_0       0.000000\n",
       "cluster_1    4435.420314\n",
       "cluster_2    4301.655834\n",
       "cluster_3    3902.391858\n",
       "cluster_4       0.000000\n",
       "cluster_5       0.000000\n",
       "cluster_6    4609.508396\n",
       "cluster_7       0.000000\n",
       "dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Wind (offshore), operationRateMax'].sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### PV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Source(esM=esM, name='PV', commodity='electricity', hasCapacityVariable=True,\n",
    "                  operationRateMax=data['PV, operationRateMax'], capacityMax=data['PV, capacityMax'],\n",
    "                  investPerCapacity=0.65, opexPerCapacity=0.65*0.02, interestRate=0.08,\n",
    "                  economicLifetime=25))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Full load hours:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "cluster_0    1113.216464\n",
       "cluster_1    1053.579422\n",
       "cluster_2    1058.005181\n",
       "cluster_3    1079.872237\n",
       "cluster_4    1140.407380\n",
       "cluster_5    1051.848141\n",
       "cluster_6    1069.843344\n",
       "cluster_7    1085.697466\n",
       "dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['PV, operationRateMax'].sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exisisting run-of-river hydroelectricity plants"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Source(esM=esM, name='Existing run-of-river plants', commodity='electricity',\n",
    "                  hasCapacityVariable=True,\n",
    "                  operationRateFix=data['Existing run-of-river plants, operationRateFix'], tsaWeight=0.01,\n",
    "                  capacityFix=data['Existing run-of-river plants, capacityFix'],\n",
    "                  investPerCapacity=0, opexPerCapacity=0.208))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.2. Methane (natural gas and biogas)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Natural gas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Source(esM=esM, name='Natural gas purchase', commodity='methane',\n",
    "                  hasCapacityVariable=False, commodityCost=0.0331*1e-3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Biogas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Source(esM=esM, name='Biogas purchase', commodity='biogas',\n",
    "                  operationRateMax=data['Biogas, operationRateMax'], hasCapacityVariable=False,\n",
    "                  commodityCost=0.05409*1e-3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4. Add conversion components to the energy system model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Combined cycle gas turbine plants"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Conversion(esM=esM, name='CCGT plants (methane)', physicalUnit=r'GW$_{el}$',\n",
    "                      commodityConversionFactors={'electricity':1, 'methane':-1/0.6, 'CO2':201*1e-6/0.6},\n",
    "                      hasCapacityVariable=True,\n",
    "                      investPerCapacity=0.65, opexPerCapacity=0.021, interestRate=0.08,\n",
    "                      economicLifetime=33))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### New combined cycle gas turbine plants for biogas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Conversion(esM=esM, name='New CCGT plants (biogas)', physicalUnit=r'GW$_{el}$',\n",
    "                      commodityConversionFactors={'electricity':1, 'biogas':-1/0.63},\n",
    "                      hasCapacityVariable=True, \n",
    "                      investPerCapacity=0.7, opexPerCapacity=0.021, interestRate=0.08,\n",
    "                      economicLifetime=33))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### New combined cycly gas turbines for hydrogen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Conversion(esM=esM, name='New CCGT plants (hydrogen)', physicalUnit=r'GW$_{el}$',\n",
    "                      commodityConversionFactors={'electricity':1, 'hydrogen':-1/0.63},\n",
    "                      hasCapacityVariable=True, \n",
    "                      investPerCapacity=0.7, opexPerCapacity=0.021, interestRate=0.08,\n",
    "                      economicLifetime=33))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Electrolyzers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Conversion(esM=esM, name='Electrolyzer', physicalUnit=r'GW$_{el}$',\n",
    "                      commodityConversionFactors={'electricity':-1, 'hydrogen':0.7},\n",
    "                      hasCapacityVariable=True, \n",
    "                      investPerCapacity=0.5, opexPerCapacity=0.5*0.025, interestRate=0.08,\n",
    "                      economicLifetime=10))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### rSOC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "capexRSOC=1.5\n",
    "\n",
    "esM.add(fn.Conversion(esM=esM, name='rSOEC', physicalUnit=r'GW$_{el}$', linkedConversionCapacityID='rSOC',\n",
    "                      commodityConversionFactors={'electricity':-1, 'hydrogen':0.6},\n",
    "                      hasCapacityVariable=True, \n",
    "                      investPerCapacity=capexRSOC/2, opexPerCapacity=capexRSOC*0.02/2, interestRate=0.08,\n",
    "                      economicLifetime=10))\n",
    "\n",
    "esM.add(fn.Conversion(esM=esM, name='rSOFC', physicalUnit=r'GW$_{el}$', linkedConversionCapacityID='rSOC',\n",
    "                      commodityConversionFactors={'electricity':1, 'hydrogen':-1/0.6},\n",
    "                      hasCapacityVariable=True, \n",
    "                      investPerCapacity=capexRSOC/2, opexPerCapacity=capexRSOC*0.02/2, interestRate=0.08,\n",
    "                      economicLifetime=10))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5. Add commodity storages to the energy system model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.1. Electricity storage"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lithium ion batteries\n",
    "\n",
    "The self discharge of a lithium ion battery is here described as 3% per month. The self discharge per hours is obtained using the equation (1-$\\text{selfDischarge}_\\text{hour})^{30*24\\text{h}} = 1-\\text{selfDischarge}_\\text{month}$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Storage(esM=esM, name='Li-ion batteries', commodity='electricity',\n",
    "                   hasCapacityVariable=True, chargeEfficiency=0.95,\n",
    "                   cyclicLifetime=10000, dischargeEfficiency=0.95, selfDischarge=1-(1-0.03)**(1/(30*24)),\n",
    "                   chargeRate=1, dischargeRate=1, doPreciseTsaModeling=False,\n",
    "                   investPerCapacity=0.151, opexPerCapacity=0.002, interestRate=0.08,\n",
    "                   economicLifetime=22))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.2. Hydrogen storage"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Hydrogen filled salt caverns\n",
    "The maximum capacity is here obtained by: dividing the given capacity (which is given for methane) by the lower heating value of methane and then multiplying it with the lower heating value of hydrogen."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Storage(esM=esM, name='Salt caverns (hydrogen)', commodity='hydrogen',\n",
    "                   hasCapacityVariable=True, capacityVariableDomain='continuous',\n",
    "                   capacityPerPlantUnit=133,\n",
    "                   chargeRate=1/470.37, dischargeRate=1/470.37, sharedPotentialID='Existing salt caverns',\n",
    "                   stateOfChargeMin=0.33, stateOfChargeMax=1, capacityMax=data['Salt caverns (hydrogen), capacityMax'],\n",
    "                   investPerCapacity=0.00011, opexPerCapacity=0.00057, interestRate=0.08,\n",
    "                   economicLifetime=30))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.3. Methane storage"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Methane filled salt caverns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Storage(esM=esM, name='Salt caverns (biogas)', commodity='biogas',\n",
    "                   hasCapacityVariable=True, capacityVariableDomain='continuous',\n",
    "                   capacityPerPlantUnit=443,\n",
    "                   chargeRate=1/470.37, dischargeRate=1/470.37, sharedPotentialID='Existing salt caverns',\n",
    "                   stateOfChargeMin=0.33, stateOfChargeMax=1, capacityMax=data['Salt caverns (methane), capacityMax'],\n",
    "                   investPerCapacity=0.00004, opexPerCapacity=0.00001, interestRate=0.08,\n",
    "                   economicLifetime=30))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.4 Pumped hydro storage"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pumped hydro storage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Storage(esM=esM, name='Pumped hydro storage', commodity='electricity',\n",
    "                   chargeEfficiency=0.88, dischargeEfficiency=0.88,\n",
    "                   hasCapacityVariable=True, selfDischarge=1-(1-0.00375)**(1/(30*24)),\n",
    "                   chargeRate=0.16, dischargeRate=0.12, capacityFix=data['Pumped hydro storage, capacityFix'],\n",
    "                   investPerCapacity=0, opexPerCapacity=0.000153))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 6. Add commodity transmission components to the energy system model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.1. Electricity transmission"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### AC cables"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "esM.add(fn.LinearOptimalPowerFlow(esM=esM, name='AC cables', commodity='electricity',\n",
    "                                  hasCapacityVariable=True, capacityFix=data['AC cables, capacityFix'],\n",
    "                                  reactances=data['AC cables, reactances']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The distances of a component are set to a normalized value of 1.\n"
     ]
    }
   ],
   "source": [
    "esM.add(fn.Transmission(esM=esM, name='AC cables', commodity='electricity',\n",
    "                                  hasCapacityVariable=True, capacityFix=data['AC cables, capacityFix']))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### DC cables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Transmission(esM=esM, name='DC cables', commodity='electricity', losses=data['DC cables, losses'],\n",
    "                        distances=data['DC cables, distances'],\n",
    "                        hasCapacityVariable=True, capacityFix=data['DC cables, capacityFix']))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.2 Methane transmission"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Methane pipeline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "esM.add(fn.Transmission(esM=esM, name='Pipelines (biogas)', commodity='biogas', \n",
    "                        distances=data['Pipelines, distances'],\n",
    "                        hasCapacityVariable=True, hasIsBuiltBinaryVariable=True, bigM=300,\n",
    "                        locationalEligibility=data['Pipelines, eligibility'],\n",
    "                        capacityMax=data['Pipelines, eligibility']*15, sharedPotentialID='pipelines',\n",
    "                        investPerCapacity=0.000037, investIfBuilt=0.000314,\n",
    "                        interestRate=0.08, economicLifetime=40))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.3 Hydrogen transmission"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Hydrogen pipelines"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "esM.add(fn.Transmission(esM=esM, name='Pipelines (hydrogen)', commodity='hydrogen',\n",
    "                        distances=data['Pipelines, distances'],\n",
    "                        hasCapacityVariable=True, hasIsBuiltBinaryVariable=True, bigM=300,\n",
    "                        locationalEligibility=data['Pipelines, eligibility'],\n",
    "                        capacityMax=data['Pipelines, eligibility']*15, sharedPotentialID='pipelines',\n",
    "                        investPerCapacity=0.000177, investIfBuilt=0.00033,\n",
    "                        interestRate=0.08, economicLifetime=40))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7. Add commodity sinks to the energy system model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.1. Electricity sinks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Electricity demand"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Sink(esM=esM, name='Electricity demand', commodity='electricity',\n",
    "                hasCapacityVariable=False, operationRateFix=data['Electricity demand, operationRateFix']))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.2. Hydrogen sinks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Fuel cell electric vehicle (FCEV) demand"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "FCEV_penetration=0.5\n",
    "esM.add(fn.Sink(esM=esM, name='Hydrogen demand', commodity='hydrogen', hasCapacityVariable=False,\n",
    "                operationRateFix=data['Hydrogen demand, operationRateFix']*FCEV_penetration))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.3. CO2 sinks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### CO2 exiting the system's boundary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "esM.add(fn.Sink(esM=esM, name='CO2 to enviroment', commodity='CO2',\n",
    "                hasCapacityVariable=False, commodityLimitID='CO2 limit', yearlyLimit=366*(1-CO2_reductionTarget)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 8. Optimize energy system model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All components are now added to the model and the model can be optimized. If the computational complexity of the optimization should be reduced, the time series data of the specified components can be clustered before the optimization and the parameter timeSeriesAggregation is set to True in the optimize call."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Clustering time series data with 7 typical periods and 24 time steps per period...\n",
      "\t\t(4.4210 sec)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "esM.cluster(numberOfTypicalPeriods=7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time series aggregation specifications:\n",
      "Number of typical periods:7, number of time steps per periods:24\n",
      "\n",
      "Declaring sets, variables and constraints for SourceSinkModel\n",
      "\tdeclaring sets... \n",
      "\tdeclaring variables... \n",
      "\tdeclaring constraints... \n",
      "\t\t(1.2341 sec)\n",
      "\n",
      "Declaring sets, variables and constraints for ConversionModel\n",
      "\tdeclaring sets... \n",
      "\tdeclaring variables... \n",
      "\tdeclaring constraints... \n",
      "\t\t(0.1875 sec)\n",
      "\n",
      "Declaring sets, variables and constraints for StorageModel\n",
      "\tdeclaring sets... \n",
      "\tdeclaring variables... \n",
      "\tdeclaring constraints... \n",
      "\t\t(1.8277 sec)\n",
      "\n",
      "Declaring sets, variables and constraints for TransmissionModel\n",
      "\tdeclaring sets... \n",
      "\tdeclaring variables... \n",
      "\tdeclaring constraints... \n",
      "\t\t(0.3437 sec)\n",
      "\n",
      "Declaring shared potential constraint...\n",
      "\t\t(0.0000 sec)\n",
      "\n",
      "Declaring commodity balances...\n",
      "\t\t(1.0310 sec)\n",
      "\n",
      "Declaring objective function...\n",
      "\t\t(0.3281 sec)\n",
      "\n",
      "Using license file C:\\Users\\there\\gurobi.lic\n",
      "Academic license - for non-commercial use only\n",
      "Read LP format model from file C:\\Users\\there\\AppData\\Local\\Temp\\tmpohypen6h.pyomo.lp\n",
      "Reading time = 0.31 seconds\n",
      "x55618: 85942 rows, 55618 columns, 264787 nonzeros\n",
      "Changed value of parameter QCPDual to 1\n",
      "   Prev: 0  Min: 0  Max: 1  Default: 0\n",
      "Changed value of parameter Threads to 3\n",
      "   Prev: 0  Min: 0  Max: 1024  Default: 0\n",
      "Parameter logfile unchanged\n",
      "   Value:   Default: \n",
      "Changed value of parameter OptimalityTol to 0.001\n",
      "   Prev: 1e-06  Min: 1e-09  Max: 0.01  Default: 1e-06\n",
      "Changed value of parameter method to 2\n",
      "   Prev: -1  Min: -1  Max: 5  Default: -1\n",
      "Changed value of parameter cuts to 0\n",
      "   Prev: -1  Min: -1  Max: 3  Default: -1\n",
      "Gurobi Optimizer version 9.0.0 build v9.0.0rc2 (win64)\n",
      "Optimize a model with 85942 rows, 55618 columns and 264787 nonzeros\n",
      "Model fingerprint: 0xb67e135e\n",
      "Variable types: 55566 continuous, 52 integer (52 binary)\n",
      "Coefficient statistics:\n",
      "  Matrix range     [2e-06, 5e+02]\n",
      "  Objective range  [1e-05, 3e-01]\n",
      "  Bounds range     [1e+00, 1e+05]\n",
      "  RHS range        [4e-02, 3e+01]\n",
      "Presolve removed 26139 rows and 15143 columns\n",
      "Presolve time: 0.37s\n",
      "Presolved: 59803 rows, 40475 columns, 207390 nonzeros\n",
      "Variable types: 40449 continuous, 26 integer (26 binary)\n",
      "Root barrier log...\n",
      "\n",
      "Ordering time: 0.86s\n",
      "\n",
      "Barrier statistics:\n",
      " Dense cols : 188\n",
      " Free vars  : 1288\n",
      " AA' NZ     : 1.230e+06\n",
      " Factor NZ  : 6.679e+06 (roughly 100 MBytes of memory)\n",
      " Factor Ops : 3.184e+09 (less than 1 second per iteration)\n",
      " Threads    : 3\n",
      "\n",
      "                  Objective                Residual\n",
      "Iter       Primal          Dual         Primal    Dual     Compl     Time\n",
      "   0   2.78674159e+05 -2.24194221e+06  3.17e+05 3.87e-03  2.17e+03     2s\n",
      "   1   2.59570369e+05 -2.15614669e+06  2.20e+05 2.00e-01  1.41e+03     2s\n",
      "   2   1.86684134e+05 -1.96135838e+06  1.51e+05 1.07e-01  9.48e+02     2s\n",
      "   3   8.46423238e+04 -1.50686486e+06  4.76e+04 3.79e-02  3.31e+02     2s\n",
      "   4   2.80234249e+04 -6.85922647e+05  2.79e+03 1.83e-03  3.64e+01     2s\n",
      "   5   1.91653046e+04 -2.13723619e+05  9.66e+01 6.54e-04  1.06e+01     2s\n",
      "   6   6.99044164e+03 -1.63349490e+05  1.83e+01 3.27e-04  3.13e+00     3s\n",
      "   7   4.11506465e+03 -6.79879556e+04  7.45e+00 1.22e-04  1.16e+00     3s\n",
      "   8   1.51308517e+03 -1.59889366e+04  1.22e+00 5.55e-04  2.00e-01     3s\n",
      "   9   5.57271886e+02 -2.99965692e+03  1.98e-01 2.16e-04  3.33e-02     3s\n",
      "  10   2.69643491e+02 -6.17100408e+02  4.71e-02 1.88e-04  7.79e-03     3s\n",
      "  11   1.57440697e+02 -2.89568051e+02  1.58e-02 9.04e-05  3.84e-03     3s\n",
      "  12   9.08052671e+01 -1.03357712e+02  3.99e-03 4.11e-05  1.65e-03     3s\n",
      "  13   7.81974606e+01 -3.59076715e+01  2.39e-03 2.34e-05  9.71e-04     3s\n",
      "  14   6.99934488e+01 -3.06365786e+00  1.43e-03 1.49e-05  6.21e-04     4s\n",
      "  15   6.54405007e+01  2.14959387e+01  1.01e-03 8.14e-06  3.74e-04     4s\n",
      "  16   6.24298144e+01  3.58210055e+01  7.40e-04 4.40e-06  2.26e-04     4s\n",
      "  17   5.66996402e+01  4.27718670e+01  2.13e-04 2.47e-06  1.18e-04     4s\n",
      "  18   5.46325910e+01  4.67867510e+01  8.00e-05 1.49e-06  6.66e-05     4s\n",
      "  19   5.39589169e+01  4.91055773e+01  4.89e-05 9.24e-07  4.12e-05     4s\n",
      "  20   5.35018917e+01  5.02664664e+01  3.13e-05 6.15e-07  2.75e-05     4s\n",
      "  21   5.32079971e+01  5.09186397e+01  2.06e-05 4.40e-07  1.94e-05     5s\n",
      "  22   5.29013263e+01  5.14687109e+01  1.03e-05 2.94e-07  1.22e-05     5s\n",
      "  23   5.27459167e+01  5.20878826e+01  4.88e-06 1.23e-07  5.59e-06     5s\n",
      "  24   5.26427343e+01  5.24377276e+01  1.58e-06 6.97e-08  1.74e-06     5s\n",
      "  25   5.26144584e+01  5.24933594e+01  8.20e-07 4.80e-08  1.03e-06     5s\n",
      "  26   5.26021250e+01  5.25436472e+01  4.93e-07 2.24e-08  4.97e-07     5s\n",
      "  27   5.25962501e+01  5.25524232e+01  3.48e-07 1.72e-08  3.72e-07     5s\n",
      "  28   5.25931992e+01  5.25595348e+01  2.74e-07 1.29e-08  2.86e-07     5s\n",
      "  29   5.25892013e+01  5.25660007e+01  1.82e-07 9.17e-09  1.97e-07     6s\n",
      "  30   5.25868839e+01  5.25730227e+01  1.27e-07 5.46e-09  1.18e-07     6s\n",
      "  31   5.25843152e+01  5.25773012e+01  6.69e-08 2.82e-09  5.96e-08     6s\n",
      "  32   5.25822789e+01  5.25803691e+01  1.85e-08 6.72e-10  1.63e-08     6s\n",
      "  33   5.25818462e+01  5.25809594e+01  9.99e-09 2.94e-10  7.56e-09     6s\n",
      "  34   5.25816872e+01  5.25811992e+01  8.71e-09 1.41e-10  4.16e-09     6s\n",
      "  35   5.25815418e+01  5.25813356e+01  4.11e-09 6.12e-11  1.76e-09     6s\n",
      "  36   5.25815027e+01  5.25813878e+01  2.83e-09 1.88e-11  9.79e-10     7s\n",
      "  37   5.25814527e+01  5.25814072e+01  1.34e-09 4.27e-12  3.87e-10     7s\n",
      "  38   5.25814324e+01  5.25814123e+01  6.13e-10 1.44e-12  1.71e-10     7s\n",
      "  39   5.25814204e+01  5.25814142e+01  9.80e-08 1.21e-12  5.27e-11     7s\n",
      "  40   5.25814194e+01  5.25814145e+01  7.86e-08 1.40e-10  4.14e-11     7s\n",
      "  41   5.25814193e+01  5.25814145e+01  2.17e-07 1.39e-10  4.10e-11     7s\n",
      "  42   5.25814193e+01  5.25814144e+01  2.97e-07 5.85e-10  4.10e-11     8s\n",
      "  43   5.25814193e+01  5.25814144e+01  2.97e-07 5.74e-10  4.11e-11     8s\n",
      "\n",
      "Barrier solved model in 43 iterations and 7.78 seconds\n",
      "Optimal objective 5.25814193e+01\n",
      "\n",
      "\n",
      "Root crossover log...\n",
      "\n",
      "    2171 DPushes remaining with DInf 2.9359415e+01                 8s\n",
      "       0 DPushes remaining with DInf 2.0579242e+01                 8s\n",
      "\n",
      "   16102 PPushes remaining with PInf 4.5041677e-02                 8s\n",
      "       0 PPushes remaining with PInf 1.3965669e-03                 9s\n",
      "\n",
      "  Push phase complete: Pinf 1.3965669e-03, Dinf 2.3044711e+01      9s\n",
      "\n",
      "\n",
      "Root simplex log...\n",
      "\n",
      "Iteration    Objective       Primal Inf.    Dual Inf.      Time\n",
      "   17018    5.2581557e+01   0.000000e+00   2.284844e+01      9s\n",
      "   18240    5.2581418e+01   0.000000e+00   4.049149e-01     10s\n",
      "   19435    5.2581426e+01   0.000000e+00   0.000000e+00     12s\n",
      "   19435    5.2581426e+01   0.000000e+00   0.000000e+00     12s\n",
      "\n",
      "Root relaxation: objective 5.258143e+01, 19435 iterations, 11.25 seconds\n",
      "\n",
      "    Nodes    |    Current Node    |     Objective Bounds      |     Work\n",
      " Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time\n",
      "\n",
      "     0     0   52.58143    0   11          -   52.58143      -     -   12s\n",
      "H    0     0                      52.6732720   52.58143  0.17%     -   12s\n",
      "     0     0     cutoff    0        52.67327   52.67327  0.00%     -   20s\n",
      "\n",
      "Explored 1 nodes (19435 simplex iterations) in 20.81 seconds\n",
      "Thread count was 3 (of 8 available processors)\n",
      "\n",
      "Solution count 1: 52.6733 \n",
      "\n",
      "Optimal solution found (tolerance 1.00e-04)\n",
      "Warning: max constraint violation (5.9330e-06) exceeds tolerance\n",
      "Warning: max bound violation (6.7416e-06) exceeds tolerance\n",
      "Best objective 5.267327195477e+01, best bound 5.267327195477e+01, gap 0.0000%\n",
      "\n",
      "Status: ok\n",
      "Return code: 0\n",
      "Message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.\n",
      "Termination condition: optimal\n",
      "Termination message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.\n",
      "Wall time: 20.807594299316406\n",
      "Error rc: 0\n",
      "Time: 21.65115451812744\n",
      "\n",
      "\n",
      "Name: x55618\n",
      "Lower bound: 52.6732719547652\n",
      "Upper bound: 52.6732719547652\n",
      "Number of objectives: 1\n",
      "Number of constraints: 85942\n",
      "Number of variables: 55618\n",
      "Number of binary variables: 52\n",
      "Number of integer variables: 52\n",
      "Number of continuous variables: 55566\n",
      "Number of nonzeros: 264787\n",
      "Sense: minimize\n",
      "\n",
      "Solve time: 25.290913581848145 sec.\n",
      "\n",
      "Processing optimization output...\n",
      "for SourceSinkModel ...    (1.1872sec)\n",
      "for ConversionModel ...    (0.9060sec)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "for StorageModel ...       (4.9676sec)\n",
      "for TransmissionModel ...  (2.8431sec)\n",
      "\t\t(9.9039 sec)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "esM.optimize(timeSeriesAggregation=True, optimizationSpecs='OptimalityTol=1e-3 method=2 cuts=0')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 9. Selected results output\n",
    "\n",
    "Plot locations (GeoPandas required)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the geopandas package for plotting the locations\n",
    "import geopandas as gpd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 43624 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "locFilePath = os.path.join(cwd, 'InputData', 'SpatialData','ShapeFiles', 'clusteredRegions.shp')\n",
    "fig, ax = fn.plotLocations(locFilePath, plotLocNames=True, indexColumn='index')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sources and Sink\n",
    "\n",
    "Show optimization summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "scrolled": false
   },
   "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></th>\n",
       "      <th></th>\n",
       "      <th>cluster_0</th>\n",
       "      <th>cluster_1</th>\n",
       "      <th>cluster_2</th>\n",
       "      <th>cluster_3</th>\n",
       "      <th>cluster_4</th>\n",
       "      <th>cluster_5</th>\n",
       "      <th>cluster_6</th>\n",
       "      <th>cluster_7</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Component</th>\n",
       "      <th>Property</th>\n",
       "      <th>Unit</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">Biogas purchase</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.264223</td>\n",
       "      <td>0.253751</td>\n",
       "      <td>0.176749</td>\n",
       "      <td>0.244162</td>\n",
       "      <td>0.351453</td>\n",
       "      <td>0.155594</td>\n",
       "      <td>0.164873</td>\n",
       "      <td>0.0659848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>commodCosts</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.264223</td>\n",
       "      <td>0.253751</td>\n",
       "      <td>0.176749</td>\n",
       "      <td>0.244162</td>\n",
       "      <td>0.351453</td>\n",
       "      <td>0.155594</td>\n",
       "      <td>0.164873</td>\n",
       "      <td>0.0659848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operation</th>\n",
       "      <th>[GW$_{biogas,LHV}$*h/a]</th>\n",
       "      <td>4884.88</td>\n",
       "      <td>4691.28</td>\n",
       "      <td>3267.67</td>\n",
       "      <td>4514</td>\n",
       "      <td>6497.55</td>\n",
       "      <td>2876.58</td>\n",
       "      <td>3048.13</td>\n",
       "      <td>1219.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Electricity demand</th>\n",
       "      <th>operation</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>133963</td>\n",
       "      <td>66116</td>\n",
       "      <td>124797</td>\n",
       "      <td>40441.2</td>\n",
       "      <td>77229.3</td>\n",
       "      <td>41413.4</td>\n",
       "      <td>28088.8</td>\n",
       "      <td>15851.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">Existing run-of-river plants</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.144316</td>\n",
       "      <td>0.0077909</td>\n",
       "      <td>0.0079499</td>\n",
       "      <td>0.00906289</td>\n",
       "      <td>0.556096</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0674723</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[GW$_{el}$]</th>\n",
       "      <td>0.693828</td>\n",
       "      <td>0.0374563</td>\n",
       "      <td>0.0382207</td>\n",
       "      <td>0.0435716</td>\n",
       "      <td>2.67354</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.324386</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operation</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>3167.33</td>\n",
       "      <td>170.988</td>\n",
       "      <td>174.478</td>\n",
       "      <td>198.904</td>\n",
       "      <td>12204.7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1480.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.144316</td>\n",
       "      <td>0.0077909</td>\n",
       "      <td>0.0079499</td>\n",
       "      <td>0.00906289</td>\n",
       "      <td>0.556096</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0674723</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hydrogen demand</th>\n",
       "      <th>operation</th>\n",
       "      <th>[GW$_{H_{2},LHV}$*h/a]</th>\n",
       "      <td>15855.2</td>\n",
       "      <td>11007.1</td>\n",
       "      <td>16452.6</td>\n",
       "      <td>5264.13</td>\n",
       "      <td>10078.3</td>\n",
       "      <td>5747.42</td>\n",
       "      <td>3710.05</td>\n",
       "      <td>1453.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">PV</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>3.09317</td>\n",
       "      <td>1.90997</td>\n",
       "      <td>2.49109</td>\n",
       "      <td>1.4497</td>\n",
       "      <td>2.19401</td>\n",
       "      <td>1.46977</td>\n",
       "      <td>0.933703</td>\n",
       "      <td>0.366282</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[GW$_{el}$]</th>\n",
       "      <td>41.8612</td>\n",
       "      <td>25.8484</td>\n",
       "      <td>33.7129</td>\n",
       "      <td>19.6194</td>\n",
       "      <td>29.6925</td>\n",
       "      <td>19.891</td>\n",
       "      <td>12.6362</td>\n",
       "      <td>4.95704</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>2.54898</td>\n",
       "      <td>1.57394</td>\n",
       "      <td>2.05282</td>\n",
       "      <td>1.19465</td>\n",
       "      <td>1.80801</td>\n",
       "      <td>1.21118</td>\n",
       "      <td>0.769433</td>\n",
       "      <td>0.30184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invest</th>\n",
       "      <th>[1e9 Euro]</th>\n",
       "      <td>27.2098</td>\n",
       "      <td>16.8014</td>\n",
       "      <td>21.9134</td>\n",
       "      <td>12.7526</td>\n",
       "      <td>19.3001</td>\n",
       "      <td>12.9291</td>\n",
       "      <td>8.21352</td>\n",
       "      <td>3.22208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operation</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>38192.5</td>\n",
       "      <td>26972.9</td>\n",
       "      <td>27184.8</td>\n",
       "      <td>20632.6</td>\n",
       "      <td>29162.1</td>\n",
       "      <td>20922.3</td>\n",
       "      <td>9413.69</td>\n",
       "      <td>5001.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.544195</td>\n",
       "      <td>0.336029</td>\n",
       "      <td>0.438268</td>\n",
       "      <td>0.255052</td>\n",
       "      <td>0.386002</td>\n",
       "      <td>0.258582</td>\n",
       "      <td>0.16427</td>\n",
       "      <td>0.0644416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">Wind (offshore)</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0</td>\n",
       "      <td>1.12104</td>\n",
       "      <td>14.8538</td>\n",
       "      <td>1.68156</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>5.04468</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[GW$_{el}$]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>4</td>\n",
       "      <td>53</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>18</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.93704</td>\n",
       "      <td>12.4158</td>\n",
       "      <td>1.40556</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.21668</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invest</th>\n",
       "      <th>[1e9 Euro]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.2</td>\n",
       "      <td>121.9</td>\n",
       "      <td>13.8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>41.4</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operation</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>12696.8</td>\n",
       "      <td>213979</td>\n",
       "      <td>20685.6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>70588.4</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.184</td>\n",
       "      <td>2.438</td>\n",
       "      <td>0.276</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.828</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">Wind (onshore)</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.98632</td>\n",
       "      <td>0</td>\n",
       "      <td>0.255394</td>\n",
       "      <td>0</td>\n",
       "      <td>3.68206</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[GW$_{el}$]</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>14.8191</td>\n",
       "      <td>0</td>\n",
       "      <td>1.90539</td>\n",
       "      <td>0</td>\n",
       "      <td>27.4704</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.6603</td>\n",
       "      <td>0</td>\n",
       "      <td>0.213476</td>\n",
       "      <td>0</td>\n",
       "      <td>3.07771</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invest</th>\n",
       "      <th>[1e9 Euro]</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>16.301</td>\n",
       "      <td>0</td>\n",
       "      <td>2.09593</td>\n",
       "      <td>0</td>\n",
       "      <td>30.2174</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operation</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>33850.5</td>\n",
       "      <td>0</td>\n",
       "      <td>2322.17</td>\n",
       "      <td>0</td>\n",
       "      <td>70813.4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.326021</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0419187</td>\n",
       "      <td>0</td>\n",
       "      <td>0.604348</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                 cluster_0  \\\n",
       "Component                    Property    Unit                                \n",
       "Biogas purchase              TAC         [1e9 Euro/a]             0.264223   \n",
       "                             commodCosts [1e9 Euro/a]             0.264223   \n",
       "                             operation   [GW$_{biogas,LHV}$*h/a]   4884.88   \n",
       "Electricity demand           operation   [GW$_{el}$*h/a]            133963   \n",
       "Existing run-of-river plants TAC         [1e9 Euro/a]             0.144316   \n",
       "                             capacity    [GW$_{el}$]              0.693828   \n",
       "                             operation   [GW$_{el}$*h/a]           3167.33   \n",
       "                             opexCap     [1e9 Euro/a]             0.144316   \n",
       "Hydrogen demand              operation   [GW$_{H_{2},LHV}$*h/a]    15855.2   \n",
       "PV                           TAC         [1e9 Euro/a]              3.09317   \n",
       "                             capacity    [GW$_{el}$]               41.8612   \n",
       "                             capexCap    [1e9 Euro/a]              2.54898   \n",
       "                             invest      [1e9 Euro]                27.2098   \n",
       "                             operation   [GW$_{el}$*h/a]           38192.5   \n",
       "                             opexCap     [1e9 Euro/a]             0.544195   \n",
       "Wind (offshore)              TAC         [1e9 Euro/a]                    0   \n",
       "                             capacity    [GW$_{el}$]                   NaN   \n",
       "                             capexCap    [1e9 Euro/a]                  NaN   \n",
       "                             invest      [1e9 Euro]                    NaN   \n",
       "                             operation   [GW$_{el}$*h/a]               NaN   \n",
       "                             opexCap     [1e9 Euro/a]                  NaN   \n",
       "Wind (onshore)               TAC         [1e9 Euro/a]                    0   \n",
       "                             capacity    [GW$_{el}$]                     0   \n",
       "                             capexCap    [1e9 Euro/a]                    0   \n",
       "                             invest      [1e9 Euro]                      0   \n",
       "                             operation   [GW$_{el}$*h/a]                 0   \n",
       "                             opexCap     [1e9 Euro/a]                    0   \n",
       "\n",
       "                                                                  cluster_1  \\\n",
       "Component                    Property    Unit                                 \n",
       "Biogas purchase              TAC         [1e9 Euro/a]              0.253751   \n",
       "                             commodCosts [1e9 Euro/a]              0.253751   \n",
       "                             operation   [GW$_{biogas,LHV}$*h/a]    4691.28   \n",
       "Electricity demand           operation   [GW$_{el}$*h/a]              66116   \n",
       "Existing run-of-river plants TAC         [1e9 Euro/a]             0.0077909   \n",
       "                             capacity    [GW$_{el}$]              0.0374563   \n",
       "                             operation   [GW$_{el}$*h/a]            170.988   \n",
       "                             opexCap     [1e9 Euro/a]             0.0077909   \n",
       "Hydrogen demand              operation   [GW$_{H_{2},LHV}$*h/a]     11007.1   \n",
       "PV                           TAC         [1e9 Euro/a]               1.90997   \n",
       "                             capacity    [GW$_{el}$]                25.8484   \n",
       "                             capexCap    [1e9 Euro/a]               1.57394   \n",
       "                             invest      [1e9 Euro]                 16.8014   \n",
       "                             operation   [GW$_{el}$*h/a]            26972.9   \n",
       "                             opexCap     [1e9 Euro/a]              0.336029   \n",
       "Wind (offshore)              TAC         [1e9 Euro/a]               1.12104   \n",
       "                             capacity    [GW$_{el}$]                      4   \n",
       "                             capexCap    [1e9 Euro/a]               0.93704   \n",
       "                             invest      [1e9 Euro]                     9.2   \n",
       "                             operation   [GW$_{el}$*h/a]            12696.8   \n",
       "                             opexCap     [1e9 Euro/a]                 0.184   \n",
       "Wind (onshore)               TAC         [1e9 Euro/a]                     0   \n",
       "                             capacity    [GW$_{el}$]                      0   \n",
       "                             capexCap    [1e9 Euro/a]                     0   \n",
       "                             invest      [1e9 Euro]                       0   \n",
       "                             operation   [GW$_{el}$*h/a]                  0   \n",
       "                             opexCap     [1e9 Euro/a]                     0   \n",
       "\n",
       "                                                                  cluster_2  \\\n",
       "Component                    Property    Unit                                 \n",
       "Biogas purchase              TAC         [1e9 Euro/a]              0.176749   \n",
       "                             commodCosts [1e9 Euro/a]              0.176749   \n",
       "                             operation   [GW$_{biogas,LHV}$*h/a]    3267.67   \n",
       "Electricity demand           operation   [GW$_{el}$*h/a]             124797   \n",
       "Existing run-of-river plants TAC         [1e9 Euro/a]             0.0079499   \n",
       "                             capacity    [GW$_{el}$]              0.0382207   \n",
       "                             operation   [GW$_{el}$*h/a]            174.478   \n",
       "                             opexCap     [1e9 Euro/a]             0.0079499   \n",
       "Hydrogen demand              operation   [GW$_{H_{2},LHV}$*h/a]     16452.6   \n",
       "PV                           TAC         [1e9 Euro/a]               2.49109   \n",
       "                             capacity    [GW$_{el}$]                33.7129   \n",
       "                             capexCap    [1e9 Euro/a]               2.05282   \n",
       "                             invest      [1e9 Euro]                 21.9134   \n",
       "                             operation   [GW$_{el}$*h/a]            27184.8   \n",
       "                             opexCap     [1e9 Euro/a]              0.438268   \n",
       "Wind (offshore)              TAC         [1e9 Euro/a]               14.8538   \n",
       "                             capacity    [GW$_{el}$]                     53   \n",
       "                             capexCap    [1e9 Euro/a]               12.4158   \n",
       "                             invest      [1e9 Euro]                   121.9   \n",
       "                             operation   [GW$_{el}$*h/a]             213979   \n",
       "                             opexCap     [1e9 Euro/a]                 2.438   \n",
       "Wind (onshore)               TAC         [1e9 Euro/a]               1.98632   \n",
       "                             capacity    [GW$_{el}$]                14.8191   \n",
       "                             capexCap    [1e9 Euro/a]                1.6603   \n",
       "                             invest      [1e9 Euro]                  16.301   \n",
       "                             operation   [GW$_{el}$*h/a]            33850.5   \n",
       "                             opexCap     [1e9 Euro/a]              0.326021   \n",
       "\n",
       "                                                                   cluster_3  \\\n",
       "Component                    Property    Unit                                  \n",
       "Biogas purchase              TAC         [1e9 Euro/a]               0.244162   \n",
       "                             commodCosts [1e9 Euro/a]               0.244162   \n",
       "                             operation   [GW$_{biogas,LHV}$*h/a]        4514   \n",
       "Electricity demand           operation   [GW$_{el}$*h/a]             40441.2   \n",
       "Existing run-of-river plants TAC         [1e9 Euro/a]             0.00906289   \n",
       "                             capacity    [GW$_{el}$]               0.0435716   \n",
       "                             operation   [GW$_{el}$*h/a]             198.904   \n",
       "                             opexCap     [1e9 Euro/a]             0.00906289   \n",
       "Hydrogen demand              operation   [GW$_{H_{2},LHV}$*h/a]      5264.13   \n",
       "PV                           TAC         [1e9 Euro/a]                 1.4497   \n",
       "                             capacity    [GW$_{el}$]                 19.6194   \n",
       "                             capexCap    [1e9 Euro/a]                1.19465   \n",
       "                             invest      [1e9 Euro]                  12.7526   \n",
       "                             operation   [GW$_{el}$*h/a]             20632.6   \n",
       "                             opexCap     [1e9 Euro/a]               0.255052   \n",
       "Wind (offshore)              TAC         [1e9 Euro/a]                1.68156   \n",
       "                             capacity    [GW$_{el}$]                       6   \n",
       "                             capexCap    [1e9 Euro/a]                1.40556   \n",
       "                             invest      [1e9 Euro]                     13.8   \n",
       "                             operation   [GW$_{el}$*h/a]             20685.6   \n",
       "                             opexCap     [1e9 Euro/a]                  0.276   \n",
       "Wind (onshore)               TAC         [1e9 Euro/a]                      0   \n",
       "                             capacity    [GW$_{el}$]                       0   \n",
       "                             capexCap    [1e9 Euro/a]                      0   \n",
       "                             invest      [1e9 Euro]                        0   \n",
       "                             operation   [GW$_{el}$*h/a]                   0   \n",
       "                             opexCap     [1e9 Euro/a]                      0   \n",
       "\n",
       "                                                                  cluster_4  \\\n",
       "Component                    Property    Unit                                 \n",
       "Biogas purchase              TAC         [1e9 Euro/a]              0.351453   \n",
       "                             commodCosts [1e9 Euro/a]              0.351453   \n",
       "                             operation   [GW$_{biogas,LHV}$*h/a]    6497.55   \n",
       "Electricity demand           operation   [GW$_{el}$*h/a]            77229.3   \n",
       "Existing run-of-river plants TAC         [1e9 Euro/a]              0.556096   \n",
       "                             capacity    [GW$_{el}$]                2.67354   \n",
       "                             operation   [GW$_{el}$*h/a]            12204.7   \n",
       "                             opexCap     [1e9 Euro/a]              0.556096   \n",
       "Hydrogen demand              operation   [GW$_{H_{2},LHV}$*h/a]     10078.3   \n",
       "PV                           TAC         [1e9 Euro/a]               2.19401   \n",
       "                             capacity    [GW$_{el}$]                29.6925   \n",
       "                             capexCap    [1e9 Euro/a]               1.80801   \n",
       "                             invest      [1e9 Euro]                 19.3001   \n",
       "                             operation   [GW$_{el}$*h/a]            29162.1   \n",
       "                             opexCap     [1e9 Euro/a]              0.386002   \n",
       "Wind (offshore)              TAC         [1e9 Euro/a]                     0   \n",
       "                             capacity    [GW$_{el}$]                    NaN   \n",
       "                             capexCap    [1e9 Euro/a]                   NaN   \n",
       "                             invest      [1e9 Euro]                     NaN   \n",
       "                             operation   [GW$_{el}$*h/a]                NaN   \n",
       "                             opexCap     [1e9 Euro/a]                   NaN   \n",
       "Wind (onshore)               TAC         [1e9 Euro/a]              0.255394   \n",
       "                             capacity    [GW$_{el}$]                1.90539   \n",
       "                             capexCap    [1e9 Euro/a]              0.213476   \n",
       "                             invest      [1e9 Euro]                 2.09593   \n",
       "                             operation   [GW$_{el}$*h/a]            2322.17   \n",
       "                             opexCap     [1e9 Euro/a]             0.0419187   \n",
       "\n",
       "                                                                 cluster_5  \\\n",
       "Component                    Property    Unit                                \n",
       "Biogas purchase              TAC         [1e9 Euro/a]             0.155594   \n",
       "                             commodCosts [1e9 Euro/a]             0.155594   \n",
       "                             operation   [GW$_{biogas,LHV}$*h/a]   2876.58   \n",
       "Electricity demand           operation   [GW$_{el}$*h/a]           41413.4   \n",
       "Existing run-of-river plants TAC         [1e9 Euro/a]                    0   \n",
       "                             capacity    [GW$_{el}$]                   NaN   \n",
       "                             operation   [GW$_{el}$*h/a]               NaN   \n",
       "                             opexCap     [1e9 Euro/a]                  NaN   \n",
       "Hydrogen demand              operation   [GW$_{H_{2},LHV}$*h/a]    5747.42   \n",
       "PV                           TAC         [1e9 Euro/a]              1.46977   \n",
       "                             capacity    [GW$_{el}$]                19.891   \n",
       "                             capexCap    [1e9 Euro/a]              1.21118   \n",
       "                             invest      [1e9 Euro]                12.9291   \n",
       "                             operation   [GW$_{el}$*h/a]           20922.3   \n",
       "                             opexCap     [1e9 Euro/a]             0.258582   \n",
       "Wind (offshore)              TAC         [1e9 Euro/a]                    0   \n",
       "                             capacity    [GW$_{el}$]                   NaN   \n",
       "                             capexCap    [1e9 Euro/a]                  NaN   \n",
       "                             invest      [1e9 Euro]                    NaN   \n",
       "                             operation   [GW$_{el}$*h/a]               NaN   \n",
       "                             opexCap     [1e9 Euro/a]                  NaN   \n",
       "Wind (onshore)               TAC         [1e9 Euro/a]                    0   \n",
       "                             capacity    [GW$_{el}$]                     0   \n",
       "                             capexCap    [1e9 Euro/a]                    0   \n",
       "                             invest      [1e9 Euro]                      0   \n",
       "                             operation   [GW$_{el}$*h/a]                 0   \n",
       "                             opexCap     [1e9 Euro/a]                    0   \n",
       "\n",
       "                                                                 cluster_6  \\\n",
       "Component                    Property    Unit                                \n",
       "Biogas purchase              TAC         [1e9 Euro/a]             0.164873   \n",
       "                             commodCosts [1e9 Euro/a]             0.164873   \n",
       "                             operation   [GW$_{biogas,LHV}$*h/a]   3048.13   \n",
       "Electricity demand           operation   [GW$_{el}$*h/a]           28088.8   \n",
       "Existing run-of-river plants TAC         [1e9 Euro/a]                    0   \n",
       "                             capacity    [GW$_{el}$]                   NaN   \n",
       "                             operation   [GW$_{el}$*h/a]               NaN   \n",
       "                             opexCap     [1e9 Euro/a]                  NaN   \n",
       "Hydrogen demand              operation   [GW$_{H_{2},LHV}$*h/a]    3710.05   \n",
       "PV                           TAC         [1e9 Euro/a]             0.933703   \n",
       "                             capacity    [GW$_{el}$]               12.6362   \n",
       "                             capexCap    [1e9 Euro/a]             0.769433   \n",
       "                             invest      [1e9 Euro]                8.21352   \n",
       "                             operation   [GW$_{el}$*h/a]           9413.69   \n",
       "                             opexCap     [1e9 Euro/a]              0.16427   \n",
       "Wind (offshore)              TAC         [1e9 Euro/a]              5.04468   \n",
       "                             capacity    [GW$_{el}$]                    18   \n",
       "                             capexCap    [1e9 Euro/a]              4.21668   \n",
       "                             invest      [1e9 Euro]                   41.4   \n",
       "                             operation   [GW$_{el}$*h/a]           70588.4   \n",
       "                             opexCap     [1e9 Euro/a]                0.828   \n",
       "Wind (onshore)               TAC         [1e9 Euro/a]              3.68206   \n",
       "                             capacity    [GW$_{el}$]               27.4704   \n",
       "                             capexCap    [1e9 Euro/a]              3.07771   \n",
       "                             invest      [1e9 Euro]                30.2174   \n",
       "                             operation   [GW$_{el}$*h/a]           70813.4   \n",
       "                             opexCap     [1e9 Euro/a]             0.604348   \n",
       "\n",
       "                                                                  cluster_7  \n",
       "Component                    Property    Unit                                \n",
       "Biogas purchase              TAC         [1e9 Euro/a]             0.0659848  \n",
       "                             commodCosts [1e9 Euro/a]             0.0659848  \n",
       "                             operation   [GW$_{biogas,LHV}$*h/a]    1219.91  \n",
       "Electricity demand           operation   [GW$_{el}$*h/a]            15851.1  \n",
       "Existing run-of-river plants TAC         [1e9 Euro/a]             0.0674723  \n",
       "                             capacity    [GW$_{el}$]               0.324386  \n",
       "                             operation   [GW$_{el}$*h/a]            1480.82  \n",
       "                             opexCap     [1e9 Euro/a]             0.0674723  \n",
       "Hydrogen demand              operation   [GW$_{H_{2},LHV}$*h/a]     1453.12  \n",
       "PV                           TAC         [1e9 Euro/a]              0.366282  \n",
       "                             capacity    [GW$_{el}$]                4.95704  \n",
       "                             capexCap    [1e9 Euro/a]               0.30184  \n",
       "                             invest      [1e9 Euro]                 3.22208  \n",
       "                             operation   [GW$_{el}$*h/a]            5001.83  \n",
       "                             opexCap     [1e9 Euro/a]             0.0644416  \n",
       "Wind (offshore)              TAC         [1e9 Euro/a]                     0  \n",
       "                             capacity    [GW$_{el}$]                    NaN  \n",
       "                             capexCap    [1e9 Euro/a]                   NaN  \n",
       "                             invest      [1e9 Euro]                     NaN  \n",
       "                             operation   [GW$_{el}$*h/a]                NaN  \n",
       "                             opexCap     [1e9 Euro/a]                   NaN  \n",
       "Wind (onshore)               TAC         [1e9 Euro/a]                     0  \n",
       "                             capacity    [GW$_{el}$]                      0  \n",
       "                             capexCap    [1e9 Euro/a]                     0  \n",
       "                             invest      [1e9 Euro]                       0  \n",
       "                             operation   [GW$_{el}$*h/a]                  0  \n",
       "                             opexCap     [1e9 Euro/a]                     0  "
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esM.getOptimizationSummary(\"SourceSinkModel\", outputLevel=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Plot installed capacities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 49776 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotLocationalColorMap(esM, 'Wind (offshore)', locFilePath, 'index', perArea=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 48828 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotLocationalColorMap(esM, 'Wind (onshore)', locFilePath, 'index', perArea=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 51856 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotLocationalColorMap(esM, 'PV', locFilePath, 'index', perArea=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Plot operation time series (either one or two dimensional)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 42496 characters]\n",
      "text/plain": [
       "<Figure size 864x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotOperation(esM, 'Electricity demand', 'cluster_0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 25820 characters]\n",
      "text/plain": [
       "<Figure size 864x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotOperationColorMap(esM, 'Electricity demand', 'cluster_0')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Conversion\n",
    "\n",
    "Show optimization summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "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></th>\n",
       "      <th></th>\n",
       "      <th>cluster_0</th>\n",
       "      <th>cluster_1</th>\n",
       "      <th>cluster_2</th>\n",
       "      <th>cluster_3</th>\n",
       "      <th>cluster_4</th>\n",
       "      <th>cluster_5</th>\n",
       "      <th>cluster_6</th>\n",
       "      <th>cluster_7</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Component</th>\n",
       "      <th>Property</th>\n",
       "      <th>Unit</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">Electrolyzer</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.0614655</td>\n",
       "      <td>0.0509074</td>\n",
       "      <td>0.545151</td>\n",
       "      <td>0.128468</td>\n",
       "      <td>0.064736</td>\n",
       "      <td>0.178004</td>\n",
       "      <td>0.996726</td>\n",
       "      <td>0.00210291</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[GW$_{el}$]</th>\n",
       "      <td>0.70638</td>\n",
       "      <td>0.585044</td>\n",
       "      <td>6.26505</td>\n",
       "      <td>1.4764</td>\n",
       "      <td>0.743966</td>\n",
       "      <td>2.04567</td>\n",
       "      <td>11.4547</td>\n",
       "      <td>0.0241673</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.0526358</td>\n",
       "      <td>0.0435944</td>\n",
       "      <td>0.466838</td>\n",
       "      <td>0.110013</td>\n",
       "      <td>0.0554364</td>\n",
       "      <td>0.152433</td>\n",
       "      <td>0.853542</td>\n",
       "      <td>0.00180082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invest</th>\n",
       "      <th>[1e9 Euro]</th>\n",
       "      <td>0.35319</td>\n",
       "      <td>0.292522</td>\n",
       "      <td>3.13252</td>\n",
       "      <td>0.738199</td>\n",
       "      <td>0.371983</td>\n",
       "      <td>1.02284</td>\n",
       "      <td>5.72734</td>\n",
       "      <td>0.0120837</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operation</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>2430.74</td>\n",
       "      <td>1835.28</td>\n",
       "      <td>25503.2</td>\n",
       "      <td>5978.44</td>\n",
       "      <td>2507.62</td>\n",
       "      <td>8210.61</td>\n",
       "      <td>52811.6</td>\n",
       "      <td>105.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.00882975</td>\n",
       "      <td>0.00731305</td>\n",
       "      <td>0.0783131</td>\n",
       "      <td>0.018455</td>\n",
       "      <td>0.00929957</td>\n",
       "      <td>0.0255709</td>\n",
       "      <td>0.143183</td>\n",
       "      <td>0.000302092</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">New CCGT plants (biogas)</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.0574716</td>\n",
       "      <td>0.232827</td>\n",
       "      <td>0.314601</td>\n",
       "      <td>0.135068</td>\n",
       "      <td>0.076445</td>\n",
       "      <td>0.086687</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00920039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[GW$_{el}$]</th>\n",
       "      <td>0.70262</td>\n",
       "      <td>2.84643</td>\n",
       "      <td>3.84617</td>\n",
       "      <td>1.65128</td>\n",
       "      <td>0.934579</td>\n",
       "      <td>1.05979</td>\n",
       "      <td>0</td>\n",
       "      <td>0.112479</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.0427166</td>\n",
       "      <td>0.173052</td>\n",
       "      <td>0.233832</td>\n",
       "      <td>0.100392</td>\n",
       "      <td>0.0568188</td>\n",
       "      <td>0.0644313</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00683832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invest</th>\n",
       "      <th>[1e9 Euro]</th>\n",
       "      <td>0.491834</td>\n",
       "      <td>1.9925</td>\n",
       "      <td>2.69232</td>\n",
       "      <td>1.1559</td>\n",
       "      <td>0.654205</td>\n",
       "      <td>0.741855</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0787356</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operation</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>1236.16</td>\n",
       "      <td>4875.83</td>\n",
       "      <td>6863.73</td>\n",
       "      <td>2843.82</td>\n",
       "      <td>1684.95</td>\n",
       "      <td>1812.25</td>\n",
       "      <td>0</td>\n",
       "      <td>213.263</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.014755</td>\n",
       "      <td>0.059775</td>\n",
       "      <td>0.0807695</td>\n",
       "      <td>0.0346769</td>\n",
       "      <td>0.0196262</td>\n",
       "      <td>0.0222556</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00236207</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                     cluster_0   cluster_1  \\\n",
       "Component                Property  Unit                                      \n",
       "Electrolyzer             TAC       [1e9 Euro/a]      0.0614655   0.0509074   \n",
       "                         capacity  [GW$_{el}$]         0.70638    0.585044   \n",
       "                         capexCap  [1e9 Euro/a]      0.0526358   0.0435944   \n",
       "                         invest    [1e9 Euro]          0.35319    0.292522   \n",
       "                         operation [GW$_{el}$*h/a]     2430.74     1835.28   \n",
       "                         opexCap   [1e9 Euro/a]     0.00882975  0.00731305   \n",
       "New CCGT plants (biogas) TAC       [1e9 Euro/a]      0.0574716    0.232827   \n",
       "                         capacity  [GW$_{el}$]         0.70262     2.84643   \n",
       "                         capexCap  [1e9 Euro/a]      0.0427166    0.173052   \n",
       "                         invest    [1e9 Euro]         0.491834      1.9925   \n",
       "                         operation [GW$_{el}$*h/a]     1236.16     4875.83   \n",
       "                         opexCap   [1e9 Euro/a]       0.014755    0.059775   \n",
       "\n",
       "                                                    cluster_2  cluster_3  \\\n",
       "Component                Property  Unit                                    \n",
       "Electrolyzer             TAC       [1e9 Euro/a]      0.545151   0.128468   \n",
       "                         capacity  [GW$_{el}$]        6.26505     1.4764   \n",
       "                         capexCap  [1e9 Euro/a]      0.466838   0.110013   \n",
       "                         invest    [1e9 Euro]         3.13252   0.738199   \n",
       "                         operation [GW$_{el}$*h/a]    25503.2    5978.44   \n",
       "                         opexCap   [1e9 Euro/a]     0.0783131   0.018455   \n",
       "New CCGT plants (biogas) TAC       [1e9 Euro/a]      0.314601   0.135068   \n",
       "                         capacity  [GW$_{el}$]        3.84617    1.65128   \n",
       "                         capexCap  [1e9 Euro/a]      0.233832   0.100392   \n",
       "                         invest    [1e9 Euro]         2.69232     1.1559   \n",
       "                         operation [GW$_{el}$*h/a]    6863.73    2843.82   \n",
       "                         opexCap   [1e9 Euro/a]     0.0807695  0.0346769   \n",
       "\n",
       "                                                     cluster_4  cluster_5  \\\n",
       "Component                Property  Unit                                     \n",
       "Electrolyzer             TAC       [1e9 Euro/a]       0.064736   0.178004   \n",
       "                         capacity  [GW$_{el}$]        0.743966    2.04567   \n",
       "                         capexCap  [1e9 Euro/a]      0.0554364   0.152433   \n",
       "                         invest    [1e9 Euro]         0.371983    1.02284   \n",
       "                         operation [GW$_{el}$*h/a]     2507.62    8210.61   \n",
       "                         opexCap   [1e9 Euro/a]     0.00929957  0.0255709   \n",
       "New CCGT plants (biogas) TAC       [1e9 Euro/a]       0.076445   0.086687   \n",
       "                         capacity  [GW$_{el}$]        0.934579    1.05979   \n",
       "                         capexCap  [1e9 Euro/a]      0.0568188  0.0644313   \n",
       "                         invest    [1e9 Euro]         0.654205   0.741855   \n",
       "                         operation [GW$_{el}$*h/a]     1684.95    1812.25   \n",
       "                         opexCap   [1e9 Euro/a]      0.0196262  0.0222556   \n",
       "\n",
       "                                                   cluster_6    cluster_7  \n",
       "Component                Property  Unit                                    \n",
       "Electrolyzer             TAC       [1e9 Euro/a]     0.996726   0.00210291  \n",
       "                         capacity  [GW$_{el}$]       11.4547    0.0241673  \n",
       "                         capexCap  [1e9 Euro/a]     0.853542   0.00180082  \n",
       "                         invest    [1e9 Euro]        5.72734    0.0120837  \n",
       "                         operation [GW$_{el}$*h/a]   52811.6       105.27  \n",
       "                         opexCap   [1e9 Euro/a]     0.143183  0.000302092  \n",
       "New CCGT plants (biogas) TAC       [1e9 Euro/a]            0   0.00920039  \n",
       "                         capacity  [GW$_{el}$]             0     0.112479  \n",
       "                         capexCap  [1e9 Euro/a]            0   0.00683832  \n",
       "                         invest    [1e9 Euro]              0    0.0787356  \n",
       "                         operation [GW$_{el}$*h/a]         0      213.263  \n",
       "                         opexCap   [1e9 Euro/a]            0   0.00236207  "
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esM.getOptimizationSummary(\"ConversionModel\", outputLevel=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 50368 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotLocationalColorMap(esM, 'Electrolyzer', locFilePath, 'index', perArea=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 13620 characters]\n",
      "text/plain": [
       "<Figure size 864x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotOperationColorMap(esM, 'New CCGT plants (biogas)', 'cluster_2')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Storage\n",
    "\n",
    "Show optimization summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "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></th>\n",
       "      <th></th>\n",
       "      <th>cluster_0</th>\n",
       "      <th>cluster_1</th>\n",
       "      <th>cluster_2</th>\n",
       "      <th>cluster_3</th>\n",
       "      <th>cluster_4</th>\n",
       "      <th>cluster_5</th>\n",
       "      <th>cluster_6</th>\n",
       "      <th>cluster_7</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Component</th>\n",
       "      <th>Property</th>\n",
       "      <th>Unit</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"7\" valign=\"top\">Li-ion batteries</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.167561</td>\n",
       "      <td>0.419777</td>\n",
       "      <td>0.83384</td>\n",
       "      <td>0.166436</td>\n",
       "      <td>0.191947</td>\n",
       "      <td>0.142931</td>\n",
       "      <td>0.119727</td>\n",
       "      <td>0.133092</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[GW$_{el}$*h]</th>\n",
       "      <td>9.9722</td>\n",
       "      <td>24.9825</td>\n",
       "      <td>49.6249</td>\n",
       "      <td>9.90524</td>\n",
       "      <td>11.4235</td>\n",
       "      <td>8.50633</td>\n",
       "      <td>7.1254</td>\n",
       "      <td>7.92079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.147617</td>\n",
       "      <td>0.369812</td>\n",
       "      <td>0.73459</td>\n",
       "      <td>0.146626</td>\n",
       "      <td>0.1691</td>\n",
       "      <td>0.125918</td>\n",
       "      <td>0.105476</td>\n",
       "      <td>0.11725</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invest</th>\n",
       "      <th>[1e9 Euro]</th>\n",
       "      <td>1.5058</td>\n",
       "      <td>3.77236</td>\n",
       "      <td>7.49337</td>\n",
       "      <td>1.49569</td>\n",
       "      <td>1.72494</td>\n",
       "      <td>1.28446</td>\n",
       "      <td>1.07594</td>\n",
       "      <td>1.19604</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operationCharge</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>3451.22</td>\n",
       "      <td>8463.54</td>\n",
       "      <td>16390.3</td>\n",
       "      <td>2934</td>\n",
       "      <td>3486.83</td>\n",
       "      <td>2848.05</td>\n",
       "      <td>2584.69</td>\n",
       "      <td>2994.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operationDischarge</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>3113.41</td>\n",
       "      <td>7635.68</td>\n",
       "      <td>14785.8</td>\n",
       "      <td>2647</td>\n",
       "      <td>3145.59</td>\n",
       "      <td>2569.27</td>\n",
       "      <td>2331.73</td>\n",
       "      <td>2701.93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.0199444</td>\n",
       "      <td>0.049965</td>\n",
       "      <td>0.0992499</td>\n",
       "      <td>0.0198105</td>\n",
       "      <td>0.0228469</td>\n",
       "      <td>0.0170127</td>\n",
       "      <td>0.0142508</td>\n",
       "      <td>0.0158416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">Pumped hydro storage</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.00243637</td>\n",
       "      <td>0.0011859</td>\n",
       "      <td>0.000125154</td>\n",
       "      <td>0.00300186</td>\n",
       "      <td>0.00110007</td>\n",
       "      <td>0.0038302</td>\n",
       "      <td>9.18e-05</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[GW$_{el}$*h]</th>\n",
       "      <td>15.924</td>\n",
       "      <td>7.751</td>\n",
       "      <td>0.818</td>\n",
       "      <td>19.62</td>\n",
       "      <td>7.19</td>\n",
       "      <td>25.034</td>\n",
       "      <td>0.6</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operationCharge</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>7065.97</td>\n",
       "      <td>3963.84</td>\n",
       "      <td>407.782</td>\n",
       "      <td>8458.49</td>\n",
       "      <td>3099.63</td>\n",
       "      <td>10675.3</td>\n",
       "      <td>292.332</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operationDischarge</th>\n",
       "      <th>[GW$_{el}$*h/a]</th>\n",
       "      <td>5471.72</td>\n",
       "      <td>3069.5</td>\n",
       "      <td>315.776</td>\n",
       "      <td>6550.04</td>\n",
       "      <td>2400.27</td>\n",
       "      <td>8266.7</td>\n",
       "      <td>226.367</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0.00243637</td>\n",
       "      <td>0.0011859</td>\n",
       "      <td>0.000125154</td>\n",
       "      <td>0.00300186</td>\n",
       "      <td>0.00110007</td>\n",
       "      <td>0.0038302</td>\n",
       "      <td>9.18e-05</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"7\" valign=\"top\">Salt caverns (biogas)</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0</td>\n",
       "      <td>0.029229</td>\n",
       "      <td>0.0565781</td>\n",
       "      <td>0.0169407</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0108859</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[GW$_{biogas,LHV}$*h]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>2156.63</td>\n",
       "      <td>4174.55</td>\n",
       "      <td>1249.95</td>\n",
       "      <td>NaN</td>\n",
       "      <td>803.203</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00766271</td>\n",
       "      <td>0.0148326</td>\n",
       "      <td>0.00444121</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00285386</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invest</th>\n",
       "      <th>[1e9 Euro]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0862651</td>\n",
       "      <td>0.166982</td>\n",
       "      <td>0.0499981</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0321281</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operationCharge</th>\n",
       "      <th>[GW$_{biogas,LHV}$*h/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>6215.24</td>\n",
       "      <td>12488.1</td>\n",
       "      <td>19518.9</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2315.06</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operationDischarge</th>\n",
       "      <th>[GW$_{biogas,LHV}$*h/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>6215.24</td>\n",
       "      <td>12488.1</td>\n",
       "      <td>19518.9</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2315.06</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0215663</td>\n",
       "      <td>0.0417455</td>\n",
       "      <td>0.0124995</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00803203</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"7\" valign=\"top\">Salt caverns (hydrogen)</th>\n",
       "      <th>TAC</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>0</td>\n",
       "      <td>0.619047</td>\n",
       "      <td>0.642299</td>\n",
       "      <td>0.176855</td>\n",
       "      <td>0</td>\n",
       "      <td>0.211586</td>\n",
       "      <td>0.632608</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capacity</th>\n",
       "      <th>[GW$_{H_{2},LHV}$*h]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1067.74</td>\n",
       "      <td>1107.85</td>\n",
       "      <td>305.043</td>\n",
       "      <td>NaN</td>\n",
       "      <td>364.947</td>\n",
       "      <td>1091.13</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>capexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0104329</td>\n",
       "      <td>0.0108248</td>\n",
       "      <td>0.00298058</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0035659</td>\n",
       "      <td>0.0106615</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>invest</th>\n",
       "      <th>[1e9 Euro]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.117452</td>\n",
       "      <td>0.121863</td>\n",
       "      <td>0.0335548</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0401442</td>\n",
       "      <td>0.120025</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operationCharge</th>\n",
       "      <th>[GW$_{H_{2},LHV}$*h/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>8368.61</td>\n",
       "      <td>9075.31</td>\n",
       "      <td>3190.62</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2932.76</td>\n",
       "      <td>11243.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>operationDischarge</th>\n",
       "      <th>[GW$_{H_{2},LHV}$*h/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>8368.61</td>\n",
       "      <td>9075.31</td>\n",
       "      <td>3190.62</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2932.76</td>\n",
       "      <td>11243.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>opexCap</th>\n",
       "      <th>[1e9 Euro/a]</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.608614</td>\n",
       "      <td>0.631474</td>\n",
       "      <td>0.173875</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.20802</td>\n",
       "      <td>0.621947</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                     cluster_0  \\\n",
       "Component               Property           Unit                                  \n",
       "Li-ion batteries        TAC                [1e9 Euro/a]               0.167561   \n",
       "                        capacity           [GW$_{el}$*h]                9.9722   \n",
       "                        capexCap           [1e9 Euro/a]               0.147617   \n",
       "                        invest             [1e9 Euro]                   1.5058   \n",
       "                        operationCharge    [GW$_{el}$*h/a]             3451.22   \n",
       "                        operationDischarge [GW$_{el}$*h/a]             3113.41   \n",
       "                        opexCap            [1e9 Euro/a]              0.0199444   \n",
       "Pumped hydro storage    TAC                [1e9 Euro/a]             0.00243637   \n",
       "                        capacity           [GW$_{el}$*h]                15.924   \n",
       "                        operationCharge    [GW$_{el}$*h/a]             7065.97   \n",
       "                        operationDischarge [GW$_{el}$*h/a]             5471.72   \n",
       "                        opexCap            [1e9 Euro/a]             0.00243637   \n",
       "Salt caverns (biogas)   TAC                [1e9 Euro/a]                      0   \n",
       "                        capacity           [GW$_{biogas,LHV}$*h]           NaN   \n",
       "                        capexCap           [1e9 Euro/a]                    NaN   \n",
       "                        invest             [1e9 Euro]                      NaN   \n",
       "                        operationCharge    [GW$_{biogas,LHV}$*h/a]         NaN   \n",
       "                        operationDischarge [GW$_{biogas,LHV}$*h/a]         NaN   \n",
       "                        opexCap            [1e9 Euro/a]                    NaN   \n",
       "Salt caverns (hydrogen) TAC                [1e9 Euro/a]                      0   \n",
       "                        capacity           [GW$_{H_{2},LHV}$*h]            NaN   \n",
       "                        capexCap           [1e9 Euro/a]                    NaN   \n",
       "                        invest             [1e9 Euro]                      NaN   \n",
       "                        operationCharge    [GW$_{H_{2},LHV}$*h/a]          NaN   \n",
       "                        operationDischarge [GW$_{H_{2},LHV}$*h/a]          NaN   \n",
       "                        opexCap            [1e9 Euro/a]                    NaN   \n",
       "\n",
       "                                                                     cluster_1  \\\n",
       "Component               Property           Unit                                  \n",
       "Li-ion batteries        TAC                [1e9 Euro/a]               0.419777   \n",
       "                        capacity           [GW$_{el}$*h]               24.9825   \n",
       "                        capexCap           [1e9 Euro/a]               0.369812   \n",
       "                        invest             [1e9 Euro]                  3.77236   \n",
       "                        operationCharge    [GW$_{el}$*h/a]             8463.54   \n",
       "                        operationDischarge [GW$_{el}$*h/a]             7635.68   \n",
       "                        opexCap            [1e9 Euro/a]               0.049965   \n",
       "Pumped hydro storage    TAC                [1e9 Euro/a]              0.0011859   \n",
       "                        capacity           [GW$_{el}$*h]                 7.751   \n",
       "                        operationCharge    [GW$_{el}$*h/a]             3963.84   \n",
       "                        operationDischarge [GW$_{el}$*h/a]              3069.5   \n",
       "                        opexCap            [1e9 Euro/a]              0.0011859   \n",
       "Salt caverns (biogas)   TAC                [1e9 Euro/a]               0.029229   \n",
       "                        capacity           [GW$_{biogas,LHV}$*h]       2156.63   \n",
       "                        capexCap           [1e9 Euro/a]             0.00766271   \n",
       "                        invest             [1e9 Euro]                0.0862651   \n",
       "                        operationCharge    [GW$_{biogas,LHV}$*h/a]     6215.24   \n",
       "                        operationDischarge [GW$_{biogas,LHV}$*h/a]     6215.24   \n",
       "                        opexCap            [1e9 Euro/a]              0.0215663   \n",
       "Salt caverns (hydrogen) TAC                [1e9 Euro/a]               0.619047   \n",
       "                        capacity           [GW$_{H_{2},LHV}$*h]        1067.74   \n",
       "                        capexCap           [1e9 Euro/a]              0.0104329   \n",
       "                        invest             [1e9 Euro]                 0.117452   \n",
       "                        operationCharge    [GW$_{H_{2},LHV}$*h/a]      8368.61   \n",
       "                        operationDischarge [GW$_{H_{2},LHV}$*h/a]      8368.61   \n",
       "                        opexCap            [1e9 Euro/a]               0.608614   \n",
       "\n",
       "                                                                      cluster_2  \\\n",
       "Component               Property           Unit                                   \n",
       "Li-ion batteries        TAC                [1e9 Euro/a]                 0.83384   \n",
       "                        capacity           [GW$_{el}$*h]                49.6249   \n",
       "                        capexCap           [1e9 Euro/a]                 0.73459   \n",
       "                        invest             [1e9 Euro]                   7.49337   \n",
       "                        operationCharge    [GW$_{el}$*h/a]              16390.3   \n",
       "                        operationDischarge [GW$_{el}$*h/a]              14785.8   \n",
       "                        opexCap            [1e9 Euro/a]               0.0992499   \n",
       "Pumped hydro storage    TAC                [1e9 Euro/a]             0.000125154   \n",
       "                        capacity           [GW$_{el}$*h]                  0.818   \n",
       "                        operationCharge    [GW$_{el}$*h/a]              407.782   \n",
       "                        operationDischarge [GW$_{el}$*h/a]              315.776   \n",
       "                        opexCap            [1e9 Euro/a]             0.000125154   \n",
       "Salt caverns (biogas)   TAC                [1e9 Euro/a]               0.0565781   \n",
       "                        capacity           [GW$_{biogas,LHV}$*h]        4174.55   \n",
       "                        capexCap           [1e9 Euro/a]               0.0148326   \n",
       "                        invest             [1e9 Euro]                  0.166982   \n",
       "                        operationCharge    [GW$_{biogas,LHV}$*h/a]      12488.1   \n",
       "                        operationDischarge [GW$_{biogas,LHV}$*h/a]      12488.1   \n",
       "                        opexCap            [1e9 Euro/a]               0.0417455   \n",
       "Salt caverns (hydrogen) TAC                [1e9 Euro/a]                0.642299   \n",
       "                        capacity           [GW$_{H_{2},LHV}$*h]         1107.85   \n",
       "                        capexCap           [1e9 Euro/a]               0.0108248   \n",
       "                        invest             [1e9 Euro]                  0.121863   \n",
       "                        operationCharge    [GW$_{H_{2},LHV}$*h/a]       9075.31   \n",
       "                        operationDischarge [GW$_{H_{2},LHV}$*h/a]       9075.31   \n",
       "                        opexCap            [1e9 Euro/a]                0.631474   \n",
       "\n",
       "                                                                     cluster_3  \\\n",
       "Component               Property           Unit                                  \n",
       "Li-ion batteries        TAC                [1e9 Euro/a]               0.166436   \n",
       "                        capacity           [GW$_{el}$*h]               9.90524   \n",
       "                        capexCap           [1e9 Euro/a]               0.146626   \n",
       "                        invest             [1e9 Euro]                  1.49569   \n",
       "                        operationCharge    [GW$_{el}$*h/a]                2934   \n",
       "                        operationDischarge [GW$_{el}$*h/a]                2647   \n",
       "                        opexCap            [1e9 Euro/a]              0.0198105   \n",
       "Pumped hydro storage    TAC                [1e9 Euro/a]             0.00300186   \n",
       "                        capacity           [GW$_{el}$*h]                 19.62   \n",
       "                        operationCharge    [GW$_{el}$*h/a]             8458.49   \n",
       "                        operationDischarge [GW$_{el}$*h/a]             6550.04   \n",
       "                        opexCap            [1e9 Euro/a]             0.00300186   \n",
       "Salt caverns (biogas)   TAC                [1e9 Euro/a]              0.0169407   \n",
       "                        capacity           [GW$_{biogas,LHV}$*h]       1249.95   \n",
       "                        capexCap           [1e9 Euro/a]             0.00444121   \n",
       "                        invest             [1e9 Euro]                0.0499981   \n",
       "                        operationCharge    [GW$_{biogas,LHV}$*h/a]     19518.9   \n",
       "                        operationDischarge [GW$_{biogas,LHV}$*h/a]     19518.9   \n",
       "                        opexCap            [1e9 Euro/a]              0.0124995   \n",
       "Salt caverns (hydrogen) TAC                [1e9 Euro/a]               0.176855   \n",
       "                        capacity           [GW$_{H_{2},LHV}$*h]        305.043   \n",
       "                        capexCap           [1e9 Euro/a]             0.00298058   \n",
       "                        invest             [1e9 Euro]                0.0335548   \n",
       "                        operationCharge    [GW$_{H_{2},LHV}$*h/a]      3190.62   \n",
       "                        operationDischarge [GW$_{H_{2},LHV}$*h/a]      3190.62   \n",
       "                        opexCap            [1e9 Euro/a]               0.173875   \n",
       "\n",
       "                                                                     cluster_4  \\\n",
       "Component               Property           Unit                                  \n",
       "Li-ion batteries        TAC                [1e9 Euro/a]               0.191947   \n",
       "                        capacity           [GW$_{el}$*h]               11.4235   \n",
       "                        capexCap           [1e9 Euro/a]                 0.1691   \n",
       "                        invest             [1e9 Euro]                  1.72494   \n",
       "                        operationCharge    [GW$_{el}$*h/a]             3486.83   \n",
       "                        operationDischarge [GW$_{el}$*h/a]             3145.59   \n",
       "                        opexCap            [1e9 Euro/a]              0.0228469   \n",
       "Pumped hydro storage    TAC                [1e9 Euro/a]             0.00110007   \n",
       "                        capacity           [GW$_{el}$*h]                  7.19   \n",
       "                        operationCharge    [GW$_{el}$*h/a]             3099.63   \n",
       "                        operationDischarge [GW$_{el}$*h/a]             2400.27   \n",
       "                        opexCap            [1e9 Euro/a]             0.00110007   \n",
       "Salt caverns (biogas)   TAC                [1e9 Euro/a]                      0   \n",
       "                        capacity           [GW$_{biogas,LHV}$*h]           NaN   \n",
       "                        capexCap           [1e9 Euro/a]                    NaN   \n",
       "                        invest             [1e9 Euro]                      NaN   \n",
       "                        operationCharge    [GW$_{biogas,LHV}$*h/a]         NaN   \n",
       "                        operationDischarge [GW$_{biogas,LHV}$*h/a]         NaN   \n",
       "                        opexCap            [1e9 Euro/a]                    NaN   \n",
       "Salt caverns (hydrogen) TAC                [1e9 Euro/a]                      0   \n",
       "                        capacity           [GW$_{H_{2},LHV}$*h]            NaN   \n",
       "                        capexCap           [1e9 Euro/a]                    NaN   \n",
       "                        invest             [1e9 Euro]                      NaN   \n",
       "                        operationCharge    [GW$_{H_{2},LHV}$*h/a]          NaN   \n",
       "                        operationDischarge [GW$_{H_{2},LHV}$*h/a]          NaN   \n",
       "                        opexCap            [1e9 Euro/a]                    NaN   \n",
       "\n",
       "                                                                     cluster_5  \\\n",
       "Component               Property           Unit                                  \n",
       "Li-ion batteries        TAC                [1e9 Euro/a]               0.142931   \n",
       "                        capacity           [GW$_{el}$*h]               8.50633   \n",
       "                        capexCap           [1e9 Euro/a]               0.125918   \n",
       "                        invest             [1e9 Euro]                  1.28446   \n",
       "                        operationCharge    [GW$_{el}$*h/a]             2848.05   \n",
       "                        operationDischarge [GW$_{el}$*h/a]             2569.27   \n",
       "                        opexCap            [1e9 Euro/a]              0.0170127   \n",
       "Pumped hydro storage    TAC                [1e9 Euro/a]              0.0038302   \n",
       "                        capacity           [GW$_{el}$*h]                25.034   \n",
       "                        operationCharge    [GW$_{el}$*h/a]             10675.3   \n",
       "                        operationDischarge [GW$_{el}$*h/a]              8266.7   \n",
       "                        opexCap            [1e9 Euro/a]              0.0038302   \n",
       "Salt caverns (biogas)   TAC                [1e9 Euro/a]              0.0108859   \n",
       "                        capacity           [GW$_{biogas,LHV}$*h]       803.203   \n",
       "                        capexCap           [1e9 Euro/a]             0.00285386   \n",
       "                        invest             [1e9 Euro]                0.0321281   \n",
       "                        operationCharge    [GW$_{biogas,LHV}$*h/a]     2315.06   \n",
       "                        operationDischarge [GW$_{biogas,LHV}$*h/a]     2315.06   \n",
       "                        opexCap            [1e9 Euro/a]             0.00803203   \n",
       "Salt caverns (hydrogen) TAC                [1e9 Euro/a]               0.211586   \n",
       "                        capacity           [GW$_{H_{2},LHV}$*h]        364.947   \n",
       "                        capexCap           [1e9 Euro/a]              0.0035659   \n",
       "                        invest             [1e9 Euro]                0.0401442   \n",
       "                        operationCharge    [GW$_{H_{2},LHV}$*h/a]      2932.76   \n",
       "                        operationDischarge [GW$_{H_{2},LHV}$*h/a]      2932.76   \n",
       "                        opexCap            [1e9 Euro/a]                0.20802   \n",
       "\n",
       "                                                                    cluster_6  \\\n",
       "Component               Property           Unit                                 \n",
       "Li-ion batteries        TAC                [1e9 Euro/a]              0.119727   \n",
       "                        capacity           [GW$_{el}$*h]               7.1254   \n",
       "                        capexCap           [1e9 Euro/a]              0.105476   \n",
       "                        invest             [1e9 Euro]                 1.07594   \n",
       "                        operationCharge    [GW$_{el}$*h/a]            2584.69   \n",
       "                        operationDischarge [GW$_{el}$*h/a]            2331.73   \n",
       "                        opexCap            [1e9 Euro/a]             0.0142508   \n",
       "Pumped hydro storage    TAC                [1e9 Euro/a]              9.18e-05   \n",
       "                        capacity           [GW$_{el}$*h]                  0.6   \n",
       "                        operationCharge    [GW$_{el}$*h/a]            292.332   \n",
       "                        operationDischarge [GW$_{el}$*h/a]            226.367   \n",
       "                        opexCap            [1e9 Euro/a]              9.18e-05   \n",
       "Salt caverns (biogas)   TAC                [1e9 Euro/a]                     0   \n",
       "                        capacity           [GW$_{biogas,LHV}$*h]            0   \n",
       "                        capexCap           [1e9 Euro/a]                     0   \n",
       "                        invest             [1e9 Euro]                       0   \n",
       "                        operationCharge    [GW$_{biogas,LHV}$*h/a]          0   \n",
       "                        operationDischarge [GW$_{biogas,LHV}$*h/a]          0   \n",
       "                        opexCap            [1e9 Euro/a]                     0   \n",
       "Salt caverns (hydrogen) TAC                [1e9 Euro/a]              0.632608   \n",
       "                        capacity           [GW$_{H_{2},LHV}$*h]       1091.13   \n",
       "                        capexCap           [1e9 Euro/a]             0.0106615   \n",
       "                        invest             [1e9 Euro]                0.120025   \n",
       "                        operationCharge    [GW$_{H_{2},LHV}$*h/a]     11243.5   \n",
       "                        operationDischarge [GW$_{H_{2},LHV}$*h/a]     11243.5   \n",
       "                        opexCap            [1e9 Euro/a]              0.621947   \n",
       "\n",
       "                                                                    cluster_7  \n",
       "Component               Property           Unit                                \n",
       "Li-ion batteries        TAC                [1e9 Euro/a]              0.133092  \n",
       "                        capacity           [GW$_{el}$*h]              7.92079  \n",
       "                        capexCap           [1e9 Euro/a]               0.11725  \n",
       "                        invest             [1e9 Euro]                 1.19604  \n",
       "                        operationCharge    [GW$_{el}$*h/a]            2994.81  \n",
       "                        operationDischarge [GW$_{el}$*h/a]            2701.93  \n",
       "                        opexCap            [1e9 Euro/a]             0.0158416  \n",
       "Pumped hydro storage    TAC                [1e9 Euro/a]                     0  \n",
       "                        capacity           [GW$_{el}$*h]                  NaN  \n",
       "                        operationCharge    [GW$_{el}$*h/a]                NaN  \n",
       "                        operationDischarge [GW$_{el}$*h/a]                NaN  \n",
       "                        opexCap            [1e9 Euro/a]                   NaN  \n",
       "Salt caverns (biogas)   TAC                [1e9 Euro/a]                     0  \n",
       "                        capacity           [GW$_{biogas,LHV}$*h]          NaN  \n",
       "                        capexCap           [1e9 Euro/a]                   NaN  \n",
       "                        invest             [1e9 Euro]                     NaN  \n",
       "                        operationCharge    [GW$_{biogas,LHV}$*h/a]        NaN  \n",
       "                        operationDischarge [GW$_{biogas,LHV}$*h/a]        NaN  \n",
       "                        opexCap            [1e9 Euro/a]                   NaN  \n",
       "Salt caverns (hydrogen) TAC                [1e9 Euro/a]                     0  \n",
       "                        capacity           [GW$_{H_{2},LHV}$*h]           NaN  \n",
       "                        capexCap           [1e9 Euro/a]                   NaN  \n",
       "                        invest             [1e9 Euro]                     NaN  \n",
       "                        operationCharge    [GW$_{H_{2},LHV}$*h/a]         NaN  \n",
       "                        operationDischarge [GW$_{H_{2},LHV}$*h/a]         NaN  \n",
       "                        opexCap            [1e9 Euro/a]                   NaN  "
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esM.getOptimizationSummary(\"StorageModel\", outputLevel=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 21456 characters]\n",
      "text/plain": [
       "<Figure size 864x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotOperationColorMap(esM, 'Li-ion batteries', 'cluster_2', \n",
    "                                   variableName='stateOfChargeOperationVariablesOptimum')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 20472 characters]\n",
      "text/plain": [
       "<Figure size 864x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotOperationColorMap(esM, 'Pumped hydro storage', 'cluster_2',\n",
    "                                  variableName='stateOfChargeOperationVariablesOptimum')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 22792 characters]\n",
      "text/plain": [
       "<Figure size 864x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotOperationColorMap(esM, 'Salt caverns (biogas)', 'cluster_2',\n",
    "                                  variableName='stateOfChargeOperationVariablesOptimum')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27792 characters]\n",
      "text/plain": [
       "<Figure size 864x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = fn.plotOperationColorMap(esM, 'Salt caverns (hydrogen)', 'cluster_2',\n",
    "                                  variableName='stateOfChargeOperationVariablesOptimum')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Transmission\n",
    "\n",
    "Show optimization summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "scrolled": true
   },
   "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></th>\n",
       "      <th></th>\n",
       "      <th>cluster_0</th>\n",
       "      <th>cluster_1</th>\n",
       "      <th>cluster_2</th>\n",
       "      <th>cluster_3</th>\n",
       "      <th>cluster_4</th>\n",
       "      <th>cluster_5</th>\n",
       "      <th>cluster_6</th>\n",
       "      <th>cluster_7</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Property</th>\n",
       "      <th>Unit</th>\n",
       "      <th>LocationIn</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"7\" valign=\"top\">TAC</th>\n",
       "      <th rowspan=\"7\" valign=\"top\">[1e9 Euro/a]</th>\n",
       "      <th>cluster_0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.00511966</td>\n",
       "      <td>0.00464921</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00426177</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_1</th>\n",
       "      <td>0.00511966</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00276739</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00422026</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_2</th>\n",
       "      <td>0.00464921</td>\n",
       "      <td>0.00276739</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00549326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00531338</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_4</th>\n",
       "      <td>0.00426177</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_6</th>\n",
       "      <td>0</td>\n",
       "      <td>0.00422026</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00531338</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_7</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00549326</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"7\" valign=\"top\">capacity</th>\n",
       "      <th rowspan=\"7\" valign=\"top\">[GW$_{H_{2},LHV}$]</th>\n",
       "      <th>cluster_0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>2.95872</td>\n",
       "      <td>0.00172466</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.15049</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_1</th>\n",
       "      <td>2.95872</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00142051</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>5.05905</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_2</th>\n",
       "      <td>0.00172466</td>\n",
       "      <td>0.00142051</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.165882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0.215968</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_4</th>\n",
       "      <td>1.15049</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.05905</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.215968</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_7</th>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.165882</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"7\" valign=\"top\">capexIfBuilt</th>\n",
       "      <th rowspan=\"7\" valign=\"top\">[1e9 Euro/a]</th>\n",
       "      <th>cluster_0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00511966</td>\n",
       "      <td>0.00464921</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00426177</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_1</th>\n",
       "      <td>0.00511966</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00276739</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00422026</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_2</th>\n",
       "      <td>0.00464921</td>\n",
       "      <td>0.00276739</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00549326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00531338</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_4</th>\n",
       "      <td>0.00426177</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00422026</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00531338</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_7</th>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00549326</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"7\" valign=\"top\">isBuilt</th>\n",
       "      <th rowspan=\"7\" valign=\"top\">[-]</th>\n",
       "      <th>cluster_0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_1</th>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_4</th>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_7</th>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"7\" valign=\"top\">operation</th>\n",
       "      <th rowspan=\"7\" valign=\"top\">[GW$_{H_{2},LHV}$*h/a]</th>\n",
       "      <th>cluster_0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1688.68</td>\n",
       "      <td>0.389774</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8325.79</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_1</th>\n",
       "      <td>24152</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.832417</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>5926.15</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_2</th>\n",
       "      <td>13.6766</td>\n",
       "      <td>7.72329</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1380.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>120.972</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_4</th>\n",
       "      <td>2.86461</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>38105</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1200.2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_7</th>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.600558</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                 cluster_0   cluster_1  \\\n",
       "Property     Unit                   LocationIn                           \n",
       "TAC          [1e9 Euro/a]           cluster_0            0  0.00511966   \n",
       "                                    cluster_1   0.00511966           0   \n",
       "                                    cluster_2   0.00464921  0.00276739   \n",
       "                                    cluster_3            0           0   \n",
       "                                    cluster_4   0.00426177           0   \n",
       "                                    cluster_6            0  0.00422026   \n",
       "                                    cluster_7            0           0   \n",
       "capacity     [GW$_{H_{2},LHV}$]     cluster_0          NaN     2.95872   \n",
       "                                    cluster_1      2.95872         NaN   \n",
       "                                    cluster_2   0.00172466  0.00142051   \n",
       "                                    cluster_3          NaN           0   \n",
       "                                    cluster_4      1.15049         NaN   \n",
       "                                    cluster_6          NaN     5.05905   \n",
       "                                    cluster_7            0         NaN   \n",
       "capexIfBuilt [1e9 Euro/a]           cluster_0          NaN  0.00511966   \n",
       "                                    cluster_1   0.00511966         NaN   \n",
       "                                    cluster_2   0.00464921  0.00276739   \n",
       "                                    cluster_3          NaN           0   \n",
       "                                    cluster_4   0.00426177         NaN   \n",
       "                                    cluster_6          NaN  0.00422026   \n",
       "                                    cluster_7            0         NaN   \n",
       "isBuilt      [-]                    cluster_0          NaN           1   \n",
       "                                    cluster_1            1         NaN   \n",
       "                                    cluster_2            1           1   \n",
       "                                    cluster_3          NaN           0   \n",
       "                                    cluster_4            1         NaN   \n",
       "                                    cluster_6          NaN           1   \n",
       "                                    cluster_7            0         NaN   \n",
       "operation    [GW$_{H_{2},LHV}$*h/a] cluster_0          NaN     1688.68   \n",
       "                                    cluster_1        24152         NaN   \n",
       "                                    cluster_2      13.6766     7.72329   \n",
       "                                    cluster_3          NaN           0   \n",
       "                                    cluster_4      2.86461         NaN   \n",
       "                                    cluster_6          NaN       38105   \n",
       "                                    cluster_7            0         NaN   \n",
       "\n",
       "                                                 cluster_2   cluster_3  \\\n",
       "Property     Unit                   LocationIn                           \n",
       "TAC          [1e9 Euro/a]           cluster_0   0.00464921           0   \n",
       "                                    cluster_1   0.00276739           0   \n",
       "                                    cluster_2            0           0   \n",
       "                                    cluster_3            0           0   \n",
       "                                    cluster_4            0           0   \n",
       "                                    cluster_6            0  0.00531338   \n",
       "                                    cluster_7   0.00549326           0   \n",
       "capacity     [GW$_{H_{2},LHV}$]     cluster_0   0.00172466         NaN   \n",
       "                                    cluster_1   0.00142051           0   \n",
       "                                    cluster_2          NaN         NaN   \n",
       "                                    cluster_3          NaN         NaN   \n",
       "                                    cluster_4          NaN         NaN   \n",
       "                                    cluster_6          NaN    0.215968   \n",
       "                                    cluster_7     0.165882         NaN   \n",
       "capexIfBuilt [1e9 Euro/a]           cluster_0   0.00464921         NaN   \n",
       "                                    cluster_1   0.00276739           0   \n",
       "                                    cluster_2          NaN         NaN   \n",
       "                                    cluster_3          NaN         NaN   \n",
       "                                    cluster_4          NaN         NaN   \n",
       "                                    cluster_6          NaN  0.00531338   \n",
       "                                    cluster_7   0.00549326         NaN   \n",
       "isBuilt      [-]                    cluster_0            1         NaN   \n",
       "                                    cluster_1            1           0   \n",
       "                                    cluster_2          NaN         NaN   \n",
       "                                    cluster_3          NaN         NaN   \n",
       "                                    cluster_4          NaN         NaN   \n",
       "                                    cluster_6          NaN           1   \n",
       "                                    cluster_7            1         NaN   \n",
       "operation    [GW$_{H_{2},LHV}$*h/a] cluster_0     0.389774         NaN   \n",
       "                                    cluster_1     0.832417           0   \n",
       "                                    cluster_2          NaN         NaN   \n",
       "                                    cluster_3          NaN         NaN   \n",
       "                                    cluster_4          NaN         NaN   \n",
       "                                    cluster_6          NaN      1200.2   \n",
       "                                    cluster_7     0.600558         NaN   \n",
       "\n",
       "                                                 cluster_4 cluster_5  \\\n",
       "Property     Unit                   LocationIn                         \n",
       "TAC          [1e9 Euro/a]           cluster_0   0.00426177         0   \n",
       "                                    cluster_1            0         0   \n",
       "                                    cluster_2            0         0   \n",
       "                                    cluster_3            0         0   \n",
       "                                    cluster_4            0         0   \n",
       "                                    cluster_6            0         0   \n",
       "                                    cluster_7            0         0   \n",
       "capacity     [GW$_{H_{2},LHV}$]     cluster_0      1.15049         0   \n",
       "                                    cluster_1          NaN         0   \n",
       "                                    cluster_2          NaN       NaN   \n",
       "                                    cluster_3          NaN         0   \n",
       "                                    cluster_4          NaN         0   \n",
       "                                    cluster_6          NaN       NaN   \n",
       "                                    cluster_7          NaN       NaN   \n",
       "capexIfBuilt [1e9 Euro/a]           cluster_0   0.00426177         0   \n",
       "                                    cluster_1          NaN         0   \n",
       "                                    cluster_2          NaN       NaN   \n",
       "                                    cluster_3          NaN         0   \n",
       "                                    cluster_4          NaN         0   \n",
       "                                    cluster_6          NaN       NaN   \n",
       "                                    cluster_7          NaN       NaN   \n",
       "isBuilt      [-]                    cluster_0            1         0   \n",
       "                                    cluster_1          NaN         0   \n",
       "                                    cluster_2          NaN       NaN   \n",
       "                                    cluster_3          NaN         0   \n",
       "                                    cluster_4          NaN         0   \n",
       "                                    cluster_6          NaN       NaN   \n",
       "                                    cluster_7          NaN       NaN   \n",
       "operation    [GW$_{H_{2},LHV}$*h/a] cluster_0      8325.79         0   \n",
       "                                    cluster_1          NaN         0   \n",
       "                                    cluster_2          NaN       NaN   \n",
       "                                    cluster_3          NaN         0   \n",
       "                                    cluster_4          NaN         0   \n",
       "                                    cluster_6          NaN       NaN   \n",
       "                                    cluster_7          NaN       NaN   \n",
       "\n",
       "                                                 cluster_6   cluster_7  \n",
       "Property     Unit                   LocationIn                          \n",
       "TAC          [1e9 Euro/a]           cluster_0            0           0  \n",
       "                                    cluster_1   0.00422026           0  \n",
       "                                    cluster_2            0  0.00549326  \n",
       "                                    cluster_3   0.00531338           0  \n",
       "                                    cluster_4            0           0  \n",
       "                                    cluster_6            0           0  \n",
       "                                    cluster_7            0           0  \n",
       "capacity     [GW$_{H_{2},LHV}$]     cluster_0          NaN           0  \n",
       "                                    cluster_1      5.05905         NaN  \n",
       "                                    cluster_2          NaN    0.165882  \n",
       "                                    cluster_3     0.215968         NaN  \n",
       "                                    cluster_4          NaN         NaN  \n",
       "                                    cluster_6          NaN         NaN  \n",
       "                                    cluster_7          NaN         NaN  \n",
       "capexIfBuilt [1e9 Euro/a]           cluster_0          NaN           0  \n",
       "                                    cluster_1   0.00422026         NaN  \n",
       "                                    cluster_2          NaN  0.00549326  \n",
       "                                    cluster_3   0.00531338         NaN  \n",
       "                                    cluster_4          NaN         NaN  \n",
       "                                    cluster_6          NaN         NaN  \n",
       "                                    cluster_7          NaN         NaN  \n",
       "isBuilt      [-]                    cluster_0          NaN           0  \n",
       "                                    cluster_1            1         NaN  \n",
       "                                    cluster_2          NaN           1  \n",
       "                                    cluster_3            1         NaN  \n",
       "                                    cluster_4          NaN         NaN  \n",
       "                                    cluster_6          NaN         NaN  \n",
       "                                    cluster_7          NaN         NaN  \n",
       "operation    [GW$_{H_{2},LHV}$*h/a] cluster_0          NaN           0  \n",
       "                                    cluster_1      5926.15         NaN  \n",
       "                                    cluster_2          NaN     1380.04  \n",
       "                                    cluster_3      120.972         NaN  \n",
       "                                    cluster_4          NaN         NaN  \n",
       "                                    cluster_6          NaN         NaN  \n",
       "                                    cluster_7          NaN         NaN  "
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "esM.getOptimizationSummary(\"TransmissionModel\", outputLevel=2).loc['Pipelines (hydrogen)']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Check that the shared capacity of the pipelines are not exceeded"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "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>cluster_0</th>\n",
       "      <th>cluster_1</th>\n",
       "      <th>cluster_2</th>\n",
       "      <th>cluster_3</th>\n",
       "      <th>cluster_4</th>\n",
       "      <th>cluster_5</th>\n",
       "      <th>cluster_6</th>\n",
       "      <th>cluster_7</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>cluster_0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>2.958720</td>\n",
       "      <td>1.301089</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.892217</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_1</th>\n",
       "      <td>2.958720</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.001421</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.407007</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_2</th>\n",
       "      <td>1.301089</td>\n",
       "      <td>0.001421</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.305141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.215968</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_4</th>\n",
       "      <td>1.892217</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_5</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.407007</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.215968</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cluster_7</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.305141</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           cluster_0  cluster_1  cluster_2  cluster_3  cluster_4  cluster_5  \\\n",
       "cluster_0        NaN   2.958720   1.301089        NaN   1.892217        0.0   \n",
       "cluster_1   2.958720        NaN   0.001421   0.000000        NaN        0.0   \n",
       "cluster_2   1.301089   0.001421        NaN        NaN        NaN        NaN   \n",
       "cluster_3        NaN   0.000000        NaN        NaN        NaN        0.0   \n",
       "cluster_4   1.892217        NaN        NaN        NaN        NaN        0.0   \n",
       "cluster_5   0.000000   0.000000        NaN   0.000000   0.000000        NaN   \n",
       "cluster_6        NaN   5.407007        NaN   0.215968        NaN        NaN   \n",
       "cluster_7   0.000000        NaN   0.305141        NaN        NaN        NaN   \n",
       "\n",
       "           cluster_6  cluster_7  \n",
       "cluster_0        NaN   0.000000  \n",
       "cluster_1   5.407007        NaN  \n",
       "cluster_2        NaN   0.305141  \n",
       "cluster_3   0.215968        NaN  \n",
       "cluster_4        NaN        NaN  \n",
       "cluster_5        NaN        NaN  \n",
       "cluster_6        NaN        NaN  \n",
       "cluster_7        NaN        NaN  "
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df=esM.componentModelingDict[\"TransmissionModel\"].capacityVariablesOptimum\n",
    "df.loc['Pipelines (biogas)']+df.loc['Pipelines (hydrogen)']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Plot installed transmission capacities"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 48464 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "transFilePath = os.path.join(cwd, 'InputData', 'SpatialData','ShapeFiles', 'AClines.shp')\n",
    "\n",
    "fig, ax = fn.plotLocations(locFilePath, indexColumn='index')                                 \n",
    "fig, ax = fn.plotTransmission(esM, 'AC cables', transFilePath, loc0='bus0', loc1='bus1', fig=fig, ax=ax)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 39360 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "transFilePath = os.path.join(cwd, 'InputData', 'SpatialData','ShapeFiles', 'DClines.shp')\n",
    "\n",
    "fig, ax = fn.plotLocations(locFilePath, indexColumn='index')                                 \n",
    "fig, ax = fn.plotTransmission(esM, 'DC cables', transFilePath, loc0='cluster0', loc1='cluster1', fig=fig, ax=ax)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 44344 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "transFilePath = os.path.join(cwd, 'InputData', 'SpatialData','ShapeFiles', 'transmissionPipeline.shp')\n",
    "\n",
    "fig, ax = fn.plotLocations(locFilePath, indexColumn='index')                                 \n",
    "fig, ax = fn.plotTransmission(esM, 'Pipelines (hydrogen)', transFilePath, loc0='loc1', loc1='loc2',\n",
    "                              fig=fig, ax=ax)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 45104 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "transFilePath = os.path.join(cwd, 'InputData', 'SpatialData','ShapeFiles', 'transmissionPipeline.shp')\n",
    "\n",
    "fig, ax = fn.plotLocations(locFilePath, indexColumn='index')                                 \n",
    "fig, ax = fn.plotTransmission(esM, 'Pipelines (biogas)', transFilePath, loc0='loc1', loc1='loc2',\n",
    "                              fig=fig, ax=ax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Postprocessing: Determine robust pipeline design"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import module expansion \"robustPipelineSizing\"\n",
    "from FINE.expansionModules import robustPipelineSizing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "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>cluster_3</th>\n",
       "      <th>cluster_4</th>\n",
       "      <th>cluster_2</th>\n",
       "      <th>cluster_7</th>\n",
       "      <th>cluster_6</th>\n",
       "      <th>cluster_5</th>\n",
       "      <th>cluster_1</th>\n",
       "      <th>cluster_0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.80045</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>-1.397279</td>\n",
       "      <td>1.382901</td>\n",
       "      <td>-43.976052</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>15.089016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.80045</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>-1.256247</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>-43.976052</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>15.089016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.80045</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>-1.256247</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>-43.976052</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>15.089016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.80045</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>-1.256247</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>-43.976052</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>15.089016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.80045</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>-1.268089</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>-43.976052</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17.521577</td>\n",
       "      <td>15.089016</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   cluster_3  cluster_4  cluster_2  cluster_7  cluster_6  cluster_5  \\\n",
       "0    1.80045   9.591229  -1.397279   1.382901 -43.976052        0.0   \n",
       "1    1.80045   9.591229  -1.256247   1.241869 -43.976052        0.0   \n",
       "2    1.80045   9.591229  -1.256247   1.241869 -43.976052        0.0   \n",
       "3    1.80045   9.591229  -1.256247   1.241869 -43.976052        0.0   \n",
       "4    1.80045   9.591229  -1.268089   1.241869 -43.976052        0.0   \n",
       "\n",
       "   cluster_1  cluster_0  \n",
       "0  17.509735  15.089016  \n",
       "1  17.509735  15.089016  \n",
       "2  17.509735  15.089016  \n",
       "3  17.509735  15.089016  \n",
       "4  17.521577  15.089016  "
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. Option to get the injection and withdrawal rates for the pipeline sizing (in kg/s)\n",
    "rates = robustPipelineSizing.getInjectionWithdrawalRates(componentName='Pipelines (hydrogen)',esM=esM) # in GWh\n",
    "# Convert GWh to kg/s: GWh * (kWh/GWh) * (kg/kWh) * (1/ timestepLengthInSeconds) with timestepLengthInSeconds\n",
    "# being 3600 seconds for the present example\n",
    "rates = rates * (10 ** 6) * (1/33.32) * (1/3600) \n",
    "rates.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "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>cluster_0</th>\n",
       "      <th>cluster_1</th>\n",
       "      <th>cluster_2</th>\n",
       "      <th>cluster_4</th>\n",
       "      <th>cluster_5</th>\n",
       "      <th>cluster_7</th>\n",
       "      <th>cluster_3</th>\n",
       "      <th>cluster_6</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15.089016</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>-1.397279</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.382901</td>\n",
       "      <td>1.80045</td>\n",
       "      <td>-43.976052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>15.089016</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>-1.256247</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>1.80045</td>\n",
       "      <td>-43.976052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>15.089016</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>-1.256247</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>1.80045</td>\n",
       "      <td>-43.976052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>15.089016</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>-1.256247</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>1.80045</td>\n",
       "      <td>-43.976052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>15.089016</td>\n",
       "      <td>17.521577</td>\n",
       "      <td>-1.268089</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>1.80045</td>\n",
       "      <td>-43.976052</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   cluster_0  cluster_1  cluster_2  cluster_4  cluster_5  cluster_7  \\\n",
       "0  15.089016  17.509735  -1.397279   9.591229        0.0   1.382901   \n",
       "1  15.089016  17.509735  -1.256247   9.591229        0.0   1.241869   \n",
       "2  15.089016  17.509735  -1.256247   9.591229        0.0   1.241869   \n",
       "3  15.089016  17.509735  -1.256247   9.591229        0.0   1.241869   \n",
       "4  15.089016  17.521577  -1.268089   9.591229        0.0   1.241869   \n",
       "\n",
       "   cluster_3  cluster_6  \n",
       "0    1.80045 -43.976052  \n",
       "1    1.80045 -43.976052  \n",
       "2    1.80045 -43.976052  \n",
       "3    1.80045 -43.976052  \n",
       "4    1.80045 -43.976052  "
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2. Option to get the injection and withdrawal rates for the pipeline sizing (in kg/s)\n",
    "op = esM.componentModelingDict[esM.componentNames['Pipelines (hydrogen)']].\\\n",
    "    getOptimalValues('operationVariablesOptimum')['values'].loc['Pipelines (hydrogen)']\n",
    "rates = robustPipelineSizing.getInjectionWithdrawalRates(operationVariablesOptimumData=op) # in GWh\n",
    "# Convert GWh to kg/s: GWh * (kWh/GWh) * (kg/kWh) * (1/ timestepLengthInSeconds) with timestepLengthInSeconds\n",
    "# being 3600 seconds for the present example\n",
    "rates = rates * (10 ** 6) * (1/33.32) * (1/3600) \n",
    "rates.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "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>cluster_0</th>\n",
       "      <th>cluster_1</th>\n",
       "      <th>cluster_2</th>\n",
       "      <th>cluster_4</th>\n",
       "      <th>cluster_5</th>\n",
       "      <th>cluster_7</th>\n",
       "      <th>cluster_3</th>\n",
       "      <th>cluster_6</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15.089016</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>-1.397279</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.382901</td>\n",
       "      <td>1.80045</td>\n",
       "      <td>-43.976052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>15.089016</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>-1.256247</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>1.80045</td>\n",
       "      <td>-43.976052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>15.089016</td>\n",
       "      <td>17.521577</td>\n",
       "      <td>-1.268089</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>1.80045</td>\n",
       "      <td>-43.976052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>15.089016</td>\n",
       "      <td>17.509735</td>\n",
       "      <td>-1.268089</td>\n",
       "      <td>9.591229</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.253711</td>\n",
       "      <td>1.80045</td>\n",
       "      <td>-43.976052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>10.966815</td>\n",
       "      <td>24.883812</td>\n",
       "      <td>-1.241869</td>\n",
       "      <td>6.324975</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.241869</td>\n",
       "      <td>1.80045</td>\n",
       "      <td>-43.976052</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   cluster_0  cluster_1  cluster_2  cluster_4  cluster_5  cluster_7  \\\n",
       "0  15.089016  17.509735  -1.397279   9.591229        0.0   1.382901   \n",
       "1  15.089016  17.509735  -1.256247   9.591229        0.0   1.241869   \n",
       "4  15.089016  17.521577  -1.268089   9.591229        0.0   1.241869   \n",
       "5  15.089016  17.509735  -1.268089   9.591229        0.0   1.253711   \n",
       "6  10.966815  24.883812  -1.241869   6.324975        0.0   1.241869   \n",
       "\n",
       "   cluster_3  cluster_6  \n",
       "0    1.80045 -43.976052  \n",
       "1    1.80045 -43.976052  \n",
       "4    1.80045 -43.976052  \n",
       "5    1.80045 -43.976052  \n",
       "6    1.80045 -43.976052  "
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Determine unique withdrawal and injection scenarios to save computation time\n",
    "rates = rates.drop_duplicates()\n",
    "rates.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(cluster_3, cluster_6)    384000.0\n",
       "(cluster_3, cluster_5)    292000.0\n",
       "(cluster_3, cluster_1)    477000.0\n",
       "(cluster_4, cluster_5)    688000.0\n",
       "(cluster_4, cluster_0)    308000.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get the lengths of the pipeline (in m)\n",
    "lengths = robustPipelineSizing.getNetworkLengthsFromESM('Pipelines (hydrogen)', esM)\n",
    "lengths = lengths * 1e3\n",
    "lengths.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify minimum and maximum pressure levels for all injection and withdrawal nodes (in bar)\n",
    "p_min_nodes = {'cluster_5': 60, 'cluster_3': 50, 'cluster_7': 50, 'cluster_1': 60, 'cluster_6': 50,\n",
    "               'cluster_4': 50, 'cluster_0': 50, 'cluster_2': 50}\n",
    "\n",
    "p_max_nodes = {'cluster_5': 100, 'cluster_3': 100, 'cluster_7': 100, 'cluster_1': 90, 'cluster_6': 100,\n",
    "               'cluster_4': 100, 'cluster_0': 100, 'cluster_2': 100}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Specify the investment cost of the available diameter classes in €/m\n",
    "\n",
    "# For single pipes\n",
    "dic_diameter_costs = {0.1063: 37.51, 0.1307: 38.45, 0.1593: 39.64, 0.2065: 42.12,\n",
    "                      0.2588: 45.26, 0.3063: 48.69, 0.3356: 51.07, 0.3844: 55.24,\n",
    "                      0.432: 59.86, 0.4796: 64.98, 0.527: 70.56, 0.578: 76.61,\n",
    "                      0.625: 82.99, 0.671: 89.95, 0.722: 97.38, 0.7686: 105.28,\n",
    "                      0.814: 113.63, 0.864: 122.28, 0.915: 131.56, 0.96: 141.3,\n",
    "                      1.011: 151.5, 1.058: 162.17, 1.104: 173.08, 1.155: 184.67,\n",
    "                      1.249: 209.24, 1.342: 235.4, 1.444: 263.66, 1.536: 293.78}\n",
    "\n",
    "# For parallel pipes\n",
    "dic_candidateMergedDiam_costs={1.342: 235.4, 1.444: 263.66, 1.536: 293.78}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Choose if a robust pipeline desin should be determined or the design should be optimized based on the\n",
    "# given injection and withdrawal rates only\n",
    "robust = True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Determine design for simple network structure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating graph with respect to given distances\n",
      "Original Network Graph:\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 31592 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating a Steiner treee\n",
      "Steiner tree:\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 18288 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compute robust scenario set for tree network (based on 56 node combinations). Threads: 7\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of robust scenarios: 56\n",
      "\t\t(13.5158 sec)\n",
      "\n",
      "Compute scenarios for each timestep. Number of timestep scenarios: 105. Threads: 7\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\t(15.9917 sec)\n",
      "\n",
      "Compute equivalent single diameters for looped (parallel) pipes\n",
      "Pressure drop coefficients for diameters with respect to robust scenarios\n",
      "Determining optimal robust pipeline design under the consideration of pressure losses and robust scenarios\n",
      "        0.04 seconds required to write file\n",
      "        0.04 seconds required for presolve\n",
      "GLPSOL: GLPK LP/MIP Solver, v4.65\n",
      "Parameter(s) specified in the command line:\n",
      " --write C:\\Users\\there\\AppData\\Local\\Temp\\tmp2u0ylw60.glpk.raw --wglp C:\\Users\\there\\AppData\\Local\\Temp\\tmp3vvuq0vq.glpk.glp\n",
      " --cpxlp C:\\Users\\there\\AppData\\Local\\Temp\\tmpo87fi2n4.pyomo.lp\n",
      "Reading problem data from 'C:\\Users\\there\\AppData\\Local\\Temp\\tmpo87fi2n4.pyomo.lp'...\n",
      "C:\\Users\\there\\AppData\\Local\\Temp\\tmpo87fi2n4.pyomo.lp:10006: warning: lower bound of variable 'x1' redefined\n",
      "C:\\Users\\there\\AppData\\Local\\Temp\\tmpo87fi2n4.pyomo.lp:10006: warning: upper bound of variable 'x1' redefined\n",
      "400 rows, 666 columns, 7915 non-zeros\n",
      "217 integer variables, all of which are binary\n",
      "10223 lines were read\n",
      "Writing problem data to 'C:\\Users\\there\\AppData\\Local\\Temp\\tmp3vvuq0vq.glpk.glp'...\n",
      "9658 lines were written\n",
      "GLPK Integer Optimizer, v4.65\n",
      "400 rows, 666 columns, 7915 non-zeros\n",
      "217 integer variables, all of which are binary\n",
      "Preprocessing...\n",
      "216 rows, 295 columns, 4864 non-zeros\n",
      "161 integer variables, all of which are binary\n",
      "Scaling...\n",
      " A: min|aij| =  6.966e-03  max|aij| =  6.429e+03  ratio =  9.228e+05\n",
      "GM: min|aij| =  5.662e-02  max|aij| =  1.766e+01  ratio =  3.120e+02\n",
      "EQ: min|aij| =  3.206e-03  max|aij| =  1.000e+00  ratio =  3.120e+02\n",
      "2N: min|aij| =  2.618e-03  max|aij| =  1.478e+00  ratio =  5.645e+02\n",
      "Constructing initial basis...\n",
      "Size of triangular part is 216\n",
      "Solving LP relaxation...\n",
      "GLPK Simplex Optimizer, v4.65\n",
      "216 rows, 295 columns, 4864 non-zeros\n",
      "      0: obj =   1.187458760e+09 inf =   2.314e+04 (162)\n",
      "    114: obj =   9.530994401e+08 inf =   2.952e-14 (0)\n",
      "*   207: obj =   1.613855536e+08 inf =   3.415e-12 (0)\n",
      "OPTIMAL LP SOLUTION FOUND\n",
      "Integer optimization begins...\n",
      "Long-step dual simplex will be used\n",
      "+   207: mip =     not found yet >=              -inf        (1; 0)\n",
      "+   231: >>>>>   1.619961800e+08 >=   1.614688365e+08   0.3% (5; 0)\n",
      "+   234: >>>>>   1.618310800e+08 >=   1.616118670e+08   0.1% (3; 2)\n",
      "+   239: mip =   1.618310800e+08 >=     tree is empty   0.0% (0; 9)\n",
      "INTEGER OPTIMAL SOLUTION FOUND\n",
      "Time used:   0.0 secs\n",
      "Memory used: 1.5 Mb (1622820 bytes)\n",
      "Writing MIP solution to 'C:\\Users\\there\\AppData\\Local\\Temp\\tmp2u0ylw60.glpk.raw'...\n",
      "1075 lines were written\n",
      "        0.23 seconds required for solver\n",
      "        0.00 seconds required to read logfile \n",
      "        0.02 seconds required to read solution file \n",
      "        0.02 seconds required for postsolve\n",
      "Do postprocessing for robust (special) scenarios. Number of scenarios: 56. Threads: 7\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\t(12.9476 sec)\n",
      "\n",
      "Do postprocessing for each timestep scenarios. Number of scenarios: 105. Threads: 7\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\t(13.0150 sec)\n",
      "\n",
      "Network with optimized diameters, looped pipes are indicated by two colored edges, Thicker edge means larger diameter\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 20200 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Compute with 7 threads and simple network structure\n",
    "\n",
    "dic_arc_optimalDiameters, dic_scen_PressLevels, dic_scen_MaxViolPress, dic_timeStep_PressLevels, \\\n",
    "    dic_timeStep_MaxViolPress, _ = robustPipelineSizing.determineDiscretePipelineDesign(\n",
    "        robust=robust, injectionWithdrawalRates=rates,\n",
    "        distances=lengths, dic_node_minPress=p_min_nodes, dic_node_maxPress=p_max_nodes, \n",
    "        dic_diameter_costs=dic_diameter_costs, dic_candidateMergedDiam_costs=dic_candidateMergedDiam_costs,\n",
    "        threads=7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating graph with respect to given distances\n",
      "Original Network Graph:\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 32752 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating a Steiner treee\n",
      "Steiner tree:\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 19304 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compute robust scenario set for tree network (based on 56 node combinations). Threads: 2\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of robust scenarios: 56\n",
      "\t\t(7.7526 sec)\n",
      "\n",
      "Compute scenarios for each timestep. Number of timestep scenarios: 105. Threads: 2\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\t(9.1734 sec)\n",
      "\n",
      "Compute equivalent single diameters for looped (parallel) pipes\n",
      "Pressure drop coefficients for diameters with respect to robust scenarios\n",
      "Determining optimal robust pipeline design under the consideration of pressure losses and robust scenarios\n",
      "        0.03 seconds required to write file\n",
      "        0.05 seconds required for presolve\n",
      "GLPSOL: GLPK LP/MIP Solver, v4.65\n",
      "Parameter(s) specified in the command line:\n",
      " --write C:\\Users\\there\\AppData\\Local\\Temp\\tmpqhnwt2u7.glpk.raw --wglp C:\\Users\\there\\AppData\\Local\\Temp\\tmpl7y4diuw.glpk.glp\n",
      " --cpxlp C:\\Users\\there\\AppData\\Local\\Temp\\tmp09ai0yxu.pyomo.lp\n",
      "Reading problem data from 'C:\\Users\\there\\AppData\\Local\\Temp\\tmp09ai0yxu.pyomo.lp'...\n",
      "C:\\Users\\there\\AppData\\Local\\Temp\\tmp09ai0yxu.pyomo.lp:10006: warning: lower bound of variable 'x1' redefined\n",
      "C:\\Users\\there\\AppData\\Local\\Temp\\tmp09ai0yxu.pyomo.lp:10006: warning: upper bound of variable 'x1' redefined\n",
      "400 rows, 666 columns, 7915 non-zeros\n",
      "217 integer variables, all of which are binary\n",
      "10223 lines were read\n",
      "Writing problem data to 'C:\\Users\\there\\AppData\\Local\\Temp\\tmpl7y4diuw.glpk.glp'...\n",
      "9658 lines were written\n",
      "GLPK Integer Optimizer, v4.65\n",
      "400 rows, 666 columns, 7915 non-zeros\n",
      "217 integer variables, all of which are binary\n",
      "Preprocessing...\n",
      "216 rows, 295 columns, 4864 non-zeros\n",
      "161 integer variables, all of which are binary\n",
      "Scaling...\n",
      " A: min|aij| =  6.966e-03  max|aij| =  6.429e+03  ratio =  9.228e+05\n",
      "GM: min|aij| =  5.662e-02  max|aij| =  1.766e+01  ratio =  3.120e+02\n",
      "EQ: min|aij| =  3.206e-03  max|aij| =  1.000e+00  ratio =  3.120e+02\n",
      "2N: min|aij| =  2.618e-03  max|aij| =  1.478e+00  ratio =  5.645e+02\n",
      "Constructing initial basis...\n",
      "Size of triangular part is 216\n",
      "Solving LP relaxation...\n",
      "GLPK Simplex Optimizer, v4.65\n",
      "216 rows, 295 columns, 4864 non-zeros\n",
      "      0: obj =   1.187458760e+09 inf =   2.314e+04 (162)\n",
      "    114: obj =   9.530994401e+08 inf =   2.952e-14 (0)\n",
      "*   207: obj =   1.613855536e+08 inf =   3.415e-12 (0)\n",
      "OPTIMAL LP SOLUTION FOUND\n",
      "Integer optimization begins...\n",
      "Long-step dual simplex will be used\n",
      "+   207: mip =     not found yet >=              -inf        (1; 0)\n",
      "+   231: >>>>>   1.619961800e+08 >=   1.614688365e+08   0.3% (5; 0)\n",
      "+   234: >>>>>   1.618310800e+08 >=   1.616118670e+08   0.1% (3; 2)\n",
      "+   239: mip =   1.618310800e+08 >=     tree is empty   0.0% (0; 9)\n",
      "INTEGER OPTIMAL SOLUTION FOUND\n",
      "Time used:   0.0 secs\n",
      "Memory used: 1.5 Mb (1622820 bytes)\n",
      "Writing MIP solution to 'C:\\Users\\there\\AppData\\Local\\Temp\\tmpqhnwt2u7.glpk.raw'...\n",
      "1075 lines were written\n",
      "        0.06 seconds required for solver\n",
      "        0.00 seconds required to read logfile \n",
      "        0.02 seconds required to read solution file \n",
      "        0.02 seconds required for postsolve\n",
      "Do postprocessing for robust (special) scenarios. Number of scenarios: 56. Threads: 2\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\t(6.5791 sec)\n",
      "\n",
      "Do postprocessing for each timestep scenarios. Number of scenarios: 105. Threads: 2\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\t(7.0935 sec)\n",
      "\n",
      "Network with optimized diameters, looped pipes are indicated by two colored edges, Thicker edge means larger diameter\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 17648 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Finished Discrete Pipeline Optimization\n"
     ]
    }
   ],
   "source": [
    "# Compute with 2 threads and simple network structure\n",
    "\n",
    "dic_arc_optimalDiameters, dic_scen_PressLevels, dic_scen_MaxViolPress, dic_timeStep_PressLevels, \\\n",
    "    dic_timeStep_MaxViolPress, _ = robustPipelineSizing.determineDiscretePipelineDesign(\n",
    "        robust=robust, injectionWithdrawalRates=rates,\n",
    "        distances=lengths, dic_node_minPress=p_min_nodes, dic_node_maxPress=p_max_nodes, \n",
    "        dic_diameter_costs=dic_diameter_costs, dic_candidateMergedDiam_costs=dic_candidateMergedDiam_costs,\n",
    "        threads=2)\n",
    "\n",
    "print(\"Finished Discrete Pipeline Optimization\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Determine design for more complex network structure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Redfine minimum and maximum pressure levels to reduce robust scenario computation time\n",
    "p_min_nodes = {'cluster_5': 50, 'cluster_3': 50, 'cluster_7': 50, 'cluster_1': 50, 'cluster_6': 50,\n",
    "               'cluster_4': 50, 'cluster_0': 50, 'cluster_2': 50}\n",
    "\n",
    "p_max_nodes = {'cluster_5': 100, 'cluster_3': 100, 'cluster_7': 100, 'cluster_1': 100, 'cluster_6': 100,\n",
    "               'cluster_4': 100, 'cluster_0': 100, 'cluster_2': 100}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of edges before segmentation: 13\n",
      "Number of nodes before segmentation: 8\n",
      "Number of edges after 1. segmentation: 144\n",
      "Number of nodes after 1. segmentation: 136\n",
      "Number of edges after 2. segmentation: 180\n",
      "Number of nodes after 2. segmentation: 172\n",
      "Minimum length [m]: 1247.6403125202671 Maximum length [m]: 34402.82497225889\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 49228 characters]\n",
      "text/plain": [
       "<Figure size 432x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Get more complex network structure\n",
    "regColumn1 = 'loc1'\n",
    "regColumn2 = 'loc2'\n",
    "\n",
    "dic_node_minPress=p_min_nodes\n",
    "dic_node_maxPress=p_max_nodes\n",
    "\n",
    "maxPipeLength= 35 * 1e3\n",
    "minPipeLength= 1 * 1e3\n",
    "\n",
    "distances_new, dic_node_minPress_new, dic_node_maxPress_new, gdfNodes, gdfEdges = \\\n",
    "    robustPipelineSizing.getRefinedShapeFile(transFilePath, regColumn1, regColumn2, dic_node_minPress,\n",
    "                                             dic_node_maxPress, minPipeLength, maxPipeLength)\n",
    "\n",
    "fig, ax = fn.plotLocations(locFilePath, indexColumn='index') \n",
    "\n",
    "gdfEdges.plot(ax=ax, color='grey')\n",
    "gdfNodes.plot(ax=ax, color='red', markersize=2)\n",
    "ax.axis('off')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating graph with respect to given distances\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 11396 characters]\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating a Steiner treee\n",
      "Steiner tree:\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 7644 characters]\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compute robust scenario set for tree network (based on 10100 node combinations). Threads: 7\n",
      "Reduced robust scenario set can be generated (pMax is equal at all nodes & pMin at exits is >= at inner and entry nodes).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of robust scenarios: 18\n",
      "\t\t(15.5744 sec)\n",
      "\n",
      "Compute scenarios for each timestep. Number of timestep scenarios: 105. Threads: 7\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\t(19.9982 sec)\n",
      "\n",
      "Compute equivalent single diameters for looped (parallel) pipes\n",
      "Pressure drop coefficients for diameters with respect to robust scenarios\n",
      "Determining optimal robust pipeline design under the consideration of pressure losses and robust scenarios\n",
      "        0.23 seconds required to write file\n",
      "        0.23 seconds required for presolve\n",
      "Using license file C:\\Users\\there\\gurobi.lic\n",
      "Academic license - for non-commercial use only\n",
      "Read LP format model from file C:\\Users\\there\\AppData\\Local\\Temp\\tmp07vxzu8i.pyomo.lp\n",
      "Reading time = 0.08 seconds\n",
      "x4919: 1901 rows, 4919 columns, 48675 nonzeros\n",
      "Gurobi Optimizer version 9.0.0 build v9.0.0rc2 (win64)\n",
      "Optimize a model with 1901 rows, 4919 columns and 48675 nonzeros\n",
      "Model fingerprint: 0xe931bed8\n",
      "Variable types: 1819 continuous, 3100 integer (3100 binary)\n",
      "Coefficient statistics:\n",
      "  Matrix range     [1e-04, 2e+07]\n",
      "  Objective range  [5e+04, 2e+07]\n",
      "  Bounds range     [1e+00, 1e+04]\n",
      "  RHS range        [1e+00, 1e+00]\n",
      "Presolve removed 1759 rows and 2692 columns\n",
      "Presolve time: 0.12s\n",
      "Presolved: 142 rows, 2227 columns, 15077 nonzeros\n",
      "Variable types: 25 continuous, 2202 integer (2202 binary)\n",
      "Found heuristic solution: objective 8.598460e+08\n",
      "Found heuristic solution: objective 7.571967e+08\n",
      "\n",
      "Root relaxation: objective 1.412693e+08, 215 iterations, 0.00 seconds\n",
      "\n",
      "    Nodes    |    Current Node    |     Objective Bounds      |     Work\n",
      " Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time\n",
      "\n",
      "     0     0 1.4127e+08    0   12 7.5720e+08 1.4127e+08  81.3%     -    0s\n",
      "H    0     0                    1.413916e+08 1.4127e+08  0.09%     -    0s\n",
      "H    0     0                    1.413805e+08 1.4127e+08  0.08%     -    0s\n",
      "     0     0 1.4129e+08    0   22 1.4138e+08 1.4129e+08  0.06%     -    0s\n",
      "     0     0 1.4129e+08    0   11 1.4138e+08 1.4129e+08  0.06%     -    0s\n",
      "     0     0 1.4133e+08    0   16 1.4138e+08 1.4133e+08  0.04%     -    0s\n",
      "H    0     0                    1.413698e+08 1.4133e+08  0.03%     -    0s\n",
      "     0     0 1.4133e+08    0   18 1.4137e+08 1.4133e+08  0.03%     -    0s\n",
      "H    0     0                    1.413613e+08 1.4133e+08  0.02%     -    0s\n",
      "     0     0 1.4133e+08    0   16 1.4136e+08 1.4133e+08  0.02%     -    0s\n",
      "     0     0 1.4133e+08    0    5 1.4136e+08 1.4133e+08  0.02%     -    0s\n",
      "     0     0 1.4133e+08    0    8 1.4136e+08 1.4133e+08  0.02%     -    0s\n",
      "H    0     0                    1.413600e+08 1.4133e+08  0.02%     -    0s\n",
      "H    0     0                    1.413537e+08 1.4133e+08  0.01%     -    0s\n",
      "     0     0 1.4134e+08    0   11 1.4135e+08 1.4134e+08  0.01%     -    0s\n",
      "     0     0 1.4134e+08    0   10 1.4135e+08 1.4134e+08  0.01%     -    0s\n",
      "     0     0 1.4134e+08    0   13 1.4135e+08 1.4134e+08  0.01%     -    0s\n",
      "     0     0 1.4134e+08    0   12 1.4135e+08 1.4134e+08  0.01%     -    0s\n",
      "     0     0 1.4134e+08    0   13 1.4135e+08 1.4134e+08  0.01%     -    0s\n",
      "     0     0 1.4134e+08    0   13 1.4135e+08 1.4134e+08  0.01%     -    0s\n",
      "H    0     0                    1.413448e+08 1.4134e+08  0.00%     -    0s\n",
      "\n",
      "Cutting planes:\n",
      "  Gomory: 2\n",
      "  MIR: 7\n",
      "  StrongCG: 1\n",
      "  GUB cover: 1\n",
      "  Inf proof: 1\n",
      "\n",
      "Explored 1 nodes (439 simplex iterations) in 0.27 seconds\n",
      "Thread count was 8 (of 8 available processors)\n",
      "\n",
      "Solution count 10: 1.41345e+08 1.41354e+08 1.4136e+08 ... 8.59846e+08\n",
      "\n",
      "Optimal solution found (tolerance 1.00e-04)\n",
      "Best objective 1.413447921754e+08, best bound 1.413380561273e+08, gap 0.0048%\n",
      "        0.69 seconds required for solver\n",
      "        0.00 seconds required to read logfile \n",
      "        0.01 seconds required to read solution file \n",
      "        0.04 seconds required for postsolve\n",
      "Do postprocessing for robust (special) scenarios. Number of scenarios: 18. Threads: 7\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\t(144.0653 sec)\n",
      "\n",
      "Do postprocessing for each timestep scenarios. Number of scenarios: 105. Threads: 7\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Percentage simulated: 100%"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\t(819.8905 sec)\n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 20168 characters]\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Determine optimal pipeline design with seven threads\n",
    "dic_arc_optimalDiameters, dic_scen_PressLevels, dic_scen_MaxViolPress, dic_timeStep_PressLevels, \\\n",
    "           dic_timeStep_MaxViolPress, gdfEdges = robustPipelineSizing.determineDiscretePipelineDesign(\n",
    "        robust=robust, injectionWithdrawalRates=rates,\n",
    "        distances=distances_new, dic_node_minPress=dic_node_minPress_new, dic_node_maxPress=dic_node_maxPress_new,\n",
    "        dic_diameter_costs=dic_diameter_costs, dic_candidateMergedDiam_costs=dic_candidateMergedDiam_costs,\n",
    "        gdfEdges=gdfEdges, regColumn1='nodeIn', regColumn2='nodeOut', threads=7, solver='gurobi')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot scenario output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get regions shapefile as geopandas GeoDataFrame\n",
    "gdf_regions = gpd.read_file(locFilePath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33784 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Visualize pipeline diameters\n",
    "fig, ax =robustPipelineSizing.plotOptimizedNetwork(gdfEdges, gdf_regions=gdf_regions, figsize=(5,5),\n",
    "    line_scaling=0.8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get a minimum and maximum pressure scenario\n",
    "dic_timeStep_PressLevels = pd.DataFrame.from_dict(dic_scen_PressLevels)\n",
    "\n",
    "scen_min = dic_timeStep_PressLevels.mean().min()\n",
    "scen_min = dic_timeStep_PressLevels.loc[:,dic_timeStep_PressLevels.mean() == scen_min].iloc[:,0]\n",
    "scen_max = dic_timeStep_PressLevels.mean().max()\n",
    "scen_max = dic_timeStep_PressLevels.loc[:,dic_timeStep_PressLevels.mean() == scen_max].iloc[:,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 37848 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax =robustPipelineSizing.plotOptimizedNetwork(gdfEdges, gdf_regions=gdf_regions, figsize=(5,5),\n",
    "    line_scaling=0.9, pressureLevels=scen_min)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 36532 characters]\n",
      "text/plain": [
       "<Figure size 360x360 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax =robustPipelineSizing.plotOptimizedNetwork(gdfEdges, gdf_regions=gdf_regions, figsize=(5,5),\n",
    "    line_scaling=0.9, pressureLevels=scen_max)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "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.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
