Ejemplo n.º 1
0
def test_no_observability():
    grid = create_net_with_bb_switch()
    grid.measurement.drop(
        grid.measurement.index[int(len(grid.measurement) * 0.1):],
        inplace=True)
    with pytest.raises(UserWarning):
        estimate(grid)
Ejemplo n.º 2
0
def test_case30_compare_classical_wls_opt_wls():
    net = nw.case30()
    pp.runpp(net)
    add_virtual_meas_from_loadflow(net)

    try:
        success = estimate(net, init='flat', algorithm="opt", estimator='wls')
        assert success
    except:
        # if failed give it a warm start
        net, ppc, eppci = pp2eppci(net)
        estimation_wls = WLSAlgorithm(1e-3, 3)
        estimation_opt = OptAlgorithm(1e-6, 1000)

        eppci = estimation_wls.estimate(eppci)
        eppci = estimation_opt.estimate(eppci, estimator="wls")
        assert estimation_opt.successful
        net = eppci2pp(net, ppc, eppci)

    net_wls = deepcopy(net)
    estimate(net_wls)
    assert np.allclose(net_wls.res_bus_est.vm_pu,
                       net.res_bus_est.vm_pu,
                       atol=1e-2)
    assert np.allclose(net_wls.res_bus_est.va_degree,
                       net.res_bus_est.va_degree,
                       atol=1e-2)
Ejemplo n.º 3
0
def test_pmu_with_trafo3w():
    net = pp.create_empty_network()

    bus_slack = pp.create_bus(net, vn_kv=110)
    pp.create_ext_grid(net, bus=bus_slack)

    bus_20_1 = pp.create_bus(net, vn_kv=20, name="b")
    pp.create_sgen(net, bus=bus_20_1, p_mw=0.03, q_mvar=0.02)

    bus_10_1 = pp.create_bus(net, vn_kv=10)
    pp.create_sgen(net, bus=bus_10_1, p_mw=0.02, q_mvar=0.02)

    bus_10_2 = pp.create_bus(net, vn_kv=10)
    pp.create_load(net, bus=bus_10_2, p_mw=0.06, q_mvar=0.01)
    pp.create_line(net,
                   from_bus=bus_10_1,
                   to_bus=bus_10_2,
                   std_type="149-AL1/24-ST1A 10.0",
                   length_km=2)

    pp.create_transformer3w(net,
                            bus_slack,
                            bus_20_1,
                            bus_10_1,
                            std_type="63/25/38 MVA 110/20/10 kV")

    pp.runpp(net)
    add_virtual_pmu_meas_from_loadflow(net, with_random_error=False)

    estimate(net, algorithm="lp", maximum_iterations=10)
    pp.runpp(net)
    assert np.allclose(net.res_bus.vm_pu, net.res_bus_est.vm_pu, atol=1e-2)
    assert np.allclose(net.res_bus.va_degree,
                       net.res_bus_est.va_degree,
                       atol=1e-1)
Ejemplo n.º 4
0
def test_zero_injection_aux_bus():
    net = pp.create_empty_network()
    bus1 = pp.create_bus(net, name="bus1", vn_kv=10.)
    bus2 = pp.create_bus(net, name="bus2", vn_kv=10.)
    bus3 = pp.create_bus(net, name="bus3", vn_kv=10.)
    bus4 = pp.create_bus(net, name="bus4", vn_kv=110.)
    
    pp.create_line_from_parameters(net, bus1, bus2, 10, r_ohm_per_km=.59, x_ohm_per_km=.35, c_nf_per_km=10.1,
                                   max_i_ka=1)
    pp.create_line_from_parameters(net, bus2, bus3, 10, r_ohm_per_km=.59, x_ohm_per_km=.35, c_nf_per_km=10.1,
                                   max_i_ka=1)
    pp.create_transformer(net, bus4, bus1, std_type="40 MVA 110/10 kV")
    pp.create_ext_grid(net, bus=bus4, vm_pu=1.0)
    pp.create_load(net, bus1, p_mw=.350, q_mvar=.100)
    pp.create_load(net, bus2, p_mw=.450, q_mvar=.100)
    pp.create_load(net, bus3, p_mw=.250, q_mvar=.100)
    
    net.bus.at[bus3, 'in_service'] = False

    # Created bb switch
    pp.runpp(net, calculate_voltage_angles=True)

    pp.create_measurement(net, "v", "bus", r2(net.res_bus.vm_pu.iloc[bus1], .002), .002, element=bus1)
    pp.create_measurement(net, "v", "bus", r2(net.res_bus.vm_pu.iloc[bus4], .002), .002, element=bus4)

    pp.create_measurement(net, "p", "bus", -r2(net.res_bus.p_mw.iloc[bus4], .002), .002, element=bus4)
    pp.create_measurement(net, "q", "bus", -r2(net.res_bus.q_mvar.iloc[bus4], .002), .002, element=bus4)

    # If measurement on the bus with bb-switch activated, it will incluence the results of the merged bus
    pp.create_measurement(net, "p", "bus", -r2(net.res_bus.p_mw.iloc[bus2], .001), .001, element=bus2)
    pp.create_measurement(net, "q", "bus", -r2(net.res_bus.q_mvar.iloc[bus2], .001), .001, element=bus2)
    pp.create_measurement(net, "p", "bus", -r2(net.res_bus.p_mw.iloc[bus1], .001), .001, element=bus1)
    pp.create_measurement(net, "q", "bus", -r2(net.res_bus.q_mvar.iloc[bus1], .001), .001, element=bus1)

    pp.create_measurement(net, "p", "line", r2(net.res_line.p_from_mw.iloc[0], .002), .002, 0, side='from')
    pp.create_measurement(net, "q", "line", r2(net.res_line.q_from_mvar.iloc[0], .002), .002, 0, side='from')

    pp.create_measurement(net, "p", "trafo", r2(net.res_trafo.p_hv_mw.iloc[0], .001), .01,
                          side="hv", element=0)  
    pp.create_measurement(net, "q", "trafo", r2(net.res_trafo.q_hv_mvar.iloc[0], .001), .01,
                          side="hv", element=0) 
    
    net_auto = deepcopy(net)
    net_aux = deepcopy(net)
    
    success_none = estimate(net, tolerance=1e-5, zero_injection=None)
    
    # In this case zero_injection in mode "aux_bus" and "auto" should be exact the same
    success_aux = estimate(net_aux, tolerance=1e-5, zero_injection='aux_bus')
    success_auto = estimate(net_auto, tolerance=1e-5, zero_injection='auto')
    assert success_none and success_aux and success_auto
    assert np.allclose(net_auto.res_bus_est.va_degree.values,net_aux.res_bus_est.va_degree.values, 1e-4, equal_nan=True)
    assert np.allclose(net_auto.res_bus_est.vm_pu.values,net_aux.res_bus_est.vm_pu.values, 1e-4, equal_nan=True)
    
    # in case zero injection was set to none, the results should be different
    assert ~np.allclose(net.res_bus_est.vm_pu.values,net_aux.res_bus_est.vm_pu.values, 1e-2, equal_nan=True)
Ejemplo n.º 5
0
def test_lp_lav():
    net = nw.case9()
    pp.runpp(net)
    add_virtual_meas_from_loadflow(net, p_std_dev=0.01, q_std_dev=0.01)

    estimate(net, algorithm="lp")

    if not np.allclose(net.res_bus.vm_pu, net.res_bus_est.vm_pu, atol=1e-2) or\
       not np.allclose(net.res_bus.va_degree, net.res_bus_est.va_degree, atol=5e-2):
        raise AssertionError("Estimation failed!")
