{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Diagnostic Function" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "A power flow calculation on a pandapower network can fail to converge (or fail to run at all) for a vast variety of reasons, which often makes debugging difficult, annoying and time consuming. To help with that, the diagnostic function automatically checks pandapower networks for the most common issues leading to errors. It provides logging output and diagnoses with a controllable level of detail. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example: faulty network\n", "\n", "To demonstrate the usage of the diagnostic function we will use a very basic exemplary pandapower network with several flaws.\n", "\n", "There will be no further explenation on how to create pandapower networks since there's a separate tutorial available in this regard." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# imports the pandapower module\n", "import pandapower as pp\n", "\n", "# defines a function that creates an example network, which will be used a lot in this tutorial\n", "# run this code first in order for the examples to work\n", "\n", "def faulty_example_network():\n", "\n", " net = pp.create_empty_network()\n", "\n", " pp.create_bus(net, name = \"110 kV bar\", vn_kv = 110, type = 'b', in_service = 'True')\n", " pp.create_bus(net, name = \"20 kV bar\", vn_kv = 20, type = 'b')\n", " pp.create_bus(net, name = \"bus 2\", vn_kv = 30, type = 'b')\n", " pp.create_bus(net, name = \"bus 3\", vn_kv = 20, type = 'b')\n", " pp.create_bus(net, name = \"bus 4\", vn_kv = 20, type = 'b')\n", " pp.create_bus(net, name = \"bus 5\", vn_kv = -20, type = 'b')\n", " pp.create_bus(net, name = \"bus 6\", vn_kv = 20, type = 'b')\n", " \n", " pp.create_ext_grid(net, 0, vm_pu = 1)\n", "\n", " pp.create_line(net, name = \"line 0\", from_bus = 1, to_bus = 2, length_km = 0, std_type = \"NAYY 4x150 SE\")\n", " pp.create_line(net, name = \"line 1\", from_bus = 2, to_bus = 3, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", " pp.create_line(net, name = \"line 2\", from_bus = 3, to_bus = 4, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", " pp.create_line(net, name = \"line 3\", from_bus = 4, to_bus = 5, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", " pp.create_line(net, name = \"line 4\", from_bus = 5, to_bus = 6, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", " pp.create_line(net, name = \"line 5\", from_bus = 6, to_bus = 1, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", "\n", " pp.create_transformer_from_parameters(net, hv_bus = 1, lv_bus = 0, i0_percent= 0.038, pfe_kw = 11.6,\n", " vscr_percent = 0.322, sn_kva = 40000.0, vn_lv_kv = 22.0,\n", " vn_hv_kv = 110.0, vsc_percent = 17.8)\n", "\n", " pp.create_load(net, 2, p_kw = -1000, q_kvar = 200, name = \"load 0\")\n", " pp.create_load(net, 3, p_kw = 1000, q_kvar = 200, name = \"load 1\")\n", " pp.create_load(net, 4, p_kw = 1000, q_kvar = 200, name = \"load 2\")\n", " pp.create_load(net, 5, p_kw = 1000, q_kvar = 200, name = \"load 3\")\n", " pp.create_load(net, 6, p_kw = 1000, q_kvar = 200, name = \"load 4\")\n", "\n", " pp.create_switch(net, bus = 1, element = 0, et = 'l')\n", " pp.create_switch(net, bus = 2, element = 0, et = 'l')\n", " pp.create_switch(net, bus = 2, element = 1, et = 'l')\n", " pp.create_switch(net, bus = 3, element = 1, et = 'l')\n", " pp.create_switch(net, bus = 3, element = 2, et = 'l')\n", " pp.create_switch(net, bus = 4, element = 2, et = 'l')\n", " pp.create_switch(net, bus = 4, element = 3, et = 'l', closed = 0)\n", " pp.create_switch(net, bus = 5, element = 3, et = 'l')\n", " pp.create_switch(net, bus = 5, element = 4, et = 'l', closed = 0)\n", " pp.create_switch(net, bus = 6, element = 4, et = 'l', closed = 0)\n", " pp.create_switch(net, bus = 6, element = 5, et = 'l')\n", " pp.create_switch(net, bus = 1, element = 5, et = 'l')\n", " \n", " return net" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Now let's create the network and try to run a load flow calculation." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "ename": "LoadflowNotConverged", "evalue": "Loadflow did not converge!", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mLoadflowNotConverged\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[1;31m# creates the example network\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mfaulty_net\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfaulty_example_network\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mpp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrunpp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfaulty_net\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32mD:\\Python\\pandapower\\pandapower\\run.py\u001b[0m in \u001b[0;36mrunpp\u001b[0;34m(net, init, calculate_voltage_angles, tolerance_kva, trafo_model, trafo_loading, enforce_q_lims, suppress_warnings, Numba, **kwargs)\u001b[0m\n\u001b[1;32m 94\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 95\u001b[0m _runpppf(net, init, ac, calculate_voltage_angles, tolerance_kva, trafo_model,\n\u001b[0;32m---> 96\u001b[0;31m trafo_loading, enforce_q_lims, suppress_warnings, Numba, **kwargs)\n\u001b[0m\u001b[1;32m 97\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 98\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[0;32mD:\\Python\\pandapower\\pandapower\\run.py\u001b[0m in \u001b[0;36m_runpppf\u001b[0;34m(net, init, ac, calculate_voltage_angles, tolerance_kva, trafo_model, trafo_loading, enforce_q_lims, suppress_warnings, Numba, **kwargs)\u001b[0m\n\u001b[1;32m 178\u001b[0m \u001b[1;31m# raise if PF was not successful. If DC -> success is always 1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 179\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"success\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 180\u001b[0;31m \u001b[1;32mraise\u001b[0m \u001b[0mLoadflowNotConverged\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Loadflow did not converge!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 181\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 182\u001b[0m \u001b[0mnet\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"_ppc\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[0;31mLoadflowNotConverged\u001b[0m: Loadflow did not converge!" ] } ], "source": [ "# creates the example network\n", "faulty_net = faulty_example_network()\n", "pp.runpp(faulty_net)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "As you can see there is at least one error in our network that prevents the load flow calculation from running properly." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Instead of analysing the code ourselves, we can use the diagnostic function to find the errors." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "\n", "_____________ PANDAPOWER DIAGNOSTIC TOOL _____________ \n", "\n", "Checking for invalid_values...\n", "\n", "bus:\n", "Invalid value found: 'bus 5' with attribute 'vn_kv' = -20.0 (data type: ). Valid input needs to be >0.\n", "line:\n", "Invalid value found: 'line 0' with attribute 'length_km' = 0.0 (data type: ). Valid input needs to be >0.\n", "\n", "SUMMARY: 2 invalid values found.\n", "\n", " --------\n", "\n", "Checking switch configuration...\n", "\n", "Power flow still does not converge with all switches closed.\n", "\n", " --------\n", "\n", "Checking for lines with impedance close to zero...\n", "\n", "Line 0: length_km: 0.0, r_ohm_per_km: 0.208, x_ohm_per_km: 0.08. Impedance is close to zero. If a direct connection between two buses was intended, please use a bus-bus-switch instead.\n", "\n", "SUMMARY: 1 line(s) with impedance close to zero found.\n", "\n", " --------\n", "\n", "Checking for components with deviating nominal voltages...\n", "\n", "Trafo(s) [0]: hv and lv connectors seem to be swapped\n", "\n", "SUMMARY: 1 components(s) with deviating nominal voltages found\n", "\n", " --------\n", "\n", "Checking for elements without a connection to an external grid...\n", "\n", "Disconnected section found, consisting of the following elements:\n", "switches: [7, 8]\n", "buses: [5]\n", "lines: [3]\n", "loads: [3]\n", "Disconnected section found, consisting of the following elements:\n", "isolated_lines: [4]\n", "\n", "SUMMARY: 6 disconnected element(s) found.\n", "\n", " --------\n", "\n", "Checking for usage of wrong reference system...\n", "\n", "Found load 0: 'load 0' with p_kw = -1000.0. In load reference system p_kw should be positive.\n", "\n", "SUMMARY: Found 1 load(s) with negative p_kw. In load reference system, p_kw should be positive. If the intention was to model a constant generation, please use an sgen instead.\n", "\n", " --------\n", "\n", "Checking for overload...\n", "\n", "Overload check failed: Power flow still does not converge with load scaled down to 0.1 percent.\n", "Overload check failed: Power flow still does not converge with generation scaled down to 0.1 percent.\n", "\n", " --------\n", "\n", "Checking for connections of different voltage levels...\n", "\n", "line 0 connects bus 1: 20 kV bar (vn_kv = 20.0) and bus 2: bus 2 (vn_kv = 30.0)\n", "line 1 connects bus 2: bus 2 (vn_kv = 30.0) and bus 3: bus 3 (vn_kv = 20.0)\n", "line 3 connects bus 4: bus 4 (vn_kv = 20.0) and bus 5: bus 5 (vn_kv = -20.0)\n", "line 4 connects bus 5: bus 5 (vn_kv = -20.0) and bus 6: bus 6 (vn_kv = 20.0)\n", "\n", "SUMMARY: 4 element(s) that connect different voltage levels found.\n", "\n", " --------\n", "\n", "_____________ END OF PANDAPOWER DIAGNOSTIC _____________ \n" ] }, { "data": { "text/plain": [ "{'different_voltage_levels_connected': {'lines': [0, 1, 3, 4]},\n", " 'disconnected_elements': [{'buses': [5],\n", " 'lines': [3],\n", " 'loads': [3],\n", " 'switches': [7, 8]},\n", " {'isolated_lines': [4]}],\n", " 'invalid_values': {'bus': [(5, 'vn_kv', -20.0, '>0')],\n", " 'line': [(0, 'length_km', 0.0, '>0')]},\n", " 'lines_with_impedance_close_to_zero': [0],\n", " 'nominal_voltages_dont_match': {'trafo': {'hv_lv_swapped': [0]}},\n", " 'overload': {'generation': 'uncertain', 'load': 'uncertain'},\n", " 'wrong_reference_system': {'loads': [0]},\n", " 'wrong_switch_configuration': 'uncertain'}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# diagnoses the faulty network\n", "pp.diagnostic(faulty_net)" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "You can scroll through the report to see all checks that have been performed and their results. In default mode, the report always looks like this:\n", "\n", "_____________ PANDAPOWER DIAGNOSTIC TOOL _____________\n", "\n", "Checking for [description of check 1]...\n", "\n", " [detailed error description]\n", " \n", "SUMMARY: [summary of errors found]\n", "\n", " --------\n", " \n", " Checking for [description of the check 2]...\n", "\n", " [detailed error description]\n", " \n", "SUMMARY: [summary of errors found]\n", "\n", " --------\n", " \n", "_____________ END OF PANDAPOWER DIAGNOSTIC _____________ \n", "\n", "\n", "The function also return a dict that contains the indices of all elements where errors were found for further usage." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Customizing the report\n", "\n", "For a more compact report, there a two options that can be passed as arguments to the diagnostic function:\n", "\n", "- warnings_only = True : only positive check results (errors found) will be in the report\n", "\n", "- detailed_report = False: only error summaries, no detailed error descriptions\n", "\n", "\n", "The default setting is:\n", "\n", "*diagnostic(net, warnings_only = False, detailed_report = True)*" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "\n", "_____________ PANDAPOWER DIAGNOSTIC TOOL _____________ \n", "\n", "Checking for invalid_values...\n", "\n", "bus:\n", "Invalid value found: 'bus 5' with attribute 'vn_kv' = -20.0 (data type: ). Valid input needs to be >0.\n", "line:\n", "Invalid value found: 'line 0' with attribute 'length_km' = 0.0 (data type: ). Valid input needs to be >0.\n", "\n", "SUMMARY: 2 invalid values found.\n", "\n", " --------\n", "\n", "Checking switch configuration...\n", "\n", "Power flow still does not converge with all switches closed.\n", "\n", " --------\n", "\n", "Checking for lines with impedance close to zero...\n", "\n", "Line 0: length_km: 0.0, r_ohm_per_km: 0.208, x_ohm_per_km: 0.08. Impedance is close to zero. If a direct connection between two buses was intended, please use a bus-bus-switch instead.\n", "\n", "SUMMARY: 1 line(s) with impedance close to zero found.\n", "\n", " --------\n", "\n", "Checking for components with deviating nominal voltages...\n", "\n", "Trafo(s) [0]: hv and lv connectors seem to be swapped\n", "\n", "SUMMARY: 1 components(s) with deviating nominal voltages found\n", "\n", " --------\n", "\n", "Checking for elements without a connection to an external grid...\n", "\n", "Disconnected section found, consisting of the following elements:\n", "switches: [7, 8]\n", "buses: [5]\n", "lines: [3]\n", "loads: [3]\n", "Disconnected section found, consisting of the following elements:\n", "isolated_lines: [4]\n", "\n", "SUMMARY: 6 disconnected element(s) found.\n", "\n", " --------\n", "\n", "Checking for usage of wrong reference system...\n", "\n", "Found load 0: 'load 0' with p_kw = -1000.0. In load reference system p_kw should be positive.\n", "\n", "SUMMARY: Found 1 load(s) with negative p_kw. In load reference system, p_kw should be positive. If the intention was to model a constant generation, please use an sgen instead.\n", "\n", " --------\n", "\n", "Checking for overload...\n", "\n", "Overload check failed: Power flow still does not converge with load scaled down to 0.1 percent.\n", "Overload check failed: Power flow still does not converge with generation scaled down to 0.1 percent.\n", "\n", " --------\n", "\n", "Checking for connections of different voltage levels...\n", "\n", "line 0 connects bus 1: 20 kV bar (vn_kv = 20.0) and bus 2: bus 2 (vn_kv = 30.0)\n", "line 1 connects bus 2: bus 2 (vn_kv = 30.0) and bus 3: bus 3 (vn_kv = 20.0)\n", "line 3 connects bus 4: bus 4 (vn_kv = 20.0) and bus 5: bus 5 (vn_kv = -20.0)\n", "line 4 connects bus 5: bus 5 (vn_kv = -20.0) and bus 6: bus 6 (vn_kv = 20.0)\n", "\n", "SUMMARY: 4 element(s) that connect different voltage levels found.\n", "\n", " --------\n", "\n", "_____________ END OF PANDAPOWER DIAGNOSTIC _____________ \n" ] }, { "data": { "text/plain": [ "{'different_voltage_levels_connected': {'lines': [0, 1, 3, 4]},\n", " 'disconnected_elements': [{'buses': [5],\n", " 'lines': [3],\n", " 'loads': [3],\n", " 'switches': [7, 8]},\n", " {'isolated_lines': [4]}],\n", " 'invalid_values': {'bus': [(5, 'vn_kv', -20.0, '>0')],\n", " 'line': [(0, 'length_km', 0.0, '>0')]},\n", " 'lines_with_impedance_close_to_zero': [0],\n", " 'nominal_voltages_dont_match': {'trafo': {'hv_lv_swapped': [0]}},\n", " 'overload': {'generation': 'uncertain', 'load': 'uncertain'},\n", " 'wrong_reference_system': {'loads': [0]},\n", " 'wrong_switch_configuration': 'uncertain'}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# report with warnings_only\n", "pp.diagnostic(faulty_net, warnings_only = True)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "\n", "_____________ PANDAPOWER DIAGNOSTIC TOOL _____________ \n", "\n", "invalid_values:\n", "\n", "bus:\n", "bus 5: 'vn_kv' = -20.0 (restriction: >0)\n", "line:\n", "line 0: 'length_km' = 0.0 (restriction: >0)\n", "\n", " --------\n", "\n", "wrong_switch_configuration:\n", "\n", "Power flow still does not converge with all switches closed.\n", "\n", " --------\n", "\n", "lines_with_impedance_close_to_zero:\n", "\n", "line 0: length_km: 0.0; r_ohm_per_km: 0.208; x_ohm_per_km: 0.08\n", "\n", " --------\n", "\n", "nominal_voltages_dont_match:\n", "\n", "trafo:\n", "hv_lv_swapped: [0]\n", "\n", " --------\n", "\n", "disconnected_elements:\n", "\n", "disonnected_section: {'switches': [7, 8], 'buses': [5], 'lines': [3], 'loads': [3]}\n", "disonnected_section: {'isolated_lines': [4]}\n", "\n", " --------\n", "\n", "wrong_reference_system:\n", "\n", "loads [0]: wrong reference system.\n", "\n", " --------\n", "\n", "overload:\n", "\n", "power flow still does not converge after load downscaling.\n", "power flow still does not converge after generation downscaling.\n", "\n", " --------\n", "\n", "different_voltage_levels_connected:\n", "\n", "lines:\n", "line 0: buses [1, 2]\n", "line 1: buses [2, 3]\n", "line 3: buses [4, 5]\n", "line 4: buses [5, 6]\n", "\n", " --------\n", "\n", "_____________ END OF PANDAPOWER DIAGNOSTIC _____________ \n" ] }, { "data": { "text/plain": [ "{'different_voltage_levels_connected': {'lines': [0, 1, 3, 4]},\n", " 'disconnected_elements': [{'buses': [5],\n", " 'lines': [3],\n", " 'loads': [3],\n", " 'switches': [7, 8]},\n", " {'isolated_lines': [4]}],\n", " 'invalid_values': {'bus': [(5, 'vn_kv', -20.0, '>0')],\n", " 'line': [(0, 'length_km', 0.0, '>0')]},\n", " 'lines_with_impedance_close_to_zero': [0],\n", " 'nominal_voltages_dont_match': {'trafo': {'hv_lv_swapped': [0]}},\n", " 'overload': {'generation': 'uncertain', 'load': 'uncertain'},\n", " 'wrong_reference_system': {'loads': [0]},\n", " 'wrong_switch_configuration': 'uncertain'}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# report with summaries only\n", "pp.diagnostic(faulty_net, report_style=\"compact\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Let's have a look a the default report again" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "\n", "_____________ PANDAPOWER DIAGNOSTIC TOOL _____________ \n", "\n", "Checking for invalid_values...\n", "\n", "bus:\n", "Invalid value found: 'bus 5' with attribute 'vn_kv' = -20.0 (data type: ). Valid input needs to be >0.\n", "line:\n", "Invalid value found: 'line 0' with attribute 'length_km' = 0.0 (data type: ). Valid input needs to be >0.\n", "\n", "SUMMARY: 2 invalid values found.\n", "\n", " --------\n", "\n", "Checking switch configuration...\n", "\n", "Power flow still does not converge with all switches closed.\n", "\n", " --------\n", "\n", "Checking for lines with impedance close to zero...\n", "\n", "Line 0: length_km: 0.0, r_ohm_per_km: 0.208, x_ohm_per_km: 0.08. Impedance is close to zero. If a direct connection between two buses was intended, please use a bus-bus-switch instead.\n", "\n", "SUMMARY: 1 line(s) with impedance close to zero found.\n", "\n", " --------\n", "\n", "Checking for components with deviating nominal voltages...\n", "\n", "Trafo(s) [0]: hv and lv connectors seem to be swapped\n", "\n", "SUMMARY: 1 components(s) with deviating nominal voltages found\n", "\n", " --------\n", "\n", "Checking for elements without a connection to an external grid...\n", "\n", "Disconnected section found, consisting of the following elements:\n", "switches: [7, 8]\n", "buses: [5]\n", "lines: [3]\n", "loads: [3]\n", "Disconnected section found, consisting of the following elements:\n", "isolated_lines: [4]\n", "\n", "SUMMARY: 6 disconnected element(s) found.\n", "\n", " --------\n", "\n", "Checking for usage of wrong reference system...\n", "\n", "Found load 0: 'load 0' with p_kw = -1000.0. In load reference system p_kw should be positive.\n", "\n", "SUMMARY: Found 1 load(s) with negative p_kw. In load reference system, p_kw should be positive. If the intention was to model a constant generation, please use an sgen instead.\n", "\n", " --------\n", "\n", "Checking for overload...\n", "\n", "Overload check failed: Power flow still does not converge with load scaled down to 0.1 percent.\n", "Overload check failed: Power flow still does not converge with generation scaled down to 0.1 percent.\n", "\n", " --------\n", "\n", "Checking for connections of different voltage levels...\n", "\n", "line 0 connects bus 1: 20 kV bar (vn_kv = 20.0) and bus 2: bus 2 (vn_kv = 30.0)\n", "line 1 connects bus 2: bus 2 (vn_kv = 30.0) and bus 3: bus 3 (vn_kv = 20.0)\n", "line 3 connects bus 4: bus 4 (vn_kv = 20.0) and bus 5: bus 5 (vn_kv = -20.0)\n", "line 4 connects bus 5: bus 5 (vn_kv = -20.0) and bus 6: bus 6 (vn_kv = 20.0)\n", "\n", "SUMMARY: 4 element(s) that connect different voltage levels found.\n", "\n", " --------\n", "\n", "_____________ END OF PANDAPOWER DIAGNOSTIC _____________ \n" ] }, { "data": { "text/plain": [ "{'different_voltage_levels_connected': {'lines': [0, 1, 3, 4]},\n", " 'disconnected_elements': [{'buses': [5],\n", " 'lines': [3],\n", " 'loads': [3],\n", " 'switches': [7, 8]},\n", " {'isolated_lines': [4]}],\n", " 'invalid_values': {'bus': [(5, 'vn_kv', -20.0, '>0')],\n", " 'line': [(0, 'length_km', 0.0, '>0')]},\n", " 'lines_with_impedance_close_to_zero': [0],\n", " 'nominal_voltages_dont_match': {'trafo': {'hv_lv_swapped': [0]}},\n", " 'overload': {'generation': 'uncertain', 'load': 'uncertain'},\n", " 'wrong_reference_system': {'loads': [0]},\n", " 'wrong_switch_configuration': 'uncertain'}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# diagnoses the faulty network\n", "pp.diagnostic(faulty_net)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Disconnected elements" ] }, { "cell_type": "raw", "metadata": { "collapsed": true }, "source": [ "Checking for isolated sections...\n", "\n", " Isolated section found consisting of 1 bus(ses):\n", " Bus 5: 'bus 5'\n", "\n", " Isolated line found: Line 4: 'line 4'.\n", "\n", "SUMMARY: 2 isolated section(s) found." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Bus 5, lines 3, 4 and load 3 are isolated by open switches. To fix that, we close switches 8 and 9." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [], "source": [ "faulty_net.switch.closed.loc[8, 9] = 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Inconsistent voltages" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "Checking for inconsistent voltages...\n", "\n", " Line 0 connects bus 1: '20 kV bar' (voltage level 20.0 kV) and bus 2: 'bus 2' (voltage level 30.0 kV)\n", "\n", " Line 1 connects bus 2: 'bus 2' (voltage level 30.0 kV) and bus 3: 'bus 3' (voltage level 20.0 kV)\n", "\n", " Line 3 connects bus 4: 'bus 4' (voltage level 20.0 kV) and bus 5: 'bus 5' (voltage level -20.0 kV)\n", "\n", " Line 4 connects bus 5: 'bus 5' (voltage level -20.0 kV) and bus 6: 'bus 6' (voltage level 20.0 kV)\n", "\n", "SUMMARY:\n", "4 line(s) that connect(s) different voltage levels found." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lines 0, 1, 3 and 4 connect different voltage levels. Apparently bus 2 (30 kV) and bus 5 (-20 kV) have wrong voltage levels values. We change that to 20 kV." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [], "source": [ "faulty_net.bus.vn_kv.loc[2, 5] = 20" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Lines with impedance zero" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "Checking for lines with impedance zero...\n", "\n", " Length of line 0 = 0 km with impedance 0. If a direct connection between two buses was intended, please use a bus-bus-switch instead.\n", "\n", "SUMMARY: 1 line(s) with impedance zero found" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Line 0 is 0 km long (and therefore its impedance is 0 ohm). We change the length to 1 km." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [], "source": [ "faulty_net.line.length_km.at[0] = 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Deviating nominal voltages" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "Checking for components with deviating nominal voltages...\n", "\n", " Trafo 0: hv and lv connectors seem to be swapped.\n", "\n", "SUMMARY:\n", "1 trafo(s) with swapped hv and lv connectors found." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We fix that by swapping the hv and lv connectors of trafo 0 back." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ "faulty_net.trafo.hv_bus.at[0] = 0\n", "faulty_net.trafo.lv_bus.at[0] = 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Invalid values" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "Checking for invalid values...\n", " Invalid value found: 'bus 0' with attribute 'in_service'= True (data type: ). Valid input needs to be boolean.\n", "\n", "SUMMARY: 1 invalid values found." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The value for the attribute 'in_service' of bus 0 is a string although it is supposed to be a boolean. We fix that." ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": true }, "outputs": [], "source": [ "faulty_net.bus.in_service.at[0] = True" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Wrong reference system" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "Checking for usage of wrong reference system...\n", "\n", " Found load 0: load 0 with p_kw = -1000. Load reference system is used, therefore p_kw should be positive.\n", "SUMMARY: Found 1 loads with negative p_kw. Load reference system is, used therefore p_kw should be positive. If the intention was to model a constant generation, please use an sgen instead." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load 0 has a p_kw value of -1000. Since pandapower uses the load reference system, the value should either be positive or an sgen should be used. We assume the former and change the value to 1000." ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true }, "outputs": [], "source": [ "faulty_net.load.p_kw.at[0] = 1000" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "\n", "_____________ PANDAPOWER DIAGNOSTIC TOOL _____________ \n", "\n", "_____________ END OF PANDAPOWER DIAGNOSTIC _____________ \n" ] }, { "data": { "text/plain": [ "{}" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# new diagnosis to check, whether we fixed all errors\n", "pp.diagnostic(faulty_net)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Apparently, all errors have been fixed. So we can try again to run a loadflow calculation." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "This pandapower network includes the following parameter tables:\n", " - bus (7 elements)\n", " - load (5 elements)\n", " - ext_grid (1 elements)\n", " - switch (12 elements)\n", " - trafo (1 elements)\n", " - line (6 elements)\n", " and the following results tables:\n", " - res_bus (7 elements)\n", " - res_trafo (1 elements)\n", " - res_load (5 elements)\n", " - res_ext_grid (1 elements)\n", " - res_line (6 elements)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pp.runpp(faulty_net)\n", "faulty_net" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now the loadflow calculation runs without problems." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Detecting overloads and wrong switch configurations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Other errors the diagnostic function can help to identify, are networks with too much load or wrong switch configurations. The function automatically checks, if the loadflow converges with all loads and generation scaled down to 0.1% or with all switches closed." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# imports the pandapower module\n", "import pandapower as pp\n", "\n", "# defines a function that creates an example network\n", "# run this code first in order for the examples to work\n", "\n", "def overload_example_network():\n", "\n", " net = pp.create_empty_network()\n", "\n", " pp.create_bus(net, name = \"110 kV bar\", vn_kv = 110, type = 'b')\n", " pp.create_bus(net, name = \"20 kV bar\", vn_kv = 20, type = 'b')\n", " pp.create_bus(net, name = \"bus 2\", vn_kv = 20, type = 'b')\n", " pp.create_bus(net, name = \"bus 3\", vn_kv = 20, type = 'b')\n", " pp.create_bus(net, name = \"bus 4\", vn_kv = 20, type = 'b')\n", " pp.create_bus(net, name = \"bus 5\", vn_kv = 20, type = 'b')\n", " pp.create_bus(net, name = \"bus 6\", vn_kv = 20, type = 'b')\n", " \n", " pp.create_ext_grid(net, 0, vm_pu = 1)\n", "\n", " pp.create_line(net, name = \"line 0\", from_bus = 1, to_bus = 2, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", " pp.create_line(net, name = \"line 1\", from_bus = 2, to_bus = 3, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", " pp.create_line(net, name = \"line 2\", from_bus = 3, to_bus = 4, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", " pp.create_line(net, name = \"line 3\", from_bus = 4, to_bus = 5, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", " pp.create_line(net, name = \"line 4\", from_bus = 5, to_bus = 6, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", " pp.create_line(net, name = \"line 5\", from_bus = 6, to_bus = 1, length_km = 1, std_type = \"NAYY 4x150 SE\")\n", "\n", " pp.create_transformer_from_parameters(net, hv_bus = 0, lv_bus = 1, i0_percent= 0.038, pfe_kw = 11.6,\n", " vscr_percent = 0.322, sn_kva = 40000.0, vn_lv_kv = 22.0,\n", " vn_hv_kv = 110.0, vsc_percent = 17.8)\n", "\n", " pp.create_load(net, 2, p_kw = 100000, q_kvar = 200, name = \"load 0\")\n", " pp.create_load(net, 3, p_kw = 100000, q_kvar = 200, name = \"load 1\")\n", " pp.create_load(net, 4, p_kw = 100000, q_kvar = 200, name = \"load 2\")\n", " pp.create_load(net, 5, p_kw = 100000, q_kvar = 200, name = \"load 3\")\n", " pp.create_load(net, 6, p_kw = 100000, q_kvar = 200, name = \"load 4\")\n", "\n", " pp.create_switch(net, bus = 1, element = 0, et = 'l')\n", " pp.create_switch(net, bus = 2, element = 0, et = 'l')\n", " pp.create_switch(net, bus = 2, element = 1, et = 'l')\n", " pp.create_switch(net, bus = 3, element = 1, et = 'l')\n", " pp.create_switch(net, bus = 3, element = 2, et = 'l')\n", " pp.create_switch(net, bus = 4, element = 2, et = 'l')\n", " pp.create_switch(net, bus = 4, element = 3, et = 'l', closed = 0)\n", " pp.create_switch(net, bus = 5, element = 3, et = 'l')\n", " pp.create_switch(net, bus = 5, element = 4, et = 'l')\n", " pp.create_switch(net, bus = 6, element = 4, et = 'l')\n", " pp.create_switch(net, bus = 6, element = 5, et = 'l')\n", " pp.create_switch(net, bus = 1, element = 5, et = 'l')\n", " \n", " return net" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "ename": "LoadflowNotConverged", "evalue": "Loadflow did not converge!", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mLoadflowNotConverged\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0moverload_net\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0moverload_example_network\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mpp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrunpp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0moverload_net\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32mD:\\Python\\pandapower\\pandapower\\run.py\u001b[0m in \u001b[0;36mrunpp\u001b[0;34m(net, init, calculate_voltage_angles, tolerance_kva, trafo_model, trafo_loading, enforce_q_lims, suppress_warnings, Numba, **kwargs)\u001b[0m\n\u001b[1;32m 94\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 95\u001b[0m _runpppf(net, init, ac, calculate_voltage_angles, tolerance_kva, trafo_model,\n\u001b[0;32m---> 96\u001b[0;31m trafo_loading, enforce_q_lims, suppress_warnings, Numba, **kwargs)\n\u001b[0m\u001b[1;32m 97\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 98\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[0;32mD:\\Python\\pandapower\\pandapower\\run.py\u001b[0m in \u001b[0;36m_runpppf\u001b[0;34m(net, init, ac, calculate_voltage_angles, tolerance_kva, trafo_model, trafo_loading, enforce_q_lims, suppress_warnings, Numba, **kwargs)\u001b[0m\n\u001b[1;32m 178\u001b[0m \u001b[1;31m# raise if PF was not successful. If DC -> success is always 1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 179\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"success\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 180\u001b[0;31m \u001b[1;32mraise\u001b[0m \u001b[0mLoadflowNotConverged\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Loadflow did not converge!\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 181\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 182\u001b[0m \u001b[0mnet\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"_ppc\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[0;31mLoadflowNotConverged\u001b[0m: Loadflow did not converge!" ] } ], "source": [ "overload_net = overload_example_network()\n", "pp.runpp(overload_net)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "\n", "_____________ PANDAPOWER DIAGNOSTIC TOOL _____________ \n", "\n", "Checking for overload...\n", "\n", "Possibly overload found: power flow converges with load scaled down to 0.1 percent.\n", "Overload check failed: Power flow still does not converge with generation scaled down to 0.1 percent.\n", "\n", " --------\n", "\n", "Checking switch configuration...\n", "\n", "Power flow still does not converge with all switches closed.\n", "\n", " --------\n", "\n", "_____________ END OF PANDAPOWER DIAGNOSTIC _____________ \n" ] }, { "data": { "text/plain": [ "{'overload': {'generation': 'uncertain', 'load': True},\n", " 'wrong_switch_configuration': 'uncertain'}" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pp.diagnostic(overload_net, warnings_only = True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you can see, with loads scaled down, the loadflow converges, which helps to isolate the problem." ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [default]", "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.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }