How to use the pandapower.auxiliary._sum_by_group 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 / pd2ppc_zero.py View on Github external
zs = (za * zb)/(za - zb)
            ys = 1 / zs.astype(complex)
            buses_all = np.hstack([buses_all, lv_buses_ppc])
            gs_all = np.hstack([gs_all, ys.real*in_service])
            bs_all = np.hstack([bs_all, ys.imag*in_service])
        elif vector_group == "YNy":
            buses_all = np.hstack([buses_all, hv_buses_ppc])
            y = 1/(z0_mag+z0_k).astype(complex)
            gs_all = np.hstack([gs_all, y.real*in_service])
            bs_all = np.hstack([bs_all, y.imag*in_service])
        elif vector_group[-1].isdigit():
            raise ValueError("Unknown transformer vector group %s - please specify vector group without phase shift number. Phase shift can be specified in net.trafo.shift_degree"%vector_group)
        else:
            raise ValueError("Transformer vector group %s is unknown / not implemented"%vector_group)

    buses, gs, bs = aux._sum_by_group(buses_all, gs_all, bs_all)
    ppc["bus"][buses, GS] += gs
    ppc["bus"][buses, BS] += bs
    del net.trafo["_ppc_idx"]
github e2nIEE / pandapower / 4_bus_Unbalanced_values.py View on Github external
sgen_3ph = net["sgen_3ph"]
    if len(sgen_3ph) > 0:
#        vl = _is_elements["sgen_3ph"] * sgen_3ph["scaling"].values.T /np.float64(1000.)
        q_a = np.hstack([q_a, sgen_3ph["q_kvar_A"].values ])
        p_a = np.hstack([p_a, sgen_3ph["p_kw_A"].values ])
        q_b = np.hstack([q_b, sgen_3ph["q_kvar_B"].values ])
        p_b = np.hstack([p_b, sgen_3ph["p_kw_B"].values ])
        q_c = np.hstack([q_c, sgen_3ph["q_kvar_C"].values ])
        p_c = np.hstack([p_c, sgen_3ph["p_kw_C"].values ])
        b = np.hstack([b, sgen_3ph["bus"].values])
    if b.size:
        bus_lookup = net["_pd2ppc_lookups"]["bus"]
        b = bus_lookup[b]
        b, PA, QA = _sum_by_group(b, p_a,q_a*1j )
        b, PB, QB = _sum_by_group(b, p_b,q_b*1j )
        b, PC, QC = _sum_by_group(b, p_c,q_c*1j )
        b,SA,SB,SC = bus_lookup,PA+QA,PB+QB,PC+QC
    return np.vstack([SA,SB,SC])
github e2nIEE / pandapower / 4_bus_Unbalanced_values.py View on Github external
b = np.hstack([b, l["bus"].values])

    sgen_3ph = net["sgen_3ph"]
    if len(sgen_3ph) > 0:
#        vl = _is_elements["sgen_3ph"] * sgen_3ph["scaling"].values.T /np.float64(1000.)
        q_a = np.hstack([q_a, sgen_3ph["q_kvar_A"].values ])
        p_a = np.hstack([p_a, sgen_3ph["p_kw_A"].values ])
        q_b = np.hstack([q_b, sgen_3ph["q_kvar_B"].values ])
        p_b = np.hstack([p_b, sgen_3ph["p_kw_B"].values ])
        q_c = np.hstack([q_c, sgen_3ph["q_kvar_C"].values ])
        p_c = np.hstack([p_c, sgen_3ph["p_kw_C"].values ])
        b = np.hstack([b, sgen_3ph["bus"].values])
    if b.size:
        bus_lookup = net["_pd2ppc_lookups"]["bus"]
        b = bus_lookup[b]
        b, PA, QA = _sum_by_group(b, p_a,q_a*1j )
        b, PB, QB = _sum_by_group(b, p_b,q_b*1j )
        b, PC, QC = _sum_by_group(b, p_c,q_c*1j )
        b,SA,SB,SC = bus_lookup,PA+QA,PB+QB,PC+QC
    return np.vstack([SA,SB,SC])
