129
PyPSA Documentation Release 0.13.1 Tom Brown (FIAS) Mar 27, 2018

PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

Embed Size (px)

Citation preview

Page 1: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA DocumentationRelease 0.13.1

Tom Brown (FIAS)

Mar 27, 2018

Page 2: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT
Page 3: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CONTENTS

1 Introduction 31.1 What PyPSA does and does not do (yet) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2 Example scripts as Jupyter notebooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3 Screenshots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4 Target user group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101.5 Other comparable software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101.6 What PyPSA uses under the hood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.7 Mailing list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.8 Citing PyPSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.9 Licence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2 Installation 132.1 Getting Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132.2 Getting a solver for linear optimisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132.3 Installing PyPSA with pip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132.4 “Manual” installation with setuptools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.5 Conservative manual installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.6 Upgrade all packages to the latest versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.7 Upgrading PyPSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3 Quick Start 173.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.2 Build a minimal network for power flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.3 Build a minimal network for optimal power flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.4 Use an existing example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4 Design 214.1 Python 2 and Python 3 compatible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.2 Network object is the overall container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.3 Buses are the fundamental nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.4 Energy flow in the model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.5 Data is stored in pandas DataFrames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.6 Static component data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.7 Time-varying data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.8 No GUI: Use Jupyter notebooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.9 Internal use of per unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.10 Set points are stored separately from actual dispatch points . . . . . . . . . . . . . . . . . . . . . . . 234.11 Pyomo for the optimisation framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

5 Components 25

i

Page 4: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

5.1 Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275.2 Sub-Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.3 Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.4 Carrier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315.5 Global Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315.6 Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.7 Storage Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385.8 Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405.9 Load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.10 Shunt Impedance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.11 Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435.12 Line Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485.13 Transformer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605.14 Transformer Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665.15 Link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705.16 Groups of Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725.17 Custom Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

6 Data Import and Export 736.1 Import from folder of CSV files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736.2 Export to folder of CSV files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736.3 Adding components one-by-one . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736.4 Adding multiple components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746.5 Adding components using pandas DataFrames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756.6 Export to netCDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756.7 Import from netCDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766.8 Export to HDF5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766.9 Import from HDF5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766.10 Import from Pypower . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

7 Power Flow 777.1 Full non-linear power flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777.2 Linear power flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

8 Optimal Power Flow 858.1 Non-Linear Optimal Power Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858.2 Linear Optimal Power Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