Ejemplo n.º 6
0
def test_lp_lav():
    net = nw.case14()
    pp.runpp(net)
    add_virtual_meas_from_loadflow(net, p_std_dev=0.01, q_std_dev=0.01)

    estimate(net, algorithm="lp")

    assert np.allclose(net.res_bus.vm_pu, net.res_bus_est.vm_pu, atol=1e-2)
    assert np.allclose(net.res_bus.va_degree,
                       net.res_bus_est.va_degree,
                       atol=5e-2)
Ejemplo n.º 7
0
def test_pmu_case14():
    net = nw.case14()

    pp.runpp(net)
    add_virtual_pmu_meas_from_loadflow(net)

    estimate(net, algorithm="lp", maximum_iterations=20)

    assert np.allclose(net.res_bus.vm_pu, net.res_bus_est.vm_pu, atol=1e-2)
    assert np.allclose(net.res_bus.va_degree,
                       net.res_bus_est.va_degree,
                       atol=1e-1)
Ejemplo n.º 8
0
def test_irwls_comp_wls():
    # it should be the same since wls will not update weight matrix
    net = nw.case14()
    pp.runpp(net)
    add_virtual_meas_from_loadflow(net)

    success = estimate(net, init='flat', algorithm="irwls", estimator='wls')
    assert success

    net_wls = deepcopy(net)
    estimate(net_wls)
    assert np.allclose(net_wls.res_bus_est.vm_pu, net.res_bus_est.vm_pu, 1e-6)
    assert np.allclose(net_wls.res_bus_est.va_degree, net.res_bus_est.va_degree, 1e-6)
def test_lp_lav():
    '''
    This will test the default LP solver installed.
    If OR-Tools is installed, it will use it. Otherwise scipy is used.
    '''
    net = nw.case9()
    pp.runpp(net)
    add_virtual_meas_from_loadflow(net, p_std_dev=0.01, q_std_dev=0.01)

    estimate(net, algorithm="lp")

    if not np.allclose(net.res_bus.vm_pu, net.res_bus_est.vm_pu, atol=1e-2) or \
            not np.allclose(net.res_bus.va_degree, net.res_bus_est.va_degree, atol=5e-2):
        raise AssertionError("Estimation failed!")
Ejemplo n.º 10
0
def test_cigre_network(init='flat'):
    # 1. create network
    # test the mv ring network with all available voltage measurements and bus powers
    # test if switches and transformer will work correctly with the state estimation
    np.random.seed(123456)
    net = nw.create_cigre_network_mv(with_der=False)
    pp.runpp(net)

    for bus, row in net.res_bus.iterrows():
        pp.create_measurement(net, "v", "bus", row.vm_pu * r(0.01), 0.01, bus)
        # if np.random.randint(0, 4) == 0:
        #    continue
        pp.create_measurement(net, "p", "bus", -row.p_mw * r(), max(0.001, abs(0.03 * row.p_mw)),
                              bus)
        pp.create_measurement(net, "q", "bus", -row.q_mvar * r(), max(0.001, abs(0.03 * row.q_mvar)),
                              bus)

    # 2. Do state estimation
    success = estimate(net, init="flat", calculate_voltage_angles=False)
    v_result = net.res_bus_est.vm_pu.values
    delta_result = net.res_bus_est.va_degree.values

    target_v = net.res_bus.vm_pu.values
    diff_v = target_v - v_result
    target_delta = net.res_bus.va_degree.values
    diff_delta = target_delta - delta_result

    assert success
    assert (np.nanmax(abs(diff_v)) < 0.0043)
    assert (np.nanmax(abs(diff_delta)) < 0.17)
Ejemplo n.º 11
0
def test_3bus_with_side_names():
    np.random.seed(2017)
    net = load_3bus_network()
    net.measurement.drop(net.measurement.index, inplace=True)
    pp.create_load(net, 1, p_mw=0.495974966, q_mvar=0.297749528)
    pp.create_load(net, 2, p_mw=1.514220983, q_mvar=0.787528929)
    pp.runpp(net)
    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[0] * r(0.01), 0.01, 0)
    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[2] * r(0.01), 0.01, 1)
    pp.create_measurement(net, "p", "bus", -net.res_bus.p_mw[0] * r(),
                          max(1.0e-3, abs(0.03 * net.res_bus.p_mw[0])), 0)
    pp.create_measurement(net, "q", "bus", -net.res_bus.q_mvar[0] * r(),
                          max(1.0e-3, abs(0.03 * net.res_bus.q_mvar[0])), 0)
    pp.create_measurement(net, "p", "bus", -net.res_bus.p_mw[2] * r(),
                          max(1.0e-3, abs(0.03 * net.res_bus.p_mw[2])), 2)
    pp.create_measurement(net, "q", "bus", -net.res_bus.q_mvar[2] * r(),
                          max(1.0e-3, abs(0.03 * net.res_bus.q_mvar[2])), 2)
    pp.create_measurement(net, "p", "line", net.res_line.p_from_mw[0] * r(),
                          max(1.0e-3, abs(0.03 * net.res_line.p_from_mw[0])), element=0, side="from")
    pp.create_measurement(net, "q", "line", net.res_line.q_from_mvar[0] * r(),
                          max(1.0e-3, abs(0.03 * net.res_line.q_from_mvar[0])), element=0, side="from")
    pp.create_measurement(net, "p", "line", net.res_line.p_to_mw[0] * r(),
                          max(1.0e-3, abs(0.03 * net.res_line.p_to_mw[0])), element=0, side="to")
    pp.create_measurement(net, "q", "line", net.res_line.q_to_mvar[0] * r(),
                          max(1.0e-3, abs(0.03 * net.res_line.q_to_mvar[0])), element=0, side="to")

    success = estimate(net, init='flat')

    assert success
    assert (np.nanmax(abs(net.res_bus_est.vm_pu.values - net.res_bus.vm_pu.values)) < 0.023)
    assert (np.nanmax(abs(net.res_bus_est.va_degree.values - net.res_bus.va_degree.values)) < 0.12)
Ejemplo n.º 12
0
def test_3bus_with_i_line_measurements():
    np.random.seed(1)
    net = load_3bus_network()
    net.measurement.drop(net.measurement.index, inplace=True)
    pp.create_load(net, 1, p_mw=0.495974966, q_mvar=0.297749528)
    pp.create_load(net, 2, p_mw=1.514220983, q_mvar=0.787528929)
    pp.runpp(net)
    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[0] * r(0.01), 0.01, 0)
    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[2] * r(0.01), 0.01, 1)
    pp.create_measurement(net, "p", "bus", net.res_bus.p_mw[0] * r(),
                          max(1.0e-3, abs(0.03 * net.res_bus.p_mw[0])), 0)
    pp.create_measurement(net, "q", "bus", net.res_bus.q_mvar[0] * r(),
                          max(1.0e-3, abs(0.03 * net.res_bus.q_mvar[0])), 0)
    pp.create_measurement(net, "p", "bus", net.res_bus.p_mw[2] * r(),
                          max(1.0e-3, abs(0.03 * net.res_bus.p_mw[2])), 2)
    pp.create_measurement(net, "q", "bus", net.res_bus.q_mvar[2] * r(),
                          max(1.0e-3, abs(0.03 * net.res_bus.q_mvar[2])), 2)
    pp.create_measurement(net, "p", "line", net.res_line.p_from_mw[0] * r(),
                          max(1.0e-3, abs(0.03 * net.res_line.p_from_mw[0])), element=0, side=0)
    pp.create_measurement(net, "q", "line", net.res_line.q_from_mvar[0] * r(),
                          max(1.0e-3, abs(0.03 * net.res_line.q_from_mvar[0])), element=0, side=0)
    pp.create_measurement(net, "i", "line", net.res_line.i_from_ka[0] * 1e3 * r(),
                          max(1.0, abs(30 * net.res_line.i_from_ka[0])), element=0, side=0)
    pp.create_measurement(net, "i", "line", net.res_line.i_from_ka[1] * 1e3 * r(),
                          max(1.0, abs(30 * net.res_line.i_from_ka[1])), element=1, side=0)

    if not estimate(net, init='flat'):
        raise AssertionError("Estimation failed!")

    assert (np.nanmax(abs(net.res_bus_est.vm_pu.values - net.res_bus.vm_pu.values)) < 0.045)
    assert (np.nanmax(abs(net.res_bus_est.va_degree.values - net.res_bus.va_degree.values)) < 0.9)
Ejemplo n.º 13
0
def runWLS(net, resultMask):
    # WLS estimated states to compare with
    est = estimate(net, init="flat", calculate_voltage_angles=False)
    wls_va_degrees = net.res_bus_est[resultMask].loc[:, ['va_degree']].values
    wls_vm_pu = net.res_bus_est[resultMask].loc[:, ['vm_pu']].values
    wls_state = np.concatenate((wls_va_degrees, wls_vm_pu))
    return wls_state.ravel()
Ejemplo n.º 14
0
def test_IEEE_case_9_with_bad_data():
    # 1. Create network
    # test grid: IEEE case 9 (HV)
    # overall: 9 buses, 8 lines
    # choosen standard deviations for different types of measurements:
    # - V: 0.01 p.u.
    # - P: 1000 kW (1kW for no load)
    # - Q: 1000 kVA (1kVA for no load)
    net = pp.networks.case9()

    pp.create_measurement(net, "v", "bus", 0.995, 0.01, bus=1)  # V at bus 1
    pp.create_measurement(net, "v", "bus", 0.992, 0.01, bus=2)  # V at bus 2
    pp.create_measurement(net, "v", "bus", 0.988, 0.01, bus=3)  # V at bus 3
    pp.create_measurement(net, "v", "bus", 0.969, 0.01, bus=4)  # V at bus 4
    pp.create_measurement(net, "v", "bus", 1.019, 0.01, bus=5)  # V at bus 5
    pp.create_measurement(net, "v", "bus", 0.999, 0.01, bus=7)  # V at bus 7
    pp.create_measurement(net, "v", "bus", 0.963, 0.01, bus=8)  # V at bus 8

    pp.create_measurement(net, "p", "bus", 73137., 1000., bus=0)  # P at bus 0
    pp.create_measurement(net, "p", "bus", 85133., 1000., bus=2)  # P at bus 2
    pp.create_measurement(net, "p", "bus", 0., 1., bus=3)  # P at bus 3
    pp.create_measurement(net, "p", "bus", 0., 1., bus=5)  # P at bus 5
    pp.create_measurement(net, "p", "bus", -99884., 1000., bus=6)  # P at bus 6
    pp.create_measurement(net, "p", "bus", 0., 10., bus=7)  # P at bus 7

    pp.create_measurement(net, "q", "bus", 24272., 1000., bus=0)  # P at bus 0
    pp.create_measurement(net, "q", "bus", 13969., 1000., bus=1)  # P at bus 1
    pp.create_measurement(net, "q", "bus", 4235., 1000., bus=2)  # P at bus 2
    pp.create_measurement(net, "q", "bus", 0., 1., bus=3)  # Q at bus 3
    pp.create_measurement(net, "q", "bus", -30177., 1000., bus=4)  # Q at bus 4
    pp.create_measurement(net, "q", "bus", 0., 10., bus=5)  # Q at bus 5
    pp.create_measurement(net, "q", "bus", -36856., 1000., bus=6)  # Q at bus 6
    pp.create_measurement(net, "q", "bus", 0., 1., bus=7)  # Q at bus 7
    pp.create_measurement(net, "q", "bus", -49673., 1000., bus=8)  # Q at bus 8

    # 2. Do state estimation
    success_SE = estimate(net, init='flat')
    v_est_SE = net.res_bus_est.vm_pu.values
    delta_SE = net.res_bus_est.va_degree.values

    # 3. Create false measurements
    pp.create_measurement(net, "p", "bus", 3000., 1000., bus=1)  # P at bus 1
    pp.create_measurement(net, "p", "bus", -2000., 1000., bus=4)  # P at bus 4

    # 4. Do chi2-test
    success_chi2 = chi2_analysis(net, init='flat')

    # 5. Perform rn_max_test
    success_rn_max = remove_bad_data(net, init='flat')
    v_est_rn_max = net.res_bus_est.vm_pu.values
    delta_est_rn_max = net.res_bus_est.va_degree.values

    diff_v = v_est_SE - v_est_rn_max
    diff_delta = delta_SE - delta_est_rn_max

    assert success_SE
    assert success_chi2
    assert success_rn_max
    assert (np.nanmax(abs(diff_v)) < 1e-5)
    assert (np.nanmax(abs(diff_delta)) < 1e-5)
Ejemplo n.º 15
0
def test_3bus_with_pq_line_from_to_measurements():
    np.random.seed(2017)
    net = load_3bus_network()
    net.measurement.drop(net.measurement.index, inplace=True)
    pp.create_load(net, 1, p_kw=495.974966, q_kvar=297.749528)
    pp.create_load(net, 2, p_kw=1514.220983, q_kvar=787.528929)
    pp.runpp(net)
    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[0] * r(0.01), 0.01, 0)
    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[2] * r(0.01), 0.01, 1)
    pp.create_measurement(net, "p", "bus", -net.res_bus.p_kw[0] * r(),
                          max(1.0, abs(0.03 * net.res_bus.p_kw[0])), 0)
    pp.create_measurement(net, "q", "bus", -net.res_bus.q_kvar[0] * r(),
                          max(1.0, abs(0.03 * net.res_bus.q_kvar[0])), 0)
    pp.create_measurement(net, "p", "bus", -net.res_bus.p_kw[2] * r(),
                          max(1.0, abs(0.03 * net.res_bus.p_kw[2])), 2)
    pp.create_measurement(net, "q", "bus", -net.res_bus.q_kvar[2] * r(),
                          max(1.0, abs(0.03 * net.res_bus.q_kvar[2])), 2)
    pp.create_measurement(net, "p", "line", net.res_line.p_from_kw[0] * r(),
                          max(1.0, abs(0.03 * net.res_line.p_from_kw[0])), element=0, bus=0)
    pp.create_measurement(net, "q", "line", net.res_line.q_from_kvar[0] * r(),
                          max(1.0, abs(0.03 * net.res_line.q_from_kvar[0])), element=0, bus=0)
    pp.create_measurement(net, "p", "line", net.res_line.p_to_kw[0] * r(),
                          max(1.0, abs(0.03 * net.res_line.p_to_kw[0])), element=0, bus=1)
    pp.create_measurement(net, "q", "line", net.res_line.q_to_kvar[0] * r(),
                          max(1.0, abs(0.03 * net.res_line.q_to_kvar[0])), element=0, bus=1)

    success = estimate(net, init='flat')

    assert success
    assert (np.nanmax(abs(net.res_bus_est.vm_pu.values - net.res_bus.vm_pu.values)) < 0.023)
    assert (np.nanmax(abs(net.res_bus_est.va_degree.values - net.res_bus.va_degree.values)) < 0.12)
Ejemplo n.º 16
0
def test_2bus():
    # 1. Create network
    net = pp.create_empty_network()
    pp.create_bus(net, name="bus1", vn_kv=1.)
    pp.create_bus(net, name="bus2", vn_kv=1.)
    pp.create_ext_grid(net, 0)
    pp.create_line_from_parameters(net, 0, 1, 1, r_ohm_per_km=1,x_ohm_per_km=0.5, c_nf_per_km=0,
                                   max_i_ka=1)

    pp.create_measurement(net, "p", "line", 0.0111, 0.05, 0, 0)  # p12
    pp.create_measurement(net, "q", "line", 0.06, 0.05, 0, 0)    # q12

    pp.create_measurement(net, "v", "bus", 1.019, 0.01, 0)  # u1
    pp.create_measurement(net, "v", "bus", 1.04, 0.01, 1)   # u2

    # 2. Do state estimation
    success = estimate(net, init='flat')

    v_result = net.res_bus_est.vm_pu.values
    delta_result = net.res_bus_est.va_degree.values

    target_v = np.array([[1.02083378, 1.03812899]])
    diff_v = target_v - v_result
    target_delta = np.array([[0.0, 3.11356604]])
    diff_delta = target_delta - delta_result

    assert success
    assert (np.nanmax(abs(diff_v)) < 1e-6)
    assert (np.nanmax(abs(diff_delta)) < 1e-6)
Ejemplo n.º 17
0
def test_IEEE_case_9_with_bad_data():
    # 1. Create network
    # test grid: IEEE case 9 (HV)
    # overall: 9 buses, 8 lines

    net = pp.networks.case9()

    pp.create_measurement(net, "v", "bus", 1.0, 0.01, bus=1)   # V at bus 1
    pp.create_measurement(net, "v", "bus", 1.02, 0.01, bus=2)   # V at bus 2
    pp.create_measurement(net, "v", "bus", 0.9822, 0.01, bus=3)   # V at bus 3
    pp.create_measurement(net, "v", "bus", 0.979, 0.01, bus=4)   # V at bus 4
    pp.create_measurement(net, "v", "bus", 1.005, 0.01, bus=5)   # V at bus 5
    pp.create_measurement(net, "v", "bus", 0.997, 0.01, bus=7)   # V at bus 7
    pp.create_measurement(net, "v", "bus", 0.953, 0.01, bus=8)   # V at bus 8

    pp.create_measurement(net, "p", "bus", 72000, 100., bus=0)
    pp.create_measurement(net, "p", "bus", 162780, 100., bus=1)
    pp.create_measurement(net, "p", "bus", 84958, 70., bus=2)
    pp.create_measurement(net, "p", "bus", 0., 1., bus=3)
    pp.create_measurement(net, "p", "bus", -89967., 20., bus=4)
    pp.create_measurement(net, "p", "bus", 0., 10., bus=5)
    pp.create_measurement(net, "p", "bus", -100059., 30., bus=6)
    pp.create_measurement(net, "p", "bus", 0., 10., bus=7)
    pp.create_measurement(net, "p", "bus", -125100, 50., bus=8)

    pp.create_measurement(net, "q", "bus", 24000, 100., bus=0)
    pp.create_measurement(net, "q", "bus", 14500, 100., bus=1)
    pp.create_measurement(net, "q", "bus", 3644, 70., bus=2)
    pp.create_measurement(net, "q", "bus", 0., 1., bus=3)
    pp.create_measurement(net, "q", "bus", -30041., 20., bus=4)
    pp.create_measurement(net, "q", "bus", 0., 10., bus=5)
    pp.create_measurement(net, "q", "bus", -35087, 30., bus=6)
    pp.create_measurement(net, "q", "bus", 0., 10., bus=7)
    pp.create_measurement(net, "q", "bus", -49900, 50., bus=8)

    # 2. Do state estimation
    success_SE = estimate(net, init='flat', ref_power=1e6)
    v_est_SE = net.res_bus_est.vm_pu.values
    delta_SE = net.res_bus_est.va_degree.values

    # 3. Create false measurement (very close to useful values)
    pp.create_measurement(net, "v", "bus", 0.2, 0.01, bus=0)  # V at bus 0

    # 4. Do chi2-test
    bad_data_detected = chi2_analysis(net, init='flat', ref_power=1e6)

    # 5. Perform rn_max_test
    success_rn_max = remove_bad_data(net, init='flat', ref_power=1e6, rn_max_threshold=7.0)
    v_est_rn_max = net.res_bus_est.vm_pu.values
    delta_est_rn_max = net.res_bus_est.va_degree.values

    diff_v = v_est_SE - v_est_rn_max
    diff_delta = delta_SE - delta_est_rn_max

    assert success_SE
    assert bad_data_detected
    assert success_rn_max
    assert (np.nanmax(abs(diff_v)) < 1e-5)
    assert (np.nanmax(abs(diff_delta)) < 1e-5)
Ejemplo n.º 18
0
def test_network_with_trafo3w_pq():
    net = pp.create_empty_network()

    bus_slack = pp.create_bus(net, vn_kv=110)
    pp.create_ext_grid(net, bus=bus_slack)

    bus_20_1 = pp.create_bus(net, vn_kv=20,name="b")
    pp.create_sgen(net, bus=bus_20_1, p_mw=0.03, q_mvar=0.02)

    bus_10_1 = pp.create_bus(net, vn_kv=10)
    pp.create_sgen(net, bus=bus_10_1, p_mw=0.02, q_mvar=0.02)

    bus_10_2 = pp.create_bus(net, vn_kv=10)
    pp.create_load(net, bus=bus_10_2, p_mw=0.06, q_mvar=0.01)
    pp.create_line(net, from_bus=bus_10_1, to_bus=bus_10_2, std_type="149-AL1/24-ST1A 10.0", length_km=2)

    pp.create_transformer3w(net, bus_slack, bus_20_1, bus_10_1, std_type="63/25/38 MVA 110/20/10 kV")

    pp.runpp(net)

    pp.create_measurement(net, "p", "line", net.res_line.p_from_mw[0], 0.001, 0, 'from')
    pp.create_measurement(net, "q", "line", net.res_line.q_from_mvar[0], 0.001, 0, 'from')
    pp.create_measurement(net, "p", "line", net.res_line.p_to_mw[0], 0.001, 0, 'to')
    pp.create_measurement(net, "q", "line", net.res_line.q_to_mvar[0], 0.001, 0, 'to')

    pp.create_measurement(net, "p", "trafo3w", net.res_trafo3w.p_hv_mw[0], 0.001, 0, 'hv')
    pp.create_measurement(net, "q", "trafo3w", net.res_trafo3w.q_hv_mvar[0], 0.001, 0, 'hv')
    pp.create_measurement(net, "p", "trafo3w", net.res_trafo3w.p_mv_mw[0], 0.002, 0, 'mv')
    pp.create_measurement(net, "q", "trafo3w", net.res_trafo3w.q_mv_mvar[0], 0.002, 0, 'mv')
    pp.create_measurement(net, "p", "trafo3w", net.res_trafo3w.p_lv_mw[0], 0.001, 0, 'lv')
    pp.create_measurement(net, "q", "trafo3w", net.res_trafo3w.q_lv_mvar[0], 0.001, 0, 'lv')

    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[0], 0.01, 0)
    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[1], 0.01, 1)

    if not estimate(net):
        raise AssertionError("Estimation failed!")

    if not (np.nanmax(np.abs(net.res_bus.vm_pu.values - net.res_bus_est.vm_pu.values)) < 0.006) or\
       not (np.nanmax(np.abs(net.res_bus.va_degree.values- net.res_bus_est.va_degree.values)) < 0.006):
        raise AssertionError("Estimation failed")
    
    #Try estimate with results initialization
    if not estimate(net, init="results"):
        raise AssertionError("Estimation failed!")
Ejemplo n.º 19
0
def test_irwls_shgm():
    net = nw.case14()
    pp.runpp(net)
    add_virtual_meas_from_loadflow(net, p_std_dev=0.01, q_std_dev=0.01)
    success = estimate(net, algorithm="irwls", estimator="shgm",
                       a=3, maximum_iterations=50)
    assert success
    assert np.allclose(net.res_bus.vm_pu, net.res_bus_est.vm_pu, 1e-2)
    assert np.allclose(net.res_bus.va_degree, net.res_bus_est.va_degree, 1e-2)
Ejemplo n.º 20
0
def test_net_with_bb_switch_fuse_one():
    net = create_net_with_bb_switch()
    success = estimate(net, tolerance=1e-5, fuse_buses_with_bb_switch=[1])
    assert success
    assert np.allclose(net.res_bus.va_degree.values,net.res_bus_est.va_degree.values, 1e-2)
    assert np.allclose(net.res_bus.vm_pu.values,net.res_bus_est.vm_pu.values, 1e-2)
    # asserting with more tolerance since the added impedance will cause some inaccuracy
    assert np.allclose(net.res_bus.p_mw.values[[0,3,4]],net.res_bus_est.p_mw.values[[0,3,4]], 1e-1)
    assert np.allclose(net.res_bus.q_mvar.values[[0,3,4]],net.res_bus_est.q_mvar.values[[0,3,4]], 1e-1)
Ejemplo n.º 21
0
def test_net_with_zero_injection():
    # @author: AndersLi
    net = pp.create_empty_network()
    b1 = pp.create_bus(net, name="Bus 1", vn_kv=220, index=1)
    b2 = pp.create_bus(net, name="Bus 2", vn_kv=220, index=2)
    b3 = pp.create_bus(net, name="Bus 3", vn_kv=220, index=3)
    b4 = pp.create_bus(net, name="Bus 4", vn_kv=220, index=4)
    
    pp.create_ext_grid(net, b1)  # set the slack bus to bus 1
    factor = 48.4 * 2 * np.pi * 50 * 1e-9  # capacity factor

    pp.create_line_from_parameters(net, 1, 2, 1, r_ohm_per_km=.0221*48.4,
                                   x_ohm_per_km=.1603*48.4, c_nf_per_km=0.00274/factor, max_i_ka=1)
    pp.create_line_from_parameters(net, 2, 3, 1, r_ohm_per_km=.0428*48.4,
                                   x_ohm_per_km=.242*48.4, c_nf_per_km=0.00384/factor, max_i_ka=1)
    l3 = pp.create_line_from_parameters(net, 2, 4, 1, r_ohm_per_km=.002*48.4,
                                        x_ohm_per_km=.0111*48.4, c_nf_per_km=0.00018/factor, max_i_ka=1)
    
    pp.create_measurement(net, "v", "bus", 1.063548, .001, b1)         # V at bus 1
    pp.create_measurement(net, "v", "bus", 1.068342, .001, b3)         # V at bus 3
    pp.create_measurement(net, "v", "bus", 1.069861, .001, b4)         # V at bus 4
    pp.create_measurement(net, "p", "bus", -40.0, 1, b1)               # P at bus 1
    pp.create_measurement(net, "q", "bus", -9.2, 1, b1)                # Q at bus 1
    # pp.create_measurement(net, "p", "bus", 0, 0.01, b2)              # P at bus 2 - not required anymore
    # pp.create_measurement(net, "q", "bus", 0, 0.01, b2)              # Q at bus 2 - not required anymore
    pp.create_measurement(net, "p", "bus", 10.0, 1, b3)                # P at bus 3
    pp.create_measurement(net, "q", "bus", 1.0, 1, b3)                 # Q at bus 3
    pp.create_measurement(net, "p", "bus", 30.0, 1, b4)                # P at bus 4
    pp.create_measurement(net, "q", "bus", -0.100, 1, b4)              # Q at bus 4
    pp.create_measurement(net, "p", "line", 30.100, 1, l3, side="to")  # Pline (bus 2 -> bus 4) at bus 4
    pp.create_measurement(net, "q", "line", -0.099, 1, l3, side="to")  # Qline (bus 2 -> bus 4) at bus 4

    success = estimate(net, tolerance=1e-10, zero_injection='auto', algorithm='wls_with_zero_constraint')
    assert success
    assert np.abs(net.res_bus_est.at[b2, 'p_mw']) < 1e-8
    assert np.abs(net.res_bus_est.at[b2, 'q_mvar']) < 1e-8

    net_given_bus = deepcopy(net)
    success = estimate(net, tolerance=1e-6, zero_injection="auto")
    success_given_bus = estimate(net, tolerance=1e-6, zero_injection=[b2])
    assert success and success_given_bus
    assert np.allclose(net.res_bus_est.va_degree.values,net_given_bus.res_bus_est.va_degree.values, 1e-3)
    assert np.allclose(net.res_bus_est.vm_pu.values,net_given_bus.res_bus_est.vm_pu.values, 1e-3)
Ejemplo n.º 22
0
def test_case9_compare_classical_wls_opt_wls():
    net = nw.case9()
    pp.runpp(net)
    add_virtual_meas_from_loadflow(net)

    # give it a warm start
    net, ppc, eppci = pp2eppci(net)
    estimation_wls = WLSAlgorithm(1e-3, 3)
    estimation_opt = OptAlgorithm(1e-6, 1000)

    eppci = estimation_wls.estimate(eppci)
    eppci = estimation_opt.estimate(eppci, estimator="wls", verbose=False)
    if not estimation_opt.successful:
        raise AssertionError("Estimation failed due to algorithm failing!")
    net = eppci2pp(net, ppc, eppci)

    net_wls = net.deepcopy()
    estimate(net_wls)

    if not np.allclose(net_wls.res_bus_est.vm_pu, net.res_bus_est.vm_pu, atol=1e-2) or \
            not np.allclose(net_wls.res_bus_est.va_degree, net.res_bus_est.va_degree, atol=1e-2):
        raise AssertionError("Estimation failed!")
Ejemplo n.º 23
0
def test_3bus_with_out_of_service_bus():
    # Test case from book "Power System State Estimation", A. Abur, A. G. Exposito, p. 20ff.
    # S_ref = 1 MVA (PP standard)
    # V_ref = 1 kV
    # Z_ref = 1 Ohm

    # The example only had per unit values, but pandapower expects kV, MVA, kW, kVar
    # Measurements should be in kW/kVar/A - Voltage in p.u.

    # 1. Create network
    net = pp.create_empty_network()
    pp.create_bus(net, name="bus1", vn_kv=1.)
    pp.create_bus(net, name="bus2", vn_kv=1.)
    pp.create_bus(net, name="bus3", vn_kv=1.)
    pp.create_bus(net, name="bus4", vn_kv=1., in_service=0)  # out-of-service bus test
    pp.create_ext_grid(net, 0)
    pp.create_line_from_parameters(net, 0, 1, 1, r_ohm_per_km=.01, x_ohm_per_km=.03, c_nf_per_km=0.,
                                   max_i_ka=1)
    pp.create_line_from_parameters(net, 0, 2, 1, r_ohm_per_km=.02, x_ohm_per_km=.05, c_nf_per_km=0.,
                                   max_i_ka=1)
    pp.create_line_from_parameters(net, 1, 2, 1, r_ohm_per_km=.03, x_ohm_per_km=.08, c_nf_per_km=0.,
                                   max_i_ka=1)

    pp.create_measurement(net, "v", "bus", 1.006, .004, 0)  # V at bus 1
    pp.create_measurement(net, "v", "bus", .968, .004, 1)   # V at bus 2

    pp.create_measurement(net, "p", "bus", .501, .010, 1)  # P at bus 2
    pp.create_measurement(net, "q", "bus", .286, .010, 1)  # Q at bus 2

    pp.create_measurement(net, "p", "line", .888, .008, 0, 0)   # Pline (bus 1 -> bus 2) at bus 1
    pp.create_measurement(net, "p", "line", 1.173, .008, 1, 0)  # Pline (bus 1 -> bus 3) at bus 1
    pp.create_measurement(net, "q", "line", .568, .008, 0, 0)   # Qline (bus 1 -> bus 2) at bus 1
    pp.create_measurement(net, "q", "line", .663, .008, 1, 0)   # Qline (bus 1 -> bus 3) at bus 1

    # 2. Do state estimation
    if not estimate(net, init='flat'):
        raise AssertionError("Estimation failed!")

    v_result = net.res_bus_est.vm_pu.values
    delta_result = net.res_bus_est.va_degree.values

    target_v = np.array([[0.9996, 0.9741, 0.9438, np.nan]])
    diff_v = target_v - v_result
    target_delta = np.array([[0., -1.2475, -2.7457, np.nan]])
    diff_delta = target_delta - delta_result

    if not (np.nanmax(abs(diff_v)) < 1e-4) or\
       not (np.nanmax(abs(diff_delta)) < 1e-4):
        raise AssertionError("Estimation failed!")
Ejemplo n.º 24
0
def test_init_slack_with_multiple_transformers(angles=True):
    np.random.seed(123)
    net = pp.create_empty_network()
    pp.create_bus(net, 220, index=0)
    pp.create_bus(net, 110, index=1)
    pp.create_bus(net, 110, index=2)
    pp.create_bus(net, 110, index=3)
    pp.create_bus(net, 10, index=4)
    pp.create_bus(net, 10, index=5)
    pp.create_bus(net, 10, index=6)
    pp.create_bus(net, 10, index=7, in_service=False)
    pp.create_std_type(net, {"sn_mva": 63, "vn_hv_kv": 110, "vn_lv_kv": 10, "vk_percent": 10.04,
            "vkr_percent": 0.31, "pfe_kw": 31.51, "i0_percent": 0.078, "shift_degree": 150,
            "tap_side": "hv", "tap_neutral": 0, "tap_min": -9, "tap_max": 9, "tap_step_degree": 0,
            "tap_step_percent": 1.5, "tap_phase_shifter": False},
            "63 MVA 110/10 kV v1.4.3 and older", element="trafo")
            
    pp.create_transformer(net, 3, 7, std_type="63 MVA 110/10 kV v1.4.3 and older", in_service=False)
    pp.create_transformer(net, 3, 4, std_type="63 MVA 110/10 kV v1.4.3 and older")
    pp.create_transformer(net, 0, 1, std_type="100 MVA 220/110 kV")
    pp.create_line(net, 1, 2, 2.0, std_type="N2XS(FL)2Y 1x120 RM/35 64/110 kV")
    pp.create_line(net, 1, 3, 2.0, std_type="N2XS(FL)2Y 1x120 RM/35 64/110 kV")
    pp.create_line(net, 4, 5, 2.0, std_type="NA2XS2Y 1x95 RM/25 12/20 kV")
    pp.create_line(net, 5, 6, 2.0, std_type="NA2XS2Y 1x95 RM/25 12/20 kV")
    pp.create_load(net, 2, p_mw=5, q_mvar=3.3)
    pp.create_load(net, 5, p_mw=0.9, q_mvar=0.5)
    pp.create_load(net, bus=6, p_mw=0.7, q_mvar=0.3)
    pp.create_ext_grid(net, bus=0, vm_pu=1.04, va_degree=10., name="Slack 220 kV")
    pp.runpp(net, calculate_voltage_angles=angles)
    for bus, row in net.res_bus[net.bus.in_service == True].iterrows():
        pp.create_measurement(net, "v", "bus", row.vm_pu * r(0.01), 0.01, bus)
        if row.p_mw != 0.:
            continue
        pp.create_measurement(net, "p", "bus", -row.p_mw * r(), max(0.001, abs(0.03 * row.p_mw)),
                              bus)
        pp.create_measurement(net, "q", "bus", -row.q_mvar * r(), max(.0001, abs(0.03 * row.q_mvar)),
                              bus)
    pp.create_measurement(net, "p", "line", net.res_line.p_from_mw[0], .01, side=1, element=0)
    pp.create_measurement(net, "q", "line", net.res_line.q_from_mvar[0], 0.01, side=1, element=0)
    pp.create_measurement(net, "p", "line", net.res_line.p_from_mw[2], .01, side=4, element=2)
    pp.create_measurement(net, "q", "line", net.res_line.q_from_mvar[2], .01, side=4, element=2)
    pp.create_measurement(net, "p", "line", net.res_line.p_from_mw[3], .01, side=5, element=3)
    pp.create_measurement(net, "q", "line", net.res_line.q_from_mvar[3], 0.01, side=5, element=3)
    success = estimate(net, init='slack', calculate_voltage_angles=angles, tolerance=1e-9)

    # pretty high error for vm_pu (half percent!)
    assert success
    assert (np.nanmax(np.abs(net.res_bus.vm_pu.values - net.res_bus_est.vm_pu.values)) < 0.006)
    assert (np.nanmax(np.abs(net.res_bus.va_degree.values- net.res_bus_est.va_degree.values)) < 0.006)
Ejemplo n.º 25
0
def test_net_oos_line():
    net = nw.case9()
    net.line.in_service.iat[4] = False
    pp.runpp(net)
    
    for line_ix in net.line.index:
        pp.create_measurement(net, "p", "line", net.res_line.at[line_ix, "p_from_mw"],
                              0.01, element=line_ix, side="from")
        pp.create_measurement(net, "q", "line", net.res_line.at[line_ix, "q_from_mvar"],
                              0.01, element=line_ix, side="from")
    
    for bus_ix in net.bus.index:
        pp.create_measurement(net, "v", "bus", net.res_bus.at[bus_ix, "vm_pu"],
                              0.01, element=bus_ix)
        
    if not estimate(net, tolerance=1e-6, zero_injection=None):
        raise AssertionError("Estimation failed!")
