Post · 25 min read· pp. 485–515

Time Series Aggregation

In this example, we are going to explore different ways to cluster the temporal resolution of PyPSA models, and what impact they have on the optimisation results and solving times. Using an hourly resolved variant of the single-node capacity expansion example, we will compare three different approaches to reduce the number of time steps in the model:

  • Sampling: Selecting a subset of the given snapshots based on a given frequency,
  • Averaging: Aggregating the snapshots by averaging them over a given frequency, and
  • Segmentation: Clustering the snapshots into segments of a given frequency and using tsam library.

We start with the usual imports and loading the hourly resolved model.

In [2]:

Copied! diagram

ipynb
import logging
import time

import pandas as pd

import pypsa

logging.getLogger().setLevel(logging.WARNING)


template_n = pypsa.Network(
    "https://tubcloud.tu-berlin.de/s/4ra3NKrLGzE42of/download/model-energy-hourly.nc"
)

import logging import time import pandas as pd import pypsa logging.getLogger().setLevel(logging.WARNING) template_n = pypsa.Network( "https://tubcloud.tu-berlin.de/s/4ra3NKrLGzE42of/download/model-energy-hourly.nc" )

text
/tmp/ipykernel_8909/3104600064.py:11: 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.
  template_n = pypsa.Network(
INFO:pypsa.network.io:Retrieving network data from https://tubcloud.tu-berlin.de/s/4ra3NKrLGzE42of/download/model-energy-hourly.nc.
text
WARNING:pypsa.network.io:Importing network from PyPSA version v0.35.0 while current version is v1.4.0. Read the release notes at `https://go.pypsa.org/release-notes` to prepare your network for import.
text
INFO:pypsa.network.io:Imported network 'Unnamed Network' has buses, carriers, generators, links, loads, storage_units, stores

Since we also want to monitor the solving times, we will use a small utility function that wraps around the solving process and returns the seconds it took to solve the model:

In [3]:

Copied! diagram

ipynb
def time_it(func, *args, **kwargs):
    """Time the execution of a function and return the elapsed time in seconds."""
    start_time = time.time()
    result = func(*args, **kwargs)
    elapsed_time = time.time() - start_time
    return result, elapsed_time


logging.getLogger().setLevel(logging.WARNING)

def time_it(func, *args, **kwargs): """Time the execution of a function and return the elapsed time in seconds.""" start_time = time.time() result = func(*args, **kwargs) elapsed_time = time.time() - start_time return result, elapsed_time logging.getLogger().setLevel(logging.WARNING)

Hourly Baseline

Additionally, we need a baseline model to compare aggregated models against. We will use the hourly resolved model for this.

In [4]:

Copied! diagram

ipynb
n_hourly = template_n.copy()

_, s_hourly = time_it(n_hourly.optimize, solver_name="gurobi")
s_hourly

n_hourly = template_n.copy() _, s_hourly = time_it(n_hourly.optimize, solver_name="gurobi") s_hourly

text
/tmp/ipykernel_8909/4243218267.py:4: 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.
  result = func(*args, **kwargs)
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  68%|██████▊   | 17/25 [00:00<00:00, 168.54it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 141.39it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 354.32it/s]
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
text
Read LP format model from file /tmp/linopy-problem-hng49g3o.lp
text
Reading time = 0.26 seconds
text
obj: 210246 rows, 96366 columns, 389916 nonzeros
text
Set parameter LogToConsole to value 0

Out[4]:

text
13.590047836303711

Sampling

We will start with the sampling approach, which is the simplest one. We simply select every NN-th snapshot from the model. The important part here is that we need to adjust the snapshot weightings accordingly, as each remaining snapshot now represents NN hours. We iterate over N from 2 to 11, i.e. from 2-hourly to 11-hourly resolved models.

In [5]:

Copied! diagram

ipynb
sampling_n = {1: n_hourly}
sampling_s = {1: s_hourly}

for resolution in range(2, 12):
    n = template_n.cluster.temporal.downsample(resolution)

    _, s = time_it(n.optimize, solver_name="gurobi")

    sampling_n[resolution] = n
    sampling_s[resolution] = s

sampling_n = {1: n_hourly} sampling_s = {1: s_hourly} for resolution in range(2, 12): n = template_n.cluster.temporal.downsample(resolution) _, s = time_it(n.optimize, solver_name="gurobi") sampling_n[resolution] = n sampling_s[resolution] = s

text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  92%|█████████▏| 23/25 [00:00<00:00, 203.88it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 195.00it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 396.67it/s]
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
text
Read LP format model from file /tmp/linopy-problem-1k4bk5ko.lp
text
Reading time = 0.12 seconds
text
obj: 105126 rows, 48186 columns, 194958 nonzeros
text
Set parameter LogToConsole to value 0
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  92%|█████████▏| 23/25 [00:00<00:00, 226.24it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 218.83it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 410.57it/s]
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
text
Read LP format model from file /tmp/linopy-problem-0evn0_is.lp
text
Reading time = 0.08 seconds
text
obj: 70086 rows, 32126 columns, 129984 nonzeros
text
Set parameter LogToConsole to value 0
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  96%|█████████▌| 24/25 [00:00<00:00, 234.44it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 230.49it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 433.03it/s]
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
text
Read LP format model from file /tmp/linopy-problem-cpdznysd.lp
text
Reading time = 0.06 seconds
text
obj: 52566 rows, 24096 columns, 97490 nonzeros
text
Set parameter LogToConsole to value 0
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  96%|█████████▌| 24/25 [00:00<00:00, 238.11it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 232.47it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 398.42it/s]
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-7ixp7ir5.lp
text
Reading time = 0.05 seconds
text
obj: 42054 rows, 19278 columns, 77983 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 253.87it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 422.66it/s]
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-ne1rpxew.lp
text
Reading time = 0.04 seconds
text
obj: 35046 rows, 16066 columns, 64988 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 255.20it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 438.46it/s]
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-h112cm82.lp
text
Reading time = 0.03 seconds
text
obj: 30054 rows, 13778 columns, 55729 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 262.13it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 438.87it/s]
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-zeznaw92.lp
text
Reading time = 0.03 seconds
text
obj: 26286 rows, 12051 columns, 48778 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  92%|█████████▏| 23/25 [00:00<00:00, 229.55it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 222.95it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 385.41it/s]
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-9q4fb10o.lp
text
Reading time = 0.03 seconds
text
obj: 23382 rows, 10720 columns, 43368 nonzeros
text
Set parameter LogToConsole to value 0
text
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-vj1koo50.lp
text
Reading time = 0.02 seconds
text
obj: 21030 rows, 9642 columns, 38994 nonzeros
text
Set parameter LogToConsole to value 0
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-4q8d2kdp.lp
text
Reading time = 0.02 seconds
text
obj: 19134 rows, 8773 columns, 35482 nonzeros
text
Set parameter LogToConsole to value 0

