{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Minimal Example pandapower\n", "\n", "\n", "## Creating a Power System\n", "\n", "We consider the following simple 3-bus example network as a minimal example:\n", "\n", "\n", "\n", "The above network can be created in pandapower as follows:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandapower as pp\n", "\n", "#create empty net\n", "net = pp.create_empty_network()\n", "\n", "#create buses\n", "bus1 = pp.create_bus(net, vn_kv=20., name=\"Bus 1\")\n", "bus2 = pp.create_bus(net, vn_kv=0.4, name=\"Bus 2\")\n", "bus3 = pp.create_bus(net, vn_kv=0.4, name=\"Bus 3\")\n", "\n", "#create bus elements\n", "pp.create_ext_grid(net, bus=bus1, vm_pu=1.02, name=\"Grid Connection\")\n", "pp.create_load(net, bus=bus3, p_mw=0.100, q_mvar=0.05, name=\"Load\")\n", "\n", "#create branch elements\n", "trafo = pp.create_transformer(net, hv_bus=bus1, lv_bus=bus2, std_type=\"0.4 MVA 20/0.4 kV\", name=\"Trafo\")\n", "line = pp.create_line(net, from_bus=bus2, to_bus=bus3, length_km=0.1, std_type=\"NAYY 4x50 SE\", name=\"Line\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data Structure\n", "\n", "Each dataframe in a pandapower net object contains the information about one pandapower element, such as line, load transformer etc." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
namevn_kvtypezonein_service
0Bus 120.0bNoneTrue
1Bus 20.4bNoneTrue
2Bus 30.4bNoneTrue
\n", "
" ], "text/plain": [ " name vn_kv type zone in_service\n", "0 Bus 1 20.0 b None True\n", "1 Bus 2 0.4 b None True\n", "2 Bus 3 0.4 b None True" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.bus" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
namestd_typefrom_busto_buslength_kmr_ohm_per_kmx_ohm_per_kmc_nf_per_kmg_us_per_kmmax_i_kadfparalleltypein_service
0LineNAYY 4x50 SE120.10.6420.083210.00.00.1421.01csTrue
\n", "
" ], "text/plain": [ " name std_type from_bus to_bus length_km r_ohm_per_km \\\n", "0 Line NAYY 4x50 SE 1 2 0.1 0.642 \n", "\n", " x_ohm_per_km c_nf_per_km g_us_per_km max_i_ka df parallel type \\\n", "0 0.083 210.0 0.0 0.142 1.0 1 cs \n", "\n", " in_service \n", "0 True " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.line" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
namestd_typehv_buslv_bussn_mvavn_hv_kvvn_lv_kvvk_percentvkr_percentpfe_kw...tap_neutraltap_mintap_maxtap_step_percenttap_step_degreetap_postap_phase_shifterparalleldfin_service
0Trafo0.4 MVA 20/0.4 kV010.420.00.46.01.4251.35...0-222.50.00False11.0True
\n", "

1 rows × 23 columns

\n", "
" ], "text/plain": [ " name std_type hv_bus lv_bus sn_mva vn_hv_kv vn_lv_kv \\\n", "0 Trafo 0.4 MVA 20/0.4 kV 0 1 0.4 20.0 0.4 \n", "\n", " vk_percent vkr_percent pfe_kw ... tap_neutral tap_min tap_max \\\n", "0 6.0 1.425 1.35 ... 0 -2 2 \n", "\n", " tap_step_percent tap_step_degree tap_pos tap_phase_shifter parallel \\\n", "0 2.5 0.0 0 False 1 \n", "\n", " df in_service \n", "0 1.0 True \n", "\n", "[1 rows x 23 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.trafo" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
namebusp_mwq_mvarconst_z_percentconst_i_percentsn_mvascalingin_servicetype
0Load20.10.050.00.0NaN1.0Truewye
\n", "
" ], "text/plain": [ " name bus p_mw q_mvar const_z_percent const_i_percent sn_mva scaling \\\n", "0 Load 2 0.1 0.05 0.0 0.0 NaN 1.0 \n", "\n", " in_service type \n", "0 True wye " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.load" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that line and transformer are created with standard types, so thath the electric parameters of are automatically filled in from the standard type library." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Power Flow\n", "\n", "We now run a power flow:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "pp.runpp(net)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And check out at the results for buses, lines an transformers:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
vm_puva_degreep_mwq_mvar
01.0200000.000000-0.107265-0.052675
11.008843-0.7601260.0000000.000000
20.9644310.1158590.1000000.050000
\n", "
" ], "text/plain": [ " vm_pu va_degree p_mw q_mvar\n", "0 1.020000 0.000000 -0.107265 -0.052675\n", "1 1.008843 -0.760126 0.000000 0.000000\n", "2 0.964431 0.115859 0.100000 0.050000" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_bus" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_from_mwq_from_mvarp_to_mwq_to_mvarpl_mwql_mvari_from_kai_to_kai_kavm_from_puva_from_degreevm_to_puva_to_degreeloading_percent
00.1053920.050696-0.1-0.050.0053920.0006960.1673250.1673260.1673261.008843-0.7601260.9644310.115859117.835208
\n", "
" ], "text/plain": [ " p_from_mw q_from_mvar p_to_mw q_to_mvar pl_mw ql_mvar i_from_ka \\\n", "0 0.105392 0.050696 -0.1 -0.05 0.005392 0.000696 0.167325 \n", "\n", " i_to_ka i_ka vm_from_pu va_from_degree vm_to_pu va_to_degree \\\n", "0 0.167326 0.167326 1.008843 -0.760126 0.964431 0.115859 \n", "\n", " loading_percent \n", "0 117.835208 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_line" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_hv_mwq_hv_mvarp_lv_mwq_lv_mvarpl_mwql_mvari_hv_kai_lv_kavm_hv_puva_hv_degreevm_lv_puva_lv_degreeloading_percent
00.1072650.052675-0.105392-0.0506960.0018730.0019790.0033820.1673251.020.01.008843-0.76012629.289513
\n", "
" ], "text/plain": [ " p_hv_mw q_hv_mvar p_lv_mw q_lv_mvar pl_mw ql_mvar i_hv_ka \\\n", "0 0.107265 0.052675 -0.105392 -0.050696 0.001873 0.001979 0.003382 \n", "\n", " i_lv_ka vm_hv_pu va_hv_degree vm_lv_pu va_lv_degree loading_percent \n", "0 0.167325 1.02 0.0 1.008843 -0.760126 29.289513 " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_trafo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Tap Changers\n", "\n", "We now lower the tap changer position, from position 0 to -1 and run another power flow:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "net.trafo.tap_pos.at[trafo] = -1\n", "pp.runpp(net)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Looking at the results shows that bus voltages at the low voltage side of the transformer have increased:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
vm_puva_degreep_mwq_mvar
01.0200000.000000-0.107015-0.052529
11.035301-0.7202450.0000000.000000
20.9921350.1095130.1000000.050000
\n", "
" ], "text/plain": [ " vm_pu va_degree p_mw q_mvar\n", "0 1.020000 0.000000 -0.107015 -0.052529\n", "1 1.035301 -0.720245 0.000000 0.000000\n", "2 0.992135 0.109513 0.100000 0.050000" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_bus" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Switches\n", "\n", "We now create an open switch at the load bus:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pp.create_switch(net, bus=bus3, element=line, et=\"l\", closed=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The open switch cuts the load bus from power supply:\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This can be verified by running a power flow and inspecting the results. The voltage at bus 2 is given as NaN:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
vm_puva_degreep_mwq_mvar
01.0200000.000000-0.0014770.000001
11.046129-0.0056370.0000000.000000
2NaNNaN0.0000000.000000
\n", "
" ], "text/plain": [ " vm_pu va_degree p_mw q_mvar\n", "0 1.020000 0.000000 -0.001477 0.000001\n", "1 1.046129 -0.005637 0.000000 0.000000\n", "2 NaN NaN 0.000000 0.000000" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pp.runpp(net)\n", "net.res_bus" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The load does not feed in:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_mwq_mvar
00.00.0
\n", "
" ], "text/plain": [ " p_mw q_mvar\n", "0 0.0 0.0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_load" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And the line is in open loop operation:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_from_mwq_from_mvarp_to_mwq_to_mvarpl_mwql_mvari_from_kai_to_kai_kavm_from_puva_from_degreevm_to_puva_to_degreeloading_percent
01.230380e-13-0.000001-4.645745e-164.580705e-201.225734e-13-0.0000010.0000026.409876e-160.0000021.046129-0.0056371.046129-0.0056490.001122
\n", "
" ], "text/plain": [ " p_from_mw q_from_mvar p_to_mw q_to_mvar pl_mw \\\n", "0 1.230380e-13 -0.000001 -4.645745e-16 4.580705e-20 1.225734e-13 \n", "\n", " ql_mvar i_from_ka i_to_ka i_ka vm_from_pu va_from_degree \\\n", "0 -0.000001 0.000002 6.409876e-16 0.000002 1.046129 -0.005637 \n", "\n", " vm_to_pu va_to_degree loading_percent \n", "0 1.046129 -0.005649 0.001122 " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_line" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Topological Analysis\n", "\n", "The structure of the network can also be directly analyzed with the topology package. It uses an interface to the NetworkX library for graph searches. There are some predefined search algorithms, such as searching for unsupplied buses:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{2}" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandapower.topology as top\n", "top.unsupplied_buses(net)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The package correctly determines that bus 2 is cut from power supply. When we close the switch, there are no unsupplied buses anymore:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "set()" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.switch.closed.at[0] = True\n", "top.unsupplied_buses(net)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Apart from predefined search functions, it is also possible to translate the pandapower network into a NetworkX graph and run searches directly on that graph.\n", "\n", "Suppose we want to find all buses that are on the same voltage level as the load bus. We then translate the grid into a graph but excluding the transformer:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "mg = top.create_nxgraph(net, include_trafos=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And search for all buses that are connected to the load bus in that graph:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[2, 1]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(top.connected_component(mg, 2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The graph search finds all buses that are on the same voltage level. Searches like these can be used for feeder identification and many more applications." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Short Circuit Analysis\n", "\n", "pandapower includes a short circuit module that complies with IEC 60909. To run a short circuit analysis, we need to define short circuit parameters for the external grid:" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "net.ext_grid[\"s_sc_max_mva\"] = 100\n", "net.ext_grid[\"rx_max\"] = 0.1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can calculate short circuits. Here, we calculate a three phase short circuit current with a fault impedance of 2 Ohms:" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "import pandapower.shortcircuit as sc\n", "sc.calc_sc(net, case=\"max\", ip=True, r_fault_ohm=2.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Initial and peak short circuit currents are given for faults at all buses:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ikss_kaskss_mwip_kark_ohmxk_ohm
02.53470787.8048244.3173182.4378164.378164
10.1266310.0877330.1826662.0059300.025290
20.1226980.0850080.1769912.0701300.033590
\n", "
" ], "text/plain": [ " ikss_ka skss_mw ip_ka rk_ohm xk_ohm\n", "0 2.534707 87.804824 4.317318 2.437816 4.378164\n", "1 0.126631 0.087733 0.182666 2.005930 0.025290\n", "2 0.122698 0.085008 0.176991 2.070130 0.033590" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_bus_sc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This concludes a short walkthrough of some pandapower features. More in-depth tutorials can be found in the pandapower documentation:\n", "https://www.pandapower.org/start/#interactive-tutorials-" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 2 }