How to use the pandapower.get_element_index function in pandapower

To help you get started, we’ve selected a few pandapower examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github e2nIEE / pandapower / pandapower / converter / pypower / from_ppc.py View on Github external
max_p_mw=ppc['gen'][i, PMAX], min_p_mw=ppc['gen'][i, PMIN],
                max_q_mvar=ppc['gen'][i, QMAX], min_q_mvar=ppc['gen'][i, QMIN],
                controllable=True)
            gen_lookup.element_type.loc[i] = 'sgen'
            if ppc['gen'][i, 1] < 0:
                logger.info('p_mw of sgen %d must be less than zero but is not.' % i)
            if ppc['gen'][i, 4] > ppc['gen'][i, 3]:
                logger.info('min_q_mvar of gen %d must be less than max_q_mvar but is not.' % i)
            if -ppc['gen'][i, 9] < -ppc['gen'][i, 8]:
                logger.info('max_p_mw of gen %d must be less than min_p_mw 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):  # create line
            Zni = ppc['bus'][to_bus, 9]**2/baseMVA  # ohm
            max_i_ka = ppc['branch'][i, 5]/ppc['bus'][to_bus, 9]/sqrt(3)
            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,
github e2nIEE / pandapower / pandapower / networks / create_examples.py View on Github external
# Shunt
    pp.create_shunt(net, pp.get_element_index(net, "bus", 'Bus HV1'), p_mw=0, q_mvar=-0.96,
                    name='Shunt')

    # ExtGrids
    pp.create_ext_grid(net, pp.get_element_index(net, "bus", 'Double Busbar 1'), vm_pu=1.03,
                       va_degree=0, name='External grid', s_sc_max_mva=10000, rx_max=0.1,
                       rx_min=0.1)
    # Gen
    pp.create_gen(net, pp.get_element_index(net, "bus", 'Bus HV4'), vm_pu=1.03, p_mw=100,
                  name='Gas turbine')

    # Impedance
    pp.create_impedance(net, pp.get_element_index(net, "bus", 'Bus HV3'),
                        pp.get_element_index(net, "bus", 'Bus HV1'), rft_pu=0.074873,
                        xft_pu=0.198872, sn_mva=100, name='Impedance')

    # xwards
    pp.create_xward(net, pp.get_element_index(net, "bus", 'Bus HV3'), ps_mw=23.942,
                    qs_mvar=-12.24187, pz_mw=2.814571, qz_mvar=0, r_ohm=0, x_ohm=12.18951,
                    vm_pu=1.02616, name='XWard 1')
    pp.create_xward(net, pp.get_element_index(net, "bus", 'Bus HV1'), ps_mw=3.776,
                    qs_mvar=-7.769979, pz_mw=9.174917, qz_mvar=0, r_ohm=0, x_ohm=50.56217,
                    vm_pu=1.024001, name='XWard 2')

    # --- Switches

    # HV
    # Bus-bus switches
    hv_bus_sw = pd.DataFrame()
    hv_bus_sw['bus_name'] = ['DB DS%s' % i for i in range(14)] + \
github e2nIEE / pandapower / pandapower / networks / create_examples.py View on Github external
'Bus SB T5.1', 'Single Busbar'] + \
                            ['Bus SB T%s.2' % i for i in range(1, 6)]
    hv_bus_sw['to_bus'] = ['Bus DB %s' % i for i in
                           ['T0', 'T1', 'T3', 'T3', 'T5', 'T5', 'T7', 'T7', 'T9', 'T9',
                            '1', '2', '3', '4', 'T1', 'T2', 'T4', 'T6', 'T8']] + \
                          ['Bus SB %s' % i for i in
                           ['1', 'T1.2', '2', 'T2.2', '3', 'T3.2', '4', 'T4.2', '5', 'T5.2']] + \
                          ['Bus SB T%s.1' % i for i in range(1, 6)]
    hv_bus_sw['type'] = ['DS']*14 + ['CB']*5 + ['DS']*10 + ['CB']*5
    hv_bus_sw['et'] = 'b'
    hv_bus_sw['closed'] = [bool(i) for i in [1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
                           1] + [1]*15]

    for _, switch in hv_bus_sw.iterrows():
        from_bus = pp.get_element_index(net, "bus", switch.from_bus)
        to_bus = pp.get_element_index(net, "bus", switch.to_bus)
        pp.create_switch(net, from_bus, to_bus, et=switch.et,
                         closed=switch.closed, type=switch.type, name=switch.bus_name)

    # Bus-Line switches
    hv_buses = net.bus[(net.bus.vn_kv == 380) | (net.bus.vn_kv == 110)].index
    hv_ls = net.line[(net.line.from_bus.isin(hv_buses)) & (net.line.to_bus.isin(hv_buses))]
    for _, line in hv_ls.iterrows():
        for bus in [line.from_bus, line.to_bus]:
            pp.create_switch(net, bus, line.name, et='l', closed=True, type='LBS',
                             name='Switch %s - %s' % (net.bus.name.at[bus], line['name']))

    # MV
    # Bus-line switches
    mv_buses = net.bus[(net.bus.vn_kv == 10) | (net.bus.vn_kv == 20)].index
    mv_ls = net.line[(net.line.from_bus.isin(mv_buses)) & (net.line.to_bus.isin(mv_buses))]
    for _, line in mv_ls.iterrows():
github e2nIEE / pandapower / pandapower / networks / create_examples.py View on Github external
to_bus = pp.get_element_index(net, "bus", lv_line.to_bus)
        pp.create_line(net, from_bus, to_bus, length_km=lv_line.length,
                       std_type=lv_line.std_type, name=lv_line.line_name)

    # --- Transformer

    hv_bus = pp.get_element_index(net, "bus", "Bus DB 2")
    lv_bus = pp.get_element_index(net, "bus", "Bus SB 1")
    pp.create_transformer_from_parameters(net, hv_bus, lv_bus,
                                          sn_mva=300, vn_hv_kv=380, vn_lv_kv=110,
                                          vkr_percent=0.06, vk_percent=8, pfe_kw=0,
                                          i0_percent=0, tap_pos=0, shift_degree=0,
                                          name='EHV-HV-Trafo')

    hv_bus = pp.get_element_index(net, "bus", "Bus MV4")
    lv_bus = pp.get_element_index(net, "bus", "Bus LV0")
    pp.create_transformer_from_parameters(net, hv_bus, lv_bus,
                                          sn_mva=0.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, tap_pos=0,
                                          shift_degree=150, name='MV-LV-Trafo')

    # Trafo3w
    hv_bus = pp.get_element_index(net, "bus", "Bus HV2")
    mv_bus = pp.get_element_index(net, "bus", "Bus MV0 20kV")
    lv_bus = pp.get_element_index(net, "bus", "Bus MV0")
    pp.create_transformer3w_from_parameters(net, hv_bus, mv_bus, lv_bus,
                                            vn_hv_kv=110, vn_mv_kv=20, vn_lv_kv=10,
                                            sn_hv_mva=40, sn_mv_mva=15, sn_lv_mva=25,
                                            vk_hv_percent=10.1, vk_mv_percent=10.1,
github e2nIEE / pandapower / pandapower / networks / create_examples.py View on Github external
name='Switch %s - %s' % (net.bus.name.at[bus], line['name']))

    # Trafoswitches
    # HV
    pp.create_switch(net, pp.get_element_index(net, "bus", 'Bus DB 2'),
                     pp.get_element_index(net, "trafo", 'EHV-HV-Trafo'), et='t', closed=True,
                     type='LBS', name='Switch DB2 - EHV-HV-Trafo')
    pp.create_switch(net, pp.get_element_index(net, "bus", 'Bus SB 1'),
                     pp.get_element_index(net, "trafo", 'EHV-HV-Trafo'), et='t', closed=True,
                     type='LBS', name='Switch SB1 - EHV-HV-Trafo')
    # LV
    pp.create_switch(net, pp.get_element_index(net, "bus", 'Bus MV4'),
                     pp.get_element_index(net, "trafo", 'MV-LV-Trafo'), et='t', closed=True,
                     type='LBS', name='Switch MV4 - MV-LV-Trafo')
    pp.create_switch(net, pp.get_element_index(net, "bus", 'Bus LV0'),
                     pp.get_element_index(net, "trafo", 'MV-LV-Trafo'), et='t', closed=True,
                     type='LBS', name='Switch LV0 - MV-LV-Trafo')

    # --- Powerflow

    # run power flow and generate result tables
    pp.runpp(net, init='dc', calculate_voltage_angles=True, Numba=False)

    return net