Averaging

The averaging approach also has equal snapshot durations, but instead of selecting data from every NN-th snapshots, we average time series data for every NN snapshots. This means that the resulting model has NN times fewer snapshots, but each snapshot represents the average of NN original snapshots. Again, we need to adjust the snapshot weightings accordingly.

In [6]:

Copied! diagram

ipynb
averaging_n = {1: n_hourly}
averaging_s = {1: s_hourly}

for resolution in range(2, 12):
    n = template_n.cluster.temporal.resample(f"{resolution}h")

    _, s = time_it(n.optimize, solver_name="gurobi")

    averaging_n[resolution] = n
    averaging_s[resolution] = s

averaging_n = {1: n_hourly} averaging_s = {1: s_hourly} for resolution in range(2, 12): n = template_n.cluster.temporal.resample(f"{resolution}h") _, s = time_it(n.optimize, solver_name="gurobi") averaging_n[resolution] = n averaging_s[resolution] = s

text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  92%|█████████▏| 23/25 [00:00<00:00, 207.83it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 201.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, 393.86it/s]
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
text
Read LP format model from file /tmp/linopy-problem-fjn3us_0.lp
text
Reading time = 0.13 seconds
text
obj: 105126 rows, 48186 columns, 195175 nonzeros
text
Set parameter LogToConsole to value 0
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  92%|█████████▏| 23/25 [00:00<00:00, 226.71it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 219.73it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 416.72it/s]
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
text
Read LP format model from file /tmp/linopy-problem-qmhc3_n0.lp
text
Reading time = 0.08 seconds
text
obj: 70086 rows, 32126 columns, 130192 nonzeros
text
Set parameter LogToConsole to value 0
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 240.30it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 238.78it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 422.94it/s]
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
text
Read LP format model from file /tmp/linopy-problem-3fnyfz6k.lp
text
Reading time = 0.06 seconds
text
obj: 52566 rows, 24096 columns, 97777 nonzeros
text
Set parameter LogToConsole to value 0
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  96%|█████████▌| 24/25 [00:00<00:00, 236.98it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 234.45it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 426.05it/s]
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-5pqepnmx.lp
text
Reading time = 0.05 seconds
text
obj: 42054 rows, 19278 columns, 78275 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 249.91it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 248.23it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 431.08it/s]
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-eujkd2r_.lp
text
Reading time = 0.04 seconds
text
obj: 35046 rows, 16066 columns, 65284 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 254.58it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 433.03it/s]
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-izcwb2o8.lp
text
Reading time = 0.04 seconds
text
obj: 30054 rows, 13778 columns, 56042 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 246.35it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 244.54it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 433.78it/s]
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-57h55ohp.lp
text
Reading time = 0.03 seconds
text
obj: 26286 rows, 12051 columns, 49143 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 262.95it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 434.96it/s]
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-bjvgfo92.lp
text
Reading time = 0.03 seconds
text
obj: 23382 rows, 10720 columns, 43678 nonzeros
text
Set parameter LogToConsole to value 0
text
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-5boagu2n.lp
text
Reading time = 0.02 seconds
text
obj: 21030 rows, 9642 columns, 39315 nonzeros
text
Set parameter LogToConsole to value 0
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-jne6y7d2.lp
text
Reading time = 0.02 seconds
text
obj: 19134 rows, 8773 columns, 35799 nonzeros
text
Set parameter LogToConsole to value 0