Ejemplo n.º 26
0
def test_init_slack_with_multiple_transformers(angles=True):
    np.random.seed(123)
    net = pp.create_empty_network()
    pp.create_bus(net, 220, index=0)
    pp.create_bus(net, 110, index=1)
    pp.create_bus(net, 110, index=2)
    pp.create_bus(net, 110, index=3)
    pp.create_bus(net, 10, index=4)
    pp.create_bus(net, 10, index=5)
    pp.create_bus(net, 10, index=6)
    pp.create_bus(net, 10, index=7, in_service=False)
    pp.create_transformer(net, 3, 7, std_type="63 MVA 110/10 kV", in_service=False)
    pp.create_transformer(net, 3, 4, std_type="63 MVA 110/10 kV")
    pp.create_transformer(net, 0, 1, std_type="100 MVA 220/110 kV")
    pp.create_line(net, 1, 2, 2.0, std_type="N2XS(FL)2Y 1x120 RM/35 64/110 kV")
    pp.create_line(net, 1, 3, 2.0, std_type="N2XS(FL)2Y 1x120 RM/35 64/110 kV")
    pp.create_line(net, 4, 5, 2.0, std_type="NA2XS2Y 1x95 RM/25 12/20 kV")
    pp.create_line(net, 5, 6, 2.0, std_type="NA2XS2Y 1x95 RM/25 12/20 kV")
    pp.create_load(net, 2, 5000, 3300)
    pp.create_load(net, 5, 900, 500)
    pp.create_load(net, 6, 700, 300)
    pp.create_ext_grid(net, bus=0, vm_pu=1.04, va_degree=10., name="Slack 220 kV")
    pp.runpp(net, calculate_voltage_angles=angles)
    for bus, row in net.res_bus[net.bus.in_service == True].iterrows():
        pp.create_measurement(net, "v", "bus", row.vm_pu * r(0.01), 0.01, bus)
        if row.p_kw != 0.:
            continue
        pp.create_measurement(net, "p", "bus", -row.p_kw * r(), max(1.0, abs(0.03 * row.p_kw)),
                              bus)
        pp.create_measurement(net, "q", "bus", -row.q_kvar * r(), max(1.0, abs(0.03 * row.q_kvar)),
                              bus)
    pp.create_measurement(net, "p", "line", net.res_line.p_from_kw[0], 10., bus=1, element=0)
    pp.create_measurement(net, "q", "line", net.res_line.q_from_kvar[0], 10., bus=1, element=0)
    pp.create_measurement(net, "p", "line", net.res_line.p_from_kw[2], 10., bus=4, element=2)
    pp.create_measurement(net, "q", "line", net.res_line.q_from_kvar[2], 10., bus=4, element=2)
    pp.create_measurement(net, "p", "line", net.res_line.p_from_kw[3], 10., bus=5, element=3)
    pp.create_measurement(net, "q", "line", net.res_line.q_from_kvar[3], 10., bus=5, element=3)
    success = estimate(net, init='slack', calculate_voltage_angles=angles)

    # pretty high error for vm_pu (half percent!)
    assert success
    assert (np.nanmax(np.abs(net.res_bus.vm_pu.values - net.res_bus_est.vm_pu.values)) < 0.006)
    assert (np.nanmax(np.abs(net.res_bus.va_degree.values
                             - net.res_bus_est.va_degree.values)) < 0.006)
Ejemplo n.º 27
0
def test_3bus():
    # 1. Create network
    net = pp.create_empty_network()
    pp.create_bus(net, name="bus1", vn_kv=1.)
    pp.create_bus(net, name="bus2", vn_kv=1.)
    pp.create_bus(net, name="bus3", vn_kv=1.)
    pp.create_ext_grid(net, 0)
    pp.create_line_from_parameters(net, 0, 1, 1, r_ohm_per_km=0.7, x_ohm_per_km=0.2, c_nf_per_km=0,
                                   max_i_ka=1)
    pp.create_line_from_parameters(net, 0, 2, 1, r_ohm_per_km=0.8, x_ohm_per_km=0.8, c_nf_per_km=0,
                                   max_i_ka=1)
    pp.create_line_from_parameters(net, 1, 2, 1, r_ohm_per_km=1, x_ohm_per_km=0.6, c_nf_per_km=0,
                                   max_i_ka=1)

    pp.create_measurement(net, "p", "line", -0.0011, 0.01, 0, 0)  # p12
    pp.create_measurement(net, "q", "line", 0.024, 0.01, 0, 0)    # q12

    pp.create_measurement(net, "p", "bus", -0.018, 0.01, 2)  # p3
    pp.create_measurement(net, "q", "bus", 0.1, 0.01, 2)   # q3

    pp.create_measurement(net, "v", "bus", 1.08, 0.05, 0)   # u1
    pp.create_measurement(net, "v", "bus", 1.015, 0.05, 2)  # u3

    # 2. Do state estimation
    if not estimate(net, init='flat'):
        raise AssertionError("Estimation failed!")
    v_result = net.res_bus_est.vm_pu.values
    delta_result = net.res_bus_est.va_degree.values

    target_v = np.array([1.0627, 1.0589, 1.0317])
    diff_v = target_v - v_result
    target_delta = np.array([0., 0.8677, 3.1381])
    diff_delta = target_delta - delta_result
    
    if not (np.nanmax(abs(diff_v)) < 1e-4) or\
       not (np.nanmax(abs(diff_delta)) < 1e-4):
        raise AssertionError("Estimation failed!")

    # Backwards check. Use state estimation results for power flow and check for equality
    net.ext_grid.vm_pu = net.res_bus_est.vm_pu.iloc[0]
    pp.create_load(net, 0, net.res_bus_est.p_mw.iloc[0], net.res_bus_est.q_mvar.iloc[0])
    pp.create_load(net, 1, net.res_bus_est.p_mw.iloc[1], net.res_bus_est.q_mvar.iloc[1])
    pp.create_load(net, 2, net.res_bus_est.p_mw.iloc[2], net.res_bus_est.q_mvar.iloc[2])
    _compare_pf_and_se_results(net)
Ejemplo n.º 28
0
def test_network_with_trafo3w_with_disabled_branch():
    net = pp.create_empty_network()

    bus_slack = pp.create_bus(net, vn_kv=110)
    pp.create_ext_grid(net, bus=bus_slack)

    bus_20_1 = pp.create_bus(net, vn_kv=20,name="b")
    pp.create_sgen(net, bus=bus_20_1, p_mw=0.03, q_mvar=0.02)

    bus_10_1 = pp.create_bus(net, vn_kv=10)
    pp.create_sgen(net, bus=bus_10_1, p_mw=0.02, q_mvar=0.02)

    bus_10_2 = pp.create_bus(net, vn_kv=10)
    pp.create_load(net, bus=bus_10_2, p_mw=0.06, q_mvar=0.01)
    pp.create_line(net, from_bus=bus_10_1, to_bus=bus_10_2, std_type="149-AL1/24-ST1A 10.0", length_km=2)
    disabled_line = pp.create_line(net, from_bus=bus_10_1, to_bus=bus_10_2, std_type="149-AL1/24-ST1A 10.0", length_km=2)
    net.line.at[disabled_line, 'in_service'] = False

    pp.create_transformer3w(net, bus_slack, bus_20_1, bus_10_1, std_type="63/25/38 MVA 110/20/10 kV")

    pp.runpp(net)

    pp.create_measurement(net, "p", "line", net.res_line.p_from_mw[0], 0.001, 0, 'from')
    pp.create_measurement(net, "q", "line", net.res_line.q_from_mvar[0], 0.001, 0, 'from')
    pp.create_measurement(net, "p", "line", net.res_line.p_to_mw[0], 0.001, 0, 'to')
    pp.create_measurement(net, "q", "line", net.res_line.q_to_mvar[0], 0.001, 0, 'to')
    pp.create_measurement(net, "p", "line", net.res_line.p_to_mw[1], 0.001, 1, 'to')
    pp.create_measurement(net, "q", "line", net.res_line.q_to_mvar[1], 0.001, 1, 'to')

    pp.create_measurement(net, "p", "trafo3w", net.res_trafo3w.p_hv_mw[0], 0.001, 0, 'hv')
    pp.create_measurement(net, "q", "trafo3w", net.res_trafo3w.q_hv_mvar[0], 0.001, 0, 'hv')
    pp.create_measurement(net, "p", "trafo3w", net.res_trafo3w.p_mv_mw[0], 0.002, 0, 'mv')
    pp.create_measurement(net, "q", "trafo3w", net.res_trafo3w.q_mv_mvar[0], 0.002, 0, 'mv')
    pp.create_measurement(net, "p", "trafo3w", net.res_trafo3w.p_lv_mw[0], 0.001, 0, 'lv')
    pp.create_measurement(net, "q", "trafo3w", net.res_trafo3w.q_lv_mvar[0], 0.001, 0, 'lv')

    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[0], 0.01, 0)
    pp.create_measurement(net, "v", "bus", net.res_bus.vm_pu[1], 0.01, 1)

    success = estimate(net)
    assert success
    assert (np.nanmax(np.abs(net.res_bus.vm_pu.values - net.res_bus_est.vm_pu.values)) < 0.006)
    assert (np.nanmax(np.abs(net.res_bus.va_degree.values- net.res_bus_est.va_degree.values)) < 0.006)
