Пример #1
0
def run(fname):

    circuit = FileOpen(fname).open()

    options = PowerFlowOptions(
        solver_type=SolverType.NR,
        retry_with_other_methods=False,
        verbose=False,
        initialize_with_existing_solution=False,
        tolerance=1e-4,
        max_iter=5,
        max_outer_loop_iter=10,
        control_q=ReactivePowerControlMode.NoControl,
        control_taps=TapsControlMode.NoControl,
        multi_core=False,
        dispatch_storage=False,
        control_p=False,
        apply_temperature_correction=False,
        branch_impedance_tolerance_mode=BranchImpedanceMode.Specified,
        q_steepness_factor=30,
        distributed_slack=False,
        ignore_single_node_islands=False,
        correction_parameter=1e-4)

    driver = SampledTimeSeries(grid=circuit,
                               options=options,
                               number_of_steps=100)
    driver.run()

    # compose the train set
    nc = circuit.compile_time_series()
    Pbus = nc.get_power_injections().real.T

    model = KNeighborsRegressor(n_neighbors=2)
    model.fit(driver.results.S.real, np.abs(driver.results.voltage))
    V_pred = model.predict(Pbus)

    model = KNeighborsRegressor(n_neighbors=2)
    model.fit(driver.results.S.real, driver.results.Sbranch.real)
    Sbr_pred = model.predict(Pbus)

    return V_pred, Sbr_pred
Пример #2
0
def run(fname):

    circuit = FileOpen(fname).open()

    pf_options = PowerFlowOptions(
        solver_type=SolverType.NR,
        retry_with_other_methods=False,
        verbose=False,
        initialize_with_existing_solution=False,
        tolerance=1e-6,
        max_iter=5,
        max_outer_loop_iter=10,
        control_q=ReactivePowerControlMode.NoControl,
        control_taps=TapsControlMode.NoControl,
        multi_core=False,
        dispatch_storage=False,
        control_p=False,
        apply_temperature_correction=False,
        branch_impedance_tolerance_mode=BranchImpedanceMode.Specified,
        q_steepness_factor=30,
        distributed_slack=False,
        ignore_single_node_islands=False,
        correction_parameter=1e-4)

    nc = circuit.compile_time_series()

    ts_driver = TimeSeries(circuit, pf_options)
    ts_driver.run()

    ptdf_driver = PtdfTimeSeries(circuit, pf_options, power_delta=10)
    ptdf_driver.run()

    npoints = int(len(circuit.time_profile) * 1)
    lhs_driver = LatinHypercubeSampling(circuit,
                                        pf_options,
                                        sampling_points=npoints)
    lhs_driver.run()

    P = nc.get_power_injections().real.T
    Q = nc.get_power_injections().imag.T
    Pbr_ts = ts_driver.results.Sbranch.real

    Pbr_ptdf = ptdf_driver.results.Sbranch.real
    P_lhs = lhs_driver.results.S_points.real
    Q_lhs = lhs_driver.results.S_points.imag
    Pbr_lhs = lhs_driver.results.Sbr_points.real

    # KNN
    n_neighbors = 3
    model = neighbors.KNeighborsRegressor(n_neighbors)
    # model.fit(P[:40], Pbr_ts[:40])
    # model.fit(P_lhs, Pbr_lhs)  # just the LHS for training
    # X = np.r_[np.c_[P_lhs, Q], np.c_[P, Q]]
    # Y = np.r_[Pbr_lhs, Pbr_ts]

    X = np.c_[P, Q][:60]
    Y = Pbr_ts[:60]

    model.fit(X, Y)  # LHS + TS for training ("dreaming")
    Pbr_knn = model.predict(np.c_[P, Q])

    fig = plt.figure(figsize=(12, 8))
    ax = fig.add_subplot(111)
    i = 10  # branch index
    ax.plot(Pbr_ts[i, :], label='Real flow', linewidth=5, c='orange')
    ax.plot(Pbr_ptdf[i, :], label='PTDF', c='b', linestyle='--')
    ax.plot(Pbr_knn[i, :], label='KNN', c='k', linestyle=':')
    ax.set_xlabel('Time')
    ax.set_ylabel('MW')
    fig.legend()
    plt.show()