def test_replace_ext_grid_gen(): for i in range(2): net = nw.example_simple() net.ext_grid["uuid"] = "test" pp.runpp(net) assert list(net.res_ext_grid.index.values) == [0] # replace_ext_grid_by_gen if i == 0: pp.replace_ext_grid_by_gen(net, 0, gen_indices=[4], add_cols_to_keep=["uuid"]) elif i == 1: pp.replace_ext_grid_by_gen(net, [0], gen_indices=[4], cols_to_keep=["uuid", "max_p_mw"]) assert not net.ext_grid.shape[0] assert not net.res_ext_grid.shape[0] assert np.allclose(net.gen.vm_pu.values, [1.03, 1.02]) assert net.res_gen.p_mw.dropna().shape[0] == 2 assert np.allclose(net.gen.index.values, [0, 4]) assert net.gen.uuid.loc[4] == "test" # replace_gen_by_ext_grid if i == 0: pp.replace_gen_by_ext_grid(net) elif i == 1: pp.replace_gen_by_ext_grid(net, [0, 4], ext_grid_indices=[2, 3]) assert np.allclose(net.ext_grid.index.values, [2, 3]) assert not net.gen.shape[0] assert not net.res_gen.shape[0] assert net.ext_grid.va_degree.dropna().shape[0] == 2 assert any(np.isclose(net.ext_grid.va_degree.values, 0)) assert net.res_ext_grid.p_mw.dropna().shape[0] == 2
def test_replace_ext_grid_gen(): net = nw.example_simple() pp.runpp(net) assert list(net.res_ext_grid.index.values) == [0] # replace_ext_grid_by_gen pp.replace_ext_grid_by_gen(net, 0) assert not net.ext_grid.shape[0] assert not net.res_ext_grid.shape[0] assert np.allclose(net.gen.vm_pu.values, [1.03, 1.02]) assert net.res_gen.p_mw.dropna().shape[0] == 2 # replace_gen_by_ext_grid pp.replace_gen_by_ext_grid(net) assert not net.gen.shape[0] assert not net.res_gen.shape[0] assert net.ext_grid.va_degree.dropna().shape[0] == 2 assert any(np.isclose(net.ext_grid.va_degree.values, 0)) assert net.res_ext_grid.p_mw.dropna().shape[0] == 2
''' ############################################################################## time_start = time.process_time() ############################################################################## # INITIALIZATION OF THE POWER NETWORK # Call the Great Britain reduced power network from Pandapower net = pandapower.networks.GBreducednetwork() # Replace static generators with standard generators pp.replace_sgen_by_gen(net) list_ext_grid = list(net.ext_grid.index) initial_slack = pp.replace_ext_grid_by_gen(net, list_ext_grid, slack=True) # Set the maximum loading of each line to 100% net.line.loc[:,'max_loading_percent'] = 100 net.trafo.loc[:,'max_loading_percent'] = 100 # Set the min/max power values of each load net.load.loc[:,'max_p_mw'] = net.load.p_mw net.load.loc[:,'min_p_mw'] = 0 # Set the min/max power values of each generator net.gen.loc[:,'max_p_mw'] = net.gen.max_p_mw/1.438 #net.ext_grid.loc[:,'max_p_mw'] = net.ext_grid.max_p_mw/1.438 net.gen.loc[:,'p_mw'] = net.gen.max_p_mw # Set generators and loads as controllable (for DC OPF)
import pandapower as pd import pandapower.networks as pn ''' net = pd.converter.from_mpc('caset.mat', f_hz=50, casename_mpc_file='caset', validate_conversion=False) ''' net = pn.case24_ieee_rts() net.load['controllable'] = True pd.replace_ext_grid_by_gen(net) pd.replace_sgen_by_gen(net) net.gen.loc[0, 'slack'] = True pd.create_bus(net, vn_kv=230, name='DCnode', index=24, max_vm_pu=1.05, min_vm_pu=0.95) pd.create_ext_grid(net, bus=24, max_q_mvar=500, min_q_mvar=0, min_p_mw=0, max_p_mw=1000, slack=False) pd.create_poly_cost(net, element=0, et='gen', cp0_eur=0, cp1_eur_per_mw=0, cp2_eur_per_mw2=0) pd.create_dcline(net, from_bus=24, to_bus=17,
def InitialCase(): ''' return: pandapower net ''' # Reference Case Based on Case24 net = pn.case24_ieee_rts() # replace pp.replace_ext_grid_by_gen(net) pp.replace_sgen_by_gen(net) # sort the gen net.gen = net.gen.sort_values(by=['bus', 'max_p_mw']) idx = net.poly_cost.index.to_list() # idx after sorting element = net.poly_cost['element'].to_list() net.gen.loc[0, 'slack'] = True # modify Gen Parameter according bus order for i in range(net.gen.shape[0]): net.gen.iloc[i, 10] = Data.PMAX[i] net.gen.iloc[i, 11] = Data.PMIN[i] net.gen.iloc[i, 12] = Data.QMAX[i] net.gen.iloc[i, 13] = Data.QMIN[i] # adding a bus for DC line pp.create_bus(net, vn_kv=230, name='DCnode', index=24, max_vm_pu=1.05, min_vm_pu=0.95) # adding a ext_grid as DC power pp.create_ext_grid(net, bus=24, vm_pu=1.05, max_q_mvar=10, min_q_mvar=0, min_p_mw=0, max_p_mw=1000, slack=False) # adding cost of ext_grid pp.create_poly_cost(net, element=0, et='ext_grid', cp0_eur=0, cp1_eur_per_mw=0, cp2_eur_per_mw2=0) # adding DC line pp.create_dcline(net, from_bus=24, to_bus=16, p_mw=0, loss_mw=5, loss_percent=5, vm_from_pu=1.05, vm_to_pu=0.95, name='DC1', max_p_mw=400, max_q_from_mvar=0, min_q_from_mvar=0, max_q_to_mvar=0, min_q_to_mvar=0) # load net.load['controllable'] = True # load-sheeding cost and load constraints for i in range(net.load.shape[0]): net.load.loc[i, 'max_p_mw'] = net.load.loc[i, 'p_mw'] net.load.loc[i, 'min_p_mw'] = 0 net.load.loc[i, 'max_q_mvar'] = net.load.loc[i, 'q_mvar'] net.load.loc[i, 'min_q_mvar'] = 0 pp.create_poly_cost(net, i, et='load', cp1_eur_per_mw=-500) return net, idx, element