<jupyter_start><jupyter_text>Security-Constrained OptimisationIn this example, the dispatch of generators is optimised using the security-constrained linear OPF, to guaranteed that no branches are overloaded by certain branch outages.<jupyter_code>import pypsa, os
import numpy as np
network = pypsa.examples.scigrid_de(from_master=True)<jupyter_output><empty_output><jupyter_text>There are some infeasibilities without line extensions.<jupyter_code>for line_name in ["316","527","602"]:
    network.lines.loc[line_name,"s_nom"] = 1200

now = network.snapshots[0]<jupyter_output><empty_output><jupyter_text>Performing security-constrained linear OPF<jupyter_code>branch_outages = network.lines.index[:15]
network.sclopf(now,branch_outages=branch_outages, solver_name='cbc')<jupyter_output><empty_output><jupyter_text>For the PF, set the P to the optimised P.<jupyter_code>network.generators_t.p_set = network.generators_t.p_set.reindex(columns=network.generators.index)
network.generators_t.p_set.loc[now] = network.generators_t.p.loc[now]

network.storage_units_t.p_set = (network.storage_units_t.p_set
                                 .reindex(columns=network.storage_units.index))
network.storage_units_t.p_set.loc[now] = network.storage_units_t.p.loc[now]<jupyter_output><empty_output><jupyter_text>Check no lines are overloaded with the linear contingency analysis<jupyter_code>p0_test = network.lpf_contingency(now,branch_outages=branch_outages)
p0_test<jupyter_output><empty_output><jupyter_text>Check loading as per unit of s_nom in each contingency<jupyter_code>max_loading = abs(p0_test.divide(network.passive_branches().s_nom,axis=0)).describe().loc["max"]
max_loading
np.allclose(max_loading,np.ones((len(max_loading))))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1061293984108967, 'fraction_numerical': 0.011350737797956867, 'mean_word_length': 8.278947368421052, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '35029', 'license': 'MIT', 'n_tokens_mistral': 627, 'n_tokens_neox': 602, 'n_words': 93, 'path': 'examples/notebooks/scigrid-sclopf.ipynb', 'repo_name': 'martacki/PyPSA', 'size': '1762'}