Segmentation

The segmentation approach is more complex. It uses a separate library called tsam to cluster the snapshots into segments of varying lengths. The sequence of snapshots is preserved as segments are only formed from neighbouring snapshots based on their similarity. For measuring similarity, it is advisable to normalise the time series data. This approach promises to capture the temporal patterns more effectively, as it can opt for higher resolution during periods of high variability and lower resolution during periods with low variability. The snapshot weightings are adjusted based on the number of snapshots in each segment.

In [7]:

Copied! diagram

ipynb
segmentation_n = {1: n_hourly}
segmentation_s = {1: s_hourly}

for resolution in range(2, 12):
    # calculate number of segments equivalent to resolution
    segments = int(8760 / resolution)

    n = template_n.cluster.temporal.segment(segments)

    # run optimization
    _, s = time_it(n.optimize, solver_name="gurobi")

    segmentation_n[resolution] = n
    segmentation_s[resolution] = s

segmentation_n = {1: n_hourly} segmentation_s = {1: s_hourly} for resolution in range(2, 12):

calculate number of segments equivalent to resolution

segments = int(8760 / resolution) n = template_n.cluster.temporal.segment(segments)

run optimization

_, s = time_it(n.optimize, solver_name="gurobi") segmentation_n[resolution] = n segmentation_s[resolution] = s

