Example #1
0
def create_test_network():
    """Creates a simple pandapower test network
    """
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, name="bus1", vn_kv=10.)
    pp.create_ext_grid(net, b1)
    b2 = pp.create_bus(net, name="bus2", geodata=(1, 2), vn_kv=.4)
    b3 = pp.create_bus(net, name="bus3", geodata=(1, 3), vn_kv=.4, index=7)
    b4 = pp.create_bus(net, name="bus4", vn_kv=10.)
    pp.create_transformer_from_parameters(net, b4, b2, vk_percent=3.75,
                                          tap_max=2, vn_lv_kv=0.4,
                                          shift_degree=150, tap_neutral=0,
                                          vn_hv_kv=10.0, vkr_percent=2.8125,
                                          tap_pos=0, tap_side="hv", tap_min=-2,
                                          tap_step_percent=2.5, i0_percent=0.68751,
                                          sn_mva=0.016, pfe_kw=0.11, name=None,
                                          in_service=True, index=None)
    # 0.016 MVA 10/0.4 kV ET 16/23  SGB

    pp.create_line_from_parameters(net, b2, b3, 1, name="line1", r_ohm_per_km=0.2067,
                                   ices=0.389985, c_nf_per_km=720.0, max_i_ka=0.328,
                                   x_ohm_per_km=0.1897522, geodata=np.array([[1, 2], [3, 4]]))
    # NAYY 1x150RM 0.6/1kV ir
    pp.create_line_from_parameters(net, b1, b4, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876)

    # NAYSEY 3x35rm/16 6/10kV

    pp.create_load(net, b2, p_mw=0.010, q_mvar=0, name="load1")
    pp.create_load(net, b3, p_mw=0.040, q_mvar=0.002, name="load2")
    pp.create_gen(net, b4, p_mw=0.200, vm_pu=1.0)
    pp.create_sgen(net, b3, p_mw=0.050, sn_mva=0.1)

    return net
def create_trafo_c35(net, branch_data):
    rk = branch_data.loc[119, 'R']
    xk = branch_data.loc[119, 'X']
    zk = (rk**2 + xk**2)**0.5
    sn = branch_data.loc[119, 'Cont Rating']
    i0_percent = -branch_data.loc[119, 'B'] * 100 * baseMVA / sn

    pp.create_transformer_from_parameters(net,
                                          hv_bus=70,
                                          lv_bus=72,
                                          sn_mva=sn,
                                          vn_hv_kv=net.bus.loc[70, "vn_kv"],
                                          vn_lv_kv=net.bus.loc[72, "vn_kv"],
                                          vk_percent=np.sign(xk) * zk * sn *
                                          100 / baseMVA,
                                          vkr_percent=rk * sn * 100 / baseMVA,
                                          max_loading_percent=100,
                                          i0_percent=i0_percent,
                                          pfe_kw=0.,
                                          tap_side="lv",
                                          tap_neutral=0,
                                          name=branch_data.loc[119, "UID"],
                                          shift_degree=0.,
                                          tap_step_percent=1.5,
                                          tap_pos=0,
                                          tap_phase_shifter=False)
def simple_net():
    net = pp.create_empty_network()
    # Create buses
    pp.create_bus(net, name='Bus ext grid', vn_kv=10., type='b')
    pp.create_bus(net, name='Bus LV0', vn_kv=0.4, type='n')
    for i in range(1, 6):
        pp.create_bus(net, name='Bus LV1.%s' % i, vn_kv=0.4, type='m')
    for i in range(1, 5):
        pp.create_bus(net, name='Bus LV2.%s' % i, vn_kv=0.4, type='m')
    pp.create_bus(net, name='Bus LV2.2.1', vn_kv=0.4, type='m')
    pp.create_bus(net, name='Bus LV2.2.2', vn_kv=0.4, type='m')
    # Create lines
    for i in range(1,6):
        pp.create_line(net, from_bus=i, to_bus=i+1, length_km=0.08, std_type='NAYY 4x120 SE')
    pp.create_line(net, from_bus=1, to_bus=7, length_km=0.12, std_type='NAYY 4x120 SE')
    pp.create_line(net, from_bus=7, to_bus=8, length_km=0.12, std_type='NAYY 4x120 SE')
    for i in range(8, 10):
        pp.create_line(net, from_bus=i, to_bus=i+1, length_km=0.12, std_type='15-AL1/3-ST1A 0.4')
    pp.create_line(net, from_bus=8, to_bus=11, length_km=0.12, std_type='15-AL1/3-ST1A 0.4')
    pp.create_line(net, from_bus=11, to_bus=12, length_km=0.12, std_type='15-AL1/3-ST1A 0.4')
    # Create external grid
    pp.create_ext_grid(net, bus=0, m_pu=1.03, va_degree=0, name='External grid',
                       s_sc_max_mva=10, rx_max=0.1, rx_min=0.1)
    # Create transformer
    pp.create_transformer_from_parameters(net, hv_bus=0, lv_bus=1, sn_mva=.4,
                                          vn_hv_kv=10, vn_lv_kv=0.4, vkr_percent=1.325,
                                          vk_percent=4, pfe_kw=0.95, i0_percent=0.2375,
                                          tap_side="hv", tap_neutral=0, tap_min=-2,
                                          tap_max=2, tap_step_percent=2.5, tp_pos=0,
                                          shift_degree=150, name='MV-LV-Trafo')
    for ind in range(1,13):
        pp.create_load(net, bus=ind,
                        p_mw=0.0035,
                        name='Prosumer %s' % ind)
    return net
def iec_60909_4_small_gen_only():
    net = pp.create_empty_network()

    b3 = pp.create_bus(net, vn_kv=110.)
    HG2 = pp.create_bus(net, vn_kv=10)  # 10.5kV?

    pp.create_gen(net,
                  HG2,
                  p_mw=0.9 * 100,
                  vn_kv=10.5,
                  xdss_pu=0.16,
                  rdss_pu=0.00453,
                  cos_phi=0.9,
                  sn_mva=100,
                  slack=True)

    pp.create_transformer_from_parameters(net,
                                          b3,
                                          HG2,
                                          sn_mva=100,
                                          pfe_kw=0,
                                          i0_percent=0,
                                          vn_hv_kv=120.,
                                          vn_lv_kv=10.5,
                                          vk_percent=12,
                                          vkr_percent=0.5)
    return net
def build_case69(df):
    net = pp.create_empty_network()
    #build 69+1 buses
    for i in range(70):
        if i == 0:
            pp.create_bus(net, vn_kv=33)
        else:
            pp.create_bus(net, vn_kv=11)
    pp.create_ext_grid(net, bus=0, vm_pu=1.02)
    #create lines based on the df, and add loads to the buses
    for index, row in df.iterrows():
        pp.create_line_from_parameters(net,
                                       from_bus=int(row['from']),
                                       to_bus=int(row['to']),
                                       length_km=1,
                                       r_ohm_per_km=float(row['rohm']),
                                       x_ohm_per_km=float(row['xohm']),
                                       c_nf_per_km=0,
                                       max_i_ka=float(row['maxi']) / 100.0)
        pp.create_load(net,
                       bus=int(row['to']),
                       p_kw=float(row['P']),
                       q_kvar=float(row['Q']))
    #add the transformer
    pp.create_transformer_from_parameters(net,
                                          hv_bus=0,
                                          lv_bus=1,
                                          sn_kva=6000.0,
                                          vn_hv_kv=33.0,
                                          vn_lv_kv=11.0,
                                          vscr_percent=0.25,
                                          vsc_percent=12.0,
                                          pfe_kw=30,
                                          i0_percent=0.06)
    return net
Example #6
0
def test_transformer_phase_shift():
    net = pp.create_empty_network()
    for side in ["hv", "lv"]:
        b1 = pp.create_bus(net, vn_kv=110.)
        b2 = pp.create_bus(net, vn_kv=20.)
        b3 = pp.create_bus(net, vn_kv=0.4)
        pp.create_ext_grid(net, b1)
        pp.create_transformer_from_parameters(
            net, b1, b2, 40000, 110, 20, 0.1, 5, 0, 0.1, 30, side,
            # 0, 2, -2, 1.25, 10, 0)
            0, 2, -2, 0, 10, 0, True)
        pp.create_transformer_from_parameters(
            net, b2, b3, 630, 20, 0.4, 0.1, 5, 0, 0.1, 20, tap_phase_shifter=True)
    pp.runpp(net, init="dc", calculate_voltage_angles=True)
    b2a_angle = net.res_bus.va_degree.at[1]
    b3a_angle = net.res_bus.va_degree.at[2]
    b2b_angle = net.res_bus.va_degree.at[4]
    b3b_angle = net.res_bus.va_degree.at[5]

    net.trafo.tap_pos.at[0] = 1
    net.trafo.tap_pos.at[2] = 1
    pp.runpp(net, init="dc", calculate_voltage_angles=True)
    assert np.isclose(b2a_angle - net.res_bus.va_degree.at[1], 10)
    assert np.isclose(b3a_angle - net.res_bus.va_degree.at[2], 10)
    assert np.isclose(b2b_angle - net.res_bus.va_degree.at[4], -10)
    assert np.isclose(b3b_angle - net.res_bus.va_degree.at[5], -10)
Example #7
0
def test_transformer_phase_shift_complex():
    test_ref = (0.99967, -30.7163)
    test_tap_pos = {
        'hv': (0.9617, -31.1568),
        'lv': (1.0391, -30.3334)
    }
    test_tap_neg = {
        'hv': (1.0407, -30.2467),
        'lv': (0.9603, -31.1306)
    }
    for side in ["hv", "lv"]:
        net = pp.create_empty_network()
        b1 = pp.create_bus(net, vn_kv=110.)
        pp.create_ext_grid(net, b1)
        b2 = pp.create_bus(net, vn_kv=20.)
        pp.create_load(net, b2, p_mw=10)
        pp.create_transformer_from_parameters(net, hv_bus=b1, lv_bus=b2, sn_mva=40, vn_hv_kv=110,
                                              vn_lv_kv=20, vkr_percent=0.1, vk_percent=5,
                                              pfe_kw=0, i0_percent=0.1, shift_degree=30,
                                              tap_side=side, tap_neutral=0, tap_max=2, tap_min=-2,
                                              tap_step_percent=2, tap_step_degree=10, tap_pos=0)
        pp.runpp(net, init="dc", calculate_voltage_angles=True)
        assert np.isclose(net.res_bus.vm_pu.at[b2], test_ref[0], rtol=1e-4)
        assert np.isclose(net.res_bus.va_degree.at[b2], test_ref[1], rtol=1e-4)

        net.trafo.tap_pos.at[0] = 2
        pp.runpp(net, init="dc", calculate_voltage_angles=True)
        assert np.isclose(net.res_bus.vm_pu.at[b2], test_tap_pos[side][0], rtol=1e-4)
        assert np.isclose(net.res_bus.va_degree.at[b2], test_tap_pos[side][1], rtol=1e-4)

        net.trafo.tap_pos.at[0] = -2
        pp.runpp(net, init="dc", calculate_voltage_angles=True)
        assert np.isclose(net.res_bus.vm_pu.at[b2], test_tap_neg[side][0], rtol=1e-4)
        assert np.isclose(net.res_bus.va_degree.at[b2], test_tap_neg[side][1], rtol=1e-4)