github e2nIEE / pandapower / pandapower / pf / runpp_3ph.py View on Github external
for typ in load_types:
            params['S'+phase+typ] = (ppci1["bus"][:, PD] +
                                     ppci1["bus"][:, QD]*1j)*0
            params['p'+phase+typ] = np.array([])  # p values from loads/sgens
            params['q'+phase+typ] = np.array([])  # q values from loads/sgens
            params['P'+phase+typ] = np.array([])  # Aggregated Active Power
            params['Q'+phase+typ] = np.array([])  # Aggregated reactive Power
            params['b'+phase+typ] = np.array([], dtype=int)  # bus map for phases
            params['b'+typ] = np.array([], dtype=int)  # aggregated bus map(s_abc)
            for element in load_elements:
                _get_elements(params,net,element,phase,typ)
            # Mapping constant power loads to buses
            if params['b'+typ].size:
                params['b'+phase+typ] = bus_lookup[params['b'+typ]]
                params['b'+phase+typ], params['P'+phase+typ],\
                    params['Q'+phase+typ] = _sum_by_group(params['b'+phase+typ],
                                                          params['p'+phase+typ],
                                                          params['q'+phase+typ] * 1j)
                params['S'+phase+typ][params['b'+phase+typ]] = \
                    (params['P'+phase+typ] + params['Q'+phase+typ])
    Sabc_del = np.vstack((params['Sadelta'],params['Sbdelta'],params['Scdelta']))
    Sabc_wye = np.vstack((params['Sawye'],params['Sbwye'],params['Scwye']))
    # last return varaible left for constant impedance loads
    return Sabc_del, Sabc_wye
github e2nIEE / pandapower / pandapower / build_opf.py View on Github external
b = np.hstack([b, l["bus"].values])

    s = net["sgen"]
    if not s.empty:
        vl = (is_elems["sgen"] & ~s["controllable"]) * s["scaling"].values.T / \
            float64(1000.)
        q = np.hstack([q, s["q_kvar"].values * vl])
        p = np.hstack([p, s["p_kw"].values * vl])
        b = np.hstack([b, s["bus"].values])
    else:
        sp = []
        sq = []

    if b.size:
        b = bus_lookup[b]
        b, vp, vq = _sum_by_group(b, p, q)

        ppc["bus"][b, PD] = vp
        ppc["bus"][b, QD] = vq
github e2nIEE / pandapower / pandapower / results_branch.py View on Github external
def _get_xward_branch_results(net, ppc, bus_lookup_aranged, pq_buses, suffix=None):
    ac = net["_options"]["ac"]

    if not "xward" in net._pd2ppc_lookups["branch"]:
        return
    f, t = net._pd2ppc_lookups["branch"]["xward"]
    p_branch_xward = ppc["branch"][f:t, PF].real
    net["res_xward"]["p_mw"].values[:] = net["res_xward"]["p_mw"].values + p_branch_xward
    if ac:
        q_branch_xward = ppc["branch"][f:t, QF].real
        net["res_xward"]["q_mvar"].values[:] = net["res_xward"]["q_mvar"].values + q_branch_xward
    else:
        q_branch_xward = np.zeros(len(p_branch_xward))
    b_pp, p, q = _sum_by_group(net["xward"]["bus"].values, p_branch_xward, q_branch_xward)
    b_ppc = bus_lookup_aranged[b_pp]

    pq_buses[b_ppc, 0] += p
    pq_buses[b_ppc, 1] += q
    aux_buses = net["_pd2ppc_lookups"]["bus"][net["_pd2ppc_lookups"]["aux"]["xward"]]
    
    res_xward_df = net["res_xward"] if suffix is None else net["res_xward%s"%suffix]
    
    res_xward_df["va_internal_degree"].values[:] = ppc["bus"][aux_buses, VA]
    res_xward_df["vm_internal_pu"].values[:] = ppc["bus"][aux_buses, VM]
    res_xward_df.index = net["xward"].index
