Skip to content

Walkthrough PyPSA Capacity Expansion Single Node

James Dunkerley edited this page Dec 3, 2026 · 8 revisions

Capacity expansion, single node: wind, solar, a battery and hydrogen for one electricity node

All walkthroughs

What it models

PyPSA's 1-Node Capacity Expansion (notebook at v1.4.0). One electricity bus has one year of load (2019, peak 10,901 MW). The model sizes wind, solar, a 3-hour battery and a hydrogen chain (electrolysis, an underground store and a turbine) at least cost. Load shedding at 2,000 EUR/MWh keeps it feasible.

Upstream keeps every third hour of the year: 2,920 timesteps, each weighted 3 hours (n.snapshot_weightings = 3). Step 3 sets the same weightings from the time axis's spacing.

Data. The series are upstream's own file (https://tubcloud.tu-berlin.de/s/9toBssWEdaLgHzq/download/time-series.csv), cut to every third row by a scratch script, as upstream does with [::3]. carriers.csv holds upstream's carrier colours. The costs are upstream's technology-data costs_2030.csv, worked into a capital cost per MW as upstream does: (annuity(0.07, lifetime) + FOM / 100) × investment. The battery's cost has two parts, a 10-year inverter and a 25-year store; with no cost calculator in the app, it is worked out the same way and typed in (80,056.73865830776).

name,color
wind,dodgerblue
solar,gold
hydrogen storage,black
battery storage,yellowgreen
load shedding,darkorange
electrolysis,magenta
turbine,red
electricity,grey
hydrogen,grey

The Python version is docs/examples/pypsa/capacity-expansion-planning-single-node/plan_capacity_for_one_electricity_node.ipynb.

Files to download

  • time-series-3h.csv: the time axis, the demand (load_mw) and the wind and solar availability (wind_pu, pv_pu), every third hour of 2019. For steps 2, 5 and 6.
  • carriers.csv: the nine carriers and their colours, for step 4.
  • time-series.csv and prepare.py: the hourly file as published, and the script that cuts it to every third hour.

Steps

1. Create the project

On Home, click New project. Name: Capacity expansion, single node. Click Create project.

Home

New project

2. Create the network with the time axis from the series file

Click New network. Name: Electricity and hydrogen. Under Time axis, choose Upload CSV, click Choose CSV and pick time-series-3h.csv: it reads 2,920 steps. Click Create network.

New network

Overview

3. Weight each timestep 3 hours

In the facts on the Overview, click Weightings, then Weight by spacing. Weightings now read 3 at every snapshot.

Edit snapshot weightings

Weightings of 3

4. Add the carriers

Open Components → Carriers. From the arrow beside Add carrier, choose Import CSV…, click Choose file and pick carriers.csv. Click Import 9 carriers.

Carriers

Import carriers

5. Add the buses, the load and the generators

For each row of the table, open its type, choose Add in a panel… from the arrow beside Add, fill the fields and click Add to draft. For two names, click Add another name, then Separate values on each field that differs. Load the demand's p_set from the load_mw column with Load CSV.

Type Names bus carrier Values
Buses electricity, hydrogen electricity, hydrogen (separate)
Loads demand electricity p_set: Load CSV, time-series-3h.csv, Value column load_mw, Load into the form
Generators load shedding electricity load shedding p_nom 10901.16, marginal_cost 2000
Generators wind, solar electricity wind, solar (separate) p_nom_extendable on; capital_cost 128306.33032200082 and 64560.14335577917 (separate)

Add the buses

Load the demand from CSV

Add the load

Add wind and solar

6. Load the wind and solar availability

In the Generators grid, hover the p_max_pu cell of wind and click Add series. In its panel click Load CSV, choose time-series-3h.csv, pick the Value column wind_pu and click Load into draft. Do the same for solar with pv_pu.

Load wind from CSV

Wind series

7. Add the battery

Open Storage units and add battery storage in a panel with the values in the table. Type the capital cost straight in: there is no cost calculator.

Field Value
bus electricity
carrier battery storage
p_nom_extendable on
cyclic_state_of_charge on
max_hours 3
efficiency_store 0.96
efficiency_dispatch 0.96
capital_cost 80056.73865830776

Add battery

8. Add the hydrogen chain

Click Advanced fields at the foot of the type list: Links and Stores appear. Add the two links and the store in a panel each, with the values in the table.