text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  92%|█████████▏| 23/25 [00:00<00:00, 207.21it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 199.22it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 337.86it/s]
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
text
Read LP format model from file /tmp/linopy-problem-xf_8utyg.lp
text
Reading time = 0.13 seconds
text
obj: 105126 rows, 48186 columns, 196032 nonzeros
text
Set parameter LogToConsole to value 0
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  92%|█████████▏| 23/25 [00:00<00:00, 224.13it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 217.98it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 399.98it/s]
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
text
Read LP format model from file /tmp/linopy-problem-i40oqdu1.lp
text
Reading time = 0.08 seconds
text
obj: 70086 rows, 32126 columns, 130934 nonzeros
text
Set parameter LogToConsole to value 0
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.:  96%|█████████▌| 24/25 [00:00<00:00, 239.40it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 234.35it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 421.87it/s]
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
text
Read LP format model from file /tmp/linopy-problem-pn7li0hm.lp
text
Reading time = 0.06 seconds
text
obj: 52566 rows, 24096 columns, 98300 nonzeros
text
Set parameter LogToConsole to value 0
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 240.98it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 239.16it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 426.06it/s]
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-6ovk3qrh.lp
text
Reading time = 0.05 seconds
text
obj: 42054 rows, 19278 columns, 78697 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 247.04it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 245.38it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 421.26it/s]
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-fadmg8wk.lp
text
Reading time = 0.04 seconds
text
obj: 35046 rows, 16066 columns, 65592 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 255.45it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 435.38it/s]
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-ogsbcbj_.lp
text
Reading time = 0.04 seconds
text
obj: 30030 rows, 13767 columns, 56209 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 251.65it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 435.50it/s]
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-517izs6g.lp
text
Reading time = 0.03 seconds
text
obj: 26286 rows, 12051 columns, 49207 nonzeros
text
Set parameter LogToConsole to value 0
text
text
Writing constraints.:   0%|          | 0/25 [00:00<?, ?it/s]
text
Writing constraints.: 100%|██████████| 25/25 [00:00<00:00, 259.14it/s]
text
text
Writing continuous variables.:   0%|          | 0/12 [00:00<?, ?it/s]
text
Writing continuous variables.: 100%|██████████| 12/12 [00:00<00:00, 428.46it/s]
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-2m7gp7ba.lp
text
Reading time = 0.03 seconds
text
obj: 23358 rows, 10709 columns, 43728 nonzeros
text
Set parameter LogToConsole to value 0
text
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-g3wm3t19.lp
text
Reading time = 0.02 seconds
text
obj: 21030 rows, 9642 columns, 39377 nonzeros
text
Set parameter LogToConsole to value 0
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-8qo_bxcp.lp
text
Reading time = 0.02 seconds
text
obj: 19110 rows, 8762 columns, 35786 nonzeros
text
Set parameter LogToConsole to value 0

Now before we go ahead with the evaluation of the different approaches, let's quickly glance at the distribution of snapshot durations obtained from the segmentation approach for a resolution equivalent to a 3-hourly model. We can see quite some variability in the segment length.

In [8]:

Copied! diagram

ipynb
segmentation_n[3].snapshot_weightings.generators.value_counts().sort_index(
    ascending=True
).plot.bar(ylabel="snapshots [number]", xlabel="snapshot duration [h]")

segmentation_n[3].snapshot_weightings.generators.value_counts().sort_index( ascending=True ).plot.bar(ylabel="snapshots [number]", xlabel="snapshot duration [h]")

Out[8]:

text
<Axes: xlabel='snapshot duration [h]', ylabel='snapshots [number]'>

No description has been provided for this image

Evaluation

Let's start our evaluation with a look at the solving times. We can see that across all approaches, the solving times quickly decay, especially as we go from hourly to 2-hourly resolved models and decrease less substantially afterwards.

In [9]:

Copied! diagram

ipynb
pd.Series(sampling_s).plot(label="sampling", legend=True)
pd.Series(averaging_s).plot(label="averaging", legend=True)
pd.Series(segmentation_s).plot(
    label="segmentation", ylabel="time [s]", xlabel="resolution [h]", legend=True
)

pd.Series(sampling_s).plot(label="sampling", legend=True) pd.Series(averaging_s).plot(label="averaging", legend=True) pd.Series(segmentation_s).plot( label="segmentation", ylabel="time [s]", xlabel="resolution [h]", legend=True )

Out[9]:

text
<Axes: xlabel='resolution [h]', ylabel='time [s]'>

No description has been provided for this image

Furthermore, we compare the relative error in total system costs compared to the hourly resolved model. We can see how the segmentation approach remains more stable than the other two approaches, especially for lower resolutions. Even with 11-hourly equivalent resolution, the segmentation approach only has a relative error of -1% compared to the hourly resolved model (i.e. it appears to be 1% cheaper). Similar patterns can be observed for the relative error in the total installed capacity of solar and batteries, two technologies that are particularly sensitive to the temporal resolution of the model.

