Post · 8 min read· pp. 390–402

Screening Curves

Compute the long-term equilibrium power plant investment for a given load duration curve (1000−1000z1000-1000z for z∈[0,1]z \in [0,1]) and a given set of generator investment options.

To read up on the theory behind screenin curves, see this lecture.

In [2]:

Copied! diagram

ipynb
import numpy as np
import pandas as pd

import pypsa

import numpy as np import pandas as pd import pypsa

Generator marginal (m) and capital (c) costs are given in EUR/MWh - numbers chosen for simple answer.

In [3]:

Copied! diagram

ipynb
generators = {
    "coal": {"m": 2, "c": 15},
    "gas": {"m": 12, "c": 10},
    "load-shedding": {"m": 1012, "c": 0},
}

generators = { "coal": {"m": 2, "c": 15}, "gas": {"m": 12, "c": 10}, "load-shedding": {"m": 1012, "c": 0}, }

The screening curve intersections are at 0.01 and 0.5.

In [4]:

Copied! diagram

ipynb
x = np.linspace(0, 1, 101)
df = pd.DataFrame({k: v["c"] + x * v["m"] for k, v in generators.items()}, index=x)
df.plot(ylim=[0, 50], title="Screening Curve");

x = np.linspace(0, 1, 101) df = pd.DataFrame({k: v["c"] + x * v["m"] for k, v in generators.items()}, index=x) df.plot(ylim=[0, 50], title="Screening Curve");

No description has been provided for this image

In [5]:

Copied! diagram

ipynb
n = pypsa.Network()

num_snapshots = 1001
n.snapshots = np.linspace(0, 1, num_snapshots)
n.snapshot_weightings = n.snapshot_weightings / num_snapshots

n.add("Bus", name="bus")

n.add("Load", name="load", bus="bus", p_set=1000 - 1000 * n.snapshots.values)

for gen in generators:
    n.add(
        "Generator",
        name=gen,
        bus="bus",
        p_nom_extendable=True,
        marginal_cost=generators[gen]["m"],
        capital_cost=generators[gen]["c"],
    )

n = pypsa.Network() num_snapshots = 1001 n.snapshots = np.linspace(0, 1, num_snapshots) n.snapshot_weightings = n.snapshot_weightings / num_snapshots n.add("Bus", name="bus") n.add("Load", name="load", bus="bus", p_set=1000 - 1000 * n.snapshots.values) for gen in generators: n.add( "Generator", name=gen, bus="bus", p_nom_extendable=True, marginal_cost=generators[gen]["m"], capital_cost=generators[gen]["c"], )

text
/tmp/ipykernel_3703/1496028825.py:1: 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.
  n = pypsa.Network()

In [6]:

Copied! diagram

ipynb
n.loads_t.p_set.plot.area(title="Load Duration Curve", ylabel="MW")

n.loads_t.p_set.plot.area(title="Load Duration Curve", ylabel="MW")

Out[6]:

text
<Axes: title={'center': 'Load Duration Curve'}, xlabel='snapshot', ylabel='MW'>

No description has been provided for this image

In [7]:

Copied! diagram

ipynb
n.optimize()
n.objective

n.optimize() n.objective

text
/tmp/ipykernel_3703/542537002.py:1: 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.
  n.optimize()
WARNING:pypsa.consistency:The following buses have carriers which are not defined. Run n.sanitize() to add them. Components with undefined carriers:
Index(['bus'], dtype='object', name='name')
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.04s
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-w2ulia91.lp
text
Reading time = 0.01 seconds
text
obj: 7010 rows, 3006 columns, 12015 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 3006 primals, 7010 duals
Objective: 1.47e+04
Solver: gurobi
Runtime: 0.01s
Dual bound: 1.47e+04
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper were not assigned to the network.

Out[7]:

text
14706.193806194067

The capacity is set by total electricity required.

NB: No load shedding since all prices are below 10 000.

In [8]:

Copied! diagram

ipynb
n.generators.p_nom_opt.round(2)

n.generators.p_nom_opt.round(2)

Out[8]:

text
name
coal             500.0
gas              490.0
load-shedding     10.0
Name: p_nom_opt, dtype: float64

In [9]:

Copied! diagram

ipynb
n.buses_t.marginal_price.plot(title="Price Duration Curve")

n.buses_t.marginal_price.plot(title="Price Duration Curve")

Out[9]:

text
<Axes: title={'center': 'Price Duration Curve'}, xlabel='snapshot'>

No description has been provided for this image

The prices correspond either to VOLL (1012) for first 0.01 or the marginal costs (12 for 0.49 and 2 for 0.5)