9 Contingency Analysis 959.1 Branch Outage Distribution Factors (BODF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959.2 Linear Power Flow Contingency Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969.3 Security-Constrained Linear Optimal Power Flow (SCLOPF) . . . . . . . . . . . . . . . . . . . . . 96

10 Plotting Networks 9710.1 Interactive plotting with plotly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9710.2 Static plotting with matplotlib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

11 Conventions 9911.1 Unit Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9911.2 Sign Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9911.3 AC/DC Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

12 Examples 10112.1 SciGRID Germany LOPF, LPF and SCLOPF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10112.2 AC-DC meshed example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

ii

Page 5: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

12.3 Storage and HVDC OPF example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10112.4 Example of linear optimal power flow with coupling to the heating sector . . . . . . . . . . . . . . . 102

13 Troubleshooting 10313.1 Library dependency issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10313.2 Consistency check on network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10313.3 Problems with power flow convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10313.4 Pitfalls/Gotchas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10413.5 Reporting bugs/issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

14 Unit Testing 105

15 Comparable Software 10715.1 Free software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10715.2 Non-free software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

16 Developers 109

17 Release Notes 11117.1 PyPSA 0.13.1 (27th March 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11117.2 PyPSA 0.13.0 (25th January 2018) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11117.3 PyPSA 0.12.0 (30th November 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11217.4 PyPSA 0.11.0 (21st October 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11317.5 PyPSA 0.10.0 (7th August 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11317.6 PyPSA 0.9.0 (29th April 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11417.7 PyPSA 0.8.0 (25th January 2017) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11417.8 PyPSA 0.7.1 (26th November 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11517.9 PyPSA 0.7.0 (20th November 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11517.10 PyPSA 0.6.2 (4th November 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11617.11 PyPSA 0.6.1 (25th August 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11617.12 PyPSA 0.6.0 (23rd August 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11617.13 PyPSA 0.5.0 (21st July 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11717.14 PyPSA 0.4.2 (17th June 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11817.15 PyPSA 0.4.1 (3rd April 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11817.16 PyPSA 0.4.0 (21st March 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11817.17 PyPSA 0.3.3 (29th February 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11917.18 PyPSA 0.3.2 (17th February 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11917.19 PyPSA 0.3.1 (7th February 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11917.20 PyPSA 0.3.0 (27th January 2016) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

18 Mailing list 121

19 Indices and tables 123

iii

Page 6: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

iv

Page 7: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Contents:

CONTENTS 1

Page 8: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

2 CONTENTS

Page 9: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

ONE

INTRODUCTION

PyPSA stands for “Python for Power System Analysis”. It is pronounced “pipes-ah”.

PyPSA is a free software toolbox for simulating and optimising modern power systems that include features such asconventional generators with unit commitment, variable wind and solar generation, storage units, coupling to otherenergy sectors, and mixed alternating and direct current networks. PyPSA is designed to scale well with large networksand long time series.

As of 2018 PyPSA is under heavy development and therefore it is recommended to use caution when using it in aproduction environment. Some APIs may change - the changes in each PyPSA version are listed in the Release Notes.

PyPSA was initially developed by the Renewable Energy Group at FIAS to carry out simulations for the CoNDyNetproject, financed by the German Federal Ministry for Education and Research (BMBF) as part of the StromnetzeResearch Initiative.

What PyPSA does and does not do (yet)

PyPSA can calculate:

• static power flow (using both the full non-linear network equations and the linearised network equations)

• linear optimal power flow (least-cost optimisation of power plant and storage dispatch within network con-straints, using the linear network equations, over several snapshots)

• security-constrained linear optimal power flow

• total electricity/energy system least-cost investment optimisation (using linear network equations, over severalsnapshots simultaneously for optimisation of generation and storage dispatch and investment in the capacitiesof generation, storage, transmission and other infrastructure)

It has models for:

• meshed multiply-connected AC and DC networks, with controllable converters between AC and DC networks

• standard types for lines and transformers following the implementation in pandapower

• conventional dispatchable generators with unit commitment

• generators with time-varying power availability, such as wind and solar generators

• storage units with efficiency losses

• simple hydroelectricity with inflow and spillage

• coupling with other energy carriers

3

Page 10: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

• basic components out of which more complicated assets can be built, such as Combined Heat and Power (CHP)units, heat pumps, resistive Power-to-Heat (P2H), Power-to-Gas (P2G), battery electric vehicles (BEVs), etc.;each of these is demonstrated in the examples

Functionality that will definitely be added soon:

• Multi-year investment optimisation

• Simple RMS simulations with the swing equation

• Distributed active power slack

• Non-linear power flow solution using analytic continuation in the complex plane following GridCal

Functionality that may be added in the future:

• Short-circuit current calculations

• Dynamic RMS simulations

• Small signal stability analysis

• Interactive web-based GUI with SVG

• OPF with the full non-linear network equations

• Dynamic EMT simulations

• Unbalanced load flow

• Port to Julia

Example scripts as Jupyter notebooks

There are extensive examples available as Jupyter notebooks. They are also described in the Examples and are availableas Python scripts in examples/.

Screenshots

Results from a PyPSA simulation can be converted into an interactive online animation using PyPSA-animation, seethe PyPSA-Eur-30 example.

Another showcase for PyPSA is the SciGRID example which demonstrates interactive plots generated with the plotlylibrary.

4 Chapter 1. Introduction

Page 11: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

1.3. Screenshots 5

Page 12: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

6 Chapter 1. Introduction

Page 13: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

1.3. Screenshots 7

Page 14: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

8 Chapter 1. Introduction

Page 15: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Optimised capacities of generation and storage for a 95% reduction in CO2 emissions in Europe compare to 1990levels:

1.3. Screenshots 9

Page 16: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Target user group

PyPSA is intended for researchers, planners and utilities who need a fast, easy-to-use and transparent tool for powersystem analysis. PyPSA is free software and can be arbitrarily extended.

Other comparable software

For a full list see Comparable Software.

10 Chapter 1. Introduction

Page 17: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free software PSATor the commercial package DIgSILENT PowerFactory.

However for power flow and optimal power flow over several time snapshots with variable renewable energy sourcesand/or storage and/or mixed AC-DC systems, it offers the flexibility of Python and the transparency of free software.

Another Python power system tool is PYPOWER, which is based on the Matlab-based MATPOWER. In contrast toPYPOWER, PyPSA has an easier-to-use data model (pandas DataFrames instead of numpy arrays), support for time-varying data inputs and support for multiply-connected networks using both AC and DC. PyPSA uses some of thesparse-matrix constructs from PYPOWER.

What PyPSA uses under the hood

PyPSA is written and tested to be compatible with Python 2.7 and Python 3.5.

It leans heavily on the following Python packages:

• pandas for storing data about components and time series

• numpy and scipy for calculations, such as linear algebra and sparse matrix calculations

• pyomo for preparing optimisation problems (currently only linear)

• plotly for interactive plotting

• matplotlib for static plotting

• networkx for some network calculations

• py.test for unit testing

• logging for managing messages

The optimisation uses pyomo so that it is independent of the preferred solver (you can use e.g. the free software GLPKor the commercial software Gurobi).

The time-expensive calculations, such as solving sparse linear equations, are carried out using the scipy.sparse libraries.

Mailing list

PyPSA has a Google Group forum / mailing list.

Citing PyPSA

If you use PyPSA for your research, we would appreciate it if you would cite the following paper:

• T. Brown, J. Hörsch, D. Schlachtberger, PyPSA: Python for Power System Analysis, 2018, Journal of OpenResearch Software, 6(1), arXiv:1707.09913, DOI:10.5334/jors.188

Please use the following BibTeX:

@article{PyPSA,author = {T. Brown and J. H\"orsch and D. Schlachtberger},title = {{PyPSA: Python for Power System Analysis}},journal = {Journal of Open Research Software},volume = {6},issue = {1},

1.6. What PyPSA uses under the hood 11

Page 18: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

number = {4},year = {2018},eprint = {1707.09913},url = {https://doi.org/10.5334/jors.188},doi = {10.5334/jors.188}

}

If you want to cite a specific PyPSA version, each release of PyPSA is stored on Zenodo with a release-specific DOI.This can be found linked from the overall PyPSA Zenodo DOI:

Licence

PyPSA is released under the GPLv3.

12 Chapter 1. Introduction

Page 19: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

TWO

INSTALLATION

Getting Python

If it’s your first time with Python, people seem to recommend Anaconda as an easy-to-use environment that includesmany basic packages. Anaconda is available for Windows, Mac OS X and GNU/Linux.

For those rolling their own on unix-like systems (GNU/Linux, Mac OS X) it’s always helpful to use a virtual envi-ronment for your python installation (and even easier to use with a virtualenv-burrito), in case you accidentally trashsomething.

Getting a solver for linear optimisation

PyPSA passes optimisation problems for Optimal Power Flow to an external solver. PyPSA is known to work with thefree software Cbc, the free software GLPK and the non-free software Gurobi (and whatever else works with Pyomo).

For Cbc, see their installation instructions. For Debian-based systems you can do simply:

sudo apt-get install coinor-cbc

For GLPK in Debian-based systems execute:

sudo apt-get install glpk-utils

and there are similar packages for other GNU/Linux distributions.

For Windows there is WinGLPK. For Mac OS X brew is your friend.

Installing PyPSA with pip

If you have the Python package installer pip then just run:

pip install pypsa

If you’re feeling adventurous, you can also install the latest master branch from github with:

pip install git+https://github.com/PyPSA/PyPSA.git

13

Page 20: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

“Manual” installation with setuptools

PyPSA relies on the following packages which are not contained in a standard Python installation:

• numpy

• scipy

• pandas

• networkx

• pyomo

It is recommended to use PyPSA with the following additional packages:

• iPython for interactive simulations

• plotly for interactive plotting

• matplotlib for static plotting

• py.test for unit testing

In a unix-based environment these packages can be obtained with the pip Python package manager:

pip install numpy scipy pandas networkx pyomo ipython

To install PyPSA, you need to download the code from the PyPSA github repository and then go to the local repositoryand run:

python setup.py install

Or if you want to develop/modify the code in the current directory, run:

python setup.py develop

Conservative manual installation

If you’re very conservative and don’t like package managers, you can just download the code from the PyPSA githubrepository and add the directory of PyPSA to your python path with e.g.:

import sys

sys.path.append("path/to/PyPSA")

import pypsa

Upgrade all packages to the latest versions

PyPSA is only tested with the latest stable versions of all the dependent packages (pandas, pyomo, networkx, etc.).Therefore it is very important that you upgrade these packages; otherwise PyPSA may not work.

To upgrade a package such as pandas with pip, do at the command line:

pip install -U pandas

14 Chapter 2. Installation

Page 21: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

In Anaconda the user manual suggests to upgrade packages with:

conda update pandas

Upgrading PyPSA

We recommend always keeping your PyPSA installation up-to-date, since bugs get fixed and new features are added.To upgrade PyPSA with pip, do at the command line:

pip install -U pandas

Don’t forget to read the Release Notes regarding API changes that might require you to update your code.

2.7. Upgrading PyPSA 15

Page 22: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

16 Chapter 2. Installation

Page 23: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

THREE

QUICK START

See also the existing Examples and the example Jupyter notebooks at http://www.pypsa.org/examples/.

Installation

For full installation instructions see Installation.

If you have the Python package installer pip then just run:

pip install pypsa

Build a minimal network for power flow

This example is downloadable at http://www.pypsa.org/examples/.

import pypsa

import numpy as np

network = pypsa.Network()

#add three busesfor i in range(3):

network.add("Bus","My bus {}".format(i))

print(network.buses)

#add three lines in a ringfor i in range(3):

network.add("Line","My line {}".format(i),bus0="My bus {}".format(i),bus1="My bus {}".format((i+1)%3),x=0.0001)

print(network.lines)

#add a generator at bus 0network.add("Generator","My gen",

bus="My bus 0",p_set=100)

17

Page 24: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

print(network.generators)

print(network.generators_t.p_set)

#add a load at bus 1network.add("Load","My load",

bus="My bus 1",p_set=100)

print(network.loads)

print(network.loads_t.p_set)

#Do a Newton-Raphson power flownetwork.pf()

print(network.lines_t.p0)

print(network.buses_t.v_ang*180/np.pi)

Build a minimal network for optimal power flow

This example is downloadable at http://www.pypsa.org/examples/.

import pypsa

import numpy as np

network = pypsa.Network()

#add three busesfor i in range(3):

network.add("Bus","My bus {}".format(i))

print(network.buses)

#add three lines in a ringfor i in range(3):

network.add("Line","My line {}".format(i),bus0="My bus {}".format(i),bus1="My bus {}".format((i+1)%3),x=0.0001,s_nom=60)

print(network.lines)

#add a generator at bus 0network.add("Generator","My gen 0",

bus="My bus 0",p_nom=100,marginal_cost=50)

#add a generator at bus 1network.add("Generator","My gen 1",

bus="My bus 1",

18 Chapter 3. Quick Start

Page 25: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

p_nom=100,marginal_cost=25)

print(network.generators)

print(network.generators_t.p_set)

#add a load at bus 2network.add("Load","My load",

bus="My bus 2",p_set=100)

print(network.loads)

print(network.loads_t.p_set)

#Do a linear OPFnetwork.lopf()

print(network.generators_t.p)

print(network.lines_t.p0)

print(network.buses_t.v_ang*180/np.pi)

Use an existing example

The examples are NOT bundled with the pip package but can be downloaded from the PyPSA github repository oras Jupyter notebooks from the PyPSA website.

import pypsa

#adjust the path to pypsa examples directorynetwork = pypsa.Network(csv_folder_name="path/to/pypsa/examples/ac-dc-meshed/ac-dc-→˓data")

#set to your favourite solversolver_name = "glpk"

network.lopf(snapshots=network.snapshots,solver_name=solver_name)

print(network.generators.p_nom_opt)

print(network.generators_t.p)

print(network.storage_units.p_nom_opt)

print(network.storage_units_t.p)

print(network.lines.s_nom_opt)

print(network.lines_t.p0)

3.4. Use an existing example 19

Page 26: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

20 Chapter 3. Quick Start

Page 27: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

FOUR

DESIGN

Python 2 and Python 3 compatible

PyPSA is written and tested to be compatible with both Python 2.7 and Python 3.5.

Network object is the overall container

The pypsa.Network is an overall container for all network components; components cannot exist without a net-work.

It is also the object on which calculations, such as power flow and optimal power flow, are performed.

Buses are the fundamental nodes

The bus is the fundamental node to which all loads, generators, storage units, lines, transformers and links attach.

You can have as many components attached to a bus as you want.

The bus’s role is to enforce energy conservation for all elements feeding in and out of it (i.e. like Kirchhoff’s CurrentLaw).

21

Page 28: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Energy flow in the model

Energy enters the model in generators, storage units or stores with higher energy before than after the simulation, andany components with efficiency greater than 1 (e.g. heat pumps).

Energy leaves the model in loads, storage units or stores with higher energy after than before the simulation, and inlines, links or storage units with efficiency less than 1.

Data is stored in pandas DataFrames

To enable efficient calculations on the different dimensions of the data, data is stored in memory using pandasDataFrames.

Other power system toolboxes use databases for data storage; given modern RAM availability and speed considera-tions, pandas DataFrames were felt to be preferable and simpler.

To see which data is stored for each component, see Components.

Static component data

For each component type (line, transformer, generator, etc.), which must be uniquely named for each network, itsbasic static data is stored in a pandas DataFrame, which is an attribute of the network object, with names that followthe component names:

• network.buses

• network.generators

• network.loads

• network.lines

• network.transformers

These are all pandas DataFrames, indexed by the unique name of the component.

The columns contain data such as impedance, capacity and the buses to which components are attached. All attributesfor each component type are listed with their properties (defaults, etc.) in Components and are accessible from thenetwork object in e.g. network.components["Bus"]["attrs"].

Network components cannot exist without a network to hold them.

Time-varying data

Some quantities, such as generator p_set (generator active power set point), generator p (generator calculated activepower), line p0 (line active power at bus0) and line p1 (line active power at bus1) may vary over time, so PyPSAoffers the possibility to store different values of these attributes for the different snapshots in network.snapshotsin the following attributes of the network object:

• network.buses_t

• network.generators_t

• network.loads_t

• network.lines_t

22 Chapter 4. Design

Page 29: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

• network.transformers_t

These are all dictionaries of pandas DataFrames, so that for example network.generators_t["p_set"] isa DataFrame with columns corresponding to generator names and index corresponding to network.snapshots.You can also access the dictionary like an attribute network.generators_t.p_set.

Time-varying data are defined as series in the listings in Components.

For input data such as p_set of a generator you can store the value statically in network.generators ifthe value does not change over network.snapshots or you can define it to be time-varying by adding acolumn to network.generators_t.p_set. If the name of the generator is in the columns of network.generators_t.p_set, then the static value in network.generators will be ignored. Some example defini-tions of input data:

#four snapshots are defined by integersnetwork.set_snapshots(range(4))

network.add("Bus", "my bus")

#add a generator whose output does not change over timenetwork.add("Generator", "Coal", bus="my bus", p_set=100)

#add a generator whose output does change over timenetwork.add("Generator", "Wind", bus="my bus", p_set=[10,50,20,30])

In this case only the generator “Wind” will appear in the columns of network.generators_t.p_set.

For output data, all time-varying data is stored in the network.components_t dictionaries, but it is only definedonce a simulation has been run.

No GUI: Use Jupyter notebooks

PyPSA has no Graphical User Interface (GUI). However it has features for plotting time series and networks (e.g.network.plot()), which works especially well in combination with Jupyter notebooks.

Internal use of per unit

Per unit values of voltage and impedance are used internally for network calculations. It is assumed internally that thebase power is 1 MVA. The base voltage depends on the component.

See also Unit Conventions.

Set points are stored separately from actual dispatch points

Dispatchable generators have a p_set series which is separate from the calculated active power series p, since theoperators’s intention may be different from what is calculated (e.g. when using distributed slack for the active power).

Pyomo for the optimisation framework

To enable portability between solvers, the OPF is formulated using the Python optimisation modelling package pyomo(which can be thought of as a Python version of GAMS).

4.8. No GUI: Use Jupyter notebooks 23

Page 30: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Pyomo also has useful features such as index sets, etc.

24 Chapter 4. Design

Page 31: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

FIVE

COMPONENTS

PyPSA represents the power system using the following components:

25

Page 32: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

com-po-nent

list_namedescription type

Net-work

net-works

Container for all components and functions which act upon the whole network.

Sub-Net-work

sub_networksSubsets of buses and passive branches (i.e. lines and transformers) that areconnected (i.e. synchronous areas).

Bus buses Electrically fundamental node where x-port objects attach.Car-rier

carri-ers

Energy carrier, such as AC, DC, heat, wind, PV or coal. Buses have direct carriersand Generators indicate their primary energy carriers. The Carrier can trackproperties relevant for global constraints, such as CO2 emissions.

Glob-al-Con-straint

global_constraintsConstraints for OPF that affect many components, such as CO2 emissionconstraints.

Line lines Lines include distribution and transmission lines, overhead lines and cables. pas-sive_branch

Line-Type

line_typesStandard line types with per length values for impedances. stan-dard_type

Trans-former

trans-form-ers

2-winding transformer. pas-sive_branch

Trans-former-Type

trans-former_types

Standard 2-winding transformer types. stan-dard_type

Link links Link between two buses with controllable active power - can be used for a transportpower flow model OR as a simplified version of point-to-point DC connection ORas a lossy energy converter. NB: for a lossless bi-directional HVDC or transportlink, set p_min_pu = -1 and efficiency = 1. NB: It is assumed that the links neitherproduce nor consume reactive power.

control-lable_branch

Load loads PQ power consumer. control-lable_one_port

Gen-erator

gener-ators

Power generator. control-lable_one_port

Storage-Unit

stor-age_units

Storage unit with fixed nominal-energy-to-nominal-power ratio. control-lable_one_port

Store stores Generic store, whose capacity may be optimised. control-lable_one_port

ShuntImpedanceshunt_impedancesShunt y = g + jb. pas-sive_one_port

This table is also available as a dictionary within each network object as network.components.

For each class of components, the data describing the components is stored in a pandas.DataFrame correspond-ing to the list_name. For example, all static data for buses is stored in network.buses. In this pandas.DataFrame the index corresponds to the unique string names of the components, while the columns correspond tothe component static attributes. For example, network.buses.v_nom gives the nominal voltages of each bus.

Time-varying series attributes are stored in a dictionary of pandas.DataFrame based on the list_name followedby _t, e.g. network.buses_t. For example, the set points for the per unit voltage magnitude at each bus for eachsnapshot can be found in network.buses_t.v_mag_pu_set. Please also read Time-varying data.

For each component class their attributes, their types (float/boolean/string/int/series), their defaults, their descrip-tions and their statuses are stored in a pandas.DataFrame in the dictionary network.components as e.g.

26 Chapter 5. Components

Page 33: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

network.components["Bus"]["attrs"]. This data is reproduced as tables for each component below.

Their status is either “Input” for those which the user specifies or “Output” for those results which PyPSA calculates.

The inputs can be either “required”, if the user must give the input, or “optional”, if PyPSA will use a sensible defaultif the user gives no input.

For functions such as Power Flow and Optimal Power Flow the inputs used and outputs given are listed in theirdocumentation.

Network

The Network is the overall container for all components. It also has the major functions as methods, such asnetwork.lopf() and network.pf().

5.1. Network 27

Page 34: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

attribute type unit default description statusname string n/a n/a Unique name Input (required)snapshots list or pan-

das.Indexn/a [”now”] List of snap-

shots or timesteps. Alltime-dependentseries quantitiesare indexed bynetwork.snapshots.To reset thesnapshots,call network.set_snapshots(new_snapshots).

Input (optional)

snapshot_weightingspandas.Series hours1.

The weightingapplied to eachsnapshot, so thatsnapshots canrepresent morethan one houror fractions ofone hour. Thisweighting isused to weightsnapshots in theLOPF objectivefunction, todetermine thestate of chargechange forstorage unitsand for calcu-lating globalconstraints.

Input (optional)

now any n/a “now” The cur-rent snap-shot/time/scenario,relevante.g. whennetwork.pf() is calledwithout a snap-shot argument.

Input (optional)

srid integer n/a 4326 Spatial Refer-ence SystemIndentifier forx,y coordinatesof buses. Itdefaults to stan-dard longitudeand latitude.

Input (optional)

buses pandas.DataFrame n/a n/a All static businformationcompiled byPyPSA frominputs. Indexis bus names,columns are busattributes.

Output

buses_t dictionaryof pan-das.DataFrames

n/a n/a All time-dependent businformationcompiled byPyPSA frominputs. Dictio-nary keys aretime-dependentseries attributes,index is net-work.snapshots,columns are busnames.

Output

lines pandas.DataFrame n/a n/a All static lineinformationcompiled byPyPSA frominputs. Indexis line names,columns are lineattributes.

Output

lines_t dictionaryof pan-das.DataFrames

n/a n/a All time-dependent lineinformationcompiled byPyPSA frominputs. Dictio-nary keys aretime-dependentseries attributes,index is net-work.snapshots,columns are linenames.

Output

components pandas.DataFrame n/a n/a For each com-ponent type(buses, lines,etc.): staticcomponentinformationcompiled byPyPSA frominputs. Indexis componentnames, columnsare componentattributes.

Output

components_t dictionaryof pan-das.DataFrames

n/a n/a For each com-ponent type(buses, lines,etc.): time-dependentcomponentinformationcompiled byPyPSA frominputs. Dictio-nary keys aretime-dependentseries attributes,index is net-work.snapshots,columns arecomponentnames.

Output

branches() pandas.DataFrame n/a n/a Dynamicallygeneratedconcatena-tion of branchDataFrames:network.lines,net-work.transformersand net-work.links.Note that thisis a copy andtherefore chang-ing entries willNOT update theoriginal.

Output

graph() networkx.OrderedMultiGraphn/a n/a Graph of net-work.

Output

28 Chapter 5. Components

Page 35: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Sub-Network

Sub-networks are determined by PyPSA and should not be entered by the user.

Sub-networks are subsets of buses and passive branches (i.e. lines and transformers) that are connected.

They have a uniform energy‘‘carrier‘‘ inherited from the buses, such as “DC”, “AC”, “heat” or “gas”. In the case of“AC” sub-networks, these correspond to synchronous areas. Only “AC” and “DC” sub-networks can contain passivebranches; all other sub-networks must contain a single isolated bus.

The power flow in sub-networks is determined by the passive flow through passive branches due to the impedances ofthe passive branches.

Sub-Network are determined by calling network.determine_network_topology().

at-tribute

type unit de-fault

description sta-tus

name string n/a n/a Unique name based on order of sub-network in list of sub-networks. Out-put

car-rier

string n/a AC Energy carrier: could be for example “AC” or “DC” (for electrical networks) or“gas” or “heat”. The carrier is determined from the buses in sub_network.

Out-put

slack_busstring n/a n/a Name of slack bus. Out-put

Bus

The bus is the fundamental node of the network, to which components like loads, generators and transmission linesattach. It enforces energy conservation for all elements feeding in and out of it (i.e. like Kirchhoff’s Current Law).

5.2. Sub-Network 29

Page 36: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

attribute type unit default description statusname string n/a n/a Unique name Input (required)v_nom float kV

1.Nominal volt-age

Input (optional)

type string n/a n/a Placeholderfor bus type.Not yet imple-mented.

Input (optional)

x float n/a0.

Position (e.g.longitude);the SpatialReference Sys-tem Identifier(SRID) is set innetwork.srid.

Input (optional)

y float n/a0.

Position (e.g.latitude); theSpatial Refer-ence SystemIdentifier(SRID) is set innetwork.srid.

Input (optional)

carrier string n/a AC Energy carrier:can be “AC” or“DC” for elec-trical buses, or“heat” or “gas”.

Input (optional)

v_mag_pu_set static or series per unit1.

Voltage magni-tude set point,per unit ofv_nom.

Input (optional)

v_mag_pu_min float per unit0.

Minimum de-sired voltage,per unit ofv_nom. This isa placeholderattribute andis not cur-rently used byany PyPSAfunctions.

Input (optional)

v_mag_pu_max float per unit inf Maximum de-sired voltage,per unit ofv_nom. This isa placeholderattribute andis not cur-rently used byany PyPSAfunctions.

Input (optional)

control string n/a PQ P,Q,V controlstrategy forPF, must be“PQ”, “PV”or “Slack”.Note that thisattribute is anoutput inher-ited from thecontrols ofthe generatorsattached to thebus; setting itdirectly on thebus will nothave any effect.

Output

sub_network string n/a n/a Name ofconnectedsub-networkto which busbelongs. Thisattribute is setby PyPSA inthe function net-work.determine_network_topology();do not set it di-rectly by hand.

Output

p series MW0.

active power atbus (positive ifnet generation atbus)

Output

q series MVar0.

reactive power(positive if netgeneration atbus)

Output

v_mag_pu series per unit1.

Voltage magni-tude, per unit ofv_nom

Output

v_ang series radians0.

Voltage angle Output

marginal_price series currency/MWh0.

Locationalmarginal pricefrom LOPFfrom power bal-ance constraint

Output

30 Chapter 5. Components

Page 37: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Carrier

The carrier describes energy carriers and defaults to AC for alternating current electricity networks. DC can be set fordirect current electricity networks. It can also take arbitrary values for arbitrary energy carriers, e.g. wind, heat,hydrogen or natural gas.

Attributes relevant for global constraints can also be stored in this table, the canonical example being CO2 emissionsof the carrier relevant for limits on CO2 emissions.

(NB: In versions of PyPSA < 0.6.0, this was called Source.)

attribute type unit default description statusname string n/a n/a Unique name Input (required)co2_emissions float tonnes/MWh

0.Emissions inCO2-tonnes-equivalentper MWhof primaryenergy (e.g.methane has 0.2tonnes_CO2/MWh_thermal).

Input (optional)

Global Constraints

Global constraints are added to OPF problems and apply to many components at once. Currently only constraintsrelated to primary energy (i.e. before conversion with losses by generators) are supported, the canonical example beingCO2 emissions for an optimisation period. Other primary-energy-related gas emissions also fall into this framework.

Other types of global constraints will be added in future, e.g. “final energy” (for limits on the share of renewable ornuclear electricity after conversion), “generation capacity” (for limits on total capacity expansion of given carriers)and “transmission capacity” (for limits on the total expansion of lines and links).

Global constraints were added in PyPSA 0.10.0 and replace the ad hoc network.co2_limit attribute.

5.4. Carrier 31

Page 38: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

attribute type unit default description statusname string n/a n/a Unique name Input (required)type string n/a primary_energy Type of con-

straint (only“primary en-ergy”, i.e. limitson the usage ofprimary energybefore generatorconversion, issupported at themoment)

Input (optional)

carrier_attribute string n/a co2_emissions If the globalconstraint isconnectedwith an energycarrier, namethe associatedcarrier attribute.This mustappear as acolumn in net-work.carriers.

Input (optional)

sense string n/a == Constraintsense; must beone of <=, == or>=

Input (optional)

constant float n/a0.

Constant forright-hand-sideof constraintfor optimisationperiod. For aCO2 constraint,this wouldbe tonnes ofCO2-equivalentemissions.

Input (optional)

mu float currency/constant0.

Shadow priceof global con-straint

Output

Generator

Generators attach to a single bus and can feed in power. It converts energy from its carrier to the carrier-type ofthe bus to which it is attached.

In the LOPF the limits which a generator can output are set by p_nom*p_max_pu and p_nom*p_min_pu, i.e. bylimits defined per unit of the nominal power p_nom.

Generators can either have static or time-varying p_max_pu and p_min_pu.

Generators with static limits are like controllable conventional generators which can dispatch anywhere betweenp_nom*p_min_pu and p_nom*p_max_pu at all times. The static factor p_max_pu, stored at network.generator.loc[gen_name,"p_max_pu"] essentially acts like a de-rating factor. In the following example

32 Chapter 5. Components

Page 39: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

p_max_pu = 0.9 and p_min_pu = 0. Since p_nom is 12000 MW, the maximum dispatchable active power is0.9*12000 MW = 10800 MW.

Generators with time-varying limits are like variable weather-dependent renewable generators. The time seriesp_max_pu, stored as a series in network.generators_t.p_max_pu[gen_name], dictates the active poweravailability for each snapshot per unit of the nominal power p_nom and another time series p_min_pu which dic-tates the minimum dispatch. These time series can take values between 0 and 1, e.g. network.generators_t.p_max_pu[gen_name] could be

This time series is then multiplied by p_nom to get the available power dispatch, which is the maximum that may bedispatched. The actual dispatch p, stored in network.generators_t.p[gen_name], may be below this value,e.g.

5.6. Generator 33

Page 40: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

For the implementation of unit commitment, see Generator unit commitment constraints.

For generators, if 𝑝 > 0 the generator is supplying active power to the bus and if 𝑞 > 0 it is supplying reactive power(i.e. behaving like a capacitor).

attribute type unit default description statusname string n/a n/a Unique name Input (required)bus string n/a n/a name of bus to

which generatoris attached

Input (required)

control string n/a PQ P,Q,V controlstrategy forPF, must be“PQ”, “PV” or“Slack”.

Input (optional)

type string n/a n/a Placeholder forgenerator type.Not yet imple-mented.

Input (optional)

p_nom float MW0.

Nominal powerfor limits inOPF.

Input (optional)

p_nom_extendable boolean n/a False Switch to allowcapacity p_nomto be extendedin OPF.

Input (optional)

p_nom_min float MW0.

If p_nom is ex-tendable in OPF,set its minimumvalue.

Input (optional)

Continued on next page

34 Chapter 5. Components

Page 41: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.1 – continued from previous pageattribute type unit default description statusp_nom_max float MW inf If p_nom is ex-

tendable in OPF,set its maximumvalue (e.g. lim-ited by technicalpotential).

Input (optional)

p_min_pu static or series per unit0.

The minimumoutput for eachsnapshot perunit of p_nomfor the OPF(e.g. for vari-able renewablegenerators thiscan changedue to weatherconditions andcompulsoryfeed-in; forconventionalgenerators itrepresents aminimal dis-patch). Notethat if comit-table is Falseand p_min_pu> 0, this repre-sents a must-runcondition.

Input (optional)

p_max_pu static or series per unit1.

The maximumoutput for eachsnapshot perunit of p_nomfor the OPF(e.g. for vari-able renewablegenerators thiscan changedue to weatherconditions; forconventionalgeneratorsit representsa maximumdispatch).

Input (optional)

p_set static or series MW0.

active power setpoint (for PF)

Input (optional)

Continued on next page

5.6. Generator 35

Page 42: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.1 – continued from previous pageattribute type unit default description statusq_set static or series MVar

0.reactive powerset point (forPF)

Input (optional)

sign float n/a1.

power sign Input (optional)

carrier string n/a n/a Prime mover en-ergy carrier (e.g.coal, gas, wind,solar); requiredfor global con-straints on pri-mary energy inOPF

Input (optional)

marginal_cost static or series currency/MWh0.

Marginal cost ofproduction of 1MWh.

Input (optional)

capital_cost float currency/MW0.

Capital costof extendingp_nom by 1MW.

Input (optional)

efficiency float per unit1.

Ratio betweenprimary energyand electricalenergy, e.g.takes value 0.4MWh_elec/MWh_thermalfor gas. Thisis required forglobal con-straints onprimary energyin OPF.

Input (optional)

committable boolean n/a False Use unit com-mitment (onlypossible ifp_nom is notextendable).

Input (optional)

start_up_cost float currency0.

Cost to start upthe generator.Only read ifcommittable isTrue.

Input (optional)

shut_down_cost float currency0.

Cost to shutdown the gener-ator. Only readif committableis True.

Input (optional)

Continued on next page

36 Chapter 5. Components

Page 43: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.1 – continued from previous pageattribute type unit default description statusmin_up_time int snapshots 0 Minimum num-

ber of snapshotsfor status to be1. Only read ifcommittable isTrue.

Input (optional)

min_down_time int snapshots 0 Minimum num-ber of snapshotsfor status to be0. Only read ifcommittable isTrue.

Input (optional)

initial_status int n/a 1 Initial status.Only read ifcommittable isTrue.

Input (optional)

ramp_limit_up float per unit NaN Maximumactive powerincrease fromone snapshotto the next,per unit of thenominal power.Ignored if NaN.

Input (optional)

ramp_limit_down float per unit NaN Maximumactive powerdecrease fromone snapshotto the next,per unit of thenominal power.Ignored if NaN.

Input (optional)

ramp_limit_start_upfloat per unit1.

Maximumactive powerincrease atstart up, perunit of thenominal power.Only read ifcommittable isTrue.

Input (optional)

ramp_limit_shut_downfloat per unit1.

Maximumactive powerdecrease atshut down,per unit of thenominal power.Only read ifcommittable isTrue.

Input (optional)

Continued on next page

5.6. Generator 37

Page 44: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.1 – continued from previous pageattribute type unit default description statusp series MW

0.active power atbus (positive ifnet generation)

Output

q series MVar0.

reactive power(positive if netgeneration)

Output

p_nom_opt float MW0.

Optimised nom-inal power.

Output

status series n/a 1 Status (1 is on,0 is off). Onlyoutputted ifcommittable isTrue.

Output

Storage Unit

Storage units attach to a single bus and are used for inter-temporal power shifting. Each storage unit has a time-varying state of charge and various efficiencies. The nominal energy is given as a fixed ratio max_hours of thenominal power. If you want to optimise the storage energy capacity independently from the storage power capacity,you should use a fundamental Store component (see below) attached with two Link components, one for chargingand one for discharging. See also the example that replaces generators and storage units with fundamental links andstores.

For storage units, if 𝑝 > 0 the storage unit is supplying active power to the bus and if 𝑞 > 0 it is supplying reactivepower (i.e. behaving like a capacitor).

38 Chapter 5. Components

Page 45: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

attribute type unit default description statusname string n/a n/a Unique name Input (required)bus string n/a n/a Name of bus to

which storageunit is attached.

Input (required)

control string n/a PQ P,Q,V controlstrategy forPF, must be“PQ”, “PV” or“Slack”.

Input (optional)

type string n/a n/a Placeholder forstorage unittype. Not yetimplemented.

Input (optional)

p_nom float MW0.

Nominal powerfor limits inOPF.

Input (optional)

p_nom_extendable boolean n/a False Switch to allowcapacity p_nomto be extendedin OPF.

Input (optional)

p_nom_min float MW0.

If p_nom is ex-tendable in OPF,set its minimumvalue.

Input (optional)

p_nom_max float MW inf If p_nom is ex-tendable in OPF,set its maximumvalue (e.g. lim-ited by poten-tial).

Input (optional)

p_min_pu static or series per unit -1. The minimumoutput for eachsnapshot perunit of p_nomfor the OPF(negative signimplies storingmode withdraw-ing power frombus).

Input (optional)

p_max_pu static or series per unit1.

The maximumoutput for eachsnapshot perunit of p_nomfor the OPF.

Input (optional)

p_set static or series MW0.

active power setpoint (for PF)

Input (optional)

q_set static or series MVar0.

reactive powerset point (forPF)

Input (optional)

sign float n/a1.

power sign Input (optional)

carrier string n/a n/a Prime mover en-ergy carrier (e.g.coal, gas, wind,solar); requiredfor global con-straints on pri-mary energy inOPF

Input (optional)

marginal_cost static or series currency/MWh0.

Marginal cost ofproduction of 1MWh.

Input (optional)

capital_cost float currency/MW0.

Capital costof extendingp_nom by 1MW.

Input (optional)

state_of_charge_initialfloat MWh0.

State of chargebefore the snap-shots in theOPF.

Input (optional)

state_of_charge_setstatic or series MWh NaN State of chargeset points forsnapshots in theOPF.

Input (optional)

cyclic_state_of_chargeboolean n/a False Switch: ifTrue, thenstate_of_charge_initialis ignored andthe initial stateof charge is setto the final stateof charge forthe group ofsnapshots in theOPF (soc[-1] =soc[len(snapshots)-1]).

Input (optional)

max_hours float hours1.

Maximum stateof charge ca-pacity in termsof hours at fulloutput capacityp_nom

Input (optional)

efficiency_store float per unit1.

Efficiency ofstorage on theway into thestorage.

Input (optional)

efficiency_dispatchfloat per unit1.

Efficiency ofstorage on theway out of thestorage.

Input (optional)

standing_loss float per unit0.

Losses perhour to state ofcharge.

Input (optional)

inflow static or series MW0.

Inflow to thestate of charge,e.g. due to riverinflow in hydroreservoir.

Input (optional)

p series MW0.

active power atbus (positive ifnet generation)

Output

q series MVar0.

reactive power(positive if netgeneration)

Output

state_of_charge series MWh NaN State of chargeas calculated bythe OPF.

Output

spill series MW0.

Spillage foreach snapshot.

Output

p_nom_opt float MW0.

Optimised nom-inal power.

Output

5.7. Storage Unit 39

Page 46: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Store

The Store connects to a single bus. It is a more fundamental component for storing energy only (it cannot convertbetween energy carriers). It inherits its energy carrier from the bus to which it is attached.

The Store, Bus and Link are fundamental components with which one can build more complicated components (Gen-erators, Storage Units, CHPs, etc.).

The Store has controls and optimisation on the size of its energy capacity, but not it’s power output; to control the poweroutput, you must put a link in front of it, see the example that replaces generators and storage units with fundamentallinks and stores.

40 Chapter 5. Components

Page 47: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

attribute type unit default description statusname string n/a n/a Unique name Input (required)bus string n/a n/a Name of bus to

which store isattached.

Input (required)

type string n/a n/a Placeholderfor store type.Not yet imple-mented.

Input (optional)

e_nom float MWh0.

Nominal energycapacity.

Input (optional)

e_nom_extendable boolean n/a False Switch to allowcapacity e_nomto be extendedin OPF.

Input (optional)

e_nom_min float MWh0.

If e_nom is ex-tendable in OPF,set its minimumvalue.

Input (optional)

e_nom_max float MWh inf If e_nom is ex-tendable in OPF,set its maximumvalue (e.g. lim-ited by technicalpotential).

Input (optional)

e_min_pu static or series per unit0.

Minimal valueof e relative toe_nom for theOPF.

Input (optional)

e_max_pu static or series per unit1.

Maximal valueof e relative toe_nom for theOPF.

Input (optional)

e_initial float MWh0.

Energy beforethe snapshots inthe OPF.

Input (optional)

e_cyclic boolean n/a False Switch: if True,then e_initial isignored and theinitial energyis set to thefinal energy forthe group ofsnapshots in theOPF.

Input (optional)

p_set static or series MW0.

active power setpoint (for PF)

Input (optional)

q_set static or series MVar0.

reactive powerset point (forPF)

Input (optional)

sign float n/a1.

power sign Input (optional)

marginal_cost static or series currency/MWh0.

Marginal cost ofproduction of 1MWh.

Input (optional)

capital_cost float currency/MWh0.

Capital costof extendinge_nom by 1MWh.

Input (optional)

standing_loss float per unit0.

Losses per hourto energy.

Input (optional)

p series MW0.

active power atbus (positive ifnet generation)

Output

q series MVar0.

reactive power(positive if netgeneration)

Output

e series MWh0.

Energy as cal-culated by theOPF.

Output

e_nom_opt float MW0.

Optimised nom-inal energy ca-pacity outputedby OPF.

Output

5.8. Store 41

Page 48: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Load

The load attaches to a single bus and consumes power as a PQ load.

For loads, if 𝑝 > 0 the load is consuming active power from the bus and if 𝑞 > 0 it is consuming reactive power (i.e.behaving like an inductor).

attribute type unit default description statusname string n/a n/a Unique name Input (required)bus string n/a n/a Name of bus to

which load is at-tached.

Input (required)

type string n/a n/a Placeholderfor load type.Not yet imple-mented.

Input (optional)

p_set static or series MW0.

Active powerconsumption(positive ifthe load isconsumingpower).

Input (optional)

q_set static or series MVar0.

Reactive powerconsumption(positive ifthe load isinductive).

Input (optional)

sign float n/a -1. power sign (op-posite sign togenerator)

Input (optional)

p series MW0.

active power atbus (positive ifnet load)

Output

q series MVar0.

reactive power(positive if netload)

Output

Shunt Impedance

Shunt impedances attach to a single bus and have a voltage-dependent admittance.

For shunt impedances the power consumption is given by 𝑠𝑖 = |𝑉𝑖|2𝑦*𝑖 so that 𝑝𝑖 + 𝑗𝑞𝑖 = |𝑉𝑖|2(𝑔𝑖− 𝑗𝑏𝑖). However thep and q below are defined directly proportional to g and b 𝑝 = |𝑉 |2𝑔 and 𝑞 = |𝑉 |2𝑏, thus if 𝑝 > 0 the shunt impedanceis consuming active power from the bus and if 𝑞 > 0 it is supplying reactive power (i.e. behaving like an capacitor).

42 Chapter 5. Components

Page 49: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

attribute type unit default description statusname string n/a n/a Unique name Input (required)bus string n/a n/a name of bus to

which generatoris attached

Input (required)

g float Siemens0.

Shunt conduc-tivity.

Input (optional)

b float Siemens0.

Shunt suscep-tance.

Input (optional)

sign float n/a -1. power sign (signconvention sothat g>0 with-draws p frombus)

Input (optional)

p series MW0.

active power atbus (positive ifnet load)

Output

q series MVar0.

reactive power(positive if netgeneration)

Output

g_pu float per unit0.

Calculatedfrom g andbus.v_nom.

Output

b_pu float per unit0.

Calculatedfrom b andbus.v_nom.

Output

Line

Lines represent transmission and distribution lines. They connect a bus0 to a bus1. They can connect either AC busesor DC buses. Power flow through lines is not directly controllable, but is determined passively by their impedancesand the nodal power imbalances. To see how the impedances are used in the power flow, see Line model.

attribute type unit default description statusname string n/a n/a Unique name Input (required)bus0 string n/a n/a Name of first

bus to whichbranch is at-tached.

Input (required)

bus1 string n/a n/a Name of sec-ond bus towhich branch isattached.

Input (required)

Continued on next page

5.11. Line 43

Page 50: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.2 – continued from previous pageattribute type unit default description statustype string n/a n/a Name of line

standard type.If this is not anempty string“”, then theline standardtype impedanceparametersare multipliedwith the linelength and di-vided/multipliedby num_parallelto compute x, r,etc. This willoverride anyvalues set in r,x, and b. If thestring is empty,PyPSA willsimply read r, x,etc.

Input (optional)

x float Ohm0.

Series reac-tance; must benon-zero for ACbranch in linearpower flow. Ifthe line has se-ries inductance𝐿 in Henriesthen 𝑥 = 2𝜋𝑓𝐿where 𝑓 is thefrequency inHertz. Seriesimpedance𝑧 = 𝑟+ 𝑗𝑥 mustbe non-zero forthe non-linearpower flow.Ignored if typedefined.

Input (required)

Continued on next page

44 Chapter 5. Components

Page 51: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.2 – continued from previous pageattribute type unit default description statusr float Ohm

0.Series resis-tance; must benon-zero for DCbranch in linearpower flow. Se-ries impedance𝑧 = 𝑟+ 𝑗𝑥 mustbe non-zero forthe non-linearpower flow.Ignored if typedefined.

Input (required)

g float Siemens0.

Shunt conduc-tivity. Shuntadmittance is𝑦 = 𝑔 + 𝑗𝑏.

Input (optional)

b float Siemens0.

Shunt suscep-tance. If theline has shuntcapacitance 𝐶in Farads then𝑏 = 2𝜋𝑓𝐶where 𝑓 is thefrequency inHertz. Shuntadmittance is𝑦 = 𝑔 + 𝑗𝑏.Ignored if typedefined.

Input (optional)

s_nom float MVA0.

Limit of ap-parent powerwhich can passthrough branch.

Input (optional)

s_nom_extendable boolean n/a False Switch to allowcapacity s_nomto be extendedin OPF.

Input (optional)

s_nom_min float MVA0.

If s_nom is ex-tendable in OPF,set its minimumvalue.

Input (optional)

s_nom_max float MVA inf If s_nom is ex-tendable in OPF,set its maximumvalue (e.g. lim-ited by poten-tial).

Input (optional)

Continued on next page

5.11. Line 45

Page 52: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.2 – continued from previous pageattribute type unit default description statuss_max_pu static or series per unit

1.The maximumallowed abso-lute flow perunit of s_nomfor the OPF(e.g. can beset <1 to ap-proximate n-1factor, or canbe time-varyingto representweather-dependentdynamic linerating foroverhead lines).

Input (optional)

capital_cost float currency/MVA0.

Capital costof extendings_nom by 1MVA.

Input (optional)

length float km0.

Length of lineused when“type” is set,also useful forcalculating thecapital cost.

Input (optional)

terrain_factor float per unit1.

Terrain factorfor increasingcapital cost.

Input (optional)

num_parallel float n/a 1 When “type”is set, this isthe number ofparallel lines(can also befractional). If“type” is empty“” this value isignored.

Input (optional)

v_ang_min float Degrees -inf Minimumvoltage an-gle differenceacross the line.This is a place-holder attributeand is not cur-rently used byany PyPSAfunctions.

Input (optional)

Continued on next page

46 Chapter 5. Components

Page 53: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.2 – continued from previous pageattribute type unit default description statusv_ang_max float Degrees inf Maximum

voltage an-gle differenceacross the line.This is a place-holder attributeand is not cur-rently used byany PyPSAfunctions.

Input (optional)

sub_network string n/a n/a Name ofconnectedsub-networkto which linesbelongs. Thisattribute is setby PyPSA inthe function net-work.determine_network_topology();do not set it di-rectly by hand.

Output

p0 series MW0.

Active power atbus0 (positive ifbranch is with-drawing powerfrom bus0).

Output

q0 series MVar0.

Reactive powerat bus0 (positiveif branch iswithdrawingpower frombus0).

Output

p1 series MW0.

Active power atbus1 (positive ifbranch is with-drawing powerfrom bus1).

Output

q1 series MVar0.

Reactive powerat bus1 (positiveif branch iswithdrawingpower frombus1).

Output

x_pu float per unit0.

Per unit se-ries reactancecalculated byPyPSA from xand bus.v_nom.

Output

Continued on next page

5.11. Line 47

Page 54: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.2 – continued from previous pageattribute type unit default description statusr_pu float per unit

0.Per unit se-ries resistancecalculated byPyPSA from rand bus.v_nom

Output

g_pu float per unit0.

Per unit shuntconductivitycalculated byPyPSA from gand bus.v_nom

Output

b_pu float per unit0.

Per unit shuntsusceptancecalculated byPyPSA from band bus.v_nom

Output

x_pu_eff float per unit0.

Effective perunit series reac-tance for linearpower flow,calculated byPyPSA fromx, tap_ratio fortransformersand bus.v_nom.

Output

r_pu_eff float per unit0.

Effective perunit series resis-tance for linearpower flow,calculated byPyPSA fromx, tap_ratio fortransformersand bus.v_nom.

Output

s_nom_opt float MVA0.

Optimisedcapacity forapparent power.

Output

mu_lower series currency/MVA0.

Shadow priceof lower s_nomlimit -F leqf. Alwaysnon-negative.

Output

mu_upper series currency/MVA0.

Shadow priceof upper s_nomlimit f leqF. Alwaysnon-negative.

Output

Line Types

Standard line types with per length values for impedances.

48 Chapter 5. Components

Page 55: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

If for a line the attribute “type” is non-empty, then these values are multiplied with the line length to get the line’selectrical parameters.

The line type parameters in the following table and the implementation in PyPSA are based on pandapower’s standardtypes, whose parameterisation is in turn loosely based on DIgSILENT PowerFactory.

attribute type unit default description statusname string n/a n/a Unique name Input (required)f_nom float Hz

50.Nominal fre-quency

Input (required)

r_per_length float Ohm per km0.

Series resistanceper length

Input (required)

x_per_length float Ohm per km0.

Series resistanceper length

Input (required)

c_per_length float nF per km0.

Shunt capaci-tance per length

Input (optional)

i_nom float kA0.

Nominal current Input (optional)

mounting string n/a ol Can be “ol” foroverhead line or“cs” for cable

Input (optional)

cross_section float mm20.

Wire cross-section

Input (optional)

references string n/a n/a Referencesfor electricalparameters

Input (optional)

If you do not import your own line types, then PyPSA will provide standard types using the following table. This tablewas initially based on pandapower’s standard types and we thank the pandapower team for allowing us to include thisdata. We take no responsibility for the accuracy of the values.

name f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferences149-AL1/24-ST1A10.0

50.0.194 0.315 11.25 0.47 ol 149 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

Continued on next page

5.12. Line Types 49

Page 56: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferences149-AL1/24-ST1A110.0

50.0.194 0.41 8.75 0.47 ol 149 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

149-AL1/24-ST1A20.0

50.0.194 0.337 10.5 0.47 ol 149 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

15-AL1/3-ST1A0.4

50.1.8769 0.35 11 0.105 ol 16 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

Continued on next page

50 Chapter 5. Components

Page 57: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferences184-AL1/30-ST1A110.0

50.0.1571 0.4 8.8 0.535 ol 184 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

184-AL1/30-ST1A20.0

50.0.1571 0.33 10.75 0.535 ol 184 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

24-AL1/4-ST1A0.4

50.1.2012 0.335 11.25 0.14 ol 24 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

Continued on next page

5.12. Line Types 51

Page 58: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferences243-AL1/39-ST1A110.0

50.0.1188 0.39 9 0.645 ol 243 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

243-AL1/39-ST1A20.0

50.0.1188 0.32 11 0.645 ol 243 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

305-AL1/39-ST1A110.0

50.0.0949 0.38 9.2 0.74 ol 305 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

Continued on next page

52 Chapter 5. Components

Page 59: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferences48-AL1/8-ST1A0.4

50.0.5939 0.3 12.2 0.21 ol 48 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

48-AL1/8-ST1A10.0

50.0.5939 0.35 10.1 0.21 ol 48 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

48-AL1/8-ST1A20.0

50.0.5939 0.372 9.5 0.21 ol 48 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

490-AL1/64-ST1A220.0

50.0.059 0.285 10 0.96 ol 490 pandapower

490-AL1/64-ST1A380.0

50.0.059 0.253 11 0.96 ol 490 pandapower

Continued on next page

5.12. Line Types 53

Page 60: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferences94-AL1/15-ST1A0.4

50.0.306 0.29 13.2 0.35 ol 94 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

94-AL1/15-ST1A10.0

50.0.306 0.33 10.75 0.35 ol 94 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

94-AL1/15-ST1A20.0

50.0.306 0.35 10 0.35 ol 94 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013)

Continued on next page

54 Chapter 5. Components

Page 61: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferencesN2XS(FL)2Y1x120RM/3564/110kV

50.0.153 0.166 112 0.366 cs 120 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013);WerthNet-zberech-nung mitErzeu-gungspro-filen

N2XS(FL)2Y1x185RM/3564/110kV

50.0.099 0.156 125 0.457 cs 185 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013);WerthNet-zberech-nung mitErzeu-gungspro-filen

Continued on next page

5.12. Line Types 55

Page 62: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferencesN2XS(FL)2Y1x240RM/3564/110kV

50.0.075 0.149 135 0.526 cs 240 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013);WerthNet-zberech-nung mitErzeu-gungspro-filen

N2XS(FL)2Y1x300RM/3564/110kV

50.0.06 0.144 144 0.588 cs 300 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013);WerthNet-zberech-nung mitErzeu-gungspro-filen

Continued on next page

56 Chapter 5. Components

Page 63: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferencesNA2XS2Y1x185RM/2512/20 kV

50.0.161 0.117 273 0.362 cs 185 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013);WerthNet-zberech-nung mitErzeu-gungspro-filen

NA2XS2Y1x240RM/2512/20 kV

50.0.122 0.112 304 0.421 cs 240 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013);WerthNet-zberech-nung mitErzeu-gungspro-filen

Continued on next page

5.12. Line Types 57

Page 64: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferencesNA2XS2Y1x95RM/2512/20 kV

50.0.313 0.132 216 0.252 cs 95 pandapower;Heuck

et al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013);WerthNet-zberech-nung mitErzeu-gungspro-filen

NAYY4x120 SE 50.

0.225 0.08 264 0.242 cs 120 pandapower;Heucket al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013);WerthNet-zberech-nung mitErzeu-gungspro-filen

Continued on next page

58 Chapter 5. Components

Page 65: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferencesNAYY4x150 SE 50.

0.208 0.08 261 0.27 cs 150 pandapower;Heucket al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013);WerthNet-zberech-nung mitErzeu-gungspro-filen

NAYY4x50 SE 50.

0.642 0.083 210 0.142 cs 50 pandapower;Heucket al.Elek-trischeEn-ergiever-sorgung8. Au-flage(2010);Vier-weg+Teubner(2013);WerthNet-zberech-nung mitErzeu-gungspro-filen

Al/St240/402-bundle220.0

50.0.06 0.301 12.5 1.29 ol 240 Oeding

and Os-wald“Elek-trischeKraftwerkeundNetze”,2011,Chapter 9

Continued on next page

5.12. Line Types 59

Page 66: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.3 – continued from previous pagename f_nom r_per_lengthx_per_lengthc_per_lengthi_nom mounting cross_sectionreferencesAl/St240/403-bundle300.0

50.0.04 0.265 13.2 1.935 ol 240 Oeding

and Os-wald“Elek-trischeKraftwerkeundNetze”,2011,Chapter 9

Al/St240/404-bundle380.0

50.0.03 0.246 13.8 2.58 ol 240 Oeding

and Os-wald“Elek-trischeKraftwerkeundNetze”,2011,Chapter 9

Transformer

Transformers represent 2-winding transformers that convert AC power from one voltage level to another. They connecta bus0 (typically at higher voltage) to a bus1 (typically at lower voltage). Power flow through transformers is notdirectly controllable, but is determined passively by their impedances and the nodal power imbalances. To see howthe impedances are used in the power flow, see Transformer model.

attribute type unit default description statusname string n/a n/a Unique name Input (required)bus0 string n/a n/a Name of first

bus (typicallyhigher volt-age) to whichtransformer isattached.

Input (required)

bus1 string n/a n/a Name of secondbus (typicallylower volt-age) to whichtransformer isattached.

Input (required)

Continued on next page

60 Chapter 5. Components

Page 67: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.4 – continued from previous pageattribute type unit default description statustype string n/a n/a Name of 2-

winding trans-former standardtype. If this isnot an emptystring “”, thenthe transformertype impedanceparameters aretaken fromthe standardtype along with“num_parallel”.This will over-ride any valuesset in r, x,g, b, s_nom,tap_ratio,tap_side andphase_shift. Ifthe string isempty, PyPSAwill simply readr, x, etc.

Input (optional)

model string n/a t Model used foradmittance ma-trix; can be “t”or “pi”; sincePyPSA Version0.8.0 it defaultsto “t” followingphysics andDIgSILENTPowerFactory;versions ofPyPSA before0.8.0 and someother power sys-tem tools, likeMATPOWER,PYPOWER,PSS/SINCALuse the lessphysical “pi”model.

Input (required)

Continued on next page

5.13. Transformer 61

Page 68: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.4 – continued from previous pageattribute type unit default description statusx float per unit

0.Series reactance(per unit, usings_nom as basepower); must benon-zero for ACbranch in linearpower flow. Se-ries impedance𝑧 = 𝑟+ 𝑗𝑥 mustbe non-zero forthe non-linearpower flow.Ignored if typedefined.

Input (required)

r float per unit0.

Series resis-tance (per unit,using s_nom asbase power);must be non-zero for DCbranch in linearpower flow. Se-ries impedance𝑧 = 𝑟+ 𝑗𝑥 mustbe non-zero forthe non-linearpower flow.Ignored if typedefined.

Input (required)

g float per unit0.

Shunt conduc-tivity (per unit,using s_nom asbase power).Ignored if typedefined.

Input (optional)

b float per unit0.

Shunt suscep-tance (per unit,using s_nom asbase power).Ignored if typedefined.

Input (optional)

s_nom float MVA0.

Limit of ap-parent powerwhich can passthrough branch.

Input (optional)

s_nom_extendable boolean n/a False Switch to allowcapacity s_nomto be extendedin OPF.

Input (optional)

Continued on next page

62 Chapter 5. Components

Page 69: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.4 – continued from previous pageattribute type unit default description statuss_nom_min float MVA

0.If s_nom is ex-tendable in OPF,set its minimumvalue.

Input (optional)

s_nom_max float MVA inf If s_nom is ex-tendable in OPF,set its maximumvalue (e.g. lim-ited by poten-tial).

Input (optional)

s_max_pu static or series per unit1.

The maximumallowed abso-lute flow perunit of s_nomfor the OPF.

Input (optional)

capital_cost float currency/MVA0.

Capital costof extendings_nom by 1MVA.

Input (optional)

num_parallel float n/a 1 When “type” isset, this is thenumber of par-allel transform-ers (can also befractional). If“type” is empty“” this value isignored.

Input (optional)

tap_ratio float per unit1.

Ratio of perunit voltagesat each bus fortap changed.Ignored if typedefined.

Input (optional)

tap_side int n/a 0 Defines if tapchanger ismodelled atthe primary 0side (usuallyhigh-voltage) orthe secondary1 side (usuallylow voltage)(must be 0 or 1,defaults to 0).Ignored if typedefined.

Input (optional)

Continued on next page

5.13. Transformer 63

Page 70: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.4 – continued from previous pageattribute type unit default description statustap_position int n/a 0 If the trans-

former has atype, determinesposition relativeto the neutraltap position.

Input (optional)

phase_shift float Degrees0.

Voltage phaseangle shift.Ignored if typedefined.

Input (optional)

v_ang_min float Degrees -inf Minimumvoltage an-gle differenceacross the trans-former. This is aplaceholder at-tribute and is notcurrently usedby any PyPSAfunctions.

Input (optional)

v_ang_max float Degrees inf Maximumvoltage an-gle differenceacross the trans-former. This is aplaceholder at-tribute and is notcurrently usedby any PyPSAfunctions.

Input (optional)

sub_network string n/a n/a Name ofconnected sub-network towhich trans-former belongs.This attribute isset by PyPSA inthe function net-work.determine_network_topology();do not set it di-rectly by hand.

Output

p0 series MW0.

Active power atbus0 (positive ifbranch is with-drawing powerfrom bus0).

Output

Continued on next page

64 Chapter 5. Components

Page 71: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.4 – continued from previous pageattribute type unit default description statusq0 series MVar

0.Reactive powerat bus0 (positiveif branch iswithdrawingpower frombus0).

Output

p1 series MW0.

Active power atbus1 (positive ifbranch is with-drawing powerfrom bus1).

Output

q1 series MVar0.

Reactive powerat bus1 (positiveif branch iswithdrawingpower frombus1).

Output

x_pu float per unit0.

Per unit se-ries reactancecalculated byPyPSA from xand bus.v_nom.

Output

r_pu float per unit0.

Per unit se-ries resistancecalculated byPyPSA from rand bus.v_nom

Output

g_pu float per unit0.

Per unit shuntconductivitycalculated byPyPSA from gand bus.v_nom

Output

b_pu float per unit0.

Per unit shuntsusceptancecalculated byPyPSA from band bus.v_nom

Output

x_pu_eff float per unit0.

Effective perunit series reac-tance for linearpower flow,calculated byPyPSA fromx, tap_ratio fortransformersand bus.v_nom.

Output

Continued on next page

5.13. Transformer 65

Page 72: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Table 5.4 – continued from previous pageattribute type unit default description statusr_pu_eff float per unit

0.Effective perunit series resis-tance for linearpower flow,calculated byPyPSA fromx, tap_ratio fortransformersand bus.v_nom.

Output

s_nom_opt float MVA0.

Optimisedcapacity forapparent power.

Output

mu_lower series currency/MVA0.

Shadow priceof lower s_nomlimit -F leqf. Alwaysnon-negative.

Output

mu_upper series currency/MVA0.

Shadow priceof upper s_nomlimit f leqF. Alwaysnon-negative.

Output

Transformer Types

Standard 2-winding transformer types.

If for a transformer the attribute “type” is non-empty, then these values are used for the transformer’s electrical param-eters.

The transformer type parameters in the following table and the implementation in PyPSA are based on pandapower’sstandard types, whose parameterisation is in turn loosely based on DIgSILENT PowerFactory.

66 Chapter 5. Components

Page 73: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

attribute type unit default description statusname string n/a n/a Unique name Input (required)f_nom float Hz

50.Nominal fre-quency

Input (required)

s_nom float MVA0.

Rated apparentpower

Input (required)

v_nom_0 float kV0.

Nominal volt-age on highvoltage side

Input (required)

v_nom_1 float kV0.

Nominal volt-age on lowvoltage side

Input (required)

vsc float Percent0.

Short circuitvoltage

Input (required)

vscr float Percent0.

Real part ofshort circuitvoltage

Input (required)

pfe float kW0.

No load (opencircuit) ironlosses

Input (required)

i0 float Percent0.

No load (opencircuit) current

Input (required)

phase_shift float Degrees0.

Phase shift an-gle

Input (required)

tap_side int n/a 0 Defines if tapchanger ismodelled atthe primary 0side (usuallyhigh-voltage) orthe secondary1 side (usuallylow voltage)(must be 0 or 1,defaults to 0)

Input (required)

tap_neutral int n/a 0 rated tap posi-tion, i.e. po-sition at whichthe winding ra-tio correspondsto the ratio ofthe rated volt-ages

Input (required)

tap_min int n/a 0 minimum tapposition

Input (required)

tap_max int n/a 0 maximum tapposition

Input (required)

tap_step float Percent0.

tap step size inpercentage ofvoltage change

Input (required)

references string n/a n/a Referencesfor electricalparameters

Input (optional)

5.14. Transformer Types 67

Page 74: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

If you do not import your own transformer types, then PyPSA will provide standard types using the following table.This table was initially based on pandapower’s standard types and we thank the pandapower team for allowing us toinclude this data. We take no responsibility for the accuracy of the values.

68 Chapter 5. Components

Page 75: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

name f_nom s_nomv_nom_0v_nom_1vsc vscr pfe i0 phase_shifttap_sidetap_neutraltap_mintap_maxtap_stepreferences0.25MVA10/0.4kV

50.0.250 10 0.4 4 1.2 0.6 0.24 150 0 0 -2 2 2.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

0.25MVA20/0.4kV

50.0.250 20 0.4 6 1.44 0.8 0.32 150 0 0 -2 2 2.5 pandapowe;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filenr

0.4MVA10/0.4kV

50.0.400 10 0.4 4 1.325 0.95 0.2375 150 0 0 -2 2 2.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

0.4MVA20/0.4kV

50.0.400 20 0.4 6 1.425 1.35 0.3375 150 0 0 -2 2 2.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

0.63MVA10/0.4kV

50.0.630 10 0.4 4 1.0794 1.18 0.1873 150 0 0 -2 2 2.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

0.63MVA20/0.4kV

50.0.630 20 0.4 6 1.206 1.65 0.2619 150 0 0 -2 2 2.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

100MVA220/110kV

50.100.0 220.0 110.0 12.0 0.26 55 0.06 0 0 0 -9 9 1.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

160MVA380/110kV

50.160.0 380.0 110.0 12.2 0.25 60 0.06 0 0 0 -9 9 1.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

25MVA110/10kV

50. 25.110 10 10.04 0.276 28.51 0.073 150 0 0 -9 9 1.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

25MVA110/20kV

50. 25.110.0 20.0 11.2 0.282 29 0.071 150 0 0 -9 9 1.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

40MVA110/10kV

50. 40.110 10 10.04 0.295 30.45 0.076 150 0 0 -9 9 1.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

40MVA110/20kV

50. 40.110.0 20.0 11.2 0.302 31 0.08 150 0 0 -9 9 1.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

63MVA110/10kV

50. 63.110 10 10.04 0.31 31.51 0.078 150 0 0 -9 9 1.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

63MVA110/20kV

50. 63.110.0 20.0 11.2 0.322 33 0.086 150 0 0 -9 9 1.5 pandapower;Oswald

-Trans-for-ma-toren-Vor-lesungsskriptElek-trischeEn-ergiev-er-sorgungI;WerthNet-zberech-nungmitErzeu-gungspro-filen

5.14. Transformer Types 69

Page 76: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Link

The Link is a component introduced in PyPSA 0.5.0 for controllable directed flows between two buses bus0 andbus1 with arbitrary energy carriers. It can have an efficiency loss and a marginal cost; for this reason its default set-tings allow only for power flow in one direction, from bus0 to bus1 (i.e. p_min_pu = 0). To build a bidirectionallossless link, set efficiency = 1, marginal_cost = 0 and p_min_pu = -1.

The Link component can be used for any element with a controllable power flow: a bidirectional point-to-pointHVDC link, a unidirectional lossy HVDC link, a converter between an AC and a DC network, a heat pump or resistiveheater from an AC/DC bus to a heat bus, etc.

NB: Link has replaced the Converter component for linking AC with DC buses and the TransportLinkcomponent for providing controllable flows between AC buses. If you want to replace Converter andTransportLink components in your old code, use the Link with efficiency = 1, marginal_cost =0, p_min_pu = -1, p_max_pu = 1 and p_nom* = s_nom*.

70 Chapter 5. Components

Page 77: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

attribute type unit default description statusname string n/a n/a Unique name Input (required)bus0 string n/a n/a Name of first

bus to whichlink is attached.

Input (required)

bus1 string n/a n/a Name of secondbus to whichlink is attached.

Input (required)

type string n/a n/a Placeholderfor link type.Not yet imple-mented.

Input (optional)

efficiency static or series per unit1.

Efficiency ofpower transferfrom bus0 tobus1. (Can betime-dependentto representtemperature-dependentCoefficient ofPerformanceof a heat pumpfrom an electricto a heat bus.)

Input (optional)

p_nom float MVA0.

Limit of ac-tive powerwhich can passthrough link.

Input (optional)

p_nom_extendable boolean n/a False Switch to allowcapacity p_nomto be extendedin OPF.

Input (optional)

p_nom_min float MVA0.

If p_nom is ex-tendable in OPF,set its minimumvalue.

Input (optional)

p_nom_max float MVA inf If p_nom is ex-tendable in OPF,set its maximumvalue (e.g. lim-ited by poten-tial).

Input (optional)

p_set static or series MW0.

The dispatch setpoint for p0 ofthe link in PF.

Input (optional)

p_min_pu static or series per unit ofp_nom 0.

Minimal dis-patch (can alsobe negative) perunit of p_nomfor the link inOPF.

Input (optional)

p_max_pu static or series per unit ofp_nom 1.

Maximal dis-patch (can alsobe negative) perunit of p_nomfor the link inOPF.

Input (optional)

capital_cost float currency/MW0.

Capital costof extendingp_nom by 1MW.

Input (optional)

marginal_cost static or series currency/MWh0.

Marginal costof transfering1 MWh (be-fore efficiencylosses) frombus0 to bus1.NB: marginalcost only makessense in OPF ifp_max_pu >= 0.

Input (optional)

length float km0.

Length of line,useful for calcu-lating the capitalcost.

Input (optional)

terrain_factor float per unit1.

Terrain factorfor increasingcapital cost.

Input (optional)

p0 series MW0.

Active power atbus0 (positive ifbranch is with-drawing powerfrom bus0).

Output

p1 series MW0.

Active power atbus1 (positive ifbranch is with-drawing powerfrom bus1).

Output

p_nom_opt float MVA0.

Optimised ca-pacity for activepower.

Output

mu_lower series currency/MVA0.

Shadow priceof lower p_nomlimit -F leqf. Alwaysnon-negative.

Output

mu_upper series currency/MVA0.

Shadow priceof upper p_nomlimit f leqF. Alwaysnon-negative.

Output

5.15. Link 71

Page 78: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Link with multiple outputs or inputs

Links can also be defined with multiple outputs in fixed ratio to the power in the single input by defining new columnsbus2, bus3, etc. (bus followed by an integer) in network.links along with associated columns for the efficien-cies efficiency2, efficiency3, etc. The different outputs are then proportional to the input according to theefficiency; see Controllable branch flows: links for how these are used in the LOPF and the example of a CHP with afixed power-heat ratio.

To define the new columns bus2, efficiency2, bus3, efficiency3, etc. in network.links you need tooverride the standard component attributes by passing pypsa.Network() an override_component_attrsargument. See the section Custom Components and the example of a CHP with a fixed power-heat ratio.

If the column bus2 exists, values in the column are not compulsory for all links; if the link has no 2nd output, simplyleave it empty network.links.at["my_link","bus2"] = "".

For links with multiple inputs in fixed ratio to a single output, simply reverse the flow in a link with one input andmultiple outputs by setting my_link.p_max_pu = 0 and my_link.p_min_pu = -1.

For multiple inputs to multiple outputs, connect a multi-to-single link to a single-to-multi link with an auxiliary bus inthe middle.

Groups of Components

In the code components are grouped according to their properties in sets such as network.one_port_components and network.branch_components.

One-ports share the property that they all connect to a single bus, i.e. generators, loads, storage units, etc.. They sharethe attributes bus, p_set, q_set, p, q.

Branches connect two buses. A copy of their attributes can be accessed as a group by the function network.branches(). They share the attributes bus0, bus1.

Passive branches are branches whose power flow is not directly controllable, but is determined passively by theirimpedances and the nodal power imbalances, i.e. lines and transformers.

Controllable branches are branches whose power flow can be controlled by e.g. the LOPF optimisation, i.e. links.

Custom Components

If you want to define your own components and override the standard functionality of PyPSA, you can eas-ily override the standard components by passing pypsa.Network() the arguments override_components andoverride_component_attrs.

For this network, these will replace the standard definitions in pypsa.components.components and pypsa.components.component_attrs, which correspond to the repository CSV files pypsa/components.csvand pypsa/component_attrs/*.csv.

components is a pandas.DataFrame with the component name, list_name and description.component_attrs is a pypsa.descriptors.Dict of pandas.DataFrame with the attribute properties for each com-ponent. Just follow the formatting for the standard components.

There are examples for defining new components in the git repository in examples/new_components/, includ-ing an example of overriding e.g. network.lopf() for functionality for combined-heat-and-power (CHP) plants.

72 Chapter 5. Components

Page 79: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

SIX

DATA IMPORT AND EXPORT

PyPSA is intended to be data format agnostic, but given the reliance internally on pandas DataFrames, it is natural touse comma-separated-variable (CSV) files.

The import-export functionality can be found in pypsa/io.py.

Import from folder of CSV files

Create a folder with CSVs for each component type (e.g. generators.csv, storage_units.csv), then aCSV for each time-dependent variable (e.g. generators-p_max_pu.csv, loads-p_set.csv).

Then run

network.import_from_csv_folder(csv_folder_name)

See the Examples in pypsa/examples/.

Note that is is NOT necessary to add every single column, only those where values differ from the defaults listed inComponents. All empty values/columns are filled with the defaults.

Export to folder of CSV files

The network can be exported as a folder of csv files:

network.export_to_csv_folder(csv_folder_name)

If the folder does not exist it will be created.

All non-default static and series attributes of all components will be exported.

Static attributes are exported in one CSV file per component, e.g. generators.csv.

Series attributes are exported in one CSV file per component per attribute, e.g. generators-p_set.csv.

Adding components one-by-one

Networks can also be built “manually” in code by calling

network.add(class_name, name, **kwargs)

where class_name is for example "Line","Bus","Generator","StorageUnit and name is the uniquename of the component. Other attributes can also be specified:

73

Page 80: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

network.add("Bus","my_bus_0")network.add("Bus","my_bus_1",v_nom=380)network.add("Line","my_line_name",bus0="my_bus_0",bus1="my_bus_1",length=34,r=2,x=4)

Any attributes which are not specified will be given the default value from Components.

This method is slow for many components; instead use madd or import_components_from_dataframe (seebelow).

Adding multiple components

Multiple components can be added by calling

network.madd(class_name, names, **kwargs)

where class_name is for example "Line","Bus","Generator","StorageUnit and names is a list ofunique names of the components. Other attributes can also be specified as scalars, lists, arrays, pandas Series or pandasDataFrames.

Make sure when adding static attributes as pandas Series that they are indexed by names. Make sure when addingtime-varying attributes as pandas DataFrames that their index is a superset of network.snapshots and their columns area subset of names.

import pandas as pd, numpy as np

buses = range(13)snapshots = range(7)

n = pypsa.Network()

n.set_snapshots(snapshots)

n.madd("Bus",buses)

#add load as numpy arrayn.madd("Load",

n.buses.index + " load",bus=buses,p_set=np.random.rand(len(snapshots),len(buses)))

#add wind availability as pandas DataFramewind = pd.DataFrame(np.random.rand(len(snapshots),len(buses)),

index=n.snapshots,columns=buses)

#use a suffix to avoid boilerplate to rename everythingn.madd("Generator",

buses,suffix=' wind',bus=buses,p_nom_extendable=True,capital_cost=1e5,p_max_pu=wind)

Any attributes which are not specified will be given the default value from Components.

74 Chapter 6. Data Import and Export

Page 81: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Adding components using pandas DataFrames

To add multiple components whose static attributes are given in a pandas DataFrame, use

network.import_components_from_dataframe(dataframe, cls_name)

dataframe is a pandas DataFrame whose index is the names of the components and whose columns are the non-default attributes. cls_name is the component name, e.g. "Line","Bus","Generator","StorageUnit.If columns are missing then defaults are used. If extra columns are added, these are left in the resulting componentDataFrame.

import pandas as pd

buses = ['Berlin', 'Frankfurt', 'Munich', 'Hamburg']

network.import_components_from_dataframe(pd.DataFrame({"v_nom" : 380,"control" : 'PV'},

index=buses),"Bus")

network.import_components_from_dataframe(pd.DataFrame({"carrier" : "solar","bus" : buses,"p_nom_extendable" : True,"capital_cost" : 6e4},

index=[b+" PV" for b in buses]),"Generator")

To import time-varying information use

network.import_series_from_dataframe(dataframe, cls_name, attr)

cls_name is the component name, attr is the time-varying attribute and dataframe is a pandas DataFramewhose index is network.snapshots and whose columns are a subset of the relevant components.

Following the previous example:

import numpy as np

network.set_snapshots(range(10))network.import_series_from_dataframe(pd.DataFrame(np.random.rand(10,4),

columns=network.generators.index,index=range(10)),

"Generator","p_max_pu")

Export to netCDF

Export network and components to a netCDF file.

netCDF files take up less space than CSV files and are faster to load.

netCDF is also preferred over HDF5 because netCDF is structured more cleanly, is easier to use from other program-ming languages, can limit float precision to save space and supports lazy loading.

Both static and series attributes of components are exported, but only if they have non-default values.

network.export_to_netcdf(file.nc)

If file.nc does not already exist, it is created.

6.5. Adding components using pandas DataFrames 75

Page 82: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Import from netCDF

Import network data from netCDF file file.nc:

network.import_from_hdf5(file.nc)

Export to HDF5

Export network and components to an HDF store.

NB: netCDF is preferred over HDF5 because netCDF is structured more cleanly, is easier to use from other program-ming languages, can limit float precision to save space and supports lazy loading.

Both static and series attributes of components are exported, but only if they have non-default values.

network.export_to_hdf5(path)

If path does not already exist, it is created.

Import from HDF5

Import network data from HDF5 store at path:

network.import_from_hdf5(path)

Import from Pypower

PyPSA supports import from Pypower’s ppc dictionary/numpy.array format version 2.

from pypower.api import case30

ppc = case30()

network.import_from_pypower_ppc(ppc)

76 Chapter 6. Data Import and Export

Page 83: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

SEVEN

POWER FLOW

See the module pypsa.pf.

Full non-linear power flow

The non-linear power flow network.pf() works for AC networks and by extension for DC networks too (with awork-around described below).

The non-linear power flow network.pf() can be called for a particular snapshot as network.pf(snapshot) or on an iterable of snapshots as network.pf(snapshots) to calculate the non-linearpower flow on a selection of snapshots at once (which is more performant than calling network.pf on each snap-shot separately). If no argument is passed, it will be called on all network.snapshots.

Non-linear power flow for AC networks

The power flow ensures for given inputs (load and power plant dispatch) that the following equation is satisfied foreach bus 𝑖:

𝑆𝑖 = 𝑃𝑖 + 𝑗𝑄𝑖 = 𝑉𝑖𝐼*𝑖 = 𝑉𝑖

⎛⎝∑︁𝑗

𝑌𝑖𝑗𝑉𝑗

⎞⎠*

where 𝑉𝑖 = |𝑉𝑖|𝑒𝑗𝜃𝑖 is the complex voltage, whose rotating angle is taken relative to the slack bus.

𝑌𝑖𝑗 is the bus admittance matrix, based on the branch impedances and any shunt admittances attached to the buses.

For the slack bus 𝑖 = 0 it is assumed |𝑉0| is given and that 𝜃0 = 0; P and Q are to be found.

For the PV buses, P and |𝑉 | are given; Q and 𝜃 are to be found.

For the PQ buses, P and Q are given; |𝑉 | and 𝜃 are to be found.

If PV and PQ are the sets of buses, then there are |𝑃𝑉 | + 2|𝑃𝑄| real equations to solve:

Re

⎡⎣𝑉𝑖

⎛⎝∑︁𝑗

𝑌𝑖𝑗𝑉𝑗

⎞⎠*⎤⎦− 𝑃𝑖 = 0 ∀ 𝑖 ∈ 𝑃𝑉 ∪ 𝑃𝑄

Im

⎡⎣𝑉𝑖

⎛⎝∑︁𝑗

𝑌𝑖𝑗𝑉𝑗

⎞⎠*⎤⎦−𝑄𝑖 = 0 ∀ 𝑖 ∈ 𝑃𝑄

To be found: 𝜃𝑖∀𝑖 ∈ 𝑃𝑉 ∪ 𝑃𝑄 and |𝑉𝑖|∀𝑖 ∈ 𝑃𝑄.

77

Page 84: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

These equations 𝑓(𝑥) = 0 are solved using the Newton-Raphson method, with the Jacobian:

𝜕𝑓

𝜕𝑥=

(︃𝜕𝑃𝜕𝜃

𝜕𝑃𝜕|𝑉 |

𝜕𝑄𝜕𝜃

𝜕𝑄𝜕|𝑉 |

)︃

and the initial “flat” guess of 𝜃𝑖 = 0 and |𝑉𝑖| = 1 for unknown quantities.

Line model

Lines are modelled with the standard equivalent PI model. In the future a model with distributed parameters may beadded.

If the series impedance is given by

𝑧 = 𝑟 + 𝑗𝑥

and the shunt admittance is given by

𝑦 = 𝑔 + 𝑗𝑏

then the currents and voltages at buses 0 and 1 for a line:

are related by (︂𝑖0𝑖1

)︂=

(︂1𝑧 + 𝑦

2 − 1𝑧

− 1𝑧

1𝑧 + 𝑦

2

)︂(︂𝑣0𝑣1

)︂

78 Chapter 7. Power Flow

Page 85: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Transformer model

The transformer models here are largely based on the implementation in pandapower, which is loosely based onDIgSILENT PowerFactory.

Transformers are modelled either with the equivalent T model (the default, since this represents the physics better) orwith the equivalent PI model. The can be controlled by setting transformer attribute model to either t or pi.

The tap changer can either be modelled on the primary, high voltage side 0 (the default) or on the secondary, lowvoltage side 1. This is set with attribute tap_side.

If the transformer type is not given, then tap_ratio is defined by the user, defaulting to 1.. If the type is given,then the user can specify the tap_position which results in a tap ratio 𝜏 given by:

𝜏 = 1 + (tap_position − tap_neutral) · tap_step100

For a transformer with tap ratio 𝜏 on the primary side tap_side = 0 and phase shift 𝜃shift, the equivalent T modelis given by:

For a transformer with tap ratio 𝜏 on the secondary side tap_side = 1 and phase shift 𝜃shift, the equivalent T modelis given by:

7.1. Full non-linear power flow 79

Page 86: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

For the admittance matrix, the T model is transformed into a PI model with the wye-delta transformation.

For a transformer with tap ratio 𝜏 on the primary side tap_side = 0 and phase shift 𝜃shift, the equivalent PI modelis given by:

for which the currents and voltages are related by:(︂𝑖0𝑖1

)︂=

(︂1𝑧 + 𝑦

2 − 1𝑧

1𝜏𝑒−𝑗𝜃

− 1𝑧

1𝜏𝑒𝑗𝜃

(︀1𝑧 + 𝑦

2

)︀1𝜏2

)︂(︂𝑣0𝑣1

)︂For a transformer with tap ratio 𝜏 on the secondary side tap_side = 1 and phase shift 𝜃shift, the equivalent PImodel is given by:

80 Chapter 7. Power Flow

Page 87: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

for which the currents and voltages are related by:(︂𝑖0𝑖1

)︂=

(︂ (︀1𝑧 + 𝑦

2

)︀1𝜏2 − 1

𝑧1

𝜏𝑒−𝑗𝜃

− 1𝑧

1𝜏𝑒𝑗𝜃

1𝑧 + 𝑦

2

)︂(︂𝑣0𝑣1

)︂

Non-linear power flow for DC networks

For meshed DC networks the equations are a special case of those for AC networks, with the difference that allquantities are real.

To solve the non-linear equations for a DC network, ensure that the series reactance 𝑥 and shunt susceptance 𝑏 arezero for all branches, pick a Slack bus (where 𝑉0 = 1) and set all other buses to be ‘PQ’ buses. Then executenetwork.pf().

The voltage magnitudes then satisfy at each bus 𝑖:

𝑃𝑖 = 𝑉𝑖𝐼𝑖 = 𝑉𝑖

∑︁𝑗

𝐺𝑖𝑗𝑉𝑗

where all quantities are real.

𝐺𝑖𝑗 is based only on the branch resistances and any shunt conductances attached to the buses.

Inputs

For the non-linear power flow, the following data for each component are used. For almost all values, defaults areassumed if not explicitly set. For the defaults and units, see Components.

bus.{v_nom, v_mag_pu_set (if PV generators are attached)}

load.{p_set, q_set}

generator.{control, p_set, q_set (for control PQ)}

storage_unit.{control, p_set, q_set (for control PQ)}

store.{p_set, q_set}

7.1. Full non-linear power flow 81

Page 88: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

shunt_impedance.{b, g}

line.{x, r, b, g}

transformer.{x, r, b, g}

link.{p_set}

Note that the control strategy for active and reactive power PQ/PV/Slack is set on the generators NOT on the buses.Buses then inherit the control strategy from the generators attached at the bus (defaulting to PQ if there is no generatorattached). Any PV generator will make the whole bus a PV bus. For PV buses, the voltage magnitude set point is seton the bus, not the generator, with bus.v_mag_pu_set since it is a bus property.

Note that for lines and transformers you MUST make sure that 𝑟+𝑗𝑥 is non-zero, otherwise the bus admittance matrixwill be singular.

Outputs

bus.{v_mag_pu, v_ang, p, q}

load.{p, q}

generator.{p, q}

storage_unit.{p, q}

store.{p, q}

shunt_impedance.{p, q}

line.{p0, q0, p1, q1}

transformer.{p0, q0, p1, q1}

link.{p0, p1}

Linear power flow

The linear power flow network.lpf() can be called for a particular snapshot as network.lpf(snapshot)or on an iterable of snapshots as network.lpf(snapshots) to calculate the non-linear power flow on aselection of snapshots at once (which is more performant than calling network.lpf on each snapshot separately).If no argument is passed, it will be called on all network.snapshots.

For AC networks, it is assumed for the linear power flow that reactive power decouples, there are no voltage magnitudevariations, voltage angles differences across branches are small and branch resistances are much smaller than branchreactances (i.e. it is good for overhead transmission lines).

For AC networks, the linear load flow is calculated using small voltage angle differences and the series reactancesalone.

It is assumed that the active powers 𝑃𝑖 are given for all buses except the slack bus and the task is to find the voltageangles 𝜃𝑖 at all buses except the slack bus, where it is assumed 𝜃0 = 0.

To find the voltage angles, the following linear set of equations are solved

𝑃𝑖 =∑︁𝑗

(𝐾𝐵𝐾𝑇 )𝑖𝑗𝜃𝑗 −∑︁𝑙

𝐾𝑖𝑙𝑏𝑙𝜃shift𝑙

where 𝐾 is the incidence matrix of the network, 𝐵 is the diagonal matrix of inverse branch series reactances 𝑥𝑙

multiplied by the tap ratio 𝜏𝑙, i.e. 𝐵𝑙𝑙 = 𝑏𝑙 = 1𝑥𝑙𝜏𝑙

and 𝜃shift𝑙 is the phase shift for a transformer. The matrix 𝐾𝐵𝐾𝑇

82 Chapter 7. Power Flow

Page 89: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

is singular with a single zero eigenvalue for a connected network, therefore the row and column corresponding to theslack bus is deleted before inverting.

The flows p0 in the network branches at bus0 can then be found by multiplying by the transpose incidence matrixand inverse series reactances:

𝐹𝑙 =∑︁𝑖

(𝐵𝐾𝑇 )𝑙𝑖𝜃𝑖 − 𝑏𝑙𝜃shift𝑙

For DC networks, it is assumed for the linear power flow that voltage magnitude differences across branches are allsmall.

For DC networks, the linear load flow is calculated using small voltage magnitude differences and series resistancesalone.

The linear load flow for DC networks follows the same calculation as for AC networks, but replacing the voltageangles by the difference in voltage magnitude 𝛿𝑉𝑛,𝑡 and the series reactance by the series resistance 𝑟𝑙.

Inputs

For the linear power flow, the following data for each component are used. For almost all values, defaults are assumedif not explicitly set. For the defaults and units, see Components.

bus.{v_nom}

load.{p_set}

generator.{p_set}

storage_unit.{p_set}

store.{p_set}

shunt_impedance.{g}

line.{x}

transformer.{x}

link.{p_set}

Note that for lines and transformers you MUST make sure that 𝑥 is non-zero, otherwise the bus admittance matrix willbe singular.

Outputs

bus.{v_mag_pu, v_ang, p}

load.{p}

generator.{p}

storage_unit.{p}

store.{p}

shunt_impedance.{p}

line.{p0, p1}

transformer.{p0, p1}

link.{p0, p1}

7.2. Linear power flow 83

Page 90: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

84 Chapter 7. Power Flow

Page 91: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

EIGHT

OPTIMAL POWER FLOW

See the module pypsa.opf.

Non-Linear Optimal Power Flow

Optimisation with the full non-linear power flow equations is not yet supported.

Linear Optimal Power Flow

Optimisation with the linearised power flow equations for (mixed) AC and DC networks is fully supported.

All constraints and variables are listed below.

Overview

Execute:

network.lopf(snapshots, solver_name="glpk", solver_io=None,extra_functionality=None, solver_options={}, keep_files=False,formulation="angles")

where snapshots is an iterable of snapshots, solver_name is a string, e.g. “gurobi” or “glpk”, solver_iois a string, extra_functionality is a function of network and snapshots that is called before the solver (seebelow), solver_options is a dictionary of flags to pass to the solver, keep_files means that the .lp file issaved and formulation is a string in ["angles","cycles","kirchhoff","ptdf"] (see Passive branchflow formulations for more details).

The linear OPF module can optimises the dispatch of generation and storage and the capacities of generation, storageand transmission.

It is assumed that the load is inelastic and must be met in every snapshot (this will be relaxed in future versions).

The optimisation currently uses continuous variables for most functionality; unit commitment with binary variables isalso implemented for generators.

The objective function is the total system cost for the snapshots optimised.

Each snapshot can be given a weighting 𝑤𝑡 to represent e.g. multiple hours.

This set-up can also be used for stochastic optimisation, if you interpret the weighting as a probability.

Each transmission asset has a capital cost.

85

Page 92: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Each generation and storage asset has a capital cost and a marginal cost.

WARNING: If the transmission capacity is changed in passive networks, then the impedance will also change (i.e. ifparallel lines are installed). This is NOT reflected in the LOPF, so the network equations may no longer be valid. Notealso that all the expansion is continuous.

Optimising dispatch only: a market model

Capacity optimisation can be turned off so that only the dispatch is optimised, like a short-run electricity market model.

For simplified transmission representation using Net Transfer Capacities (NTCs), there is a Link component whichdoes controllable power flow like a transport model (and can also represent a point-to-point HVDC link).

Optimising total annual system costs

To minimise long-run annual system costs for meeting an inelastic electrical load, capital costs for transmission andgeneration should be set to the annualised investment costs in e.g. EUR/MW/a, marginal costs for dispatch to e.g.EUR/MWh and the weightings (now with units hours per annum, h/a) are chosen such that∑︁

𝑡

𝑤𝑡 = 8760

In this case the objective function gives total system cost in EUR/a to meet the total load.

Stochastic optimisation

For the very simplest stochastic optimisation you can use the weightings w_t as probabilities for the snapshots, whichcan represent different load/weather conditions. More sophisticated functionality is planned.

Variables and notation summary

𝑛 ∈ 𝑁 = {0, . . . |𝑁 | − 1} label the buses

𝑡 ∈ 𝑇 = {0, . . . |𝑇 | − 1} label the snapshots

𝑙 ∈ 𝐿 = {0, . . . |𝐿| − 1} label the branches

𝑠 ∈ 𝑆 = {0, . . . |𝑆| − 1} label the different generator/storage types at each bus

𝑤𝑡 weighting of time 𝑡 in the objective function

𝑔𝑛,𝑠,𝑡 dispatch of generator 𝑠 at bus 𝑛 at time 𝑡

𝑔𝑛,𝑠 nominal power of generator 𝑠 at bus 𝑛

𝑔𝑛,𝑠,𝑡 availability of generator 𝑠 at bus 𝑛 at time 𝑡 per unit of nominal power

𝑢𝑛,𝑠,𝑡 binary status variable for generator with unit commitment

𝑠𝑢𝑐𝑛,𝑠,𝑡 start-up cost if generator with unit commitment is started at time 𝑡

𝑠𝑑𝑐𝑛,𝑠,𝑡 shut-down cost if generator with unit commitment is shut down at time 𝑡

𝑐𝑛,𝑠 capital cost of extending generator nominal power by one MW

𝑜𝑛,𝑠 marginal cost of dispatch generator for one MWh

𝑓𝑙,𝑡 flow of power in branch 𝑙 at time 𝑡

86 Chapter 8. Optimal Power Flow

Page 93: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

𝐹𝑙 capacity of branch 𝑙

𝜂𝑛,𝑠 efficiency of generator 𝑠 at bus 𝑛

𝜂𝑙 efficiency of controllable link 𝑙

𝑒𝑠 CO2-equivalent-tonne-per-MWh of the fuel carrier 𝑠

Further definitions are given below.

Objective function

See pypsa.opf.define_linear_objective(network,snapshots).

The objective function is composed of capital costs 𝑐 for each component and operation costs 𝑜 for generators∑︁𝑛,𝑠

𝑐𝑛,𝑠𝑔𝑛,𝑠 +∑︁𝑛,𝑠

𝑐𝑛,𝑠ℎ̄𝑛,𝑠 +∑︁𝑙

𝑐𝑙𝐹𝑙

+∑︁𝑡

𝑤𝑡

[︃∑︁𝑛,𝑠

𝑜𝑛,𝑠,𝑡𝑔𝑛,𝑠,𝑡 +∑︁𝑛,𝑠

𝑜𝑛,𝑠,𝑡ℎ𝑛,𝑠,𝑡

]︃+∑︁𝑡

[𝑠𝑢𝑐𝑛,𝑠,𝑡 + 𝑠𝑑𝑐𝑛,𝑠,𝑡]

Additional variables which do not appear in the objective function are the storage uptake variable, the state of chargeand the voltage angle for each bus.

Generator constraints

These are defined in pypsa.opf.define_generator_variables_constraints(network,snapshots).

Generator nominal power and generator dispatch for each snapshot may be optimised.

Each generator has a dispatch variable 𝑔𝑛,𝑠,𝑡 where 𝑛 labels the bus, 𝑠 labels the particular generator at the bus (e.g. itcan represent wind/gas/coal generators at the same bus in an aggregated network) and 𝑡 labels the time.

It obeys the constraints:

𝑔𝑛,𝑠,𝑡 * 𝑔𝑛,𝑠 ≤ 𝑔𝑛,𝑠,𝑡 ≤ 𝑔𝑛,𝑠,𝑡 * 𝑔𝑛,𝑠

where 𝑔𝑛,𝑠 is the nominal power (generator.p_nom) and 𝑔𝑛,𝑠,𝑡 and 𝑔𝑛,𝑠,𝑡 are time-dependent restrictions on thedispatch (per unit of nominal power) due to e.g. wind availability or power plant de-rating.

For generators with time-varying p_max_pu in network.generators_t the per unit availability 𝑔𝑛,𝑠,𝑡 is a timeseries.

For generators with static p_max_pu in network.generators the per unit availability is a constant.

If the generator’s nominal power 𝑔𝑛,𝑠 is also the subject of optimisation (generator.p_nom_extendable ==True) then limits generator.p_nom_min and generator.p_nom_max on the installable nominal power mayalso be introduced, e.g.

𝑔𝑛,𝑠 ≤ 𝑔𝑛,𝑠 ≤ 𝑔𝑛,𝑠

Generator unit commitment constraints

These are defined in pypsa.opf.define_generator_variables_constraints(network,snapshots).

8.2. Linear Optimal Power Flow 87

Page 94: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

The implementation follows Chapter 4.3 of Convex Optimization of Power Systems by Joshua Adam Taylor (CUP,2015).

Unit commitment can be turned on for any generator by setting committable to be True. This introduces a timesseries of new binary status variables 𝑢𝑛,𝑠,𝑡 ∈ {0, 1}, which indicates whether the generator is running (1) or not (0) inperiod 𝑡. The restrictions on generator output now become:

𝑢𝑛,𝑠,𝑡 * 𝑔𝑛,𝑠,𝑡 * 𝑔𝑛,𝑠 ≤ 𝑔𝑛,𝑠,𝑡 ≤ 𝑢𝑛,𝑠,𝑡 * 𝑔𝑛,𝑠,𝑡 * 𝑔𝑛,𝑠 ∀𝑛, 𝑠, 𝑡

so that if 𝑢𝑛,𝑠,𝑡 = 0 then also 𝑔𝑛,𝑠,𝑡 = 0.

If 𝑇min_up is the minimum up time then we have

𝑡+𝑇min_up∑︁𝑡′=𝑡

𝑢𝑛,𝑠,𝑡′ ≥ 𝑇min_up(𝑢𝑛,𝑠,𝑡 − 𝑢𝑛,𝑠,𝑡−1) ∀𝑛, 𝑠, 𝑡

(i.e. if the generator has just started up (𝑢𝑛,𝑠,𝑡 − 𝑢𝑛,𝑠,𝑡−1 = 1) then it has to run for at least 𝑇min_up periods). Similarlyfor a minimum down time of 𝑇min_down

𝑡+𝑇min_down∑︁𝑡′=𝑡

(1 − 𝑢𝑛,𝑠,𝑡′) ≥ 𝑇min_down(𝑢𝑛,𝑠,𝑡−1 − 𝑢𝑛,𝑠,𝑡) ∀𝑛, 𝑠, 𝑡

For non-zero start up costs 𝑠𝑢𝑐𝑛,𝑠 a new variable 𝑠𝑢𝑐𝑛,𝑠,𝑡 ≥ 0 is introduced for each time period 𝑡 and added to theobjective function. The variable satisfies

𝑠𝑢𝑐𝑛,𝑠,𝑡 ≥ 𝑠𝑢𝑐𝑛,𝑠(𝑢𝑛,𝑠,𝑡 − 𝑢𝑛,𝑠,𝑡−1) ∀𝑛, 𝑠, 𝑡

so that it is only non-zero if 𝑢𝑛,𝑠,𝑡 − 𝑢𝑛,𝑠,𝑡−1 = 1, i.e. the generator has just started, in which case the inequality issaturated 𝑠𝑢𝑐𝑛,𝑠,𝑡 = 𝑠𝑢𝑐𝑛,𝑠. Similarly for the shut down costs 𝑠𝑑𝑐𝑛,𝑠,𝑡 ≥ 0 we have

𝑠𝑑𝑐𝑛,𝑠,𝑡 ≥ 𝑠𝑑𝑐𝑛,𝑠(𝑢𝑛,𝑠,𝑡−1 − 𝑢𝑛,𝑠,𝑡) ∀𝑛, 𝑠, 𝑡

Generator ramping constraints

These are defined in pypsa.opf.define_generator_variables_constraints(network,snapshots).

The implementation follows Chapter 4.3 of Convex Optimization of Power Systems by Joshua Adam Taylor (CUP,2015).

Ramp rate limits can be defined for increasing power output 𝑟𝑢𝑛,𝑠 and decreasing power output 𝑟𝑑𝑛,𝑠. By defaultthese are null and ignored. They should be given per unit of the generator nominal power. The generator dispatch thenobeys

−𝑟𝑑𝑛,𝑠 * 𝑔𝑛,𝑠 ≤ (𝑔𝑛,𝑠,𝑡 − 𝑔𝑛,𝑠,𝑡−1) ≤ 𝑟𝑢𝑛,𝑠 * 𝑔𝑛,𝑠

for 𝑡 ∈ {1, . . . |𝑇 | − 1}.

For generators with unit commitment you can also specify ramp limits at start-up 𝑟𝑢𝑠𝑢𝑛,𝑠 and shut-down 𝑟𝑑𝑠𝑑𝑛,𝑠

[−𝑟𝑑𝑛,𝑠 * 𝑢𝑛,𝑠,𝑡 − 𝑟𝑑𝑠𝑑𝑛,𝑠(𝑢𝑛,𝑠,𝑡−1 − 𝑢𝑛,𝑠,𝑡)] 𝑔𝑛,𝑠 ≤ (𝑔𝑛,𝑠,𝑡 − 𝑔𝑛,𝑠,𝑡−1) ≤ [𝑟𝑢𝑛,𝑠 * 𝑢𝑛,𝑠,𝑡−1 + 𝑟𝑢𝑠𝑢𝑛,𝑠(𝑢𝑛,𝑠,𝑡 − 𝑢𝑛,𝑠,𝑡−1)] 𝑔𝑛,𝑠

88 Chapter 8. Optimal Power Flow

Page 95: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Storage Unit constraints

These are defined in pypsa.opf.define_storage_variables_constraints(network,snapshots).

Storage nominal power and dispatch for each snapshot may be optimised.

With a storage unit the maximum state of charge may not be independently optimised from the maximum poweroutput (they’re linked by the maximum hours variable) and the maximum power output is linked to the maximumpower input. To optimise these capacities independently, build a storage unit out of the more fundamental Store andLink components.

The storage nominal power is given by ℎ̄𝑛,𝑠.

In contrast to the generator, which has one time-dependent variable, each storage unit has three:

The storage dispatch ℎ𝑛,𝑠,𝑡 (when it depletes the state of charge):

0 ≤ ℎ𝑛,𝑠,𝑡 ≤ ℎ̄𝑛,𝑠

The storage uptake 𝑓𝑛,𝑠,𝑡 (when it increases the state of charge):

0 ≤ 𝑓𝑛,𝑠,𝑡 ≤ ℎ̄𝑛,𝑠

and the state of charge itself:

0 ≤ 𝑠𝑜𝑐𝑛,𝑠,𝑡 ≤ 𝑟𝑛,𝑠ℎ̄𝑛,𝑠

where 𝑟𝑛,𝑠 is the number of hours at nominal power that fill the state of charge.

The variables are related by

𝑠𝑜𝑐𝑛,𝑠,𝑡 = 𝜂𝑤𝑡

stand;𝑛,𝑠𝑠𝑜𝑐𝑛,𝑠,𝑡−1 + 𝜂store;𝑛,𝑠𝑤𝑡𝑓𝑛,𝑠,𝑡 − 𝜂−1dispatch;𝑛,𝑠𝑤𝑡ℎ𝑛,𝑠,𝑡 + 𝑤𝑡inflow𝑛,𝑠,𝑡 − 𝑤𝑡spillage𝑛,𝑠,𝑡

𝜂stand;𝑛,𝑠 is the standing losses dues to e.g. thermal losses for thermal storage. 𝜂store;𝑛,𝑠 and 𝜂dispatch;𝑛,𝑠 are the efficiencylosses for power going into and out of the storage unit.

There are two options for specifying the initial state of charge 𝑠𝑜𝑐𝑛,𝑠,𝑡=−1: you can set storage_unit.cyclic_state_of_charge = False (the default) and the value of storage_unit.state_of_charge_initial in MWh; or you can set storage_unit.cyclic_state_of_charge= True and then the optimisation assumes 𝑠𝑜𝑐𝑛,𝑠,𝑡=−1 = 𝑠𝑜𝑐𝑛,𝑠,𝑡=|𝑇 |−1.

If in the time series storage_unit_t.state_of_charge_set there are values which are not NaNs, then itwill be assumed that these are fixed state of charges desired for that time 𝑡 and these will be added as extra constraints.(A possible usage case would be a storage unit where the state of charge must empty every day.)

Store constraints

These are defined in pypsa.opf.define_store_variables_constraints(network,snapshots).

Store nominal energy and dispatch for each snapshot may be optimised.

The store nominal energy is given by 𝑒𝑛,𝑠.

The store has two time-dependent variables:

The store dispatch ℎ𝑛,𝑠,𝑡:

−∞ ≤ ℎ𝑛,𝑠,𝑡 ≤ +∞

8.2. Linear Optimal Power Flow 89

Page 96: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

and the energy:

𝑒𝑛,𝑠 ≤ 𝑒𝑛,𝑠,𝑡 ≤ 𝑒𝑛,𝑠

The variables are related by

𝑒𝑛,𝑠,𝑡 = 𝜂𝑤𝑡

stand;𝑛,𝑠𝑒𝑛,𝑠,𝑡−1 − 𝑤𝑡ℎ𝑛,𝑠,𝑡

𝜂stand;𝑛,𝑠 is the standing losses dues to e.g. thermal losses for thermal storage.

There are two options for specifying the initial energy 𝑒𝑛,𝑠,𝑡=−1: you can set store.e_cyclic = False (thedefault) and the value of store.e_initial in MWh; or you can set store.e_cyclic = True and then theoptimisation assumes 𝑒𝑛,𝑠,𝑡=−1 = 𝑒𝑛,𝑠,𝑡=|𝑇 |−1.

Passive branch flows: lines and transformers

See pypsa.opf.define_passive_branch_flows(network,snapshots) and pypsa.opf.define_passive_branch_constraints(network,snapshots) and pypsa.opf.define_branch_extension_variables(network,snapshots).

For lines and transformers, whose power flows according to impedances, the power flow 𝑓𝑙,𝑡 in AC networks is givenby the difference in voltage angles 𝜃𝑛,𝑡 at bus0 and 𝜃𝑚,𝑡 at bus1 divided by the series reactance 𝑥𝑙

𝑓𝑙,𝑡 =𝜃𝑛,𝑡 − 𝜃𝑚,𝑡

𝑥𝑙

(For DC networks, replace the voltage angles by the difference in voltage magnitude 𝛿𝑉𝑛,𝑡 and the series reactance bythe series resistance 𝑟𝑙.)

This flow is the limited by the capacity :math:F_l of the line

|𝑓𝑙,𝑡| ≤ 𝐹𝑙

Note that if 𝐹𝑙 is also subject to optimisation (branch.s_nom_extendable == True), then the impedance 𝑥of the line is NOT automatically changed with the capacity (to represent e.g. parallel lines being added).

There are two choices here:

Iterate the LOPF again with the updated impedances (see e.g. http://www.sciencedirect.com/science/article/pii/S0360544214000322#).

João Gorenstein Dedecca has also implemented a MILP version of the transmission expansion, see https://github.com/jdedecca/MILP_PyPSA, which properly takes account of the impedance with a disjunctive relaxation. This will bepulled into the main PyPSA code base soon.

Passive branch flow formulations

PyPSA implements four formulations of the linear power flow equations that are mathematically equivalent, but mayhave different solving times. These different formulations are described and benchmarked in the arXiv preprint paperLinear Optimal Power Flow Using Cycle Flows.

You can choose the formulation by passing network.lopf the argument formulation, which must be in["angles","cycles","kirchhoff","ptdf"]. angles is the standard formulations based on voltageangles described above, used for the linear power flow and found in textbooks. ptdf uses the Power Trans-fer Distribution Factor (PTDF) formulation, found for example in http://www.sciencedirect.com/science/article/pii/S0360544214000322#. kirchhoff and cycles are two new formulations based on a graph-theoretic decomposi-tion of the network flows into a spanning tree and closed cycles.

90 Chapter 8. Optimal Power Flow

Page 97: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Based on the benchmarking in Linear Optimal Power Flow Using Cycle Flows for standard networks, kirchhoffalmost always solves fastest, averaging 3 times faster than the angles formulation and up to 20 times faster in specificcases. The speedup is higher for larger networks with dispatchable generators at most nodes.

Controllable branch flows: links

See pypsa.opf.define_controllable_branch_flows(network,snapshots) and pypsa.opf.define_branch_extension_variables(network,snapshots).

For links, whose power flow is controllable, there is simply an optimisation variable for each component which satisfies

|𝑓𝑙,𝑡| ≤ 𝐹𝑙

If the link flow is positive 𝑓𝑙,𝑡 > 0 then it withdraws 𝑓𝑙,𝑡 from bus0 and feeds in 𝜂𝑙𝑓𝑙,𝑡 to bus1, where 𝜂𝑙 is the linkefficiency.

If additional output buses busi for 𝑖 = 2, 3, . . . are defined (i.e. bus2, bus3, etc) and their associated efficienciesefficiencyi, i.e. 𝜂𝑖,𝑙, then at busi the feed-in is 𝜂𝑖,𝑙𝑓𝑙,𝑡. See also Link with multiple outputs or inputs.

Nodal power balances

See pypsa.opf.define_nodal_balances(network,snapshots).

This is the most important equation, which guarantees that the power balances at each bus 𝑛 for each time 𝑡.∑︁𝑠

𝑔𝑛,𝑠,𝑡 +∑︁𝑠

ℎ𝑛,𝑠,𝑡 −∑︁𝑠

𝑓𝑛,𝑠,𝑡 −∑︁𝑙

𝐾𝑛𝑙𝑓𝑙,𝑡 =∑︁𝑠

𝑑𝑛,𝑠,𝑡 ↔ 𝑤𝑡𝜆𝑛,𝑡

Where 𝑑𝑛,𝑠,𝑡 is the exogenous load at each node (load.p_set) and the incidence matrix 𝐾𝑛𝑙 for the graph takesvalues in {−1, 0, 1} depending on whether the branch 𝑙 ends or starts at the bus. 𝜆𝑛,𝑡 is the shadow price of theconstraint, i.e. the locational marginal price, stored in network.buses_t.marginal_price.

The bus’s role is to enforce energy conservation for all elements feeding in and out of it (i.e. like Kirchhoff’s CurrentLaw).

8.2. Linear Optimal Power Flow 91

Page 98: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Global constraints

See pypsa.opf.define_global_constraints(network,snapshots).

Global constraints apply to more than one component.

Currently only “primary energy” constraints are defined. They depend on the power plant efficiency and carrier-specific attributes such as specific CO2 emissions.

Suppose there is a global constraint defined for CO2 emissions with sense <= and constant \textrm{CAP}_{CO2}.Emissions can come from generators whose energy carriers have CO2 emissions and from stores and storage unitswhose storage medium releases or absorbs CO2 when it is converted. Only stores and storage units with non-cyclicstate of charge that is different at the start and end of the simulation can contribute.

If the specific emissions of energy carrier 𝑠 is 𝑒𝑠 (carrier.co2_emissions) CO2-equivalent-tonne-per-MWhand the generator with carrier 𝑠 at node 𝑛 has efficiency 𝜂𝑛,𝑠 then the CO2 constraint is∑︁

𝑛,𝑠,𝑡

1

𝜂𝑛,𝑠𝑤𝑡 · 𝑔𝑛,𝑠,𝑡 · 𝑒𝑛,𝑠 +

∑︁𝑛,𝑠

(︀𝑒𝑛,𝑠,𝑡=−1 − 𝑒𝑛,𝑠,𝑡=|𝑇 |−1

)︀· 𝑒𝑛,𝑠 ≤ CAP𝐶𝑂2 ↔ 𝜇

The first sum is over generators; the second sum is over stores and storage units. 𝜇 is the shadow price of the constraint,i.e. the CO2 price in this case. 𝜇 is an output of the optimisation stored in network.global_constraints.mu.

Custom constraints and other functionality

PyPSA uses the Python optimisation language pyomo to construct the OPF problem. You can easily extendthe optimisation problem constructed by PyPSA using the usual pyomo syntax. To do this, pass the functionnetwork.lopf a function extra_functionality as an argument. This function must take two argumentsextra_functionality(network,snapshots) and is called after the model building is complete, but be-fore it is sent to the solver. It allows the user to add, change or remove constraints and alter the objective function.

The CHP example and the example that replaces generators and storage units with fundamental links and stores bothpass an extra_functionality argument to the LOPF to add functionality.

Inputs

For the linear optimal power flow, the following data for each component are used. For almost all values, defaults areassumed if not explicitly set. For the defaults and units, see Components.

network{snapshot_weightings}

bus.{v_nom, carrier}

load.{p_set}

generator.{p_nom, p_nom_extendable, p_nom_min, p_nom_max, p_min_pu, p_max_pu, marginal_cost, capital_cost,efficiency, carrier}

storage_unit.{p_nom, p_nom_extendable, p_nom_min, p_nom_max, p_min_pu, p_max_pu, marginal_cost,capital_cost, efficiency*, standing_loss, inflow, state_of_charge_set, max_hours, state_of_charge_initial,cyclic_state_of_charge}

store.{e_nom, e_nom_extendable, e_nom_min, e_nom_max, e_min_pu, e_max_pu, e_cyclic, e_initial, capital_cost,marginal_cost, standing_loss}

line.{x, s_nom, s_nom_extendable, s_nom_min, s_nom_max, capital_cost}

transformer.{x, s_nom, s_nom_extendable, s_nom_min, s_nom_max, capital_cost}

92 Chapter 8. Optimal Power Flow

Page 99: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

link.{p_min_pu, p_max_pu, p_nom, p_nom_extendable, p_nom_min, p_nom_max, capital_cost}

carrier.{carrier_attribute}

global_constraint.{type, carrier_attribute, sense, constant}

Note that for lines and transformers you MUST make sure that 𝑥 is non-zero, otherwise the bus admittance matrix willbe singular.

Outputs

bus.{v_mag_pu, v_ang, p, marginal_price}

load.{p}

generator.{p, p_nom_opt}

storage_unit.{p, p_nom_opt, state_of_charge, spill}

store.{p, e_nom_opt, e}

line.{p0, p1, s_nom_opt, mu_lower, mu_upper}

transformer.{p0, p1, s_nom_opt, mu_lower, mu_upper}

link.{p0, p1, p_nom_opt, mu_lower, mu_upper}

global_constraint.{mu}

8.2. Linear Optimal Power Flow 93

Page 100: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

94 Chapter 8. Optimal Power Flow

Page 101: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

NINE

CONTINGENCY ANALYSIS

See the module pypsa.contingency.

Contingency analysis is concerned with the behaviour of the power system after contingencies such as the outage ofparticular branches. Only branch outages and the resulting effects on linear power flow are considered here; extensionsfor non-linear power flow and generator outages may be added in the future.

Branch Outage Distribution Factors (BODF)

sub_network.caculate_BODF() calculates the matrix of Branch Outage Distribution Factors (BODF) andstores it as sub_network.BODF. (BODF are also called Line Outage Distribution Factors (LODF) in the literature,but in PyPSA other passive branches such as transformers are also included.)

The BODF gives the change of flow on the branches in the network following a branch outage, based on the linearpower flow.

For the outage of branch 𝑐, let 𝑓𝑏 be the flows before the outage and 𝑓(𝑐)𝑏 be the flows after the outage. Then the BODF

is defined by

𝑓(𝑐)𝑏 = 𝑓𝑏 + 𝐵𝑂𝐷𝐹𝑏𝑐𝑓𝑐

The BODF can be computed fairly directly from the Power Transfer Distribution Factors (PTDF). First build thebranch PTDF 𝐵𝑃𝑇𝐷𝐹 from the PTDF and incidence matrix 𝐾

𝐵𝑃𝑇𝐷𝐹𝑏𝑐 =∑︁𝑖

𝑃𝑇𝐷𝐹𝑏𝑖𝐾𝑖𝑐

𝐵𝑃𝑇𝐷𝐹𝑏𝑐 gives the change in flow on branch 𝑏 if a unit of power is injected at the from-bus of branch 𝑐 and withdrawnfrom the to-bus of branch 𝑐. If branch 𝑏 is the only branch connecting two regions, then 𝐵𝑃𝑇𝐷𝐹𝑏𝑏 = 1, since thepower can only flow between the two ends of the branch through the branch itself.

The off-diagonal entries of the BODF 𝑏 ̸= 𝑐 are given by:

𝐵𝑂𝐷𝐹𝑏𝑐 =𝐵𝑃𝑇𝐷𝐹𝑏𝑐

1 −𝐵𝑃𝑇𝐷𝐹𝑐𝑐

If 𝑐 is the only branch connecting two regions, so that the regions become disconnected after the outage of 𝑐, then𝐵𝑃𝑇𝐷𝐹𝑐𝑐 = 1 and 𝐵𝑂𝐷𝐹𝑏𝑐 becomes singular; this case must be treated separately since, for example, each regionwill need its own slack.

The diagonal entries of the BODF are simply:

𝐵𝑂𝐷𝐹𝑏𝑏 = −1

95

Page 102: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Linear Power Flow Contingency Analysis

network.lpf_contingency(snapshot, branch_outages) computes a base case linear power flow(LPF) with no outages for snapshot, and then cycles through the list of branches in branch_outages andcomputes the line flows after the outage of that branch using the BODF.

The function returns a pandas.DataFrame p0 with the flows in each case in each column of the DataFrame.

Security-Constrained Linear Optimal Power Flow (SCLOPF)

The Security-Constrained Linear Optimal Power Flow (SCLOPF) builds on the Linear Optimal Power Flow (LOPF)described in Optimal Power Flow by including additional constraints that branches may not become overloaded afterthe outage of a selection of branches.

The SCLOPF is called with the method:

network.sclopf(snapshots,branch_outages,**kwargs)

where branch_outages is a list of the branches whose outages should not overload the network. **kwargs areall the same arguments that may be passed to network.lopf(). (Note that network.sclopf() is implementedby adding a function to network.lopf() via the extra_functionality keyword.)

For each potential outage of a branch 𝑐 add a set of constraints for all other branches 𝑏 in the sub-network that they donot become overloaded beyond their capacity 𝐹𝑏:

|𝑓 (𝑐)𝑏,𝑡 | = |𝑓𝑏,𝑡 + 𝐵𝑂𝐷𝐹𝑏𝑐𝑓𝑐,𝑡| ≤ |𝐹𝑏| ∀𝑏

This applies for all snapshots 𝑡 considered in the optimisation.

Inputs and Outputs

See LOPF in Optimal Power Flow.

96 Chapter 9. Contingency Analysis

Page 103: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

TEN

PLOTTING NETWORKS

See the module pypsa.plot.

PyPSA has several functions available for plotting networks with different colors/widths/labels on buses and branches.

Interactive plotting with plotly

Interactive plots of networks can be created that use the d3js-based library plotly (this uses JavaScript and SVGs). Thisis meant for use with Jupyter notebooks.

Call network.iplot(); see the doc string for more instructions and the SciGRID plotly example.

Static plotting with matplotlib

Static plots of networks can be created that use the library matplotlib. This is meant for use with Jupyter notebooks,but can also be used to generate image files.

Call network.plot(); see the doc string for more instructions and the SciGRID matplotlib example.

97

Page 104: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

98 Chapter 10. Plotting Networks

Page 105: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

ELEVEN

CONVENTIONS

Unit Conventions

The units for physical quantities are chosen for easy user input.

The units follow the general rules:

Power: MW/MVA/MVar (unless per unit of nominal power, e.g. generator.p_max_pu for variable generators is perunit of generator.p_nom)

Time: h

Energy: MWh

Voltage: kV phase-phase for bus.v_nom; per unit for v_mag_pu, v_mag_pu_set, v_mag_pu_min etc.

Angles: radians, except transformer.phase_shift which is in degrees for easy input

Impedance: Ohm, except transformers which are pu, using transformer.s_nom for the base power

CO2-equivalent emissions: tonnes of CO2-equivalent per MWh_thermal of energy carrier

Sign Conventions

The sign convention in PyPSA follows other major software packages, such as MATPOWER, PYPOWER and DIgSI-LENT PowerFactory.

• The power (p,q) of generators or storage units is positive if the asset is injecting power into the bus, negative ifwithdrawing power from bus.

• The power (p,q) of loads is positive if withdrawing power from bus, negative if injecting power into bus.

• The power (p0,q0) at bus0 of a branch is positive if the branch is withdrawing power from bus0, i.e. bus0 isinjecting into branch

• Similarly the power (p1,q1) at bus1 of a branch is positive if the branch is withdrawing power from bus1,negative if the branch is injecting into bus1

• If p0 > 0 and p1 < 0 for a branch then active power flows from bus0 to bus1; p0+p1 > 0 is the active power lossesfor this direction of power flow.

AC/DC Terminology

AC stands for Alternating Current and DC stands for Direct Current.

99

Page 106: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Some people refer to the linearised power flow equations for AC networks as “DC load flow” for historical reasons,but we find this confusing when there are actual direct current elements in the network (which also have a linearisedpower flow, which would then be DC DC load flow).

Therefore for us AC means AC and DC means DC. We distinguish between the full non-linear network equations(with no approximations) and the linearised network equations (with certain approximations to make the equationslinear).

All equations are listed in the section Power Flow.

100 Chapter 11. Conventions

Page 107: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

TWELVE

EXAMPLES

See pypsa/examples/ and pypsa/test/ in the PyPSA github repository for usage cases; there are Jupyternotebooks available of these examples at http://www.pypsa.org/examples/.

SciGRID Germany LOPF, LPF and SCLOPF

See pypsa/examples/scigrid-de.

The script add_load_gen_to_scigrid.py takes the SciGRID network for Germany, attaches load and conven-tional generation data and exports the resulting network.

The script scigrid-lopf-then-pf.py then performs a linear OPF on the network for several hours, expandingany lines where capacity is needed.

Then the resulting optimised dispatch is run through a full non-linear Newton-Raphson power flow.

AC-DC meshed example

See pypsa/examples/ac-dc-meshed/.

This computes an example with three synchronous AC areas:

• The UK (Manchester, London, Norwich)

• Germany (Frankfurt and Bremen)

• Norway (a single node)

London and Bremen are connected by a point-to-point HVDC Link.

Norwich, Bremen and Norway are connected by a three-node, three-line DC network.

The example scripts do LOPF and LPF.

Storage and HVDC OPF example

See pypsa/examples/opf-storage-hvdc/

System capacity optimisation with storage, AC and DC.

101

Page 108: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

Example of linear optimal power flow with coupling to the heatingsector

See pypsa/examples/coupling-with-heating/ and http://www.pypsa.org/examples/lopf-with-heating.html.

In this example three locations are optimised, each with an electric bus and a heating bus and corresponding loads. Ateach location the electric and heating buses are connected with heat pumps; heat can also be supplied to the heat buswith a boiler. The electric buses are connected with transmission lines and there are electrical generators at two of thenodes.

102 Chapter 12. Examples

Page 109: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

THIRTEEN

TROUBLESHOOTING

Library dependency issues

If you are experiencing problems with PyPSA or with the importing of the libraries on which PyPSA depends, pleasefirst check that you are working with the latest versions of all packages.

See Upgrade all packages to the latest versions and Upgrading PyPSA.

Consistency check on network

Running network.consistency_check() will examine the network components to make sure that all compo-nents are connected to existing buses and that no impedances are singular.

Problems with power flow convergence

If your network.pf() is not converging there are two possible reasons:

• The problem you have defined is not solvable (e.g. because in reality you would have a voltage collapse)

• The problem is solvable, but there are numerical instabilities in the solving algorithm (e.g. Newton-Raphson isknown not to converge even for solvable problems; or the flat solution PyPSA uses as an initial guess is too farfrom the correction solution because of transformer phase-shifts)

There are some steps you can take to distinguish these two cases:

• Check the units you have used to define the problem are correct; see Conventions. If your units are out by afactor 1000 (e.g. using kW instead of MW) don’t be surprised if your problem is no longer solvable.

• Check with a linear power flow network.lpf() that all voltage angles differences across branches are lessthan 40 degrees. You can do this with the following code:

import pandas as pd, numpy as np

now = network.snapshots[0]

angle_diff = pd.Series(network.buses_t.v_ang.loc[now,network.lines.bus0].values -→˓network.buses_t.v_ang.loc[now,network.lines.bus1].values,index=network.lines.index)

(angle_diff*180/np.pi).describe()

103

Page 110: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

• You can seed the non-linear power flow initial guess with the voltage angles from the linear power flow. This isadvisable if you have transformers with phase shifts in the network, which lead to solutions far away from theflat initial guess of all voltage angles being zero. To seed the problem activate the use_seed switch:

network.lpf()network.pf(use_seed=True)

• Reduce all power values p_set and q_set of generators and loads to a fraction, e.g. 10%, solve the load flowand use it as a seed for the power at 20%, iteratively up to 100%.

Pitfalls/Gotchas

Some attributes are generated dynamically and are therefore only copies. If you change data in them, this will NOTupdate the original data. They are all defined as functions to make this clear.

For example:

• network.branches() returns a DataFrame which is a concatenation of network.lines andnetwork.transformers

• sub_network.generators() returns a DataFrame consisting of generators in sub_network

Reporting bugs/issues

Please do not contact the developers directly.

Please report questions to the mailing list.

If you’re relatively certain you’ve found a bug, raise it as an issue on the PyPSA Github Issues page.

104 Chapter 13. Troubleshooting

Page 111: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

FOURTEEN

UNIT TESTING

Unit testing is performed with py.test.

Tests can be found in pypsa/test/.

Power flow is tested against Pypower (the Python implementation of MATPOWER) using its built-in cases.

Unit testing of new GitHub commits is automated with Travis CI.

105

Page 112: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

106 Chapter 14. Unit Testing

Page 113: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

FIFTEEN

COMPARABLE SOFTWARE

The PyPSA paper contains a discussion of PyPSA’s features compared to other software tools and a functionalitycomparison in Table III.

Free software

PYPOWER - a Python, numpy, scipy port of MATPOWER, compared to PyPSA below

pandapower - a Python based extension of PYPOWER that uses pandas “to create an easy to use network calcula-tion program aimed at automation of power system analysis and optimization in distribution and sub-transmissionnetworks”

GridCal - a Python-based extension of PYPOWER that includes time series and load flow methods using analyticcontinuation

MATPOWER - a Matlab-based tool for static power system computations

PSAT - a general Matlab-based tool for (most) power system calculations

Open Energy Modelling Framework - Python and Pyomo based framework for optimisation which includes all energysectors in a general framework

Calliope - Python and Pyomo based framework for energy system optimisation

OSeMOSYS - systems optimization model for long-run energy planning

urbs

minpower

DiSC

IEEE OSS list

SWITCH

PowerGAMA

NEMO

Mosaik-PYPOWER

OpenDSS

MatDyn

GridLAB-D

PyCIM

107

Page 114: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

vSPD - Vectorised Scheduling, Pricing and Dispatch (vSPD) - an audited, mathematical replica of SPD, the pricingand dispatch engine used in the New Zealand electricity market.

PYPOWER

PyPSA is compared to PYPOWER in the following table:

PyPSA PYPOWERObject-oriented, data stored in pandas DataFrames Numpy integer-indexed arraysNon-linear power flow Non-linear power flowOnly linear OPF Non-linear and linear OPFOptimisation over multiple time points Single time-point optimisationGenerators, storage models, hydro, sector coupling Just generatorsMixed AC-DC modelling Just AC, single synchronous areaConceived in Python Port of Matlab-based MATPOWER

Non-free software

DIgSILENT PowerFactory

PSS/E

Neplan

PowerWorld

INTEGRAL

PLEXOS

108 Chapter 15. Comparable Software

Page 115: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

SIXTEEN

DEVELOPERS

We strongly welcome anyone interested in contributing to this project.

Submit pull requests / issues to the github repository.

Join the Mailing list.

109

Page 116: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

110 Chapter 16. Developers

Page 117: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

SEVENTEEN

RELEASE NOTES

PyPSA 0.13.1 (27th March 2018)

This release contains bug fixes for the new features introduced in 0.13.0.

• netCDF export bug fixed (components that were all standard except their name were ignored).

• HDF5 import/export bug fixed and now works with more than 1000 columns; HDF5 format is no longer depre-cated.

• When networks are copied or sliced, overridden components (introduced in 0.13.0) are also copied too.

We thank Tim Kittel for pointing out the first and second bugs. We thank Kostas Syranidis for not only pointing outthe third issue with copying overridden components, but also submitting a fix as a pull request.

For this release we acknowledge funding to Tom Brown from the RE-INVEST project.

PyPSA 0.13.0 (25th January 2018)

This release contains new features aimed at coupling power networks to other energy sectors, fixes for library depen-dencies and some minor internal API changes.

• If you want to define your own components and override the standard functionality of PyPSA, you can nowoverride the standard components by passing pypsa.Network() the arguments override_components andoverride_component_attrs, see the section on Custom Components. There are examples for definingnew components in the git repository in examples/new_components/, including an example of overridingnetwork.lopf() for functionality for combined-heat-and-power (CHP) plants.

• The Link component can now be defined with multiple outputs in fixed ratio to the power in the single inputby defining new columns bus2, bus3, etc. (bus followed by an integer) in network.links along withassociated columns for the efficiencies efficiency2, efficiency3, etc. The different outputs are thenproportional to the input according to the efficiency; see sections Link with multiple outputs or inputs andControllable branch flows: links and the example of a CHP with a fixed power-heat ratio.

• Networks can now be exported to and imported from netCDF files with network.export_to_netcdf()and network.import_from_netcdf(). This is faster than using CSV files and the files take up lessspace. Import and export with HDF5 files, introduced in PyPSA 0.12.0, is now deprecated.

• The export and import code has been refactored to be more general and abstract. This does not affect the API.

• The internally-used sets such as pypsa.components.all_components and pypsa.components.one_port_components have been moved from pypsa.components to network, i.e. network.all_components and network.one_port_components, since these sets may change from networkto network.

111

Page 118: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

• For linear power flow, PyPSA now pre-calculates the effective per unit reactance x_pu_eff for AC lines totake account of the transformer tap ratio, rather than doing it on the fly; this makes some code faster, particularlythe kirchhoff formulation of the LOPF.

• PyPSA is now compatible with networkx 2.0 and 2.1.

• PyPSA now requires Pyomo version greater than 5.3.

• PyPSA now uses the Travis CI continuous integration service to test every commit in the PyPSA GitHub repos-itory. This will allow us to catch library dependency issues faster.

We thank Russell Smith of Edison Energy for the pull request for the effective reactance that sped up the LOPF codeand Tom Edwards for pointing out the Pyomo version dependency issue.

For this release we also acknowledge funding to Tom Brown from the RE-INVEST project.

PyPSA 0.12.0 (30th November 2017)

This release contains new features and bug fixes.

• Support for Pyomo’s persistent solver interface, so if you’re making small changes to an optimisation model(e.g. tweaking a parameter), you don’t have to rebuild the model every time. To enable this, network_lopfhas been internally split into build_model, prepare_solver and solve to allow more fine-grainedcontrol of the solving steps. Currently the new Pyomo PersistentSolver interface is not in the main Pyomobranch, see the pull request; you can obtain it with pip install git+https://github.com/Pyomo/pyomo@persistent_interfaces

• Lines and transformers (i.e. passive branches) have a new attribute s_max_pu to restrict the flow in the OPF,just like p_max_pu for generators and links. It works by restricting the absolute value of the flow per unitof the nominal rating abs(flow) <= s_max_pu*s_nom. For lines this can represent an n-1 contingencyfactor or it can be time-varying to represent weather-dependent dynamic line rating.

• The marginal_cost attribute of generators, storage units, stores and links can now be time dependent.

• When initialising the Network object, i.e. network = pypsa.Network(), the first keyword argument isnow import_name instead of csv_folder_name. With import_name PyPSA recognises whether it isa CSV folder or an HDF5 file based on the file name ending and deals with it appropriately. Example usage:nw1 = pypsa.Network("my_store.h5") and nw2 = pypsa.Network("/my/folder"). Thekeyword argument csv_folder_name is still there but is deprecated.

• The value network.objective is now read from the Pyomo results attribute Upper Bound instead ofLower Bound. This is because for MILP problems under certain circumstances CPLEX records the Lowerbound as the relaxed value. Upper bound is correctly recorded as the integer objective value.

• Bug fix due to changes in pandas 0.21.0: A bug affecting various places in the code, including causingnetwork.lopf to fail with GLPK, is fixed. This is because in pandas 0.21.0 the sum of an empty Se-ries/DataFrame returns NaN, whereas before it returned zero. This is a subtle bug; we hope we’ve fixed allinstances of it, but get in touch if you notice NaNs creeping in where they shouldn’t be. All our tests run fine.

• Bug fix due to changes in scipy 1.0.0: For the new version of scipy, csgraph has to be imported explicit.

• Bug fix: A bug whereby logging level was not always correctly being seen by the OPF results printout is fixed.

• Bug fix: The storage unit spillage had a bug in the LOPF, whereby it was not respecting network.snapshot_weightings properly.

We thank René Garcia Rosas, João Gorenstein Dedecca, Marko Kolenc, Matteo De Felice and Florian Kühnlenz forpromptly notifying us about issues.

112 Chapter 17. Release Notes

Page 119: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

PyPSA 0.11.0 (21st October 2017)

This release contains new features but no changes to existing APIs.

• There is a new function network.iplot() which creates an interactive plot in Jupyter notebooks using theplotly library. This reveals bus and branch properties when the mouse hovers over them and allows users toeasily zoom in and out on the network. See the SciGRID example for a showcase of this feature and also the(sparse) documentation Plotting Networks.

• There is a new function network.madd() for adding multiple new components to thenetwork. This is significantly faster than repeatedly calling network.add() and usesthe functions network.import_components_from_dataframe() and network.import_series_from_dataframe() internally. Documentation and examples can be found atAdding multiple components.

• There are new functions network.export_to_hdf5() and network.import_from_hdf5() for ex-porting and importing networks as single files in the Hierarchical Data Format.

• In the network.lopf() function the KKT shadow prices of the branch limit constraints are now outputtedas series called mu_lower and mu_upper.

We thank Bryn Pickering for introducing us to plotly and helping to hack together the first working prototype usingPyPSA.

PyPSA 0.10.0 (7th August 2017)

This release contains some minor new features and a few minor but important API changes.

• There is a new component Global Constraints for implementing constraints that effect many components atonce (see also the LOPF subsection Global constraints). Currently only constraints related to primary energy(i.e. before conversion with losses by generators) are supported, the canonical example being CO2 emissions foran optimisation period. Other primary-energy-related gas emissions also fall into this framework. Other typesof global constraints will be added in future, e.g. “final energy” (for limits on the share of renewable or nuclearelectricity after conversion), “generation capacity” (for limits on total capacity expansion of given carriers)and “transmission capacity” (for limits on the total expansion of lines and links). This replaces the ad hocnetwork.co2_limit attribute. If you were using this, instead of network.co2_limit = my_capdo network.add("GlobalConstraint", "co2_limit", type="primary_energy",carrier_attribute="co2_emissions", sense="<=", constant=my_cap). The shadowprices of the global constraints are automatically saved in network.global_constraints.mu.

• The LOPF output network.buses_t.marginal_price is now defined differently if network.snapshot_weightings are not 1. Previously if the generator at the top of the merit order hadmarginal_cost c and the snapshot weighting was w, the marginal_price was cw. Now it is c, which ismore standard. See also Nodal power balances.

• network.pf() now returns a dictionary of pandas DataFrames, each indexed by snapshots and sub-networks.converged is a table of booleans indicating whether the power flow has converged; error gives the deviationof the non-linear solution; n_iter the number of iterations required to achieve the tolerance.

• network.consistency_check() now includes checking for potentially infeasible values ingenerator.p_{min,max}_pu.

• The PyPSA version number is now saved in network.pypsa_version. In future versions of PyPSA thisinformation will be used to upgrade data to the latest version of PyPSA.

• network.sclopf() has an extra_functionality argument that behaves like that for network.lopf().

17.4. PyPSA 0.11.0 (21st October 2017) 113

Page 120: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

• Component attributes which are strings are now better handled on import and in the consistency checking.

• There is a new generation investment screening curve example showing the long-term equilibrium of generationinvestment for a given load profile and comparing it to a screening curve analysis.

• There is a new logging example that demonstrates how to control the level of logging that PyPSA reports back,e.g. error/warning/info/debug messages.

• Sundry other bug fixes and improvements.

• All examples have been updated appropriately.

Thanks to Nis Martensen for contributing the return values of network.pf() and Konstantinos Syranidis for con-tributing the improved network.consistency_check().

PyPSA 0.9.0 (29th April 2017)

This release mostly contains new features with a few minor API changes.

• Unit commitment as a MILP problem is now available for generators in the Linear Optimal Power Flow (LOPF).If you set committable == True for the generator, an addition binary online/offline status is created. Min-imum part loads, minimum up times, minimum down times, start up costs and shut down costs are implemented.See the documentation at Generator unit commitment constraints and the unit commitment example. Note thata generator cannot currently have both unit commitment and capacity expansion optimisation.

• Generator ramping limits have also been implemented for all generators. See the documentation at Generatorramping constraints and the unit commitment example.

• Different mathematically-equivalent formulations for the Linear Optimal Power Flow (LOPF) are now docu-mented in Passive branch flow formulations and the arXiv preprint paper Linear Optimal Power Flow UsingCycle Flows. The new formulations can solve up to 20 times faster than the standard angle-based formulation.

• You can pass the network.lopf function the solver_io argument for pyomo.

• There are some improvements to network clustering and graphing.

• API change: The attribute network.now has been removed since it was unnecessary. Now, if you do notpass a snapshots argument to network.pf() or network.lpf(), these functions will default to network.snapshots rather than network.now.

• API change: When reading in network data from CSV files, PyPSA will parse snapshot dates as proper datetimesrather than text strings.

João Gorenstein Dedecca has also implemented a MILP version of the transmission expansion, see https://github.com/jdedecca/MILP_PyPSA, which properly takes account of the impedance with a disjunctive relaxation. This will bepulled into the main PyPSA code base soon.

PyPSA 0.8.0 (25th January 2017)

This is a major release which contains important new features and changes to the internal API.

• Standard types are now available for lines and transformers so that you do not have to calculate the electricalparameters yourself. For lines you just need to specify the type and the length, see Line Types. For transformersyou just need to specify the type, see Transformer Types. The implementation of PyPSA’s standard types isbased on pandapower’s standard types. The old interface of specifying r, x, b and g manually is still available.

114 Chapter 17. Release Notes

Page 121: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

• The transformer model has been substantially overhauled, see Transformer model. The equivalent model nowdefaults to the more accurate T model rather than the PI model, which you can control by setting the attributemodel. Discrete tap steps are implemented for transformers with types. The tap changer can be defined on theprimary side or the secondary side. In the PF there was a sign error in the implementation of the transformerphase_shift, which has now been fixed. In the LPF and LOPF angle formulation the phase_shift hasnow been implemented consistently. See the new transformer example.

• There is now a rudimentary import function for pandapower networks, but it doesn’t yet work with all switchesand 3-winding transformers.

• The object interface for components has been completely removed. Objects for each component are no longerstored in e.g. network.lines["obj"] and the descriptor interface for components is gone. You can onlyaccess component attributes through the dataframes, e.g. network.lines.

• Component attributes are now defined in CSV files in pypsa/component_attrs/. You canaccess these CSVs in the code via the dictionary network.components, e.g. network.components["Line"]["attrs"] will show a pandas DataFrame with all attributes and their types, de-faults, units and descriptions. These CSVs are also sourced for the documentation in Components, so thedocumentation will always be up-to-date.

• All examples have been updated appropriately.

PyPSA 0.7.1 (26th November 2016)

This release contains bug fixes, a minor new feature and more warnings.

• The unix-only library resource is no longer imported by default, which was causing errors for Windowsusers.

• Bugs in the setting and getting of time-varying attributes for the object interface have been fixed.

• The Link attribute efficiency can now be make time-varying so that e.g. heat pump Coefficient of Perfor-mance (COP) can change over time due to ambient temperature variations (see the heat pump example).

• network.snapshots is now cast to a pandas.Index.

• There are new warnings, including when you attach components to non-existent buses.

Thanks to Marius Vespermann for promptly pointing out the resource bug.

PyPSA 0.7.0 (20th November 2016)

This is a major release which contains changes to the API, particularly regarding time-varying component attributes.

• network.generators_t are no longer pandas.Panels but dictionaries of pandas.DataFrames, with variablecolumns, so that you can be flexible about which components have time-varying attributes; please read Time-varying data carefully. Essentially you can either set a component attribute e.g. p_max_pu of Generator, tobe static by setting it in the DataFrame network.generators, or you can let it be time-varying by defining anew column labelled by the generator name in the DataFrame network.generators_t["p_max_pu"]as a series, which causes the static value in network.generators for that generator to be ignored. TheDataFrame network.generators_t["p_max_pu"] now only includes columns which are specificallydefined to be time-varying, thus saving memory.

• The following component attributes can now be time-varying: Link.p_max_pu, Link.p_min_pu,Store.e_max_pu and Store.e_min_pu. This allows the demand-side management scheme of https://arxiv.org/abs/1401.4121 to be implemented in PyPSA.

17.8. PyPSA 0.7.1 (26th November 2016) 115

Page 122: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

• The properties dispatch, p_max_pu_fixed and p_min_pu_fixed of Generator andStorageUnit are now removed, because the ability to make p_max_pu and p_min_pu either staticor time-varying removes the need for this distinction.

• All messages are sent through the standard Python library logging, so you can control the level of messagesto be e.g. debug, info, warning or error. All verbose switches and print statements have been removed.

• There are now more warnings.

• You can call network.consistency_check() to make sure all your components are well defined; seeTroubleshooting.

All examples have been updated to accommodate the changes listed below.

PyPSA 0.6.2 (4th November 2016)

This release fixes a single library dependency issue:

• pf: A single line has been fixed so that it works with new pandas versions >= 0.19.0.

We thank Thorben Meiners for promptly pointing out this issue with the new versions of pandas.

PyPSA 0.6.1 (25th August 2016)

This release fixes a single critical bug:

• opf: The latest version of Pyomo (4.4.1) had a bad interaction with pandas when a pandas.Index was used toindex variables. To fix this, the indices are now cast to lists; compatibility with less recent versions of Pyomo isalso retained.

We thank Joao Gorenstein Dedecca for promptly notifying us of this bug.

PyPSA 0.6.0 (23rd August 2016)

Like the 0.5.0 release, this release contains API changes, which complete the integration of sector coupling. You mayhave to update your old code. Models for Combined Heat and Power (CHP) units, heat pumps, resistive Power-to-Heat(P2H), Power-to-Gas (P2G), battery electric vehicles (BEVs) and chained hydro reservoirs can now be built (see thesector coupling examples). The refactoring of time-dependent variable handling has been postponed until the 0.7.0release. In 0.7.0 the object interface to attributes may also be removed; see below.

All examples have been updated to accommodate the changes listed below.

Sector coupling

• components, opt: A new Store component has been introduced which stores energy, inheriting the energycarrier from the bus to which it is attached. The component is more fundamental than the StorageUnit,which is equivalent to a Store and two Link for storing and dispatching. The Generator is equivalent to aStore with a lossy Link. There is an example which shows the equivalences.

• components, opt: The Source component and the Generator attribute gen.source have been renamedCarrier and gen.carrier, to be consistent with the bus.carrier attribute. Please update your oldcode.

116 Chapter 17. Release Notes

Page 123: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

• components, opt: The Link attributes link.s_nom* have been renamed link.p_nom* to reflect the factthat the link can only dispatch active power. Please update your old code.

• components, opt: The TransportLink and Converter components, which were deprecated in 0.5.0, havebeen now completely removed. Please update your old code to use Link instead.

Downgrading object interface

The intention is to have only the pandas DataFrame interface for accessing component attributes, to make the codesimpler. The automatic generation of objects with descriptor access to attributes may be removed altogether.

• examples: Patterns of for loops through network.components.obj have been removed.

• components: The methods on Bus like bus.generators() and bus.loads() have been removed.

• components: network.add() no longer returns the object.

Other

• components, opf: Unlimited upper bounds for e.g. generator.p_nom_max or line.s_nom_max wereprevious set using np.nan; now they are set using float("inf") which is more logical. You may have toupdate your old code accordingly.

• components: A memory leak whereby references to component.network were not being correctly deletedhas been fixed.

PyPSA 0.5.0 (21st July 2016)

This is a relatively major release with some API changes, primarily aimed at allowing coupling with other energycarriers (heat, gas, etc.). The specification for a change and refactoring to the handling of time series has also beenprepared (see Time-varying data), which will be implemented in the next major release PyPSA 0.6.0 in the late summerof 2016.

An example of the coupling between electric and heating sectors can be found in the GitHub repository at pypsa/examples/coupling-with-heating/ and at http://www.pypsa.org/examples/lopf-with-heating.html.

• components: To allow other energy carriers, the attribute current_type fur buses and sub-neworks (sub-networks inherit the attribute from their buses) has been replaced by carrier which can take generic stringvalues (such as “heat” or “gas”). The values “DC” and “AC” have a special meaning and PyPSA will treat linesand transformers within these sub-networks according to the load flow equations. Other carriers can only havesingle buses in sub-networks connected by passive branches (since they have no load flow).

• components: A new component for a controllable directed link Link has been introduced; TransportLinkand Converter are now deprecated and will be removed soon in an 0.6.x release. Please move your codeover now. See Link for more details and a description of how to update your code to work with the new Linkcomponent. All the examples in the GitHub repository in pypsa/examples/ have been updated to us theLink.

• graph: A new sub-module pypsa.graph has been introduced to replace most of the networkx functionalitywith scipy.sparse methods, which are more performant the the pure python methods of networkx. The discoveryof network connected components is now significantly faster.

• io: The function network.export_to_csv_folder() has been rewritten to only export non-defaultvalues of static and series component attributes. Static and series attributes of all components are not exported ifthey are default values. The functionality to selectively export series has been removed from the export function,because it was clumsy and hard to use. See Export to folder of CSV files for more details.

17.13. PyPSA 0.5.0 (21st July 2016) 117

Page 124: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

• plot: Plotting networks is now more performant (using matplotlib LineCollections) and allows generic branchesto be plotted, not just lines.

• test: Unit testing for Security-Constrained Linear Optimal Power Flow (SCLOPF) has been introduced.

PyPSA 0.4.2 (17th June 2016)

This release improved the non-linear power flow performance and included other small refactorings:

• pf: The non-linear power flow network.pf() now accepts a list of snapshots network.pf(snapshots)and has been refactored to be much more performant.

• pf: Neither network.pf() nor network.lpf() accept the now argument anymore - for the power flowon a specific snapshot, either set network.now or pass the snapshot as an argument.

• descriptors: The code has been refactored and unified for each simple descriptor.

• opt: Constraints now accept both an upper and lower bound with ><.

• opf: Sub-optimal solutions can also be read out of pyomo.

PyPSA 0.4.1 (3rd April 2016)

This was mostly a bug-fixing and unit-testing release:

• pf: A bug was fixed in the full non-linear power flow, whereby the reactive power output of PV generators wasnot being set correctly.

• io: When importing from PYPOWER ppc, the generators, lines, transformers and shunt impedances are givennames like G1, G2, ..., L1, T1, S1, to help distinguish them. This change was introduced because the above bugwas not caught by the unit-testing because the generators were named after the buses.

• opf: A Python 3 dict.keys() list/iterator bug was fixed for the spillage.

• test: Unit-testing for the pf and opf with inflow was improved to catch bugs better.

We thank Joao Gorenstein Dedecca for a bug fix.

PyPSA 0.4.0 (21st March 2016)

Additional features:

• New module pypsa.contingency for contingency analysis and security-constrained LOPF

• New module pypsa.geo for basic manipulation of geographic data (distances and areas)

• Re-formulation of LOPF to improve optimisation solving time

• New objects pypsa.opt.LExpression and pypsa.opt.LConstraint to make the bypassing of pyomo for linear prob-lem construction easier to use

• Deep copying of networks with network.copy() (i.e. all components, time series and network attributesare copied)

• Stricter requirements for PyPI (e.g. pandas must be at least version 0.17.1 to get all the new features)

• Updated SciGRID-based model of Germany

118 Chapter 17. Release Notes

Page 125: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

• Various small bug fixes

We thank Steffen Schroedter, Bjoern Laemmerzahl and Joao Gorenstein Dedecca for comments and bug fixes.

PyPSA 0.3.3 (29th February 2016)

Additional features:

• network.lpf can be called on an iterable of snapshots i.e. network.lpf(snapshots), which ismore performant that calling network.lpf on each snapshot separately.

• Bug fix on import/export of transformers and shunt impedances (which were left out before).

• Refactoring of some internal code.

• Better network clustering.

PyPSA 0.3.2 (17th February 2016)

In this release some minor API changes were made:

• The Newton-Raphson tolerance network.nr_x_tol was moved to being an argument of the functionnetwork.pf(x_tol=1e-6) instead. This makes more sense and is then available in the docstring ofnetwork.pf.

• Following similar reasoning network.opf_keep_files was moved to being an argument of the functionnetwork.lopf(keep_files=False).

PyPSA 0.3.1 (7th February 2016)

In this release some minor API changes were made:

• Optimised capacities of generators/storage units and branches are now written to p_nom_opt and s_nom_optrespectively, instead of over-writing p_nom and s_nom

• The p_max/min limits of controllable branches are now p_max/min_pu per unit of s_nom, for consistency withgeneration and to allow unidirectional HVDCs / transport links for the capacity optimisation.

• network.remove() and io.import_series_from_dataframe() both take as argument class_name instead oflist_name or the object - this is now fully consistent with network.add(“Line”,”my line x”).

• The booleans network.topology_determined and network.dependent_values_calculated have been totally re-moved - this was causing unexpected behaviour. Instead, to avoid repeated unnecessary calculations, the expertuser can call functions with skip_pre=True.

PyPSA 0.3.0 (27th January 2016)

In this release the pandas.Panel interface for time-dependent variables was introduced. This replaced the manualattachment of pandas.DataFrames per time-dependent variable as attributes of the main component pandas.DataFrame.

17.17. PyPSA 0.3.3 (29th February 2016) 119

Page 126: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

120 Chapter 17. Release Notes

Page 127: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

EIGHTEEN

MAILING LIST

PyPSA has a Google Group forum / mailing list.

Anyone can join and anyone can read the posts; only members of the group can post to the list.

The intention is to have a place where announcements of new releases can be made and to discuss issues and sug-gest/contribute features for future development.

121

Page 128: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

PyPSA Documentation, Release 0.13.1

122 Chapter 18. Mailing list

Page 129: PyPSA Documentation Documentation, Release 0.13.0 PyPSA is not as fully featured as other power system simulation tools such as the Matlab-based free softwarePSAT

CHAPTER

NINETEEN

INDICES AND TABLES

• genindex

• modindex

• search

123