Type Name bus0 / bus bus1 carrier Values
Links electrolysis electricity hydrogen electrolysis p_nom_extendable on, efficiency 0.6217, capital_cost 237278.87451815803
Links turbine hydrogen electricity turbine p_nom_extendable on, efficiency 0.41, capital_cost 146916.38859501746
Stores hydrogen storage hydrogen hydrogen storage e_nom_extendable on, e_cyclic on, capital_cost 187.40297262504282

Advanced fields

Add electrolysis

Add store

9. Save the components

The draft holds 22 changes. Click Save version, give it the title Components as upstream writes them, and click Save v3.

Save a new version

10. Solve the model

Click Solve. Keep Method Optimize and the defaults, and click Solve. The Solve page follows the run until it succeeds. Hover the objective for its full value.

Solve dialog

Run succeeded

11. Read the sizes

Click View results. With Results on, p_nom_opt in the Generators, Storage units and Links grids and e_nom_opt in the Stores grid hold the sizes.

Generator capacity

Battery capacity

Link capacity

Store capacity

12. Costs and energy

In each grid, click Columns and tick Capex under Statistics (and Opex in Generators, Withdrawal in Loads). The load withdraws 66.27 TWh.

Generator costs

Load withdrawal

13. Count the hours

Open Visualisation and click Add chart. Component: Buses. From Value, click Write a formula…: Name hours_covered, Expression total_timestep_weight(), then Apply. Close the panel and click Show data: 8,760 hours.

Hours covered

14. Read the price and the hydrogen level

In the Buses grid, click the electricity row's marginal_price chip: its Mean is the price. Then in the Stores grid click the hydrogen storage row's e chip: the store fills from February to October.

Electricity price

Hydrogen level

15. See the solve on the Overview

Open Overview. Its Installed capacity card counts p_nom only: 10.9 GW, all load shedding, with none of the wind, solar or storage the solve built.

Installed capacity on the Overview

Results

Quantity Value
Objective (step 10) 10,132,586,933.37859
Wind 32,583.318314 MW
Solar 26,089.521123 MW
Battery 14,047.946668 MW
Electrolysis 3,118.498489 MW
Turbine 9,692.63366 MW
Hydrogen store 3,672,190.854893 MWh
Capex: wind, solar, battery 4,180,646,002.61; 1,684,343,223.80; 1,124,632,795.07
Capex: electrolysis, turbine, store 739,953,811.64; 1,424,006,733.34; 688,179,482.25
Load shedding opex 290,824,884.667485
Load withdrawal 66,266,089.12 MWh
Hours covered 8,760
Mean electricity price 139.501934 currency/MWh

💡 Key learnings

  • A system run on wind and solar needs storage at two time scales. The battery shifts solar from day to night. Hydrogen, made by electrolysis, held in an underground store and burnt in a turbine, shifts energy between seasons: the store fills from February to October and empties over the winter.
  • Cheap to store a lot, dear to move it fast. Hydrogen loses most of its energy on the round trip (0.62 × 0.41, about 25% comes back), but its store is cheap per MWh, so it holds 3.7 TWh, about 87 times the battery's 42 GWh (14 GW for 3 hours). The battery is efficient but dear per MWh, so it covers only a few hours.
  • Load shedding is a safety valve with a price. At 2,000 per MWh it meets about 0.2% of the demand, in the tightest hours, where building more would cost more than going without.
  • Wind and solar are overbuilt. About 59 GW of them serve a peak of 10.9 GW, because they produce only part of the time.
  • Snapshot weightings trade detail for speed. Keeping every third hour and weighting each 3 makes the problem three times smaller while energy and costs still add up to a full year, 8,760 hours. The cost is that peaks and swings within the 3 hours are lost.

Bugs

  • #2752 The series panel cuts off its Min, Max and Mean tiles, and prints float noise at full precision (open)

Missing features

  • #1801 No energy balance chart, and no sum of one attribute across components over time (open)
  • #2749 There is no capital cost calculator; a cost with several parts must be summed by hand (open)
  • #2750 A custom statistic cannot be saved with the network or shown as one number (open)

Hard to do

  • #2766 Statistic columns in the components grid cut off large values (open)
  • #1797 Rows with different values need one Add component sheet each (closed)
  • #2753 Links and Stores are hidden behind a button labelled "Advanced fields", which reveals types, not fields (open)
  • #2754 The objective is shown to four significant figures only (open)
  • #2755 After a capacity expansion, the Overview's Installed capacity shows p_nom, not p_nom_opt (open)
  • #2756 A formula with one value draws one wide column; the number shows only under Show data (open)
  • #2746 The network's Overview ignores the open draft: "No buses yet" and 0 of each type (open)
  • #2761 Create network is below the dialog's fold once a CSV time axis is read (open)

Clone this wiki locally