Post · 18 min read· pp. 580–596

Myopic Pathway Planning

In this example, we demonstrate how to use PyPSA to plan a myopic pathway for emission reductions. That means that we optimize the system for each investment period sequentially subject to set emission reduction targets per period. In consequence, the model does not foresee future costs or benefits of investments. This is in contrast to a pathway optimisation with perfect foresight, where the model optimizes the system for all investment periods at once.

Here, we build a model from the single-node capacity expansion example and model a myopic decision process for the investment periods 2025, 2035, and 2045. The model is set up to reduce emissions from 30 MtCO2/a in 2025 to 10 MtCO2/a in 2035 and 3 MtCO2/a in 2045. Note that the goal here is not necessarily to showcase a realistic scenario, but rather to demonstrate how it is possible to model a myopic decision process in PyPSA.

In [2]:

Copied! diagram

ipynb
import pandas as pd

import pypsa
from pypsa.costs import annuity

temp = pypsa.examples.model_energy()
temp.remove("Generator", "load shedding")
n = temp.copy()

INVESTMENT_PERIODS = [2025, 2035, 2045]

import pandas as pd import pypsa from pypsa.costs import annuity temp = pypsa.examples.model_energy() temp.remove("Generator", "load shedding") n = temp.copy() INVESTMENT_PERIODS = [2025, 2035, 2045]

text
/tmp/ipykernel_4375/1597258187.py:6: PyPSA2Warning: pandas reads strings as `str` dtype since 3.0. PyPSA converts them back to object dtype on import, but keeps `str` from PyPSA 2.0 on. Set `pypsa.options.future.string_dtype` to True to opt in now or to False to keep the current behaviour.
  temp = pypsa.examples.model_energy()
text
INFO:pypsa.network.io:Imported network 'Model-Energy' has buses, carriers, generators, links, loads, storage_units, stores

First, we add a new component for each investment period and carrier to the network. These components are used to model the individual investment decisions for each period. For instance, for solar, there will be a Generator component for each investment period, e.g. solar-2025, solar-2035, and solar-2045 with the corresponding build_year attributes.

We can also keep pre-existing capacities as non-extendable components. Here, we keep 5 GW each of wind and solar capacities, assuming 2015 as build year.

In [3]:

Copied! diagram

ipynb
# Assume 5 GW of wind and solar capacity each, built in 2015
n.generators.loc[:, ["build_year", "p_nom", "p_nom_extendable"]] = 2015, 5_000, False

# all other storage components need to be removed
n.remove("Link", n.links.index)
n.remove("StorageUnit", n.storage_units.index)
n.remove("Store", n.stores.index)

for year in INVESTMENT_PERIODS:
    n.add(
        "Generator",
        temp.generators.index + f"-{year}",
        build_year=year,
        p_max_pu=temp.generators_t.p_max_pu.rename(
            columns=lambda s: s + f"-{year}"
        ).loc[:, ::-1],
        **temp.generators.rename(index=lambda s: s + f"-{year}").drop(
            columns=["build_year", "p_max_pu"]
        ),
    )

    n.add(
        "Link",
        temp.links.index,
        suffix=f"-{year}",
        build_year=year,
        **temp.links.rename(index=lambda s: s + f"-{year}").drop(
            columns=["build_year"]
        ),
    )

    n.add(
        "StorageUnit",
        temp.storage_units.index,
        suffix=f"-{year}",
        build_year=year,
        **temp.storage_units.rename(index=lambda s: s + f"-{year}").drop(
            columns=["build_year"]
        ),
    )

    n.add(
        "Store",
        temp.stores.index,
        suffix=f"-{year}",
        build_year=year,
        **temp.stores.rename(index=lambda s: s + f"-{year}").drop(
            columns=["build_year"]
        ),
    )

Assume 5 GW of wind and solar capacity each, built in 2015

n.generators.loc[:, ["build_year", "p_nom", "p_nom_extendable"]] = 2015, 5_000, False

all other storage components need to be removed