Ejemplo n.º 29
0
def test_net_unobserved_island():
    net = pp.create_empty_network()
    bus1 = pp.create_bus(net, name="bus1", vn_kv=10.)
    bus2 = pp.create_bus(net, name="bus2", vn_kv=10.)
    bus3 = pp.create_bus(net, name="bus3", vn_kv=10.)
    bus4 = pp.create_bus(net, name="bus4", vn_kv=110.)
    
    pp.create_line_from_parameters(net, bus1, bus2, 10, r_ohm_per_km=.59, x_ohm_per_km=.35, c_nf_per_km=10.1,
                                   max_i_ka=1)
    pp.create_line_from_parameters(net, bus2, bus3, 10, r_ohm_per_km=.59, x_ohm_per_km=.35, c_nf_per_km=10.1,
                                   max_i_ka=1)
    pp.create_transformer(net, bus4, bus1, std_type="40 MVA 110/10 kV")
    pp.create_ext_grid(net, bus=bus4, vm_pu=1.0)
    pp.create_load(net, bus1, p_mw=.350, q_mvar=.100)
    pp.create_load(net, bus2, p_mw=.450, q_mvar=.100)
    pp.create_load(net, bus3, p_mw=.250, q_mvar=.100)
    
    # Created bb switch
    pp.runpp(net, calculate_voltage_angles=True)
    
    pp.create_measurement(net, "v", "bus", r2(net.res_bus.vm_pu.iloc[bus1], .002), .002, element=bus1)
    pp.create_measurement(net, "v", "bus", r2(net.res_bus.vm_pu.iloc[bus4], .002), .002, element=bus4)
    
    pp.create_measurement(net, "p", "bus", -r2(net.res_bus.p_mw.iloc[bus4], .002), .002, element=bus4)
    pp.create_measurement(net, "q", "bus", -r2(net.res_bus.q_mvar.iloc[bus4], .002), .002, element=bus4)
    
    # IF pq of bus2 is not available makes bus3 an unobserved island
#    pp.create_measurement(net, "p", "bus", -r2(net.res_bus.p_mw.iloc[bus2], .001), .001, element=bus2)
#    pp.create_measurement(net, "q", "bus", -r2(net.res_bus.q_mvar.iloc[bus2], .001), .001, element=bus2)
    pp.create_measurement(net, "p", "bus", -r2(net.res_bus.p_mw.iloc[bus1], .001), .001, element=bus1)
    pp.create_measurement(net, "q", "bus", -r2(net.res_bus.q_mvar.iloc[bus1], .001), .001, element=bus1)
    
    pp.create_measurement(net, "p", "line", r2(net.res_line.p_from_mw.iloc[0], .002), .002, 0, side='from')
    pp.create_measurement(net, "q", "line", r2(net.res_line.q_from_mvar.iloc[0], .002), .002, 0, side='from')
    
    pp.create_measurement(net, "p", "trafo", r2(net.res_trafo.p_hv_mw.iloc[0], .001), .01,
                          side="hv", element=0)  
    pp.create_measurement(net, "q", "trafo", r2(net.res_trafo.q_hv_mvar.iloc[0], .001), .01,
                          side="hv", element=0) 

    success = estimate(net, tolerance=1e-6, zero_injection=None)
    assert success
Ejemplo n.º 30
0
def test_3bus_with_2_slacks():
    # load the net which already contains 3 buses
    net = load_3bus_network()
    # add the same net with different slack (no galvanic connection)
    # skip bus index 4 as further stability test
    pp.create_bus(net, name="bus5", vn_kv=1., index=5)
    pp.create_bus(net, name="bus6", vn_kv=1., index=6)
    pp.create_bus(net, name="bus7", vn_kv=1., index=7)
    pp.create_ext_grid(net, 5)
    pp.create_line_from_parameters(net, 5, 6, 1, r_ohm_per_km=.01, x_ohm_per_km=.03, c_nf_per_km=0.,
                                   max_i_ka=1)
    pp.create_line_from_parameters(net, 5, 7, 1, r_ohm_per_km=.02, x_ohm_per_km=.05, c_nf_per_km=0.,
                                   max_i_ka=1)
    pp.create_line_from_parameters(net, 6, 7, 1, r_ohm_per_km=.03, x_ohm_per_km=.08, c_nf_per_km=0.,
                                   max_i_ka=1)

    pp.create_measurement(net, "v", "bus", 1.006, .004, element=5)  # V at bus 5
    pp.create_measurement(net, "v", "bus", .968, .004, element=6)   # V at bus 6

    pp.create_measurement(net, "p", "bus", -.501, .010, element=6)  # P at bus 6
    pp.create_measurement(net, "q", "bus", -.286, .010, element=6)  # Q at bus 6

    pp.create_measurement(net, "p", "line", .888, .008, 3, 5)   # Pline (bus 5 -> bus 6) at bus 5
    pp.create_measurement(net, "p", "line", 1.173, .008, 4, 5)  # Pline (bus 5 -> bus 7) at bus 5
    pp.create_measurement(net, "q", "line", .568, .008, 3, 5)   # Qline (bus 5 -> bus 6) at bus 5
    pp.create_measurement(net, "q", "line", .663, .008, 4, 5)   # Qline (bus 5 -> bus 7) at bus 5

    # 2. Do state estimation
    success = estimate(net, init='flat', maximum_iterations=10)
    v_result = net.res_bus_est.vm_pu.values
    delta_result = net.res_bus_est.va_degree.values

    target_v = np.array([0.9996, 0.9741, 0.9438, np.nan, 0.9996, 0.9741, 0.9438])
    diff_v = target_v - v_result
    target_delta = np.array([0.0, -1.2475469989322963, -2.7457167371166862, np.nan, 0.0,
                             -1.2475469989322963, -2.7457167371166862])
    diff_delta = target_delta - delta_result

    assert success
    assert (np.nanmax(abs(diff_v)) < 1e-4)
    assert (np.nanmax(abs(diff_delta)) < 1e-4)