github e2nIEE / pandapower / pandapower / networks / create_examples.py View on Github external
# --- Other

    # Shunt
    pp.create_shunt(net, pp.get_element_index(net, "bus", 'Bus HV1'), p_mw=0, q_mvar=-0.96,
                    name='Shunt')

    # ExtGrids
    pp.create_ext_grid(net, pp.get_element_index(net, "bus", 'Double Busbar 1'), vm_pu=1.03,
                       va_degree=0, name='External grid', s_sc_max_mva=10000, rx_max=0.1,
                       rx_min=0.1)
    # Gen
    pp.create_gen(net, pp.get_element_index(net, "bus", 'Bus HV4'), vm_pu=1.03, p_mw=100,
                  name='Gas turbine')

    # Impedance
    pp.create_impedance(net, pp.get_element_index(net, "bus", 'Bus HV3'),
                        pp.get_element_index(net, "bus", 'Bus HV1'), rft_pu=0.074873,
                        xft_pu=0.198872, sn_mva=100, name='Impedance')

    # xwards
    pp.create_xward(net, pp.get_element_index(net, "bus", 'Bus HV3'), ps_mw=23.942,
                    qs_mvar=-12.24187, pz_mw=2.814571, qz_mvar=0, r_ohm=0, x_ohm=12.18951,
                    vm_pu=1.02616, name='XWard 1')
    pp.create_xward(net, pp.get_element_index(net, "bus", 'Bus HV1'), ps_mw=3.776,
                    qs_mvar=-7.769979, pz_mw=9.174917, qz_mvar=0, r_ohm=0, x_ohm=50.56217,
                    vm_pu=1.024001, name='XWard 2')

    # --- Switches

    # HV
    # Bus-bus switches
    hv_bus_sw = pd.DataFrame()
github e2nIEE / pandapower / pandapower / converter / pypower / from_ppc.py View on Github external
init1 = concat([net.line.from_bus, net.line.to_bus], axis=1).drop_duplicates()
        init2 = concat([net.trafo.hv_bus, net.trafo.lv_bus], axis=1).drop_duplicates()
    init1['hv_bus'] = nan
    init1['lv_bus'] = nan
    init2['from_bus'] = nan
    init2['to_bus'] = nan
    try:
        already_used_branches = concat([init1, init2], axis=0, sort=True)
    except TypeError:
        # pandas < 0.21 legacy
        already_used_branches = concat([init1, init2], axis=0)
    already_used_branches['number'] = zeros([already_used_branches.shape[0], 1]).astype(int)
    BRANCHES = DataFrame(ppc_net['branch'][:, [0, 1, 8, 9]])
    for i in BRANCHES.index:
        from_bus = pp.get_element_index(net, 'bus', name=int(ppc_net['branch'][i, 0]))
        to_bus = pp.get_element_index(net, 'bus', name=int(ppc_net['branch'][i, 1]))
        from_vn_kv = ppc_net['bus'][from_bus, 9]
        to_vn_kv = ppc_net['bus'][to_bus, 9]
        ratio = BRANCHES[2].at[i]
        angle = BRANCHES[3].at[i]
        # from line results
        if (from_vn_kv == to_vn_kv) & ((ratio == 0) | (ratio == 1)) & (angle == 0):
            pp_res["branch"] = append(pp_res["branch"], array(net.res_line[
                (net.line.from_bus == from_bus) &
                (net.line.to_bus == to_bus)]
                [['p_from_mw', 'q_from_mvar', 'p_to_mw', 'q_to_mvar']])[
                int(already_used_branches.number.loc[
                   (already_used_branches.from_bus == from_bus) &
                   (already_used_branches.to_bus == to_bus)].values)].reshape(1, 4), 0)
            already_used_branches.number.loc[(already_used_branches.from_bus == from_bus) &
                                             (already_used_branches.to_bus == to_bus)] += 1
        # from trafo results