Example #8
0
def test_generator_book():
    net=pp.create_empty_network()
    b1= pp.create_bus(net, 110)
    b2= pp.create_bus(net, 6)

    pp.create_ext_grid(net, b1, s_sc_max_mva=300, rx_max=0.1, s_sc_min_mva=250, rx_min=0.1)
    pp.create_transformer_from_parameters(net, b1, b2, 25, 110, 6, 0.5, 15, 15,0.1)
    pp.create_shunt(net, b2, 25, 0, 6)
    pp.create_gen(net, b2, 0, 1, sn_mva=25, vn_kv=6.3, xdss_pu=0.11, cos_phi=np.cos(np.arcsin(0.8)))
    sc.calc_sc(net, tk_s=2.5e-2)
Example #9
0
def add_test_trafo(net):
    b1, b2, ln = add_grid_connection(net, zone="test_trafo")
    b3 = pp.create_bus(net, vn_kv=0.4, zone="test_trafo")
    pp.create_transformer_from_parameters(net,
                                          b2,
                                          b3,
                                          vk_percent=5.,
                                          vkr_percent=2.,
                                          i0_percent=.4,
                                          pfe_kw=2.,
                                          sn_mva=0.4,
                                          vn_hv_kv=22,
                                          vn_lv_kv=0.42,
                                          tap_max=10,
                                          tap_neutral=5,
                                          tap_min=0,
                                          tap_step_percent=1.25,
                                          tap_pos=3,
                                          shift_degree=150,
                                          tap_side="hv",
                                          parallel=2)
    t2 = pp.create_transformer_from_parameters(
        net,
        b2,
        b3,
        vk_percent=5.,
        vkr_percent=2.,
        i0_percent=.4,
        pfe_kw=2,
        sn_mva=0.4,
        vn_hv_kv=22,
        vn_lv_kv=0.42,
        tap_max=10,
        tap_neutral=5,
        tap_min=0,
        tap_step_percent=1.25,
        tap_pos=3,
        tap_side="hv",
        shift_degree=150,
        index=pp.get_free_id(net.trafo) + 1)
    pp.create_switch(net, b3, t2, et="t", closed=False)
    pp.create_transformer_from_parameters(net,
                                          b2,
                                          b3,
                                          vk_percent=5.,
                                          vkr_percent=2.,
                                          i0_percent=1.,
                                          pfe_kw=20,
                                          sn_mva=0.4,
                                          vn_hv_kv=20,
                                          vn_lv_kv=0.4,
                                          in_service=False)
    pp.create_load(net, b3, p_mw=0.2, q_mvar=0.05)
    net.last_added_case = "test_trafo"
    return net
Example #10
0
def test_opf_varying_max_line_loading():
    """ Testing a  simple network with transformer for loading
    constraints with OPF using a generator """

    # boundaries
    vm_max = 1.5
    vm_min = 0.5
    max_trafo_loading = 800
    max_line_loading = 13

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_transformer_from_parameters(net, 0, 1, vk_percent=3.75, tap_max=2, vn_lv_kv=0.4,
                                          shift_degree=150, tap_neutral=0, vn_hv_kv=10.0,
                                          vkr_percent=2.8125, tap_pos=0, tap_side="hv", tap_min=-2,
                                          tap_step_percent=2.5, i0_percent=0.68751, sn_mva=0.016,
                                          pfe_kw=0.11, name=None, in_service=True, index=None,
                                          max_loading_percent=max_trafo_loading)



    pp.create_sgen(net, 3, p_mw=0.1, controllable=True, min_p_mw=0.005, max_p_mw=0.15, max_q_mvar=0.025,
                   min_q_mvar=-0.025)
    pp.create_sgen(net, 2, p_mw=0.1, controllable=True, min_p_mw=0.005, max_p_mw=0.15, max_q_mvar=0.025,
                   min_q_mvar=-0.025)
    pp.create_poly_cost(net, 0, "sgen", cp1_eur_per_mw=10)
    pp.create_poly_cost(net, 1, "sgen", cp1_eur_per_mw=10)
    pp.create_ext_grid(net, 0)
    pp.create_poly_cost(net, 0, "ext_grid", cp1_eur_per_mw=.1)
    pp.create_line_from_parameters(net, 1, 2, 1, name="line1", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, max_i_ka=0.200, x_ohm_per_km=0.1159876,
                                   max_loading_percent=20)
    pp.create_line_from_parameters(net, 1, 3, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, max_i_ka=0.100, x_ohm_per_km=0.1159876,
                                   max_loading_percent=10)

    # run OPF
    pp.runopp(net, init="flat")
    assert net["OPF_converged"]

    assert np.allclose(net["_ppc"]["branch"][:, 5], np.array([0.02771281+0.j,  0.00692820+0.j,  0.12800000+0.j]))


    # assert and check result
    logger.debug("test_opf_sgen_loading")
    logger.debug("res_sgen:\n%s" % net.res_sgen)
    logger.debug("res_line.loading_percent:\n%s" % net.res_line.loading_percent)
    assert net.res_line.loading_percent.at[0] - 20 < 1e-2
    logger.debug("res_line.loading_percent:\n%s" % net.res_line.loading_percent)
    assert net.res_line.loading_percent.at[1] - 10 < 1e-2
Example #11
0
def test_tap_phase_shifter_default():
    expected_default = False
    net = pp.create_empty_network()
    pp.create_bus(net, 110)
    pp.create_bus(net, 20)
    data = pp.load_std_type(net, "25 MVA 110/20 kV", "trafo")
    if "tap_phase_shifter" in data:
        del data["tap_phase_shifter"]
    pp.create_std_type(net, data, "without_tap_shifter_info", "trafo")
    pp.create_transformer_from_parameters(net, 0, 1, 25e3, 110, 20, 0.4, 12, 20, 0.07)
    pp.create_transformer(net, 0, 1, "without_tap_shifter_info")
    assert (net.trafo.tap_phase_shifter == expected_default).all()
Example #12
0
def test_opf_gen_loading():
    """ Testing a  simple network with transformer for loading
    constraints with OPF using a generator """

    # wide open voltage boundaries to make sure they don't interfere with loading constraints
    vm_max = 1.5
    vm_min = 0.5
    max_line_loading = 11

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_transformer_from_parameters(net, 0, 1, vk_percent=3.75,
                                          tap_max=2, vn_lv_kv=0.4,
                                          shift_degree=150, tap_neutral=0,
                                          vn_hv_kv=10.0, vkr_percent=2.8125,
                                          tap_pos=0, tap_side="hv", tap_min=-2,
                                          tap_step_percent=2.5, i0_percent=0.68751,
                                          sn_mva=0.016, pfe_kw=0.11, name=None,
                                          in_service=True, index=None, max_loading_percent=145)
    pp.create_gen(net, 3, p_mw=0.01, controllable=True, min_p_mw=0.005, max_p_mw=0.015,
                  max_q_mvar=0.05, min_q_mvar=-0.05)
    pp.create_poly_cost(net, 0, "gen", cp1_eur_per_mw=-10)
    pp.create_ext_grid(net, 0)
    pp.create_poly_cost(net, 0, "ext_grid", cp1_eur_per_mw=.1)
    pp.create_line_from_parameters(net, 1, 2, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=max_line_loading)
    pp.create_line_from_parameters(net, 2, 3, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=max_line_loading)

    # run OPF

    pp.runopp(net, OPF_VIOLATION=1e-1, OUT_LIM_LINE=2,
              PDIPM_GRADTOL=1e-10, PDIPM_COMPTOL=1e-10, PDIPM_COSTTOL=1e-10)
    assert net["OPF_converged"]

    # assert and check result
    logger.debug("test_opf_gen_loading")
    logger.debug("res_gen:\n%s" % net.res_gen)
    logger.debug("res_line.loading_percent:\n%s" % net.res_line.loading_percent)
    assert max(net.res_line.loading_percent) < max_line_loading
    logger.debug("res_trafo.loading_percent:\n%s" % net.res_trafo.loading_percent)
    assert max(net.res_trafo.loading_percent) < 145
    assert max(net.res_bus.vm_pu) < vm_max
    assert min(net.res_bus.vm_pu) > vm_min
Example #13
0
def net_transformer():
    net = pp.create_empty_network(sn_kva=2e3)
    b1a = pp.create_bus(net, vn_kv=10.)
    b1b = pp.create_bus(net, vn_kv=10.)
    b2 = pp.create_bus(net, vn_kv=.4)
    pp.create_bus(net, vn_kv=0.4, in_service=False) #add out of service bus to test oos indexing
    pp.create_ext_grid(net, b1a, s_sc_max_mva=100., s_sc_min_mva=40., rx_min=0.1, rx_max=0.1)
    pp.create_switch(net, b1a, b1b, et="b")
    pp.create_transformer_from_parameters(net, b1b, b2, vn_hv_kv=11., vn_lv_kv=0.42, vsc_percent=6.,
                                          vscr_percent=0.5, pfe_kw=1.4, shift_degree=0.0,
                                          tp_side="hv", tp_mid=0, tp_min=-2, tp_max=2, tp_pos=2,
                                          tp_st_percent=2.5, parallel=2, sn_kva=400, i0_percent=0.5)
    pp.create_shunt(net, b2, q_kvar=500, p_kw=500) #adding a shunt shouldn't change the result
    return net
Example #14
0
def test_opf_sgen_loading():
    """ Testing a  simple network with transformer for loading
    constraints with OPF using a generator """

    # boundaries
    vm_max = 1.5
    vm_min = 0.5
    max_trafo_loading = 800
    max_line_loading = 13

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_transformer_from_parameters(net, 0, 1, vk_percent=3.75, tap_max=2, vn_lv_kv=0.4,
                                          shift_degree=150, tap_neutral=0, vn_hv_kv=10.0,
                                          vkr_percent=2.8125, tap_pos=0, tap_side="hv", tap_min=-2,
                                          tap_step_percent=2.5, i0_percent=0.68751, sn_mva=0.016,
                                          pfe_kw=0.11, name=None, in_service=True, index=None,
                                          max_loading_percent=max_trafo_loading)
    pp.create_sgen(net, 3, p_mw=0.01, controllable=True, min_p_mw=0.005, max_p_mw=.015,
                   max_q_mvar=0.025, min_q_mvar=-0.025)
    pp.create_poly_cost(net, 0, "sgen", cp1_eur_per_mw=-10)
    pp.create_ext_grid(net, 0)
    pp.create_poly_cost(net, 0, "ext_grid", cp1_eur_per_mw=.1)
    pp.create_line_from_parameters(net, 1, 2, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=max_line_loading)
    pp.create_line_from_parameters(net, 2, 3, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=max_line_loading)

    # run OPF
    for init in ["pf", "flat"]:
        pp.runopp(net, init=init)
        assert net["OPF_converged"]

    # assert and check result
    logger.debug("test_opf_sgen_loading")
    logger.debug("res_sgen:\n%s" % net.res_sgen)
    logger.debug("res_line.loading_percent:\n%s" % net.res_line.loading_percent)
    assert max(net.res_line.loading_percent) - max_line_loading < 0.15
    logger.debug("res_trafo.loading_percent:\n%s" % net.res_trafo.loading_percent)
    assert max(net.res_trafo.loading_percent) < max_trafo_loading
    assert max(net.res_bus.vm_pu) < vm_max
    assert min(net.res_bus.vm_pu) > vm_min
    # check connectivity check
    pp.runopp(net, check_connectivity=True)
