def from_ppc(ppc, f_hz=50, validate_conversion=False, **kwargs):
    '\n    This function converts pypower case files to pandapower net structure.\n\n    INPUT:\n\n        **ppc** : The pypower case file.\n\n    OPTIONAL:\n\n        **f_hz** (float, 50) - The frequency of the network.\n\n        **validate_conversion** (bool, False) - If True, validate_from_ppc is run after conversion.\n            For running the validation, the ppc must already contain the pypower\n            powerflow results or pypower must be importable.\n\n        ****kwargs** keyword arguments for validate_from_ppc if validate_conversion is True\n\n    OUTPUT:\n\n        **net** : pandapower net.\n\n    EXAMPLE:\n\n        import pandapower.converter as pc\n\n        from pypower import case4gs\n\n        ppc_net = case4gs.case4gs()\n\n        net = pc.from_ppc(ppc_net, f_hz=60)\n\n    '
    if Series((ppc['bus'][:, BASE_KV] <= 0)).any():
        logger.info('There are false baseKV given in the pypower case file.')
    baseMVA = ppc['baseMVA']
    omega = (pi * f_hz)
    MAX_VAL = 99999.0
    net = pp.create_empty_network(f_hz=f_hz, sn_mva=baseMVA)
    for i in range(len(ppc['bus'])):
        pp.create_bus(net, name=int(ppc['bus'][(i, 0)]), vn_kv=ppc['bus'][(i, 9)], type='b', zone=ppc['bus'][(i, 10)], in_service=bool((ppc['bus'][(i, 1)] != 4)), max_vm_pu=ppc['bus'][(i, 11)], min_vm_pu=ppc['bus'][(i, 12)])
        if (ppc['bus'][(i, 2)] > 0):
            pp.create_load(net, i, p_mw=ppc['bus'][(i, 2)], q_mvar=ppc['bus'][(i, 3)], controllable=False)
        elif (ppc['bus'][(i, 2)] < 0):
            pp.create_sgen(net, i, p_mw=(- ppc['bus'][(i, 2)]), q_mvar=(- ppc['bus'][(i, 3)]), type='', controllable=False)
        elif (ppc['bus'][(i, 3)] != 0):
            pp.create_load(net, i, p_mw=ppc['bus'][(i, 2)], q_mvar=ppc['bus'][(i, 3)], controllable=False)
        if ((ppc['bus'][(i, 4)] != 0) or (ppc['bus'][(i, 5)] != 0)):
            pp.create_shunt(net, i, p_mw=ppc['bus'][(i, 4)], q_mvar=(- ppc['bus'][(i, 5)]))
    gen_lookup = DataFrame(nan, columns=['element', 'element_type'], index=range(len(ppc['gen'][:, 0])))
    if (len(ppc['gen'].shape) == 1):
        ppc['gen'] = array(ppc['gen'], ndmin=2)
    for i in range(len(ppc['gen'][:, 0])):
        (current_bus_type, current_bus_idx, same_bus_gen_idx, first_same_bus_in_service_gen_idx, last_same_bus_in_service_gen_idx) = _gen_bus_info(ppc, i)
        if (current_bus_type == 3):
            if (i == first_same_bus_in_service_gen_idx):
                gen_lookup.element.loc[i] = pp.create_ext_grid(net, bus=current_bus_idx, vm_pu=ppc['gen'][(last_same_bus_in_service_gen_idx, 5)], va_degree=ppc['bus'][(current_bus_idx, 8)], in_service=bool((ppc['gen'][(i, 7)] > 0)), 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)])
                gen_lookup.element_type.loc[i] = 'ext_grid'
                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))
            else:
                current_bus_type = 1
        elif (current_bus_type == 2):
            if (i == first_same_bus_in_service_gen_idx):
                gen_lookup.element.loc[i] = pp.create_gen(net, bus=current_bus_idx, vm_pu=ppc['gen'][(last_same_bus_in_service_gen_idx, 5)], p_mw=ppc['gen'][(i, 1)], in_service=bool((ppc['gen'][(i, 7)] > 0)), controllable=True, 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)])
                gen_lookup.element_type.loc[i] = 'gen'
                if (ppc['gen'][(i, 1)] < 0):
                    logger.info(('p_mw of gen %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))
            else:
                current_bus_type = 1
        if (current_bus_type == 1):
            gen_lookup.element.loc[i] = pp.create_sgen(net, bus=current_bus_idx, p_mw=ppc['gen'][(i, 1)], q_mvar=ppc['gen'][(i, 2)], type='', in_service=bool((ppc['gen'][(i, 7)] > 0)), 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))
    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)
            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) * 1000000000.0) / 2), max_i_ka=max_i_ka, type='ol', max_loading_percent=100, 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
                tap_side = 'hv'
            else:
                hv_bus = to_bus
                vn_hv_kv = to_vn_kv
                lv_bus = from_bus
                vn_lv_kv = from_vn_kv
                tap_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)]
            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) / 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_mva=sn, vn_hv_kv=vn_hv_kv, vn_lv_kv=vn_lv_kv, vk_percent=((((sign(xk) * zk) * sn) * 100) / baseMVA), vkr_percent=(((rk * sn) * 100) / baseMVA), max_loading_percent=100, pfe_kw=0, i0_percent=i0_percent, shift_degree=ppc['branch'][(i, 9)], tap_step_percent=abs(ratio_1), tap_pos=sign(ratio_1), tap_side=tap_side, tap_neutral=0)
    if ('gencost' in ppc):
        if (len(ppc['gencost'].shape) == 1):
            ppc['gencost'] = ppc['gencost'].reshape((1, (- 1)))
        if (ppc['gencost'].shape[0] <= gen_lookup.shape[0]):
            idx_p = range(ppc['gencost'].shape[0])
            idx_q = []
        elif (ppc['gencost'].shape[0] > gen_lookup.shape[0]):
            idx_p = range(gen_lookup.shape[0])
            idx_q = range(gen_lookup.shape[0], ppc['gencost'].shape[0])
        if (ppc['gencost'].shape[0] >= (2 * gen_lookup.shape[0])):
            idx_p = range(gen_lookup.shape[0])
            idx_q = range(gen_lookup.shape[0], (2 * gen_lookup.shape[0]))
        for idx in idx_p:
            _create_costs(net, ppc, gen_lookup, 'p', idx)
        for idx in idx_q:
            _create_costs(net, ppc, gen_lookup, 'q', idx)
    if validate_conversion:
        logger.setLevel(logging.DEBUG)
        if (not validate_from_ppc(ppc, net, **kwargs)):
            logger.error('Validation failed.')
    net._options = {}
    net._options['gen_lookup'] = gen_lookup
    return net