github e2nIEE / pandapower / pandapower / build_bus.py View on Github external
q_mvar = (sn_mva * i0 / 100.) ** 2 - pfe_mw **2
        q_mvar[q_mvar<0] = 0
        q_mvar= np.sqrt(q_mvar)

        vn_hv_trafo = trafo3w["vn_hv_kv"].values
        vn_hv_bus = ppc["bus"][bus_lookup[trafo3w.hv_bus.values], BASE_KV]
        v_ratio = (vn_hv_bus / vn_hv_trafo) ** 2

        q = np.hstack([q, q_mvar * v_ratio])
        p = np.hstack([p, pfe_mw * v_ratio])
        b = np.hstack([b, net._pd2ppc_lookups["aux"]["trafo3w"]])

    # if array is not empty
    if b.size:
        b = bus_lookup[b]
        b, vp, vq = _sum_by_group(b, p, q)

        ppc["bus"][b, GS] = vp
        ppc["bus"][b, BS] = -vq
github e2nIEE / pandapower / pandapower / build_bus.py View on Github external
if "motor" not in sgen.type.values:
        return
    motor = sgen[sgen.type == "motor"]
    for par in ["sn_mva", "rx", "k"]:
        if any(pd.isnull(motor[par])):
            raise UserWarning("%s needs to be specified for all motors in net.sgen.%s" % (par, par))
    bus_lookup = net["_pd2ppc_lookups"]["bus"]
    motor_buses = motor.bus.values
    motor_buses_ppc = bus_lookup[motor_buses]

    z_motor = 1 / (motor.sn_mva.values * 1e-3) / motor.k  # vn_kv**2 becomes 1**2=1 in per unit
    x_motor = z_motor / np.sqrt(motor.rx ** 2 + 1)
    r_motor = motor.rx * x_motor
    y_motor = 1 / (r_motor + x_motor * 1j)

    buses, gs, bs = _sum_by_group(motor_buses_ppc, y_motor.real, y_motor.imag)
    ppc["bus"][buses, GS] = gs
    ppc["bus"][buses, BS] = bs
github e2nIEE / pandapower / 4_bus_Unbalanced_values.py View on Github external
sgen_3ph = net["sgen_3ph"]
    if len(sgen_3ph) > 0:
#        vl = _is_elements["sgen_3ph"] * sgen_3ph["scaling"].values.T /np.float64(1000.)
        q_a = np.hstack([q_a, sgen_3ph["q_kvar_A"].values ])
        p_a = np.hstack([p_a, sgen_3ph["p_kw_A"].values ])
        q_b = np.hstack([q_b, sgen_3ph["q_kvar_B"].values ])
        p_b = np.hstack([p_b, sgen_3ph["p_kw_B"].values ])
        q_c = np.hstack([q_c, sgen_3ph["q_kvar_C"].values ])
        p_c = np.hstack([p_c, sgen_3ph["p_kw_C"].values ])
        b = np.hstack([b, sgen_3ph["bus"].values])
    if b.size:
        bus_lookup = net["_pd2ppc_lookups"]["bus"]
        b = bus_lookup[b]
        b, PA, QA = _sum_by_group(b, p_a,q_a*1j )
        b, PB, QB = _sum_by_group(b, p_b,q_b*1j )
        b, PC, QC = _sum_by_group(b, p_c,q_c*1j )
        b,SA,SB,SC = bus_lookup,PA+QA,PB+QB,PC+QC
    return np.vstack([SA,SB,SC])
github e2nIEE / pandapower / pandapower / results_bus.py View on Github external
if len(net[element]):
            write_pq_results_to_element(net, ppc, element)
            p_el, q_el, bus_el = get_p_q_b(net, element)
            if element == "sgen":
                p = np.hstack([p, -p_el])
                q = np.hstack([q, -q_el])
            else:
                p = np.hstack([p, p_el])
                q = np.hstack([q, q_el])
            b = np.hstack([b, bus_el])

    if not ac:
        q = np.zeros(len(p))

    # sum pq results from every element to be written to net['bus'] later on
    b_pp, vp, vq = _sum_by_group(b.astype(int), p, q)
    b_ppc = bus_lookup_aranged[b_pp]
    bus_pq[b_ppc, 0] = vp
    bus_pq[b_ppc, 1] = vq
    return bus_pq