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=<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.

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

Execute contingency analysis using the lightsim2grid library. This works much faster than using pandapower. 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, 0-start, are required! This function can be passed through to pandapower.timeseries.run_timeseries as the run_control_fct argument.

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

pandapower.contingency.get_element_limits(net)

Construct the dictionary of element limits

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

Check if elements are within limits

pandapower.contingency.report_contingency_results(element_limits, contingency_results, branch_tol=0.001, bus_tol=1e-06)

Print log messages for elements with violations of limits