n.remove("Link", n.links.index) n.remove("StorageUnit", n.storage_units.index) n.remove("Store", n.stores.index) for year in INVESTMENT_PERIODS: n.add( "Generator", temp.generators.index + f"-{year}", build_year=year, p_max_pu=temp.generators_t.p_max_pu.rename( columns=lambda s: s + f"-{year}" ).loc[:, ::-1], **temp.generators.rename(index=lambda s: s + f"-{year}").drop( columns=["build_year", "p_max_pu"] ), ) n.add( "Link", temp.links.index, suffix=f"-{year}", build_year=year, **temp.links.rename(index=lambda s: s + f"-{year}").drop( columns=["build_year"] ), ) n.add( "StorageUnit", temp.storage_units.index, suffix=f"-{year}", build_year=year, **temp.storage_units.rename(index=lambda s: s + f"-{year}").drop( columns=["build_year"] ), ) n.add( "Store", temp.stores.index, suffix=f"-{year}", build_year=year, **temp.stores.rename(index=lambda s: s + f"-{year}").drop( columns=["build_year"] ), )

text
/tmp/ipykernel_4375/1906912180.py:32: FutureWarning: The StorageUnit component is deprecated and will be removed in PyPSA 2.0. Use the Store component, which supports `max_hours`, `efficiency_store`, `efficiency_dispatch` and `inflow`, or convert existing storage units with `n.c.storage_units.convert_to_stores()`.
  n.add(
text
/tmp/ipykernel_4375/1906912180.py:32: FutureWarning: The StorageUnit component is deprecated and will be removed in PyPSA 2.0. Use the Store component, which supports `max_hours`, `efficiency_store`, `efficiency_dispatch` and `inflow`, or convert existing storage units with `n.c.storage_units.convert_to_stores()`.
  n.add(
text
/tmp/ipykernel_4375/1906912180.py:32: FutureWarning: The StorageUnit component is deprecated and will be removed in PyPSA 2.0. Use the Store component, which supports `max_hours`, `efficiency_store`, `efficiency_dispatch` and `inflow`, or convert existing storage units with `n.c.storage_units.convert_to_stores()`.
  n.add(

In this way, the attributes of components can vary over the investment periods, e.g. the capital_cost of solar PV and battery storage can decrease over time, or the capacity factors (p_max_pu) of wind generators can increase over time.

In [4]:

Copied! diagram

ipynb
n.generators.loc["solar-2035", "capital_cost"] *= 0.9
n.generators.loc["solar-2045", "capital_cost"] *= 0.85

n.storage_units.loc["battery storage-2035", "capital_cost"] *= 0.9
n.storage_units.loc["battery storage-2045", "capital_cost"] *= 0.85

n.generators_t.p_max_pu.loc[:, "wind-2035"] *= 1.1
n.generators_t.p_max_pu.loc[:, "wind-2045"] *= 1.15

n.generators.loc["solar-2035", "capital_cost"] *= 0.9 n.generators.loc["solar-2045", "capital_cost"] *= 0.85 n.storage_units.loc["battery storage-2035", "capital_cost"] *= 0.9 n.storage_units.loc["battery storage-2045", "capital_cost"] *= 0.85 n.generators_t.p_max_pu.loc[:, "wind-2035"] *= 1.1 n.generators_t.p_max_pu.loc[:, "wind-2045"] *= 1.15

Let us also add some pre-existing conventional generators to the network with emissions from burning fossil fuels.

We add some old coal generators, which will retire by 2035, and some gas generators, which will retire by 2045. We also let the model invest in new gas generators in 2035, with slightly higher cost but better efficiency.

In [5]:

Copied! diagram

ipynb
n.add(
    "Carrier",
    ["coal", "gas"],
    color=["gray", "lightcoral"],
    co2_emissions=[0.336, 0.198],
)

n.add(
    "Generator",
    "coal",
    carrier="coal",
    bus="electricity",
    p_nom=4_000,
    p_nom_extendable=False,
    build_year=1990,
    lifetime=40,
    capital_cost=annuity(0.07, 40) * 4_000_000,
    efficiency=0.35,
    marginal_cost=30,
)

n.add(
    "Generator",
    "gas",
    carrier="gas",
    bus="electricity",
    p_nom=6_000,
    p_nom_extendable=False,
    build_year=2005,
    lifetime=35,
    capital_cost=annuity(0.07, 35) * 800_000,
    efficiency=0.5,
    marginal_cost=60,
)

n.add(
    "Generator",
    "gas-2035",
    carrier="gas",
    bus="electricity",
    p_nom_extendable=True,
    build_year=2035,
    lifetime=35,
    capital_cost=annuity(0.07, 35) * 900_000,
    efficiency=0.55,
    marginal_cost=55,
)

n.add( "Carrier", ["coal", "gas"], color=["gray", "lightcoral"], co2_emissions=[0.336, 0.198], ) n.add( "Generator", "coal", carrier="coal", bus="electricity", p_nom=4_000, p_nom_extendable=False, build_year=1990, lifetime=40, capital_cost=annuity(0.07, 40) * 4_000_000, efficiency=0.35, marginal_cost=30, ) n.add( "Generator", "gas", carrier="gas", bus="electricity", p_nom=6_000, p_nom_extendable=False, build_year=2005, lifetime=35, capital_cost=annuity(0.07, 35) * 800_000, efficiency=0.5, marginal_cost=60, ) n.add( "Generator", "gas-2035", carrier="gas", bus="electricity", p_nom_extendable=True, build_year=2035, lifetime=35, capital_cost=annuity(0.07, 35) * 900_000, efficiency=0.55, marginal_cost=55, )

In the next step, we define the investment periods and the emission reduction targets for each period. Note that each investment period represents a duration of 10 years, hence the annual targets are scaled to represent total emissions over the entire period.

In [6]:

Copied! diagram

ipynb
n.set_investment_periods(INVESTMENT_PERIODS)
n.investment_period_weightings *= 10

REDUCTION_PATH = [300e6, 100e6, 20e6]

for i, year in enumerate(INVESTMENT_PERIODS):
    n.add(
        "GlobalConstraint",
        f"co2-limit-{year}",
        type="primary_energy",
        carrier_attribute="co2_emissions",
        investment_period=year,
        constant=REDUCTION_PATH[i],
        sense="<=",
    )

n.set_investment_periods(INVESTMENT_PERIODS) n.investment_period_weightings *= 10 REDUCTION_PATH = [300e6, 100e6, 20e6] for i, year in enumerate(INVESTMENT_PERIODS): n.add( "GlobalConstraint", f"co2-limit-{year}", type="primary_energy", carrier_attribute="co2_emissions", investment_period=year, constant=REDUCTION_PATH[i], sense="<=", )

text
INFO:pypsa.network.index:Repeating time-series for each investment period and converting snapshots to a pandas.MultiIndex.

To optimize only a single investment period at a time, we have to make a selection of the relevant snapshots (i.e. all that fall into the investment period). Passing this selection to n.optimize() will exclude investment variables of any inactive components (where the build year falls into future investment periods), and also only optimise the dispatch variables for the time steps in the investment period.

In [7]:

Copied! diagram

ipynb
def optimize_period(n: pypsa.Network, period: int):
    snapshots = n.snapshots[n.snapshots.get_level_values("period") == period]
    return n.optimize(
        multi_investment_periods=True,
        snapshots=snapshots,
    )


optimize_period(n, 2025)

display(n.generators.p_nom_opt)

display(n.global_constraints)

def optimize_period(n: pypsa.Network, period: int): snapshots = n.snapshots[n.snapshots.get_level_values("period") == period] return n.optimize( multi_investment_periods=True, snapshots=snapshots, ) optimize_period(n, 2025) display(n.generators.p_nom_opt) display(n.global_constraints)

text
/tmp/ipykernel_4375/36310589.py:3: PyPSA2Warning: From PyPSA 2.0 on, the objective leaves out the capital costs of existing capacity on extendable assets, which improves LP conditioning. Pass `include_objective_constant` to `n.optimize` to choose per call. Set `pypsa.options.future.exclude_objective_constant` to True to opt in now or to False to keep the current behaviour.
  return n.optimize(
text
INFO:pypsa.optimization.window:Building the multi-period model over a MultiIndex `snapshot`. Opt into the flat representation via `pypsa.options.optimization.model_snapshot_index = 'flat'`.
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io:Writing objective.
text
Writing constraints.:   0%|          | 0/26 [00:00<?, ?it/s]
text
Writing constraints.:  77%|███████▋  | 20/26 [00:00<00:00, 193.99it/s]
text
Writing constraints.: 100%|██████████| 26/26 [00:00<00:00, 180.89it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 311.75it/s]
text
INFO:linopy.io: Writing time: 0.21s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-xdi14_4l.lp
text
Reading time = 0.10 seconds
text
obj: 87620 rows, 40899 columns, 162117 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 102219 primals, 227780 duals
Objective: 2.05e+10
Solver: gurobi
Runtime: 0.72s
Dual bound: 2.05e+10
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Generator-ext-p-lower, Generator-ext-p-upper, Link-ext-p-lower, Link-ext-p-upper, Store-ext-e-lower, Store-ext-e-upper, Store-ext-p-lower, Store-ext-p-upper, Store-ext-p_store-lower, Store-ext-p_store-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance, Store-energy_balance were not assigned to the network.
text
name
wind          5000.000000
solar         5000.000000
wind-2025     4361.538462
solar-2025    5351.989786
wind-2035        0.000000
solar-2035       0.000000
wind-2045        0.000000
solar-2045       0.000000
coal          4000.000000
gas           6000.000000
gas-2035         0.000000
Name: p_nom_opt, dtype: float64
typeinvestment_periodbuscarrier_attributesenseconstantscalingramdomainmumu_ram
name
co2-limit-2025primary_energy2025.0co2_emissions<=300000000.01.0NaN-20.0111640.0
co2-limit-2035primary_energy2035.0co2_emissions<=100000000.01.0NaN0.0000000.0
co2-limit-2045primary_energy2045.0co2_emissions<=20000000.01.0NaN0.0000000.0

In the results we can see that any components after 2025 are not touched in the first investment period. The CO2 constraint is mildly binding at 20 €/tCO2, which is the price of CO2 in the first period. The energy mix is still dominated by coal and gas, with some solar and wind added to the system.

In [8]:

Copied! diagram

ipynb
n.statistics.energy_balance().div(1e6).round(2)

n.statistics.energy_balance().div(1e6).round(2)

Out[8]:

period202520352045
componentcarrierbus_carrier
Generatorcoalelectricity27.89NaNNaN
gaselectricity8.14NaNNaN
solarelectricity11.71NaNNaN
windelectricity18.53NaNNaN
LinkelectrolysiselectricityNaNNaNNaN
turbinehydrogenNaNNaNNaN
electrolysishydrogenNaNNaNNaN
turbineelectricityNaNNaNNaN
Load-electricity-66.27NaNNaN
StorageUnitbattery storageelectricity-0.01NaNNaN
Storehydrogen storagehydrogenNaNNaNNaN

For the second investment period, we need to freeze the capacities that were built in the first period, so that they are not changed in the second period (see freeze_period() function below). Then we can again select the relevant snapshots and optimize the system for the second investment period -- and so on for any further investment periods.

In [9]:

Copied! diagram

ipynb
def freeze_period(n: pypsa.Network, period: int):
    for c in n.components[["Generator", "Link", "StorageUnit", "Store"]]:
        attr = "e_nom" if c.name == "Store" else "p_nom"
        c.static[attr] = c.static[attr + "_opt"]
        c.static.loc[c.static.build_year == period, attr + "_extendable"] = False


freeze_period(n, 2025)
optimize_period(n, 2035)

freeze_period(n, 2035)
optimize_period(n, 2045)

def freeze_period(n: pypsa.Network, period: int): for c in n.components[["Generator", "Link", "StorageUnit", "Store"]]: attr = "e_nom" if c.name == "Store" else "p_nom" c.static[attr] = c.static[attr + "_opt"] c.static.loc[c.static.build_year == period, attr + "_extendable"] = False freeze_period(n, 2025) optimize_period(n, 2035) freeze_period(n, 2035) optimize_period(n, 2045)

text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io:Writing objective.
text
Writing constraints.:   0%|          | 0/40 [00:00<?, ?it/s]
text
Writing constraints.:  52%|█████▎    | 21/40 [00:00<00:00, 205.79it/s]
text
Writing constraints.: 100%|██████████| 40/40 [00:00<00:00, 179.21it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 296.19it/s]
text
INFO:linopy.io: Writing time: 0.28s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-5x5_0vfe.lp
text
Reading time = 0.17 seconds
text
obj: 146014 rows, 70093 columns, 264311 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 102213 primals, 227774 duals
Objective: 2.32e+10
Solver: gurobi
Runtime: 2.01s
Dual bound: 2.32e+10
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Generator-ext-p-lower, Generator-ext-p-upper, Link-fix-p-lower, Link-fix-p-upper, Link-ext-p-lower, Link-ext-p-upper, Store-fix-e-lower, Store-fix-e-upper, Store-ext-e-lower, Store-ext-e-upper, Store-fix-p-lower, Store-fix-p-upper, Store-ext-p-lower, Store-ext-p-upper, Store-fix-p_store-lower, Store-fix-p_store-upper, Store-ext-p_store-lower, Store-ext-p_store-upper, StorageUnit-fix-p_dispatch-lower, StorageUnit-fix-p_dispatch-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-fix-p_store-lower, StorageUnit-fix-p_store-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-fix-state_of_charge-lower, StorageUnit-fix-state_of_charge-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance, Store-energy_balance were not assigned to the network.
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io:Writing objective.
text
Writing constraints.:   0%|          | 0/40 [00:00<?, ?it/s]
text
Writing constraints.:  52%|█████▎    | 21/40 [00:00<00:00, 200.33it/s]
text
Writing constraints.: 100%|██████████| 40/40 [00:00<00:00, 170.80it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 287.92it/s]
text
INFO:linopy.io: Writing time: 0.29s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-nub8fq77.lp
text
Reading time = 0.23 seconds
text
obj: 198567 rows, 96366 columns, 348984 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 102206 primals, 227767 duals
Objective: 3.33e+10
Solver: gurobi
Runtime: 1.42s
Dual bound: 3.33e+10
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Generator-ext-p-lower, Generator-ext-p-upper, Link-fix-p-lower, Link-fix-p-upper, Link-ext-p-lower, Link-ext-p-upper, Store-fix-e-lower, Store-fix-e-upper, Store-ext-e-lower, Store-ext-e-upper, Store-fix-p-lower, Store-fix-p-upper, Store-ext-p-lower, Store-ext-p-upper, Store-fix-p_store-lower, Store-fix-p_store-upper, Store-ext-p_store-lower, Store-ext-p_store-upper, StorageUnit-fix-p_dispatch-lower, StorageUnit-fix-p_dispatch-upper, StorageUnit-ext-p_dispatch-lower, StorageUnit-ext-p_dispatch-upper, StorageUnit-fix-p_store-lower, StorageUnit-fix-p_store-upper, StorageUnit-ext-p_store-lower, StorageUnit-ext-p_store-upper, StorageUnit-fix-state_of_charge-lower, StorageUnit-fix-state_of_charge-upper, StorageUnit-ext-state_of_charge-lower, StorageUnit-ext-state_of_charge-upper, StorageUnit-energy_balance, Store-energy_balance were not assigned to the network.

Out[9]:

text
('ok', 'optimal')

After the loop has finished, we can inspect the results of all investment periods. For instance, we can see how the endogenous CO2 price increases with each investment period.

In [10]:

Copied! diagram

ipynb
n.global_constraints

n.global_constraints

Out[10]:

typeinvestment_periodbuscarrier_attributesenseconstantscalingramdomainmumu_ram
name
co2-limit-2025primary_energy2025.0co2_emissions<=300000000.01.0NaN-20.0111640.0
co2-limit-2035primary_energy2035.0co2_emissions<=100000000.01.0NaN-32.8570330.0
co2-limit-2045primary_energy2045.0co2_emissions<=20000000.01.0NaN-162.1803460.0

The energy balance and CAPEX statistics also tell us the story that the coal power plants that are phased out in 2035 are largely replaced by a large amount of new gas power plants. Only in 2045, the model starts to double down on renewables and storage investments to meet more ambitious emission reduction targets. By then, the new gas power plants are barely used, while their capital costs are still to be paid off.

In [11]:

Copied! diagram

ipynb
display(n.statistics.energy_balance().div(1e6).round(1))

display(n.statistics.capex().div(1e6).round(1))

display(n.statistics.energy_balance().div(1e6).round(1)) display(n.statistics.capex().div(1e6).round(1))

period202520352045
componentcarrierbus_carrier
Generatorcoalelectricity27.9NaNNaN
gaselectricity8.127.25.6
solarelectricity11.713.528.1
windelectricity18.525.635.9
LinkelectrolysiselectricityNaNNaN-2.5
turbinehydrogenNaNNaN-1.6
electrolysishydrogenNaNNaN1.6
turbineelectricityNaNNaN0.6
Load-electricity-66.3-66.3-66.3
StorageUnitbattery storageelectricity-0.0-0.0-1.4
Storehydrogen storagehydrogenNaNNaNNaN
period202520352045
componentcarrier
Generatorcoal12001.5NaNNaN
gas3707.26329.82622.6
solar5315.46259.513244.2
wind9515.513717.820120.2
LinkelectrolysisNaNNaN885.2
turbineNaNNaN3572.3
StorageUnitbattery storage83.8271.912049.0
Storehydrogen storageNaNNaN592.8

Total annual system costs increase as emissions must be reduced. The data shown does not account for a social discount rate.

In [12]:

Copied! diagram

ipynb
(n.statistics.capex().sum() + n.statistics.opex().sum()).div(1e6).round(1)

(n.statistics.capex().sum() + n.statistics.opex().sum()).div(1e6).round(1)

Out[12]:

text
period
2025    43873.4
2035    41828.4
2045    56141.8
dtype: float64

Some data wrangling is needed to plot the progression of operational generation capacities over time.

In [13]:

Copied! diagram

ipynb
df = (
    pd.concat(
        {
            year: n.generators.query(
                f"build_year <= {year} and build_year + lifetime > {year}"
            )
            .groupby("carrier")
            .p_nom_opt.sum()
            for year in INVESTMENT_PERIODS
        },
        axis=1,
    )
    .fillna(0)
    .T.div(1e3)
)

df.plot.area(
    stacked=True,
    linewidth=0,
    ylabel="GW",
    xlabel="Year",
    title="Operational Capacity",
    color=df.columns.map(n.carriers.color),
)

df = ( pd.concat( { year: n.generators.query( f"build_year <= {year} and build_year + lifetime > {year}" ) .groupby("carrier") .p_nom_opt.sum() for year in INVESTMENT_PERIODS }, axis=1, ) .fillna(0) .T.div(1e3) ) df.plot.area( stacked=True, linewidth=0, ylabel="GW", xlabel="Year", title="Operational Capacity", color=df.columns.map(n.carriers.color), )

Out[13]:

text
<Axes: title={'center': 'Operational Capacity'}, xlabel='Year', ylabel='GW'>

No description has been provided for this image

Where to go from here?

A few ideas to explore further in this notebook:

  • Try different exogenous emission reduction paths. How do they affect total costs and cumulative emissions?
  • Decrease the capital cost of components over time in different ways. How does this affect the optimal build-out?
  • Decrease the capital cost of components over time as a function of the cumulative installed capacity to simulate learning effects.
  • Increase the capacity factors of wind and solar components over time to varying extents. How does this affect the optimal build-out?
  • Compare the myopic pathway with a full pathway optimization. How do they differ in terms of costs, cumulative emissions, stranded assets? A code snippet is provided blow.

In [14]:

Copied! diagram

ipynb
# for c in n.iterate_components({"Generator", "Link", "StorageUnit", "Store"}):
#     attr = "e_nom" if c.name == "Store" else "p_nom"
#     c.df.loc[c.df.build_year >= 2025, attr + "_extendable"] = True

# n.optimize(
#     multi_investment_periods=True,
#     log_to_console=True,
# )

for c in n.iterate_components({"Generator", "Link", "StorageUnit", "Store"}):

attr = "e_nom" if c.name == "Store" else "p_nom"

c.df.loc[c.df.build_year >= 2025, attr + "_extendable"] = True

n.optimize(

multi_investment_periods=True,

log_to_console=True,

)

diagram 2026-11-05

diagram 2025-08-04