Example #15
0
def test_power_station_unit():
    net = pp.create_empty_network()
    b1, b2, b3, b4 = pp.create_buses(net, 4, 20)
    b5 = pp.create_bus(net, 10)

    pp.create_ext_grid(net, b1, s_sc_max_mva=250, rx_max=0.1)

    pp.create_line(net, b1, b2, std_type="305-AL1/39-ST1A 110.0", length_km=10)
    pp.create_line(net, b2, b3, std_type="305-AL1/39-ST1A 110.0", length_km=10)
    pp.create_line(net, b3, b4, std_type="305-AL1/39-ST1A 110.0", length_km=50)

    pp.create_transformer_from_parameters(net, b4, b5, 25, 20, 10, 0.41104, 10.3, 0.1, 0.1)
    pp.create_gen(net, b5, vn_kv=10, xdss_pu=0.12, cos_phi=0.8, p_mw=0, sn_mva=10)

    sc.calc_sc(net)
Example #16
0
def add_trafos(network, df=None, file=None):
    """
    Add transformers to the specified network. Pass either a DataFrame or a pathstring to a csv-file.
    
    Parameters
    ----------
    network : pandapowerNet
        PandaPower network representation.
    df : DataFrame
        DataFrame with bus characteristics.
    file : str
        Path to csv-file with transformer characteristics.
        
    Return
    ------
    net : pandapowerNet
        PandaPower network representation with added transformers.
    """

    # copy network
    net = copy.deepcopy(network)
    
    # load trafos
    trafos = check_arguments(df, file)

    # create dictonairy of busnames and busindices
    busdict = dict(zip(net.bus.name, net.bus.index))
    
    # parameter trafos
    parameter_trafos = trafos[trafos.std_type.isna() == True]

    for index, trafo in parameter_trafos.iterrows():       
        pp.create_transformer_from_parameters(net, name=trafo['name'], hv_bus=busdict[trafo.hv_bus],
                                              lv_bus=busdict[trafo.lv_bus], sn_mva=trafo.sn_mva,
                                              vn_hv_kv=trafo.vn_hv_kv, vn_lv_kv=trafo.vn_lv_kv, 
                                              vkr_percent=trafo.vkr_percent, vk_percent=trafo.vk_percent,
                                              pfe_kw=trafo.pfe_kw, i0_percent=trafo.i0_percent, 
                                              in_service=trafo.in_service, parallel=trafo.parallel)

    # default trafos
    default_trafos = trafos[trafos.std_type.isna() == False]

    for index, trafo in default_trafos.iterrows():
        pp.create_transformer(net, name=trafo['name'], hv_bus=busdict[trafo.hv_bus],
                              lv_bus=busdict[trafo.lv_bus], std_type=trafo.std_type, 
                              in_service=trafo.in_service, parallel=trafo.parallel)
        
    return net
def test_tap_dependent_impedance_restore():
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, 110)
    b2 = pp.create_bus(net, 20)
    pp.create_ext_grid(net, b1)
    pp.create_load(net, b2, 20)
    pp.create_transformer_from_parameters(net, b1, b2, 40, 110, 21, 0.5, 12.3,
                                          25, 0.11, 0, 'hv', 10, 20, 0, 1.8,
                                          180, 10)

    characteristic_vk = Characteristic.from_points(net, ((0, 13.5), (10, 12.3),
                                                         (20, 11.1)))
    characteristic_vkr = Characteristic.from_points(net, ((0, 0.52), (10, 0.5),
                                                          (20, 0.53)))
    TapDependentImpedance(net,
                          0,
                          characteristic_vk.index,
                          output_variable='vk_percent',
                          restore=True)
    TapDependentImpedance(net,
                          0,
                          characteristic_vkr.index,
                          output_variable='vkr_percent',
                          restore=True)

    pp.runpp(net, run_control=True)
    # remember the losses for the neutral position
    pl_mw_neutral = net.res_trafo.pl_mw.at[0]
    assert net.trafo.vk_percent.at[0] == 12.3
    assert net.trafo.vkr_percent.at[0] == 0.5

    net.trafo.tap_pos = 0
    pp.runpp(net, run_control=True)
    # check if the impedance has been restored
    assert net.trafo.vk_percent.at[0] == 12.3
    assert net.trafo.vkr_percent.at[0] == 0.5
    # check if the losses are different than at the neutral position -> the tap-dependent impedance has been conbsidered
    assert abs(net.res_trafo.pl_mw.at[0] - pl_mw_neutral) > 0.015

    net.trafo.tap_pos = 20
    pp.runpp(net, run_control=True)
    # check if the impedance has been restored
    assert net.trafo.vk_percent.at[0] == 12.3
    assert net.trafo.vkr_percent.at[0] == 0.5
    # check if the losses are different than at the neutral position -> the tap-dependent impedance has been conbsidered
    assert abs(net.res_trafo.pl_mw.at[0] - pl_mw_neutral) > 0.002
Example #18
0
def test_opf_gen_loading():
    """ Testing a  simple network with transformer for loading
    constraints with OPF using a generator """

    # wide open voltage boundaries to make sure they don't interfere with loading constraints
    vm_max = 1.5
    vm_min = 0.5
    max_line_loading = 11

    # create net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_transformer_from_parameters(net, 0, 1, vsc_percent=3.75,
                                          tp_max=2, vn_lv_kv=0.4,
                                          shift_degree=150, tp_mid=0,
                                          vn_hv_kv=10.0, vscr_percent=2.8125,
                                          tp_pos=0, tp_side="hv", tp_min=-2,
                                          tp_st_percent=2.5, i0_percent=0.68751,
                                          sn_kva=16.0, pfe_kw=0.11, name=None,
                                          in_service=True, index=None, max_loading_percent=145)
    pp.create_gen(net, 3, p_kw=-10, controllable=True, max_p_kw=-15, min_p_kw=-5, max_q_kvar=50,
                  min_q_kvar=-50, cost_per_kw = -100)
    pp.create_ext_grid(net, 0)
    pp.create_line_from_parameters(net, 1, 2, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, imax_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=max_line_loading)
    pp.create_line_from_parameters(net, 2, 3, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, imax_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=max_line_loading)

    # run OPF
    pp.runopp(net, verbose=False)
    assert net["OPF_converged"]

    # assert and check result
    logger.debug("test_opf_gen_loading")
    logger.debug("res_gen:\n%s" % net.res_gen)
    logger.debug("res_line.loading_percent:\n%s" % net.res_line.loading_percent)
    assert max(net.res_line.loading_percent) < max_line_loading
    logger.debug("res_trafo.loading_percent:\n%s" % net.res_trafo.loading_percent)
    assert max(net.res_trafo.loading_percent) < 145
    assert net.OPF_converged
Example #19
0
def test_opf_gen_voltage():
    """ Testing a  simple network with transformer for voltage
    constraints with OPF using a generator """

    # boundaries:
    vm_max = 1.05
    vm_min = 0.95

    # ceate net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_transformer_from_parameters(net, 0, 1, vk_percent=3.75,
                                          tap_max=2, vn_lv_kv=0.4,
                                          shift_degree=150, tap_neutral=0,
                                          vn_hv_kv=10.0, vkr_percent=2.8125,
                                          tap_pos=0, tap_side="hv", tap_min=-2,
                                          tap_step_percent=2.5, i0_percent=0.68751,
                                          sn_mva=0.016, pfe_kw=0.11, name=None,
                                          in_service=True, index=None, max_loading_percent=200)
    pp.create_gen(net, 3, p_mw=0.01, controllable=True, min_p_mw=0, max_p_mw=0.025, max_q_mvar=0.5,
                  min_q_mvar=-0.5)
    pp.create_poly_cost(net, 0, "gen", cp1_eur_per_mw=10)
    pp.create_ext_grid(net, 0)
    pp.create_line_from_parameters(net, 1, 2, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=100000)
    pp.create_line_from_parameters(net, 2, 3, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=100000)

    # run OPF
    for init in ["pf", "flat"]:
        pp.runopp(net, init=init)
        assert net["OPF_converged"]

    # check and assert result
    logger.debug("test_opf_gen_voltage")
    logger.debug("res_gen:\n%s" % net.res_gen)
    logger.debug("res_bus.vm_pu: \n%s" % net.res_bus.vm_pu)
    assert max(net.res_bus.vm_pu) < vm_max
    assert min(net.res_bus.vm_pu) > vm_min
Example #20
0
def test_opf_gen_voltage():
    """ Testing a  simple network with transformer for voltage
    constraints with OPF using a generator """

    # boundaries:
    vm_max = 1.05
    vm_min = 0.95

    # ceate net
    net = pp.create_empty_network()
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4)
    pp.create_transformer_from_parameters(net, 0, 1, vsc_percent=3.75,
                                          tp_max=2, vn_lv_kv=0.4,
                                          shift_degree=150, tp_mid=0,
                                          vn_hv_kv=10.0, vscr_percent=2.8125,
                                          tp_pos=0, tp_side="hv", tp_min=-2,
                                          tp_st_percent=2.5, i0_percent=0.68751,
                                          sn_kva=16.0, pfe_kw=0.11, name=None,
                                          in_service=True, index=None, max_loading_percent=200)
    pp.create_gen(net, 3, p_kw=-10, controllable=True, max_p_kw=-25, min_p_kw=-5, max_q_kvar=50,
                  min_q_kvar=-50, cost_per_kw = -100)
    pp.create_ext_grid(net, 0)
    pp.create_line_from_parameters(net, 1, 2, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, imax_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=100000)
    pp.create_line_from_parameters(net, 2, 3, 1, name="line2", r_ohm_per_km=0.876,
                                   c_nf_per_km=260.0, imax_ka=0.123, x_ohm_per_km=0.1159876,
                                   max_loading_percent=100000)

    # run OPF
    pp.runopp(net, verbose=False)
    assert net["OPF_converged"]

    # check and assert result
    logger.debug("test_opf_gen_voltage")
    logger.debug("res_gen:\n%s" % net.res_gen)
    logger.debug("res_bus.vm_pu: \n%s" % net.res_bus.vm_pu)
    assert max(net.res_bus.vm_pu) < vm_max
    assert min(net.res_bus.vm_pu) > vm_min
    assert net.OPF_converged
def add_test_trafo(net):
    b1, b2, ln = add_grid_connection(net, zone="test_trafo")
    b3 = pp.create_bus(net, vn_kv=0.4, zone="test_trafo")
    pp.create_transformer_from_parameters(net,
                                          b2,
                                          b3,
                                          vsc_percent=5.,
                                          vscr_percent=2.,
                                          i0_percent=1.,
                                          pfe_kw=20,
                                          sn_kva=400,
                                          vn_hv_kv=20,
                                          vn_lv_kv=0.4)
    t2 = pp.create_transformer_from_parameters(
        net,
        b2,
        b3,
        vsc_percent=5.,
        vscr_percent=2.,
        i0_percent=1.,
        pfe_kw=20,
        sn_kva=400,
        vn_hv_kv=20,
        vn_lv_kv=0.4,
        index=pp.get_free_id(net.trafo) + 1)
    pp.create_switch(net, b3, t2, et="t", closed=False)
    pp.create_transformer_from_parameters(net,
                                          b2,
                                          b3,
                                          vsc_percent=5.,
                                          vscr_percent=2.,
                                          i0_percent=1.,
                                          pfe_kw=20,
                                          sn_kva=400,
                                          vn_hv_kv=20,
                                          vn_lv_kv=0.4,
                                          in_service=False)
    pp.create_load(net, b3, p_kw=200, q_kvar=50)
    net.last_added_case = "test_trafo"
    return net