github e2nIEE / pandapower / pandapower / converter / pypower / from_ppc.py View on Github external
max_q_mvar=ppc['gen'][i, QMAX], min_q_mvar=ppc['gen'][i, QMIN],
                controllable=True)
            gen_lookup.element_type.loc[i] = 'sgen'
            if ppc['gen'][i, 1] < 0:
                logger.info('p_mw of sgen %d must be less than zero but is not.' % i)
            if ppc['gen'][i, 4] > ppc['gen'][i, 3]:
                logger.info('min_q_mvar of gen %d must be less than max_q_mvar but is not.' % i)
            if -ppc['gen'][i, 9] < -ppc['gen'][i, 8]:
                logger.info('max_p_mw of gen %d must be less than min_p_mw 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):  # create line
            Zni = ppc['bus'][to_bus, 9]**2/baseMVA  # ohm
            max_i_ka = ppc['branch'][i, 5]/ppc['bus'][to_bus, 9]/sqrt(3)
            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', max_loading_percent=100,
github e2nIEE / pandapower / pandapower / networks / create_examples.py View on Github external
'Bus SB T3.1', 'Single Busbar', 'Bus SB T4.1', 'Single Busbar',
                             'Bus SB T5.1', 'Single Busbar'] + \
                            ['Bus SB T%s.2' % i for i in range(1, 6)]
    hv_bus_sw['to_bus'] = ['Bus DB %s' % i for i in
                           ['T0', 'T1', 'T3', 'T3', 'T5', 'T5', 'T7', 'T7', 'T9', 'T9',
                            '1', '2', '3', '4', 'T1', 'T2', 'T4', 'T6', 'T8']] + \
                          ['Bus SB %s' % i for i in
                           ['1', 'T1.2', '2', 'T2.2', '3', 'T3.2', '4', 'T4.2', '5', 'T5.2']] + \
                          ['Bus SB T%s.1' % i for i in range(1, 6)]
    hv_bus_sw['type'] = ['DS']*14 + ['CB']*5 + ['DS']*10 + ['CB']*5
    hv_bus_sw['et'] = 'b'
    hv_bus_sw['closed'] = [bool(i) for i in [1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
                           1] + [1]*15]

    for _, switch in hv_bus_sw.iterrows():
        from_bus = pp.get_element_index(net, "bus", switch.from_bus)
        to_bus = pp.get_element_index(net, "bus", switch.to_bus)
        pp.create_switch(net, from_bus, to_bus, et=switch.et,
                         closed=switch.closed, type=switch.type, name=switch.bus_name)

    # Bus-Line switches
    hv_buses = net.bus[(net.bus.vn_kv == 380) | (net.bus.vn_kv == 110)].index
    hv_ls = net.line[(net.line.from_bus.isin(hv_buses)) & (net.line.to_bus.isin(hv_buses))]
    for _, line in hv_ls.iterrows():
        for bus in [line.from_bus, line.to_bus]:
            pp.create_switch(net, bus, line.name, et='l', closed=True, type='LBS',
                             name='Switch %s - %s' % (net.bus.name.at[bus], line['name']))

    # MV
    # Bus-line switches
    mv_buses = net.bus[(net.bus.vn_kv == 10) | (net.bus.vn_kv == 20)].index
    mv_ls = net.line[(net.line.from_bus.isin(mv_buses)) & (net.line.to_bus.isin(mv_buses))]
github e2nIEE / pandapower / pandapower / networks / create_examples.py View on Github external
for _, load in lv_loads.iterrows():
        bus_idx = pp.get_element_index(net, "bus", load.bus)
        pp.create_load(net, bus_idx, p_mw=load.p, q_mvar=load.q, name=load.load_name)

    # --- Other

    # Shunt
    pp.create_shunt(net, pp.get_element_index(net, "bus", 'Bus HV1'), p_mw=0, q_mvar=-0.96,
                    name='Shunt')

    # ExtGrids
    pp.create_ext_grid(net, pp.get_element_index(net, "bus", 'Double Busbar 1'), vm_pu=1.03,
                       va_degree=0, name='External grid', s_sc_max_mva=10000, rx_max=0.1,
                       rx_min=0.1)
    # Gen
    pp.create_gen(net, pp.get_element_index(net, "bus", 'Bus HV4'), vm_pu=1.03, p_mw=100,
                  name='Gas turbine')

    # Impedance
    pp.create_impedance(net, pp.get_element_index(net, "bus", 'Bus HV3'),
                        pp.get_element_index(net, "bus", 'Bus HV1'), rft_pu=0.074873,
                        xft_pu=0.198872, sn_mva=100, name='Impedance')

    # xwards
    pp.create_xward(net, pp.get_element_index(net, "bus", 'Bus HV3'), ps_mw=23.942,
                    qs_mvar=-12.24187, pz_mw=2.814571, qz_mvar=0, r_ohm=0, x_ohm=12.18951,
                    vm_pu=1.02616, name='XWard 1')
    pp.create_xward(net, pp.get_element_index(net, "bus", 'Bus HV1'), ps_mw=3.776,
                    qs_mvar=-7.769979, pz_mw=9.174917, qz_mvar=0, r_ohm=0, x_ohm=50.56217,
                    vm_pu=1.024001, name='XWard 2')

    # --- Switches