This function converts pypower case files to pandapower net structure.

INPUT:

    **ppc** : The pypower case file.

OPTIONAL:

    **f_hz** (float, 50) - The frequency of the network.

    **validate_conversion** (bool, False) - If True, validate_from_ppc is run after conversion.
        For running the validation, the ppc must already contain the pypower
        powerflow results or pypower must be importable.

    ****kwargs** keyword arguments for validate_from_ppc if validate_conversion is True

OUTPUT:

    **net** : pandapower net.

EXAMPLE:

    import pandapower.converter as pc

    from pypower import case4gs

    ppc_net = case4gs.case4gs()

    net = pc.from_ppc(ppc_net, f_hz=60)
def from_ppc(ppc, f_hz=50, validate_conversion=False, **kwargs):
    '\n    This function converts pypower case files to pandapower net structure.\n\n    INPUT:\n\n        **ppc** : The pypower case file.\n\n    OPTIONAL:\n\n        **f_hz** (float, 50) - The frequency of the network.\n\n        **validate_conversion** (bool, False) - If True, validate_from_ppc is run after conversion.\n            For running the validation, the ppc must already contain the pypower\n            powerflow results or pypower must be importable.\n\n        ****kwargs** keyword arguments for validate_from_ppc if validate_conversion is True\n\n    OUTPUT:\n\n        **net** : pandapower net.\n\n    EXAMPLE:\n\n        import pandapower.converter as pc\n\n        from pypower import case4gs\n\n        ppc_net = case4gs.case4gs()\n\n        net = pc.from_ppc(ppc_net, f_hz=60)\n\n    '
    if Series((ppc['bus'][:, BASE_KV] <= 0)).any():
        logger.info('There are false baseKV given in the pypower case file.')
    baseMVA = ppc['baseMVA']
    omega = (pi * f_hz)
    MAX_VAL = 99999.0
    net = pp.create_empty_network(f_hz=f_hz, sn_mva=baseMVA)
    for i in range(len(ppc['bus'])):
        pp.create_bus(net, name=int(ppc['bus'][(i, 0)]), vn_kv=ppc['bus'][(i, 9)], type='b', zone=ppc['bus'][(i, 10)], in_service=bool((ppc['bus'][(i, 1)] != 4)), max_vm_pu=ppc['bus'][(i, 11)], min_vm_pu=ppc['bus'][(i, 12)])
        if (ppc['bus'][(i, 2)] > 0):
            pp.create_load(net, i, p_mw=ppc['bus'][(i, 2)], q_mvar=ppc['bus'][(i, 3)], controllable=False)
        elif (ppc['bus'][(i, 2)] < 0):
            pp.create_sgen(net, i, p_mw=(- ppc['bus'][(i, 2)]), q_mvar=(- ppc['bus'][(i, 3)]), type=, controllable=False)
        elif (ppc['bus'][(i, 3)] != 0):
            pp.create_load(net, i, p_mw=ppc['bus'][(i, 2)], q_mvar=ppc['bus'][(i, 3)], controllable=False)
        if ((ppc['bus'][(i, 4)] != 0) or (ppc['bus'][(i, 5)] != 0)):
            pp.create_shunt(net, i, p_mw=ppc['bus'][(i, 4)], q_mvar=(- ppc['bus'][(i, 5)]))
    gen_lookup = DataFrame(nan, columns=['element', 'element_type'], index=range(len(ppc['gen'][:, 0])))
    if (len(ppc['gen'].shape) == 1):
        ppc['gen'] = array(ppc['gen'], ndmin=2)
    for i in range(len(ppc['gen'][:, 0])):
        (current_bus_type, current_bus_idx, same_bus_gen_idx, first_same_bus_in_service_gen_idx, last_same_bus_in_service_gen_idx) = _gen_bus_info(ppc, i)
        if (current_bus_type == 3):
            if (i == first_same_bus_in_service_gen_idx):
                gen_lookup.element.loc[i] = pp.create_ext_grid(net, bus=current_bus_idx, vm_pu=ppc['gen'][(last_same_bus_in_service_gen_idx, 5)], va_degree=ppc['bus'][(current_bus_idx, 8)], in_service=bool((ppc['gen'][(i, 7)] > 0)), 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)])
                gen_lookup.element_type.loc[i] = 'ext_grid'
                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))
            else:
                current_bus_type = 1
        elif (current_bus_type == 2):
            if (i == first_same_bus_in_service_gen_idx):
                gen_lookup.element.loc[i] = pp.create_gen(net, bus=current_bus_idx, vm_pu=ppc['gen'][(last_same_bus_in_service_gen_idx, 5)], p_mw=ppc['gen'][(i, 1)], in_service=bool((ppc['gen'][(i, 7)] > 0)), controllable=True, 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)])
                gen_lookup.element_type.loc[i] = 'gen'
                if (ppc['gen'][(i, 1)] < 0):
                    logger.info(('p_mw of gen %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))
            else:
                current_bus_type = 1
        if (current_bus_type == 1):
            gen_lookup.element.loc[i] = pp.create_sgen(net, bus=current_bus_idx, p_mw=ppc['gen'][(i, 1)], q_mvar=ppc['gen'][(i, 2)], type=, in_service=bool((ppc['gen'][(i, 7)] > 0)), 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))
    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)
            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) * 1000000000.0) / 2), max_i_ka=max_i_ka, type='ol', max_loading_percent=100, 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
                tap_side = 'hv'
            else:
                hv_bus = to_bus
                vn_hv_kv = to_vn_kv
                lv_bus = from_bus
                vn_lv_kv = from_vn_kv
                tap_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)]
            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) / 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_mva=sn, vn_hv_kv=vn_hv_kv, vn_lv_kv=vn_lv_kv, vk_percent=((((sign(xk) * zk) * sn) * 100) / baseMVA), vkr_percent=(((rk * sn) * 100) / baseMVA), max_loading_percent=100, pfe_kw=0, i0_percent=i0_percent, shift_degree=ppc['branch'][(i, 9)], tap_step_percent=abs(ratio_1), tap_pos=sign(ratio_1), tap_side=tap_side, tap_neutral=0)
    if ('gencost' in ppc):
        if (len(ppc['gencost'].shape) == 1):
            ppc['gencost'] = ppc['gencost'].reshape((1, (- 1)))
        if (ppc['gencost'].shape[0] <= gen_lookup.shape[0]):
            idx_p = range(ppc['gencost'].shape[0])
            idx_q = []
        elif (ppc['gencost'].shape[0] > gen_lookup.shape[0]):
            idx_p = range(gen_lookup.shape[0])
            idx_q = range(gen_lookup.shape[0], ppc['gencost'].shape[0])
        if (ppc['gencost'].shape[0] >= (2 * gen_lookup.shape[0])):
            idx_p = range(gen_lookup.shape[0])
            idx_q = range(gen_lookup.shape[0], (2 * gen_lookup.shape[0]))
        for idx in idx_p:
            _create_costs(net, ppc, gen_lookup, 'p', idx)
        for idx in idx_q:
            _create_costs(net, ppc, gen_lookup, 'q', idx)
    if validate_conversion:
        logger.setLevel(logging.DEBUG)
        if (not validate_from_ppc(ppc, net, **kwargs)):
            logger.error('Validation failed.')
    net._options = {}
    net._options['gen_lookup'] = gen_lookup
    return net