Example #22
0
def test_convenience_create_functions():
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, 110.)
    b2 = pp.create_bus(net, 110.)
    b3 = pp.create_bus(net, 20)
    pp.create_ext_grid(net, b1)
    pp.create_line_from_parameters(net, b1, b2, length_km=20., r_ohm_per_km=0.0487,
                                   x_ohm_per_km=0.1382301, c_nf_per_km=160., max_i_ka=0.664)

    l0 = pp.create_load_from_cosphi(net, b2, 10, 0.95, "underexcited", name="load")
    pp.runpp(net, init="flat")
    assert net.load.p_mw.at[l0] == 9.5
    assert net.load.q_mvar.at[l0] > 0
    assert np.sqrt(net.load.p_mw.at[l0] ** 2 + net.load.q_mvar.at[l0] ** 2) == 10
    assert np.isclose(net.res_bus.vm_pu.at[b2], 0.99990833838)
    assert net.load.name.at[l0] == "load"

    sh0 = pp.create_shunt_as_capacitor(net, b2, 10, loss_factor=0.01, name="shunt")
    pp.runpp(net, init="flat")
    assert np.isclose(net.res_shunt.q_mvar.at[sh0], -10.043934174)
    assert np.isclose(net.res_shunt.p_mw.at[sh0], 0.10043933665)
    assert np.isclose(net.res_bus.vm_pu.at[b2], 1.0021942964)
    assert net.shunt.name.at[sh0] == "shunt"

    sg0 = pp.create_sgen_from_cosphi(net, b2, 5, 0.95, "overexcited", name="sgen")
    pp.runpp(net, init="flat")
    assert np.sqrt(net.sgen.p_mw.at[sg0] ** 2 + net.sgen.q_mvar.at[sg0] ** 2) == 5
    assert net.sgen.p_mw.at[sg0] == 4.75
    assert net.sgen.q_mvar.at[sg0] > 0
    assert np.isclose(net.res_bus.vm_pu.at[b2], 1.0029376578)
    assert net.sgen.name.at[sg0] == "sgen"

    tol = 1e-6
    base_z = 110 ** 2 / 100
    sind = pp.create_series_reactor_as_impedance(net, b1, b2, r_ohm=100, x_ohm=200, sn_mva=100)
    assert net.impedance.at[sind, 'rft_pu'] - 100 / base_z < tol
    assert net.impedance.at[sind, 'xft_pu'] - 200 / base_z < tol

    tid = pp.create_transformer_from_parameters(net, hv_bus=b2, lv_bus=b3, sn_mva=0.1, vn_hv_kv=110,
                                                vn_lv_kv=20, vkr_percent=5, vk_percent=20,
                                                pfe_kw=1, i0_percent=1)
    pp.create_load(net, b3, 0.1)
    assert net.trafo.at[tid, 'df'] == 1
    pp.runpp(net)
    tr_l = net.res_trafo.at[tid, 'loading_percent']
    net.trafo.at[tid, 'df'] = 2
    pp.runpp(net)
    tr_l_2 = net.res_trafo.at[tid, 'loading_percent']
    assert tr_l == tr_l_2 * 2
    net.trafo.at[tid, 'df'] = 0
    with pytest.raises(UserWarning):
        pp.runpp(net)
def add_test_trafo_tap(net):
    b1, b2, ln = add_grid_connection(net, zone="test_trafo_tap")
    b3 = pp.create_bus(net, vn_kv=0.4, zone="test_trafo_tap")
    pp.create_transformer_from_parameters(net,
                                          b2,
                                          b3,
                                          vsc_percent=5.,
                                          vscr_percent=2.,
                                          i0_percent=1.,
                                          pfe_kw=20,
                                          sn_kva=400,
                                          vn_hv_kv=22,
                                          vn_lv_kv=0.4,
                                          tp_max=10,
                                          tp_mid=5,
                                          tp_min=0,
                                          tp_st_percent=1.25,
                                          tp_pos=3,
                                          tp_side="hv")
    pp.create_load(net, b3, p_kw=200, q_kvar=50)
    net.last_added_case = "test_trafo_tap"
    return net
def test_tap_dependent_impedance_control():
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, 110)
    b2 = pp.create_bus(net, 20)
    pp.create_ext_grid(net, b1)
    pp.create_transformer_from_parameters(net, b1, b2, 40, 110, 21, 0.5, 12.3,
                                          25, 0.11, 0, 'hv', 10, 20, 0, 1.8,
                                          180, 10)

    characteristic_vk = Characteristic.from_points(net, ((0, 13.5), (10, 12.3),
                                                         (20, 11.1)))
    characteristic_vkr = Characteristic.from_points(net, ((0, 0.52), (10, 0.5),
                                                          (20, 0.53)))
    TapDependentImpedance(net,
                          0,
                          characteristic_vk.index,
                          output_variable='vk_percent',
                          restore=False)
    TapDependentImpedance(net,
                          0,
                          characteristic_vkr.index,
                          output_variable='vkr_percent',
                          restore=False)

    pp.runpp(net, run_control=True)
    assert net.trafo.vk_percent.at[0] == 12.3
    assert net.trafo.vkr_percent.at[0] == 0.5

    net.trafo.tap_pos = 0
    pp.runpp(net, run_control=True)
    assert net.trafo.vk_percent.at[0] == 13.5
    assert net.trafo.vkr_percent.at[0] == 0.52

    net.trafo.tap_pos = 20
    pp.runpp(net, run_control=True)
    assert net.trafo.vk_percent.at[0] == 11.1
    assert net.trafo.vkr_percent.at[0] == 0.53
Example #25
0
def iec_60909_4_small_gen_only():
    net = pp.create_empty_network()
    net.sn_mva = 56

    b3 = pp.create_bus(net, vn_kv=110.)
    HG2 = pp.create_bus(net, vn_kv=10)

    t1 = pp.create_transformer_from_parameters(net,
                                               b3,
                                               HG2,
                                               sn_mva=100,
                                               pfe_kw=0,
                                               i0_percent=0,
                                               vn_hv_kv=120.,
                                               vn_lv_kv=10.5,
                                               vk_percent=12,
                                               vkr_percent=0.5,
                                               vk0_percent=12,
                                               vkr0_percent=0.5,
                                               mag0_percent=100,
                                               mag0_rx=0,
                                               si0_hv_partial=0.5,
                                               vector_group="YNd")
    pp.create_gen(net,
                  HG2,
                  p_mw=0.9 * 100,
                  vn_kv=10.5,
                  xdss_pu=0.16,
                  rdss_ohm=0.005,
                  cos_phi=0.9,
                  sn_mva=100,
                  pg_percent=7.5,
                  slack=True,
                  power_station_trafo=t1)

    return net