Except for (infinitesimally small) points at the screening curve intersections, which correspond to changing the load duration near the intersection, so that capacity changes. This explains 7 = (12+10 - 15) (replacing coal with gas) and 22 = (12+10) (replacing load-shedding with gas).

Note: What remains unclear is what is causing l = 0... it should be 2.

In [10]:

Copied! diagram

ipynb
n.buses_t.marginal_price.round(2).sum(axis=1).value_counts()

n.buses_t.marginal_price.round(2).sum(axis=1).value_counts()

Out[10]:

text
2.0       499
12.0      489
1012.0     10
22.0        1
7.0         1
0.0         1
Name: count, dtype: int64

In [11]:

Copied! diagram

ipynb
n.generators_t.p.plot(ylim=[0, 600], title="Generation Dispatch")

n.generators_t.p.plot(ylim=[0, 600], title="Generation Dispatch")

Out[11]:

text
<Axes: title={'center': 'Generation Dispatch'}, xlabel='snapshot'>

No description has been provided for this image

Demonstrate zero-profit condition.

  1. The total cost is given by

In [12]:

Copied! diagram

ipynb
weights = n.snapshot_weightings.objective
(
    n.generators.p_nom_opt * n.generators.capital_cost
    + weights @ n.generators_t.p * n.generators.marginal_cost
)

weights = n.snapshot_weightings.objective ( n.generators.p_nom_opt * n.generators.capital_cost

  • weights @ n.generators_t.p * n.generators.marginal_cost )

Out[12]:

text
name
coal             8249.750250
gas              6400.839161
load-shedding      55.604396
dtype: float64
  1. The total revenue by

In [13]:

Copied! diagram

ipynb
weights @ n.generators_t.p.mul(n.buses_t.marginal_price["bus"], axis=0)

weights @ n.generators_t.p.mul(n.buses_t.marginal_price["bus"], axis=0)

Out[13]:

text
name
coal             8249.750250
gas              6400.839161
load-shedding      55.604396
Name: objective, dtype: float64

Now, take the capacities from the above long-term equilibrium, then disallow expansion.

Show that the resulting market prices are identical.

This holds in this example, but does not necessarily hold and breaks down in some circumstances (for example, when there is a lot of storage and inter-temporal shifting).

In [14]:

Copied! diagram

ipynb
n.generators.p_nom_extendable = False
n.generators.p_nom = n.generators.p_nom_opt

n.generators.p_nom_extendable = False n.generators.p_nom = n.generators.p_nom_opt

In [15]:

Copied! diagram

ipynb
n.optimize();

n.optimize();

text
WARNING:pypsa.consistency:The following buses have carriers which are not defined. Run n.sanitize() to add them. Components with undefined carriers:
Index(['bus'], dtype='object', name='name')
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.02s
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-mg50vqtf.lp
text
Reading time = 0.01 seconds
text
obj: 7007 rows, 3003 columns, 9009 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 3003 primals, 7007 duals
Objective: 2.31e+03
Solver: gurobi
Runtime: 0.00s
Dual bound: 2.31e+03
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 were not assigned to the network.

In [16]:

Copied! diagram

ipynb
n.buses_t.marginal_price.plot(title="Price Duration Curve")

n.buses_t.marginal_price.plot(title="Price Duration Curve")

Out[16]:

text
<Axes: title={'center': 'Price Duration Curve'}, xlabel='snapshot'>

No description has been provided for this image

In [17]:

Copied! diagram

ipynb
n.buses_t.marginal_price.sum(axis=1).value_counts()

n.buses_t.marginal_price.sum(axis=1).value_counts()

Out[17]:

text
2.0       500
12.0      490
1012.0     10
0.0         1
Name: count, dtype: int64

Demonstrate zero-profit condition. Differences are due to singular times, see above, not a problem

  1. Total costs

In [18]:

Copied! diagram

ipynb
(
    n.generators.p_nom * n.generators.capital_cost
    + weights @ n.generators_t.p * n.generators.marginal_cost
)

( n.generators.p_nom * n.generators.capital_cost

  • weights @ n.generators_t.p * n.generators.marginal_cost )

Out[18]:

text
name
coal             8249.750250
gas              6400.839161
load-shedding      55.604396
dtype: float64
  1. Total revenue

In [19]:

Copied! diagram

ipynb
weights @ n.generators_t.p.mul(n.buses_t.marginal_price["bus"], axis=0)

weights @ n.generators_t.p.mul(n.buses_t.marginal_price["bus"], axis=0)

Out[19]:

text
name
coal             8242.257742
gas              6395.944056
load-shedding      55.604396
Name: objective, dtype: float64

diagram 2026-08-05

diagram 2020-02-28