In [10]:

Copied! diagram

ipynb
def tsc(n):
    return (n.statistics.capex().sum() + n.statistics.opex().sum()) / 1e9


pd.concat(
    [
        pd.Series({("sampling", res): tsc(n) for res, n in sampling_n.items()}),
        pd.Series({("averaging", res): tsc(n) for res, n in averaging_n.items()}),
        pd.Series({("segmentation", res): tsc(n) for res, n in segmentation_n.items()}),
    ]
).unstack(0).div(tsc(n_hourly)).sub(1).mul(100).plot(
    ylabel="relative objective error [%]", xlabel="resolution [h]", legend=True
)

def tsc(n): return (n.statistics.capex().sum() + n.statistics.opex().sum()) / 1e9 pd.concat( [ pd.Series({("sampling", res): tsc(n) for res, n in sampling_n.items()}), pd.Series({("averaging", res): tsc(n) for res, n in averaging_n.items()}), pd.Series({("segmentation", res): tsc(n) for res, n in segmentation_n.items()}), ] ).unstack(0).div(tsc(n_hourly)).sub(1).mul(100).plot( ylabel="relative objective error [%]", xlabel="resolution [h]", legend=True )

Out[10]:

text
<Axes: xlabel='resolution [h]', ylabel='relative objective error [%]'>

No description has been provided for this image

In [11]:

Copied! diagram

ipynb
def solar(n):
    return n.generators.loc["solar", "p_nom_opt"]


pd.concat(
    [
        pd.Series({("sampling", res): solar(n) for res, n in sampling_n.items()}),
        pd.Series({("averaging", res): solar(n) for res, n in averaging_n.items()}),
        pd.Series(
            {("segmentation", res): solar(n) for res, n in segmentation_n.items()}
        ),
    ]
).unstack(0).div(solar(n_hourly)).sub(1).mul(100).plot(
    ylabel="relative solar capacity error [%]", xlabel="resolution [h]", legend=True
)

def solar(n): return n.generators.loc["solar", "p_nom_opt"] pd.concat( [ pd.Series({("sampling", res): solar(n) for res, n in sampling_n.items()}), pd.Series({("averaging", res): solar(n) for res, n in averaging_n.items()}), pd.Series( {("segmentation", res): solar(n) for res, n in segmentation_n.items()} ), ] ).unstack(0).div(solar(n_hourly)).sub(1).mul(100).plot( ylabel="relative solar capacity error [%]", xlabel="resolution [h]", legend=True )

Out[11]:

text
<Axes: xlabel='resolution [h]', ylabel='relative solar capacity error [%]'>

No description has been provided for this image

In [12]:

Copied! diagram

ipynb
def battery(n):
    return n.storage_units.loc["battery storage", "p_nom_opt"]


pd.concat(
    [
        pd.Series({("sampling", res): battery(n) for res, n in sampling_n.items()}),
        pd.Series({("averaging", res): battery(n) for res, n in averaging_n.items()}),
        pd.Series(
            {("segmentation", res): battery(n) for res, n in segmentation_n.items()}
        ),
    ]
).unstack(0).div(battery(n_hourly)).sub(1).mul(100).plot(
    ylabel="relative battery capacity error [%]", xlabel="resolution [h]", legend=True
)

def battery(n): return n.storage_units.loc["battery storage", "p_nom_opt"] pd.concat( [ pd.Series({("sampling", res): battery(n) for res, n in sampling_n.items()}), pd.Series({("averaging", res): battery(n) for res, n in averaging_n.items()}), pd.Series( {("segmentation", res): battery(n) for res, n in segmentation_n.items()} ), ] ).unstack(0).div(battery(n_hourly)).sub(1).mul(100).plot( ylabel="relative battery capacity error [%]", xlabel="resolution [h]", legend=True )

Out[12]:

text
<Axes: xlabel='resolution [h]', ylabel='relative battery capacity error [%]'>

No description has been provided for this image

diagram 2026-11-05

diagram 2025-08-04