Contingency analysis

We can define N-1 cases to be analysed as contingencies. This means that indices of net.line, net.trafo, net.trafo3w can be defined as contingencies, which are switched off one at a time. The power system is analyzed with power flow calculations, and the min/max values among all the N-1 cases are obtained for relevant variables.

A tutorial that introduces this feature with an example is available at Contingency analysis

pandapower.contingency.run_contingency(net, nminus1_cases, pf_options=None, pf_options_nminus1=None, write_to_net=True, contingency_evaluation_function=runpp, **kwargs)

Obtain either loading (N-0) or max. loading (N-0 and all N-1 cases), and min/max bus voltage magnitude. The variable temperature_degree_celsius can be used in addition to loading_percent to obtain max. temperature. In the returned dictionary, the variable loading_percent represents the loading in N-0 case, max_loading_percent and min_loading_percent represent highest and lowest observed loading_percent among all calculated N-1 cases. The same convention applies to temperature_degree_celsius when applicable. This function can be passed through to pandapower.timeseries.run_timeseries() as the run_control_fct argument.

Parameters:
  • net (pandapowerNet) – The pandapower network

  • nminus1_cases (dict) – describes all N-1 cases, e.g. {“line”: {“index”: [1, 2, 3]}, “trafo”: {“index”: [0]}, “trafo3w”: {“index”: [1]}}

  • pf_options (dict) – options for power flow calculation in N-0 case

  • pf_options_nminus1 (dict) – options for power flow calculation in N-1 cases

  • write_to_net (bool) – whether to write the results of contingency analysis to net (in res_ tables). The results will be written for the following additional variables: table res_bus with columns max_vm_pu, min_vm_pu, tables res_line, res_trafo, res_trafo3w with columns max_loading_percent, min_loading_percent, causes_overloading, cause_element, cause_index, table res_line with columns max_temperature_degree_celsius, min_temperature_degree_celsius (if tdpf set to True) “causes_overloading”: does this element, when defining the N-1 case, cause overloading of other elements? the overloading is defined by net.line[“max_loading_percent_nminus1”] (if set) or net.line[“max_loading_percent”] “cause_element”: element (“line”, “trafo”, “trafo3w”) that causes max. loading of this element “cause_index”: index of the element (“line”, “trafo”, “trafo3w”) that causes max. loading of this element

  • contingency_evaluation_function (callable) – function to use for power flow calculation, default runpp

Returns:

contingency results dict of arrays per element for index, min/max result

Return type:

dict

pandapower.contingency.run_contingency_ls2g(net, nminus1_cases, contingency_evaluation_function=runpp, **kwargs)

Execute contingency analysis using the lightsim2grid library. This works much faster than using pandapower. This function can be passed through to pandapower.timeseries.run_timeseries as the run_control_fct argument.

Limitation

The results for branch flows are valid only for the “from_bus” of lines and “hv_bus” of transformers. This can lead to a small difference to the results using pandapower. The results are written in pandapower results tables. Make sure that the N-1 cases do not lead to isolated grid, otherwise results with pandapower and this function will be different. Reason: pandapower selects a different gen as slack if the grid becomes isolated, but lightsim2grid would simply return nan as results for such a contingency situation.

Warning

continuous bus indices, starting from 0, are required!

The results will written for the following additional variables: table res_bus with columns “max_vm_pu”, “min_vm_pu”, tables res_line, res_trafo, res_trafo3w with columns “max_loading_percent”, “min_loading_percent”, “causes_overloading”, “cause_element”, “cause_index”, table res_line with columns “max_temperature_degree_celsius”, “min_temperature_degree_celsius” (if “tdpf” set to True) “causes_overloading”: does this element, when defining the N-1 case, cause overloading of other elements? the overloading is defined by net.line[“max_loading_percent_nminus1”] (if set) or net.line[“max_loading_percent”] “cause_element”: element (“line”, “trafo”, “trafo3w”) that causes max. loading of this element “cause_index”: index of the element (“line”, “trafo”, “trafo3w”) that causes max. loading of this element “congestion_caused_mva”: overall congestion in the grid in MVA during the N-1 case due to the failure of the element

Parameters:
  • net (pandapowerNet) – The pandapower network

  • nminus1_cases (dict) – describes all N-1 cases, e.g. {“line”: {“index”: [1, 2, 3]}, “trafo”: {“index”: [0]}} Note: trafo3w is not supported

  • contingency_evaluation_function (callable) – function to use for power flow calculation, default runpp (but only relevant for N-0 case)

pandapower.contingency.get_element_limits(net)

Construct the dictionary of element limits

Parameters:

net (pandapowerNet)

Returns:

element limits

Return type:

dict

pandapower.contingency.check_elements_within_limits(element_limits, contingency_results, nminus1=False, branch_tol=1e-3, bus_tol=1e-6)

Check if elements are within limits

Parameters:
  • element_limits (dict)

  • contingency_results (dict)

  • nminus1 (bool)

  • branch_tol (float) – tolerance of the limit violation check for branch limits

  • bus_tol (float) – tolerance of the limit violation check for bus limits

Returns:

True if all within limits (no violations), False if any limits violated

Return type:

bool

pandapower.contingency.report_contingency_results(element_limits, contingency_results, branch_tol=1e-3, bus_tol=1e-6)

Print log messages for elements with violations of limits

Parameters:
  • element_limits (dict)

  • contingency_results (dict)

  • branch_tol (float) – tolerance for branch results

  • bus_tol (float) – tolerance for bus results