def case34_3ph():
    """
    Create the IEEE 34 bus from IEEE PES Test Feeders:
    "https://site.ieee.org/pes-testfeeders/resources/ā€.

    OUTPUT:
        **net** - The pandapower format network.
    """
    net = pp.create_empty_network()

    # Linedata
    # CF-300
    line_data = {
        'c_nf_per_km': 3.8250977,
        'r_ohm_per_km': 0.69599766,
        'x_ohm_per_km': 0.5177677,
        'c0_nf_per_km': 1.86976748,
        'r0_ohm_per_km': 1.08727498,
        'x0_ohm_per_km': 1.47374703,
        'max_i_ka': 0.23,
        'type': 'ol'
    }
    pp.create_std_type(net, line_data, name='CF-300', element='line')

    # CF-301
    line_data = {
        'c_nf_per_km': 3.66884364,
        'r_ohm_per_km': 1.05015841,
        'x_ohm_per_km': 0.52265586,
        'c0_nf_per_km': 1.82231544,
        'r0_ohm_per_km': 1.48350255,
        'x0_ohm_per_km': 1.60203942,
        'max_i_ka': 0.18,
        'type': 'ol'
    }
    pp.create_std_type(net, line_data, name='CF-301', element='line')

    # CF-302
    line_data = {
        'c_nf_per_km': 0.8751182,
        'r_ohm_per_km': 0.5798427,
        'x_ohm_per_km': 0.30768221,
        'c0_nf_per_km': 0.8751182,
        'r0_ohm_per_km': 0.5798427,
        'x0_ohm_per_km': 0.30768221,
        'max_i_ka': 0.14,
        'type': 'ol'
    }
    pp.create_std_type(net, line_data, name='CF-302', element='line')

    # CF-303
    line_data = {
        'c_nf_per_km': 0.8751182,
        'r_ohm_per_km': 0.5798427,
        'x_ohm_per_km': 0.30768221,
        'c0_nf_per_km': 0.8751182,
        'r0_ohm_per_km': 0.5798427,
        'x0_ohm_per_km': 0.30768221,
        'max_i_ka': 0.14,
        'type': 'ol'
    }
    pp.create_std_type(net, line_data, name='CF-303', element='line')

    # CF-304
    line_data = {
        'c_nf_per_km': 0.90382554,
        'r_ohm_per_km': 0.39802955,
        'x_ohm_per_km': 0.29436416,
        'c0_nf_per_km': 0.90382554,
        'r0_ohm_per_km': 0.39802955,
        'x0_ohm_per_km': 0.29436416,
        'max_i_ka': 0.18,
        'type': 'ol'
    }
    pp.create_std_type(net, line_data, name='CF-304', element='line')

    # Busses
    bus0 = pp.create_bus(net,
                         name='Bus 0',
                         vn_kv=24.9,
                         type='n',
                         zone='34_BUS')
    bus_800 = pp.create_bus(net,
                            name='Bus 800',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_802 = pp.create_bus(net,
                            name='Bus 802',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_806 = pp.create_bus(net,
                            name='Bus 806',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_808 = pp.create_bus(net,
                            name='Bus 808',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_810 = pp.create_bus(net,
                            name='Bus 810',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_812 = pp.create_bus(net,
                            name='Bus 812',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_814 = pp.create_bus(net,
                            name='Bus 814',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_850 = pp.create_bus(net,
                            name='Bus 850',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_816 = pp.create_bus(net,
                            name='Bus 816',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_818 = pp.create_bus(net,
                            name='Bus 818',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_820 = pp.create_bus(net,
                            name='Bus 820',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_822 = pp.create_bus(net,
                            name='Bus 822',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_824 = pp.create_bus(net,
                            name='Bus 824',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_826 = pp.create_bus(net,
                            name='Bus 826',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_828 = pp.create_bus(net,
                            name='Bus 828',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_830 = pp.create_bus(net,
                            name='Bus 830',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_854 = pp.create_bus(net,
                            name='Bus 854',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_852 = pp.create_bus(net,
                            name='Bus 852',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_832 = pp.create_bus(net,
                            name='Bus 832',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_858 = pp.create_bus(net,
                            name='Bus 858',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_834 = pp.create_bus(net,
                            name='Bus 834',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_842 = pp.create_bus(net,
                            name='Bus 842',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_844 = pp.create_bus(net,
                            name='Bus 844',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_846 = pp.create_bus(net,
                            name='Bus 846',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_848 = pp.create_bus(net,
                            name='Bus 848',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_860 = pp.create_bus(net,
                            name='Bus 860',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_836 = pp.create_bus(net,
                            name='Bus 836',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_840 = pp.create_bus(net,
                            name='Bus 840',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_862 = pp.create_bus(net,
                            name='Bus 862',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_838 = pp.create_bus(net,
                            name='Bus 838',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_864 = pp.create_bus(net,
                            name='Bus 864',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')
    bus_888 = pp.create_bus(net,
                            name='Bus 888',
                            vn_kv=4.16,
                            type='n',
                            zone='34_BUS')
    bus_890 = pp.create_bus(net,
                            name='Bus 890',
                            vn_kv=4.16,
                            type='n',
                            zone='34_BUS')
    bus_856 = pp.create_bus(net,
                            name='Bus 856',
                            vn_kv=24.9,
                            type='n',
                            zone='34_BUS')

    # Lines
    pp.create_line(net,
                   bus_800,
                   bus_802,
                   length_km=0.786384,
                   std_type='CF-300',
                   name='Line 0')
    pp.create_line(net,
                   bus_802,
                   bus_806,
                   length_km=0.527304,
                   std_type='CF-300',
                   name='Line 1')
    pp.create_line(net,
                   bus_806,
                   bus_808,
                   length_km=9.823704,
                   std_type='CF-300',
                   name='Line 2')
    pp.create_line(net,
                   bus_808,
                   bus_810,
                   length_km=1.769059,
                   std_type='CF-303',
                   name='Line 3')
    pp.create_line(net,
                   bus_808,
                   bus_812,
                   length_km=11.43000,
                   std_type='CF-300',
                   name='Line 4')
    pp.create_line(net,
                   bus_812,
                   bus_814,
                   length_km=9.061704,
                   std_type='CF-300',
                   name='Line 5')
    # pp.create_line(net, bus_814, bus_850, length_km=0.003048, std_type='CF-301',
    #                name='Line 6')
    pp.create_line(net,
                   bus_816,
                   bus_818,
                   length_km=0.521208,
                   std_type='CF-302',
                   name='Line 7')
    pp.create_line(net,
                   bus_816,
                   bus_824,
                   length_km=3.112008,
                   std_type='CF-301',
                   name='Line 8')
    pp.create_line(net,
                   bus_818,
                   bus_820,
                   length_km=14.67612,
                   std_type='CF-302',
                   name='Line 9')
    pp.create_line(net,
                   bus_820,
                   bus_822,
                   length_km=4.187952,
                   std_type='CF-302',
                   name='Line 10')
    pp.create_line(net,
                   bus_824,
                   bus_826,
                   length_km=0.923544,
                   std_type='CF-303',
                   name='Line 11')
    pp.create_line(net,
                   bus_824,
                   bus_828,
                   length_km=0.256032,
                   std_type='CF-301',
                   name='Line 12')
    pp.create_line(net,
                   bus_828,
                   bus_830,
                   length_km=6.230112,
                   std_type='CF-301',
                   name='Line 13')
    pp.create_line(net,
                   bus_830,
                   bus_854,
                   length_km=0.158496,
                   std_type='CF-301',
                   name='Line 14')
    pp.create_line(net,
                   bus_832,
                   bus_858,
                   length_km=1.493520,
                   std_type='CF-301',
                   name='Line 15')
    pp.create_line(net,
                   bus_834,
                   bus_860,
                   length_km=0.615696,
                   std_type='CF-301',
                   name='Line 16')
    pp.create_line(net,
                   bus_834,
                   bus_842,
                   length_km=0.085344,
                   std_type='CF-301',
                   name='Line 17')
    pp.create_line(net,
                   bus_836,
                   bus_840,
                   length_km=0.262128,
                   std_type='CF-301',
                   name='Line 18')
    pp.create_line(net,
                   bus_836,
                   bus_862,
                   length_km=0.085344,
                   std_type='CF-301',
                   name='Line 19')
    pp.create_line(net,
                   bus_842,
                   bus_844,
                   length_km=0.411480,
                   std_type='CF-301',
                   name='Line 20')
    pp.create_line(net,
                   bus_844,
                   bus_846,
                   length_km=1.109472,
                   std_type='CF-301',
                   name='Line 21')
    pp.create_line(net,
                   bus_846,
                   bus_848,
                   length_km=0.161544,
                   std_type='CF-301',
                   name='Line 22')
    pp.create_line(net,
                   bus_850,
                   bus_816,
                   length_km=0.094488,
                   std_type='CF-301',
                   name='Line 23')
    # pp.create_line(net, bus_852, bus_832, length_km=0.003048, std_type='CF-301',
    #                name='Line 24')
    pp.create_line(net,
                   bus_854,
                   bus_856,
                   length_km=7.110984,
                   std_type='CF-303',
                   name='Line 25')
    pp.create_line(net,
                   bus_854,
                   bus_852,
                   length_km=11.22578,
                   std_type='CF-301',
                   name='Line 26')
    pp.create_line(net,
                   bus_858,
                   bus_864,
                   length_km=0.493776,
                   std_type='CF-302',
                   name='Line 27')
    pp.create_line(net,
                   bus_858,
                   bus_834,
                   length_km=1.776984,
                   std_type='CF-301',
                   name='Line 28')
    pp.create_line(net,
                   bus_860,
                   bus_836,
                   length_km=0.816864,
                   std_type='CF-301',
                   name='Line 29')
    pp.create_line(net,
                   bus_860,
                   bus_838,
                   length_km=1.481328,
                   std_type='CF-304',
                   name='Line 30')
    pp.create_line(net,
                   bus_888,
                   bus_890,
                   length_km=3.218688,
                   std_type='CF-300',
                   name='Line 31')

    # Substation
    pp.create_transformer_from_parameters(net,
                                          bus0,
                                          bus_800,
                                          sn_mva=2.5,
                                          vn_hv_kv=24.9,
                                          vn_lv_kv=24.9,
                                          vkr_percent=1.0,
                                          vk_percent=8.062257,
                                          pfe_kw=0.0,
                                          i0_percent=0.0,
                                          shift_degree=0.0,
                                          vkr0_percent=1.0,
                                          vk0_percent=8.062257,
                                          vector_group='YNyn',
                                          mag0_percent=100.0,
                                          mag0_rx=0,
                                          si0_hv_partial=0.9,
                                          tap_side='lv',
                                          tap_neutral=0,
                                          tap_max=2,
                                          tap_min=-2,
                                          tap_step_percent=2.5,
                                          tap_pos=-2,
                                          name='Substation')
    # Regulator 1
    pp.create_transformer_from_parameters(net,
                                          bus_814,
                                          bus_850,
                                          sn_mva=1,
                                          vn_hv_kv=24.9,
                                          vn_lv_kv=24.9,
                                          vkr_percent=0.320088,
                                          vk_percent=0.357539,
                                          pfe_kw=0.0,
                                          i0_percent=0.0,
                                          shift_degree=0.0,
                                          vkr0_percent=0.452171,
                                          vk0_percent=0.665505,
                                          vector_group='YNyn',
                                          mag0_percent=100.0,
                                          mag0_rx=0,
                                          si0_hv_partial=0.9,
                                          tap_side='lv',
                                          tap_neutral=0,
                                          tap_max=16,
                                          tap_min=-16,
                                          tap_step_percent=0.625,
                                          tap_pos=0,
                                          tap_phase_shifter=False,
                                          name='Regulator 1')

    # Regulator 2
    pp.create_transformer_from_parameters(net,
                                          bus_852,
                                          bus_832,
                                          sn_mva=1,
                                          vn_hv_kv=24.9,
                                          vn_lv_kv=24.9,
                                          vkr_percent=0.320088,
                                          vk_percent=0.357539,
                                          pfe_kw=0.0,
                                          i0_percent=0.0,
                                          shift_degree=0.0,
                                          vkr0_percent=0.452171,
                                          vk0_percent=0.665505,
                                          vector_group='YNyn',
                                          mag0_percent=100.0,
                                          mag0_rx=0,
                                          si0_hv_partial=0.9,
                                          tap_side='lv',
                                          tap_neutral=0,
                                          tap_max=16,
                                          tap_min=-16,
                                          tap_step_percent=0.625,
                                          tap_pos=0,
                                          tap_phase_shifter=False,
                                          name='Regulator 2')
    # Traformer
    pp.create_transformer_from_parameters(net,
                                          bus_832,
                                          bus_888,
                                          sn_mva=0.5,
                                          vn_hv_kv=24.9,
                                          vn_lv_kv=4.16,
                                          vkr_percent=1.9,
                                          vk_percent=4.5,
                                          pfe_kw=0.0,
                                          i0_percent=0.0,
                                          shift_degree=0.0,
                                          vkr0_percent=1.9,
                                          vk0_percent=4.5,
                                          vector_group='YNyn',
                                          mag0_percent=100.0,
                                          mag0_rx=0,
                                          si0_hv_partial=0.9,
                                          name='Traformer')

    # Loads
    pp.create_asymmetric_load(net,
                              bus_806,
                              p_a_mw=0,
                              p_b_mw=0.03,
                              p_c_mw=0.025,
                              q_a_mvar=0,
                              q_b_mvar=0.015,
                              q_c_mvar=0.014,
                              name='Load 806',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_810,
                              p_a_mw=0,
                              p_b_mw=0.016,
                              p_c_mw=0,
                              q_a_mvar=0,
                              q_b_mvar=0.008,
                              q_c_mvar=0,
                              name='Load 810',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_820,
                              p_a_mw=0.034,
                              p_b_mw=0,
                              p_c_mw=0,
                              q_a_mvar=0.017,
                              q_b_mvar=0,
                              q_c_mvar=0,
                              name='Load 820',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_822,
                              p_a_mw=0.135,
                              p_b_mw=0,
                              p_c_mw=0,
                              q_a_mvar=0.07,
                              q_b_mvar=0,
                              q_c_mvar=0,
                              name='Load 822',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_824,
                              p_a_mw=0,
                              p_b_mw=0.005,
                              p_c_mw=0,
                              q_a_mvar=0,
                              q_b_mvar=0.002,
                              q_c_mvar=0,
                              name='Load 824',
                              type='delta')
    pp.create_asymmetric_load(net,
                              bus_826,
                              p_a_mw=0,
                              p_b_mw=0.04,
                              p_c_mw=0,
                              q_a_mvar=0,
                              q_b_mvar=0.02,
                              q_c_mvar=0,
                              name='Load 826',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_828,
                              p_a_mw=0,
                              p_b_mw=0,
                              p_c_mw=0.004,
                              q_a_mvar=0,
                              q_b_mvar=0,
                              q_c_mvar=0.002,
                              name='Load 828',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_830,
                              p_a_mw=0.007,
                              p_b_mw=0,
                              p_c_mw=0,
                              q_a_mvar=0.003,
                              q_b_mvar=0,
                              q_c_mvar=0,
                              name='Load 830',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_856,
                              p_a_mw=0,
                              p_b_mw=0.004,
                              p_c_mw=0,
                              q_a_mvar=0,
                              q_b_mvar=0.002,
                              q_c_mvar=0,
                              name='Load 856',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_858,
                              p_a_mw=0.007,
                              p_b_mw=0.002,
                              p_c_mw=0.006,
                              q_a_mvar=0.003,
                              q_b_mvar=0.001,
                              q_c_mvar=0.003,
                              name='Load 858',
                              type='delta')
    pp.create_asymmetric_load(net,
                              bus_864,
                              p_a_mw=0.002,
                              p_b_mw=0,
                              p_c_mw=0,
                              q_a_mvar=0.001,
                              q_b_mvar=0,
                              q_c_mvar=0,
                              name='Load 864',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_834,
                              p_a_mw=0.004,
                              p_b_mw=0.015,
                              p_c_mw=0.013,
                              q_a_mvar=0.002,
                              q_b_mvar=0.008,
                              q_c_mvar=0.007,
                              name='Load 834',
                              type='delta')
    pp.create_asymmetric_load(net,
                              bus_860,
                              p_a_mw=0.016,
                              p_b_mw=0.02,
                              p_c_mw=0.11,
                              q_a_mvar=0.008,
                              q_b_mvar=0.01,
                              q_c_mvar=0.055,
                              name='Load 860',
                              type='delta')
    pp.create_asymmetric_load(net,
                              bus_836,
                              p_a_mw=0.03,
                              p_b_mw=0.01,
                              p_c_mw=0.042,
                              q_a_mvar=0.015,
                              q_b_mvar=0.006,
                              q_c_mvar=0.022,
                              name='Load 836',
                              type='delta')
    pp.create_asymmetric_load(net,
                              bus_840,
                              p_a_mw=0.018,
                              p_b_mw=0.022,
                              p_c_mw=0,
                              q_a_mvar=0.009,
                              q_b_mvar=0.011,
                              q_c_mvar=0,
                              name='Load 840',
                              type='delta')
    pp.create_asymmetric_load(net,
                              bus_838,
                              p_a_mw=0,
                              p_b_mw=0.028,
                              p_c_mw=0,
                              q_a_mvar=0,
                              q_b_mvar=0.014,
                              q_c_mvar=0,
                              name='Load 838',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_844,
                              p_a_mw=0.009,
                              p_b_mw=0,
                              p_c_mw=0,
                              q_a_mvar=0.005,
                              q_b_mvar=0,
                              q_c_mvar=0,
                              name='Load 844',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_846,
                              p_a_mw=0,
                              p_b_mw=0.025,
                              p_c_mw=0.012,
                              q_a_mvar=0,
                              q_b_mvar=0.02,
                              q_c_mvar=0.011,
                              name='Load 846',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_848,
                              p_a_mw=0,
                              p_b_mw=0.023,
                              p_c_mw=0,
                              q_a_mvar=0,
                              q_b_mvar=0.011,
                              q_c_mvar=0,
                              name='Load 848',
                              type='wye')

    pp.create_asymmetric_load(net,
                              bus_860,
                              p_a_mw=0.02,
                              p_b_mw=0.02,
                              p_c_mw=0.02,
                              q_a_mvar=0.016,
                              q_b_mvar=0.016,
                              q_c_mvar=0.016,
                              name='Load 860 spot',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_840,
                              p_a_mw=0.009,
                              p_b_mw=0.009,
                              p_c_mw=0.009,
                              q_a_mvar=0.007,
                              q_b_mvar=0.007,
                              q_c_mvar=0.007,
                              name='Load 840 spot',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_844,
                              p_a_mw=0.135,
                              p_b_mw=0.135,
                              p_c_mw=0.135,
                              q_a_mvar=0.105,
                              q_b_mvar=0.105,
                              q_c_mvar=0.105,
                              name='Load 844 spot',
                              type='wye')
    pp.create_asymmetric_load(net,
                              bus_848,
                              p_a_mw=0.02,
                              p_b_mw=0.02,
                              p_c_mw=0.02,
                              q_a_mvar=0.016,
                              q_b_mvar=0.016,
                              q_c_mvar=0.016,
                              name='Load 848 spot',
                              type='delta')
    pp.create_asymmetric_load(net,
                              bus_890,
                              p_a_mw=0.15,
                              p_b_mw=0.15,
                              p_c_mw=0.15,
                              q_a_mvar=0.075,
                              q_b_mvar=0.075,
                              q_c_mvar=0.075,
                              name='Load 890 spot',
                              type='delta')
    pp.create_asymmetric_load(net,
                              bus_830,
                              p_a_mw=0.01,
                              p_b_mw=0.01,
                              p_c_mw=0.025,
                              q_a_mvar=0.005,
                              q_b_mvar=0.005,
                              q_c_mvar=0.01,
                              name='Load 830 spot',
                              type='delta')

    # External grid
    pp.create_ext_grid(net,
                       bus0,
                       vm_pu=1.0,
                       va_degree=0.0,
                       s_sc_max_mva=10.0,
                       s_sc_min_mva=10.0,
                       rx_max=1,
                       rx_min=1,
                       r0x0_max=1,
                       x0x_max=1)

    # Distributed generators
    pp.create_sgen(net,
                   bus_848,
                   p_mw=0.66,
                   q_mvar=0.500,
                   name='DG 1',
                   max_p_mw=0.66,
                   min_p_mw=0,
                   max_q_mvar=0.5,
                   min_q_mvar=0)
    pp.create_sgen(net,
                   bus_890,
                   p_mw=0.50,
                   q_mvar=0.375,
                   name='DG 2',
                   max_p_mw=0.50,
                   min_p_mw=0,
                   max_q_mvar=0.375,
                   min_q_mvar=0)
    pp.create_sgen(net,
                   bus_822,
                   p_mw=0.2,
                   type='PV',
                   name='PV 1',
                   max_p_mw=0.2,
                   min_p_mw=0,
                   max_q_mvar=0,
                   min_q_mvar=0)
    pp.create_sgen(net,
                   bus_856,
                   p_mw=0.2,
                   type='PV',
                   name='PV 2',
                   max_p_mw=0.2,
                   min_p_mw=0,
                   max_q_mvar=0,
                   min_q_mvar=0)
    pp.create_sgen(net,
                   bus_838,
                   p_mw=0.2,
                   type='PV',
                   name='PV 3',
                   max_p_mw=0.2,
                   min_p_mw=0,
                   max_q_mvar=0,
                   min_q_mvar=0)
    pp.create_sgen(net,
                   bus_822,
                   p_mw=0.3,
                   type='WP',
                   name='WP 1',
                   max_p_mw=0.3,
                   min_p_mw=0,
                   max_q_mvar=0,
                   min_q_mvar=0)
    pp.create_sgen(net,
                   bus_826,
                   p_mw=0.3,
                   type='WP',
                   name='WP 2',
                   max_p_mw=0.3,
                   min_p_mw=0,
                   max_q_mvar=0,
                   min_q_mvar=0)
    pp.create_sgen(net,
                   bus_838,
                   p_mw=0.3,
                   type='WP',
                   name='WP 3',
                   max_p_mw=0.3,
                   min_p_mw=0,
                   max_q_mvar=0,
                   min_q_mvar=0)

    # Shunt capacity bank
    pp.create_shunt(net,
                    bus_840,
                    q_mvar=-0.12,
                    name='SCB 1',
                    step=4,
                    max_step=4)
    pp.create_shunt(net,
                    bus_864,
                    q_mvar=-0.12,
                    name='SCB 2',
                    step=4,
                    max_step=4)

    # storage
    pp.create_storage(net,
                      bus_810,
                      p_mw=0.2,
                      max_e_mwh=1.0,
                      sn_mva=1.0,
                      soc_percent=50,
                      min_e_mwh=0.2,
                      name='Storage')

    pp.add_zero_impedance_parameters(net)

    return net


# net = case34_3ph()
# pp.pf.runpp_3ph.runpp_3ph(net)
# print(net.res_bus_3ph)
# print(net.sn_mva)
################################ CREATE TRAFOS ###############################

#with tap changers

pp.create_transformer_from_parameters(net,
                                      hv_bus=202,
                                      lv_bus=75,
                                      sn_mva=0.4,
                                      vn_hv_kv=20.5,
                                      vn_lv_kv=0.23,
                                      vk_percent=4.,
                                      vkr_percent=0.04,
                                      pfe_kw=0.75,
                                      i0_percent=1.8,
                                      shift_degree=150,
                                      in_service=True,
                                      parallel=1,
                                      name='E.T. NODE 1',
                                      tap_side='hv',
                                      tap_pos=0,
                                      tap_neutral=0,
                                      tap_min=-2,
                                      tap_max=2,
                                      tap_step_percent=2.5,
                                      tap_step_degree=0,
                                      tap_phase_shifter=False,
                                      df=1,
                                      index=75)
pp.create_transformer_from_parameters(net,
                                      hv_bus=202,
                                      lv_bus=76,
                                      sn_mva=0.63,
Example #28
0
def from_ppc(ppc, f_hz=50, validate_conversion=False):
    """
    This function converts pypower case files to pandapower net structure.

    INPUT:

        **ppc** - The pypower case file.

    OPTIONAL:

        **f_hz** - The frequency of the network.

    OUTPUT:

        **net**

    EXAMPLE:

        import pandapower.converter as pc

        from pypower import case4gs

        ppc_net = case4gs.case4gs()

        pp_net = cv.from_ppc(ppc_net, f_hz=60)

    """
    # --- catch common failures
    if Series(ppc['bus'][:, 9] <= 0).any():
        logger.info('There are false baseKV given in the pypower case file.')

    # --- general_parameters
    baseMVA = ppc['baseMVA']  # MVA
    omega = pi * f_hz  # 1/s
    MAX_VAL = 99999.

    net = pp.create_empty_network(f_hz=f_hz)

    # --- bus data -> create buses, sgen, load, shunt
    for i in range(len(ppc['bus'])):
        # create buses
        pp.create_bus(net,
                      name=int(ppc['bus'][i, 0]),
                      vn_kv=ppc['bus'][i, 9],
                      type="b",
                      zone=ppc['bus'][i, 6],
                      in_service=bool(ppc['bus'][i, 1] != 4),
                      max_vm_pu=ppc['bus'][i, 11],
                      min_vm_pu=ppc['bus'][i, 12])
        # create sgen, load
        if ppc['bus'][i, 2] > 0:
            pp.create_load(net,
                           i,
                           p_kw=ppc['bus'][i, 2] * 1e3,
                           q_kvar=ppc['bus'][i, 3] * 1e3)
        elif ppc['bus'][i, 2] < 0:
            pp.create_sgen(net,
                           i,
                           p_kw=ppc['bus'][i, 2] * 1e3,
                           q_kvar=ppc['bus'][i, 3] * 1e3,
                           type="")
        elif ppc['bus'][i, 3] != 0:
            pp.create_load(net,
                           i,
                           p_kw=ppc['bus'][i, 2] * 1e3,
                           q_kvar=ppc['bus'][i, 3] * 1e3)
        # create shunt
        if ppc['bus'][i, 4] != 0 or ppc['bus'][i, 5] != 0:
            pp.create_shunt(net,
                            i,
                            p_kw=ppc['bus'][i, 4] * 1e3,
                            q_kvar=-ppc['bus'][i, 5] * 1e3)
    # unused data of ppc: Vm, Va (partwise: in ext_grid), zone

    # --- gen data -> create ext_grid, gen, sgen
    for i in range(len(ppc['gen'])):
        # if in ppc is only one gen -> numpy initially uses one dim array -> change to two dim array
        if len(ppc["gen"].shape) == 1:
            ppc["gen"] = array(ppc["gen"], ndmin=2)
        current_bus_idx = pp.get_element_index(net,
                                               'bus',
                                               name=int(ppc['gen'][i, 0]))
        current_bus_type = int(ppc['bus'][current_bus_idx, 1])
        # create ext_grid
        if current_bus_type == 3:
            if len(pp.get_connected_elements(net, 'ext_grid',
                                             current_bus_idx)) > 0:
                logger.info('At bus %d an ext_grid already exists. ' %
                            current_bus_idx +
                            'Because of that generator %d ' % i +
                            'is converted not as an ext_grid but as a sgen')
                current_bus_type = 1
            else:
                pp.create_ext_grid(net,
                                   bus=current_bus_idx,
                                   vm_pu=ppc['gen'][i, 5],
                                   va_degree=ppc['bus'][current_bus_idx, 8],
                                   in_service=bool(ppc['gen'][i, 7] > 0),
                                   max_p_kw=-ppc['gen'][i, 9] * 1e3,
                                   min_p_kw=-ppc['gen'][i, 8] * 1e3,
                                   max_q_kvar=ppc['gen'][i, 3] * 1e3,
                                   min_q_kvar=ppc['gen'][i, 4] * 1e3)
                if ppc['gen'][i, 4] > ppc['gen'][i, 3]:
                    logger.info(
                        'min_q_kvar of gen %d must be less than max_q_kvar but is not.'
                        % i)
                if -ppc['gen'][i, 9] < -ppc['gen'][i, 8]:
                    logger.info(
                        'max_p_kw of gen %d must be less than min_p_kw but is not.'
                        % i)
        # create gen
        elif current_bus_type == 2:
            pp.create_gen(net,
                          bus=current_bus_idx,
                          vm_pu=ppc['gen'][i, 5],
                          p_kw=-ppc['gen'][i, 1] * 1e3,
                          in_service=bool(ppc['gen'][i, 7] > 0),
                          max_p_kw=-ppc['gen'][i, 9] * 1e3,
                          min_p_kw=-ppc['gen'][i, 8] * 1e3,
                          max_q_kvar=ppc['gen'][i, 3] * 1e3,
                          min_q_kvar=ppc['gen'][i, 4] * 1e3,
                          controllable=True)
            if ppc['gen'][i, 4] > ppc['gen'][i, 3]:
                logger.info(
                    'min_q_kvar of gen %d must be less than max_q_kvar but is not.'
                    % i)
            if -ppc['gen'][i, 9] < -ppc['gen'][i, 8]:
                logger.info(
                    'max_p_kw of gen %d must be less than min_p_kw but is not.'
                    % i)
        # create sgen
        if current_bus_type == 1:
            pp.create_sgen(net,
                           bus=current_bus_idx,
                           p_kw=-ppc['gen'][i, 1] * 1e3,
                           q_kvar=-ppc['gen'][i, 2] * 1e3,
                           type="",
                           in_service=bool(ppc['gen'][i, 7] > 0),
                           max_p_kw=-ppc['gen'][i, 9] * 1e3,
                           min_p_kw=-ppc['gen'][i, 8] * 1e3,
                           max_q_kvar=ppc['gen'][i, 3] * 1e3,
                           min_q_kvar=ppc['gen'][i, 4] * 1e3,
                           controllable=True)
            if ppc['gen'][i, 4] > ppc['gen'][i, 3]:
                logger.info(
                    'min_q_kvar of gen %d must be less than max_q_kvar but is not.'
                    % i)
            if -ppc['gen'][i, 9] < -ppc['gen'][i, 8]:
                logger.info(
                    'max_p_kw of gen %d must be less than min_p_kw but is not.'
                    % i)
    # unused data of ppc: Vg (partwise: in ext_grid and gen), mBase, Pc1, Pc2, Qc1min, Qc1max,
    # Qc2min, Qc2max, ramp_agc, ramp_10, ramp_30,ramp_q, apf

    # --- branch data -> create line, trafo
    for i in range(len(ppc['branch'])):
        from_bus = pp.get_element_index(net,
                                        'bus',
                                        name=int(ppc['branch'][i, 0]))
        to_bus = pp.get_element_index(net,
                                      'bus',
                                      name=int(ppc['branch'][i, 1]))

        from_vn_kv = ppc['bus'][from_bus, 9]
        to_vn_kv = ppc['bus'][to_bus, 9]
        if (from_vn_kv == to_vn_kv) & ((ppc['branch'][i, 8] == 0) | (ppc['branch'][i, 8] == 1)) & \
           (ppc['branch'][i, 9] == 0):
            Zni = ppc['bus'][to_bus, 9]**2 / baseMVA  # ohm
            max_i_ka = ppc['branch'][i, 5] / ppc['bus'][to_bus, 9]
            if max_i_ka == 0.0:
                max_i_ka = MAX_VAL
                logger.debug(
                    "ppc branch rateA is zero -> Using MAX_VAL instead to calculate "
                    + "maximum branch flow")
            pp.create_line_from_parameters(
                net,
                from_bus=from_bus,
                to_bus=to_bus,
                length_km=1,
                r_ohm_per_km=ppc['branch'][i, 2] * Zni,
                x_ohm_per_km=ppc['branch'][i, 3] * Zni,
                c_nf_per_km=ppc['branch'][i, 4] / Zni / omega * 1e9 / 2,
                max_i_ka=max_i_ka,
                type='ol',
                in_service=bool(ppc['branch'][i, 10]))

        else:
            if from_vn_kv >= to_vn_kv:
                hv_bus = from_bus
                vn_hv_kv = from_vn_kv
                lv_bus = to_bus
                vn_lv_kv = to_vn_kv
                tp_side = 'hv'
            else:
                hv_bus = to_bus
                vn_hv_kv = to_vn_kv
                lv_bus = from_bus
                vn_lv_kv = from_vn_kv
                tp_side = 'lv'
                if from_vn_kv == to_vn_kv:
                    logger.warning(
                        'The pypower branch %d (from_bus, to_bus)=(%d, %d) is considered'
                        ' as a transformer because of a ratio != 0 | 1 but it connects '
                        'the same voltage level', i, ppc['branch'][i, 0],
                        ppc['branch'][i, 1])
            rk = ppc['branch'][i, 2]
            xk = ppc['branch'][i, 3]
            zk = (rk**2 + xk**2)**0.5
            sn = ppc['branch'][i, 5] * 1e3
            if sn == 0.0:
                sn = MAX_VAL
                logger.debug(
                    "ppc branch rateA is zero -> Using MAX_VAL instead to calculate "
                    + "apparent power")
            ratio_1 = 0 if ppc['branch'][i, 8] == 0 else (ppc['branch'][i, 8] -
                                                          1) * 100
            i0_percent = -ppc['branch'][i, 4] * 100 * baseMVA * 1e3 / sn
            if i0_percent < 0:
                logger.info(
                    'A transformer always behaves inductive consumpting but the '
                    'susceptance of pypower branch %d (from_bus, to_bus)=(%d, %d) is '
                    'positive.', i, ppc['branch'][i, 0], ppc['branch'][i, 1])

            pp.create_transformer_from_parameters(
                net,
                hv_bus=hv_bus,
                lv_bus=lv_bus,
                sn_kva=sn,
                vn_hv_kv=vn_hv_kv,
                vn_lv_kv=vn_lv_kv,
                vsc_percent=zk * sn / 1e3,
                vscr_percent=rk * sn / 1e3,
                pfe_kw=0,
                i0_percent=i0_percent,
                shift_degree=ppc['branch'][i, 9],
                tp_st_percent=abs(ratio_1) if ratio_1 else nan,
                tp_pos=sign(ratio_1) if ratio_1 else nan,
                tp_side=tp_side if ratio_1 else None,
                tp_mid=0 if ratio_1 else nan)
    # unused data of ppc: rateB, rateC

    # ToDo: gencost, areas are currently unconverted
    if validate_conversion:
        # set logger level to debug
        logger.setLevel(10)
        if not validate_from_ppc(ppc, net):
            logger.error("Validation failed.")

    return net
def grid():
    net = pp.create_empty_network()  
    file = 'Sitel_Invade_MV_Topology.xlsx' 
    xl = pd.ExcelFile(Path(str(os.getcwd()) + '/'+ file))  
    MVNetwork = xl.parse('Linies') 
    x_ohm_per_km = MVNetwork['Reactancia_ohm_km'][0]
    c_uf_per_km = MVNetwork['Capacitat_uF_km'][0]
    r_ohm_per_km = MVNetwork['Resistencia_ohm_km'][0]

#IMPORTANT: no change in the capacitance units has been made. In pandapower documentation it is 
#a the magnitude around 240, what we already have. if multiplied by 1000 to change it from micro 
#to nano farads, overload is of 300%. Make sure with Estabanell they are giving us micro. Meanwhile,
#it is left as the value of micro as it is the most similar of a reasonable magnitude
    
    line_data = {"c_nf_per_km": c_uf_per_km , "r_ohm_per_km": r_ohm_per_km, "x_ohm_per_km": x_ohm_per_km, "max_i_ka":0.415}
    pp.create_std_type(net, line_data, "line_ESTABANELL", element='line')

    MVNetworkbusses = xl.parse('Busses')
    for i in MVNetworkbusses['name']:
        pp.create_bus(net, vn_kv=20.5,name=i, max_vm_pu=1.1, min_vm_pu=0.9)

    MVNetworkbussesTrafos = xl.parse('Trafos')
    for i in range(len(MVNetworkbussesTrafos['name'])):
        pp.create_bus(net, vn_kv= MVNetworkbussesTrafos['vn_lv_kv'][i], name=MVNetworkbussesTrafos['name'][i], max_vm_pu=1.1, min_vm_pu=0.9)

    ## per aconseguir els Id's tant dels empalmaments com els nusos a la banda LV dels trafos:
    l=MVNetworkbusses['Id Bus']                 #dataframe
    r=l.append(MVNetworkbussesTrafos['Id Bus']) #r still a DataFrame
    r=r.values.tolist()                         #r list
    net.bus.insert(5, 'Id Bus', r)  
    net.bus = net.bus.set_index("Id Bus", drop = False)


    pp.create_transformer_from_parameters(net, hv_bus=202, lv_bus=75, sn_mva=0.4, vn_hv_kv=20.5, vn_lv_kv=0.23, vk_percent=4., vkr_percent=0.04, pfe_kw=0.75, i0_percent=1.8, shift_degree=150, in_service=True, parallel=1, name='E.T. NODE 1', tap_side='hv', tap_pos=0, tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tap_step_degree=0, tap_phase_shifter=False, df=1, index=75)    
    pp.create_transformer_from_parameters(net, hv_bus=202, lv_bus=76, sn_mva=0.63, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=4.09, vkr_percent=0.0409, pfe_kw=0.548, i0_percent=0.9, shift_degree=150, in_service=True, parallel=1, name='E.T. NODE 2', tap_side='hv',tap_pos=0, tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tap_step_degree=0, tap_phase_shifter=True, df=1, index=76)
    pp.create_transformer_from_parameters(net, hv_bus=204, lv_bus=22, sn_mva=1, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=6., vkr_percent=0.08, pfe_kw=1.4, i0_percent=1.3, shift_degree=150, in_service=True, parallel=1, name='E.T.CUARTEL', tap_side='hv', tap_pos=0,tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tap_step_degree=0, tap_phase_shifter=True,df=1, index=22)
    pp.create_transformer_from_parameters(net, hv_bus=209, lv_bus=26, sn_mva=0.63, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=4., vkr_percent=0.053, pfe_kw=1.03, i0_percent=1.6, shift_degree=150, in_service=True, parallel=1, name='E.T.PEDRALS',  tap_side='hv',tap_pos=0, tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tap_step_degree=0, tap_phase_shifter=True,df=1, index=26) 
    pp.create_transformer_from_parameters(net, hv_bus=213, lv_bus=30, sn_mva=0.8, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=6., vkr_percent=0.06, pfe_kw=1.4, i0_percent=1.3, shift_degree=150, in_service=True, parallel=1, name='E.T. LA MUTUA',tap_side='hv', tap_pos=0,tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tap_step_degree=0, tap_phase_shifter=True, df=1,index=30)
    pp.create_transformer_from_parameters(net, hv_bus=219, lv_bus=34, sn_mva=0.63, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=4.28, vkr_percent=0.0428, pfe_kw=1.3, i0_percent=1.05, shift_degree=150, in_service=True, parallel=1, name='E.T. LA LLEƓ', tap_side='hv',tap_pos=0, tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tap_step_degree=0, tap_phase_shifter=True,df=1, index=34)
    pp.create_transformer_from_parameters(net, hv_bus=220, lv_bus=64, sn_mva=0.63, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=4., vkr_percent=0.04, pfe_kw=1.3, i0_percent=1.6, shift_degree=150, in_service=True, parallel=1, name='E.T. PRADES 1',tap_side='hv',tap_pos=0, tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tap_step_degree=0, tap_phase_shifter=True,df=1, index=64)
    pp.create_transformer_from_parameters(net, hv_bus=228, lv_bus=42, sn_mva=0.4, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=4.05, vkr_percent=0.054, pfe_kw=0.768, i0_percent=1.72, shift_degree=150, in_service=True, parallel=1, name='E.T. ECUADOR', tap_side='hv', tap_pos=0, tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tap_step_degree=0, tap_phase_shifter=True,df=1, index=42)
    pp.create_transformer_from_parameters(net, hv_bus=230, lv_bus=46, sn_mva=0.4, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=5., vkr_percent=0.066, pfe_kw=1.193, i0_percent=0.45, shift_degree=150, in_service=True, parallel=1, name='E.T. URUGUAI', tap_side='hv',tap_pos=0, tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tap_step_degree=0, tap_phase_shifter=True, df=1, index=46)
    pp.create_transformer_from_parameters(net, hv_bus=232, lv_bus=50, sn_mva=0.63, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=4., vkr_percent=0.053, pfe_kw=1.3, i0_percent=1.6, shift_degree=150, in_service=True, parallel=1, name='E.T. LA TORRETA', tap_side='hv',tap_pos=0, tap_neutral=0, tap_min=-2, tap_max=2,tap_step_percent=2.5,tap_step_degree=0,tap_phase_shifter=True,df=1, index=50)
    pp.create_transformer_from_parameters(net, hv_bus=234, lv_bus=54, sn_mva=0.4, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=4., vkr_percent=0.04, pfe_kw=0.93, i0_percent=1.8, shift_degree=150, in_service=True, parallel=1,name='E.T. COSTA BRAVA 1', tap_side='hv',tap_pos=0, tap_neutral=0, tap_min=-2,tap_max=2,tap_step_percent=2.5,tap_step_degree=0,tap_phase_shifter=True, df=1, index=54)
    pp.create_transformer_from_parameters(net, hv_bus=236, lv_bus=58, sn_mva=0.4, vn_hv_kv=20.5, vn_lv_kv=0.23, vk_percent=4., vkr_percent=0.04, pfe_kw=0.93, i0_percent=1.8, shift_degree=150,in_service=True,parallel=1,name='E.T. NOVA VERDAGUER 1',tap_side='hv',tap_pos=0, tap_neutral=0,tap_min=-2,tap_max=2,tap_step_percent=2.5,tap_step_degree=0,tap_phase_shifter=True, df=1, index=58)
    pp.create_transformer_from_parameters(net, hv_bus=236, lv_bus=66, sn_mva=0.4, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=4., vkr_percent=0.04, pfe_kw=0.75, i0_percent=1.8, shift_degree=150, in_service=True, parallel=1,name='E.T. NOVA VERDAGUER 2',tap_side='hv',tap_pos=0, tap_neutral=0,tap_min=-2,tap_max=2,tap_step_percent=2.5,tap_step_degree=0,tap_phase_shifter=True, df=1,index=66)
    pp.create_transformer_from_parameters(net, hv_bus=238, lv_bus=61, sn_mva=0.25, vn_hv_kv=20.5, vn_lv_kv=0.4, vk_percent=4., vkr_percent=0.04, pfe_kw=0.65, i0_percent=2, shift_degree=150, in_service=True, parallel=1, name='E.T. GRANADA', tap_side='hv', tap_pos=0, tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tap_step_degree=0, tap_phase_shifter=True, df=1, index=61)

    for i in range(len(MVNetwork['Id TedisNet'])): 
        pp.create_line(net, from_bus=MVNetworkbusses['Id Bus'][i], to_bus=MVNetworkbusses['Id Bus'][i+1], length_km=MVNetwork['Length_km'][i], std_type="line_ESTABANELL", name=MVNetwork['origen'][i])
    net.line.insert(14, 'Id linia', MVNetwork['Id TedisNet'])

    #the slack bus will act as an external grid
    pp.create_ext_grid(net, bus=201, vm_pu=1.0, va_degree=0.0, in_service=True, name="Grid Connection")

    return(net)
Example #30
0
    def build_case_grid(self):
        grid = pp.create_empty_network()

        # Substation buses 1
        bus0 = pp.create_bus(
            grid,
            vn_kv=2 * self.base_unit_v / 1000,
            min_vm_pu=1.0,
            max_vm_pu=1.02,
            name="bus-0-0",
        )
        bus1 = pp.create_bus(
            grid,
            vn_kv=self.base_unit_v / 1000,
            min_vm_pu=1.0,
            max_vm_pu=1.02,
            name="bus-1-1",
        )
        bus2 = pp.create_bus(
            grid,
            vn_kv=self.base_unit_v / 1000,
            min_vm_pu=1.0,
            max_vm_pu=1.02,
            name="bus-2-2",
        )
        bus3 = pp.create_bus(
            grid,
            vn_kv=self.base_unit_v / 1000,
            min_vm_pu=1.0,
            max_vm_pu=1.02,
            name="bus-3-3",
        )

        # Substation buses 2
        pp.create_bus(
            grid,
            vn_kv=2 * self.base_unit_v / 1000,
            min_vm_pu=1.0,
            max_vm_pu=1.02,
            name="bus-4-0",
        )
        pp.create_bus(
            grid,
            vn_kv=self.base_unit_v / 1000,
            min_vm_pu=1.0,
            max_vm_pu=1.02,
            name="bus-5-1",
        )
        pp.create_bus(
            grid,
            vn_kv=self.base_unit_v / 1000,
            min_vm_pu=1.0,
            max_vm_pu=1.02,
            name="bus-6-2",
        )
        pp.create_bus(
            grid,
            vn_kv=self.base_unit_v / 1000,
            min_vm_pu=1.0,
            max_vm_pu=1.02,
            name="bus-7-3",
        )

        # Transformer
        pp.create_transformer_from_parameters(
            grid,
            hv_bus=bus0,
            lv_bus=bus1,
            name="trafo-0",
            sn_mva=3.5,
            vn_hv_kv=2 * self.base_unit_v / 1000,
            vn_lv_kv=self.base_unit_v / 1000,
            vk_percent=12.5,
            vkr_percent=0.0,
            pfe_kw=0.0,
            i0_percent=0.0,
            shift_degree=0.0,
            max_loading_percent=100.0,
        )

        pp.create_line_from_parameters(
            grid,
            bus1,
            bus2,
            length_km=1.0,
            r_ohm_per_km=0.0,
            x_ohm_per_km=1.0 / 4.0 * self.base_unit_z,
            c_nf_per_km=0.0,
            max_i_ka=self.convert_per_unit_to_ka(5.0),
            name="line-0",
            type="ol",
            max_loading_percent=100.0,
        )

        pp.create_line_from_parameters(
            grid,
            bus2,
            bus3,
            length_km=1.0,
            r_ohm_per_km=0.0,
            x_ohm_per_km=1.0 / 6.0 * self.base_unit_z,
            c_nf_per_km=0.0,
            max_i_ka=self.convert_per_unit_to_ka(5.0),
            name="line-1",
            type="ol",
            max_loading_percent=100.0,
        )

        pp.create_line_from_parameters(
            grid,
            bus3,
            bus1,
            length_km=1.0,
            r_ohm_per_km=0.0,
            x_ohm_per_km=1.0 / 5.0 * self.base_unit_z,
            c_nf_per_km=0.0,
            max_i_ka=self.convert_per_unit_to_ka(4.0),
            name="line-2",
            type="ol",
            max_loading_percent=100.0,
        )

        # Loads
        pp.create_load(grid, bus1, p_mw=2, name="load-0", controllable=False)
        pp.create_load(grid, bus2, p_mw=3, name="load-1", controllable=False)
        pp.create_load(grid, bus3, p_mw=6, name="load-2", controllable=False)

        # Generators
        pp.create_gen(
            grid,
            bus0,
            p_mw=0,
            min_p_mw=0,
            max_p_mw=1,
            vm_pu=1.01,
            name="gen-0",
            controllable=True,
            slack=True,
        )
        pp.create_gen(
            grid,
            bus2,
            p_mw=0,
            min_p_mw=0,
            max_p_mw=5,
            vm_pu=1.01,
            name="gen-1",
            controllable=True,
        )
        pp.create_gen(
            grid,
            bus3,
            p_mw=0,
            min_p_mw=0,
            max_p_mw=8,
            vm_pu=1.01,
            name="gen-2",
            controllable=True,
        )

        # External grids
        pp.create_ext_grid(
            grid,
            bus0,
            va_degree=0.0,
            name="ext-grid-0",
            max_p_mw=3.0,
            min_p_mw=0.0,
            max_loading_percent=100.0,
        )

        grid.trafo[
            "b_pu"] = 28.0  # Empirically: x = vk_percent / 100 * 1 / sn_mva
        grid.trafo["max_p_pu"] = 3.5  # sn_mva

        return grid