Skip to content

Walkthrough PyPSA Quickstart 3

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

Quickstart 3: sizing solar and a battery for a data centre

All walkthroughs

What it models

PyPSA's Quickstart 3 - Investments & Storage. A data centre in Seville has a constant 100 MW demand. Grid power costs 120 EUR/MWh. The operator can build solar PV and a 4-hour battery. The question is the least-cost size of each over a year of hourly timesteps.

Part Overnight cost Lifetime Discount rate
Solar PV 400 EUR/kW 25 years 5%
Battery storage 150 EUR/kWh 25 years 5%
Battery inverter 170 EUR/kW 25 years, as in PyPSA's code 5%

The round-trip efficiency is 90%, so each direction is √0.9 = 0.9486832980505138.

The costs are entered as PyPSA's own overnight_cost, discount_rate and lifetime, and PyPSA annualises them when it solves. The battery's overnight_cost is its two parts summed per MW of power: 170,000 for the inverter plus 4 × 150,000 for the storage, 770,000 in all.

Upstream downloads its solar series from model.energy. This walkthrough uses a fixed copy of it, 8,760 hours of 2011, as the Python version docs/examples/pypsa/example-3/build_the_data_centre_network.ipynb does.

Files to download

Steps

1. Create the project

On Home, click New project. Name: Quickstart 3. Click Create project.

Home New project

2. Create the network with the time axis from the CSV

Click New network. Name: Seville data centre. Under Time axis, click Upload CSV, choose example_3_solar.csv and keep the snapshot column: it reads 8,760 steps. Click Create network.

The dialog has no Framework choice: a blank network is PyPSA. Create network is below the bottom of the screen once the CSV is read; scroll the dialog to reach it.

Time axis from the CSV The network

3. Add the carriers

Open Components → Carriers, then More ways to add carriers → Add in a panel…. Names grid, solar and battery, using Add another name. Click Add 3 carriers to draft.

Add in a panel Three carriers

4. Add the bus, the load and the grid supply

In the same way, add a Bus seville; a Load demand on seville with p_set 100 MW; and a Generator grid on seville, carrier grid, with p_nom 100 MW and marginal_cost 120.

Type Name bus carrier Values
Bus seville
Load demand seville p_set 100
Generator grid seville grid p_nom 100, marginal_cost 120

Add the load Add the grid supply

5. Add solar with its availability

Add a Generator solar on seville, carrier solar, with the values in the table. Open Costs and Capacity for all their fields. Next to Availability, click Load CSV, choose example_3_solar.csv, and click Load into the form.

Field Value
p_nom_extendable on
overnight_cost (Costs) 400000 currency/MW
discount_rate (Costs) 0.05
lifetime (Capacity) 25
p_max_pu (Availability) Load CSV: example_3_solar.csv, value column solar

There is no cost calculator any more; overnight_cost, discount_rate and lifetime take its place.

Solar costs Load from CSV Series in the form

6. Add the battery

Add a StorageUnit battery on seville, carrier battery, with the values in the table. Its overnight_cost is the inverter's 170 EUR/kW plus 4 hours of storage at 150 EUR/kWh.

Field Value
p_nom_extendable on
max_hours 4
efficiency_store 0.9486832980505138
efficiency_dispatch 0.9486832980505138
overnight_cost (Costs) 770000 currency/MW
discount_rate (Costs) 0.05
lifetime (Capacity) 25

Add the battery

7. Save the components

The header reads Draft · 9 changes: eight components and the solar series. Click Save version, then Save v2.

The draft Save a new version

8. Solve

Click Solve. Keep the defaults: Method Optimize, Solver HiGHS and Algorithm Default. Click Solve in the dialog and wait until the header reads Succeeded.

Solve button Solve dialog Solve succeeded

9. Read the objective

The page moves to Solve. Outcome shows the objective to four figures; the Solver log below gives it in full.

Outcome Objective in the solver log

10. Read the sizes

Click View results. In Generators, p_nom_opt for solar is the solar size; in Storage units, p_nom_opt for battery is the battery's power.

View results Solar capacity Battery capacity

11. Read the costs and the energy

Open Visualisation. On Investment cost by carrier, Operating cost by carrier and Generation share by carrier, click Show data.

Visualisation Investment cost Generation share

12. Chart the battery capex and the average cost

Click Add chart, choose Component Storage units and Value Capex, and click Show data. Add another chart on Loads: in Value, click Write a formula…, name it average_cost, type objective() / sum(withdrawal(Load)) and click Apply.

Chart Component Value
Battery capex Storage units Capex · currency
average_cost Loads Formula objective() / sum(withdrawal(Load))

Investment cost by carrier counts generators only, so the battery's capex needs its own chart. A written formula takes no unit.

Capex option Battery capex Average cost formula Average cost

13. See when the grid is used and how the battery runs

Dispatch over time by carrier shows grid supply in winter. In the results' Generators, click the series in the grid row's p column for its mean; in Storage units, open the battery row's state_of_charge for its most.

Dispatch over time Grid dispatch series Grid dispatch Battery state of charge Network menu

Results

Quantity Value
Objective (Outcome) 4.129 × 10⁷
Objective (solver log) 4.1292841859e+07
Solar p_nom_opt 709.685014 MW
Battery p_nom_opt 342.58008 MW
Solar capex 20,141,558.267 currency
Battery capex 18,716,311.835 currency
Grid opex 2,434,971.757 currency
Grid energy 20,291.431 MWh
Average cost 47.138
Grid mean dispatch 2.316373 MW
Battery state of charge, most 1,370.320319 MWh

Curtailed solar costs nothing, so more than one dispatch reaches the same cost, and the solar energy can differ from one solve to another.

💡 Key learnings

  • Solar is built far beyond the demand. A 100 MW load gets 710 MW of solar, because solar produces only part of the day and less in winter. The surplus at noon is either stored or curtailed.
  • Storage turns daytime solar into night-time supply. The 4-hour battery, 343 MW, charges at midday and discharges at night, so the grid supplies only about 2% of the energy, mostly in winter.
  • Building beats buying. Grid power costs 120 per MWh; with solar and the battery the average cost falls to about 47.
  • Investment and running costs are compared over the same year. An overnight cost is spread over the lifetime at the discount rate, an annuity, so one year of capacity can be weighed against one year of grid purchases.

Bugs

  • #2757 A component costed by overnight_cost reads capital_cost 0 in the results grid and Capital cost by carrier (open)
  • #2758 With no lines, Peak line loading explains its dash with "The two sides share no component…" (open)
  • #2759 Dispatch charts run the axis below zero when no value is negative (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)
  • #2751 A written formula takes no unit (open)

Hard to do

  • #2369 A run can give another optimum than PyPSA where the answer is not unique, with nothing to say so (open)
  • #2761 Create network is below the dialog's fold once a CSV time axis is read (open)
  • #2754 The objective is shown to four significant figures only (open)
  • #2760 Investment cost by carrier counts generators only, leaving out storage (open)
  • #2752 The series panel cuts off its Min, Max and Mean tiles, and prints float noise at full precision (open)

Clone this wiki locally