def run_grid(output_dir, data, datapoints): # 1. create test net #net = simple_test_net() net = nw.create_cigre_network_lv() # 2. create (random) data source n_timesteps = datapoints profiles, ds = load_input(data=data) # profiles, ds = create_data_source(n_timesteps) # n_timesteps # 3. create controllers (to control P values of the load and the sgen) net = create_controllers(net, ds) # time steps to be calculated. Could also be a list with non-consecutive time steps time_steps = range(0, n_timesteps) # 4. the output writer with the desired results to be stored to files. ow = create_output_writer(net, time_steps, output_dir) # 5. the main time series function run_timeseries(net, time_steps) '''Try to clear memory''' # for element in dir(): # if element[0:2] != "__": # del globals()[element] # del element del n_timesteps del profiles del ds del time_steps del ow del net gc.collect()
def test_violated_buses(): net = nw.create_cigre_network_lv() pp.runpp(net) # set the range of vm.pu min_vm_pu = 0.92 max_vm_pu = 1.1 # print out the list of violated_bus's index violated_bus = tb.violated_buses(net, min_vm_pu, max_vm_pu) assert set(violated_bus) == set(net["bus"].index[[16, 35, 36, 40]])
def test_cigre_lv(): net = pn.create_cigre_network_lv() pp.runpp(net) all_vn_kv = pd.Series([20, 0.4]) assert net.bus.vn_kv.isin(all_vn_kv).all() assert len(net.bus) == 44 assert len(net.line) == 37 assert len(net.gen) == 0 assert len(net.sgen) == 0 assert len(net.shunt) == 0 assert len(net.trafo) == 3 assert len(net.load) == 15 assert len(net.ext_grid) == 1 assert len(net.switch) == 3 assert net.converged is True
def test_select_subnet(): # This network has switches of type 'l' and 't' net = nw.create_cigre_network_mv() # Do nothing same_net = pp.select_subnet(net, net.bus.index) assert pp.dataframes_equal(net.bus, same_net.bus) assert pp.dataframes_equal(net.switch, same_net.switch) assert pp.dataframes_equal(net.trafo, same_net.trafo) assert pp.dataframes_equal(net.line, same_net.line) assert pp.dataframes_equal(net.load, same_net.load) assert pp.dataframes_equal(net.ext_grid, same_net.ext_grid) # Remove everything empty = pp.select_subnet(net, set()) assert len(empty.bus) == 0 assert len(empty.line) == 0 assert len(empty.load) == 0 assert len(empty.trafo) == 0 assert len(empty.switch) == 0 assert len(empty.ext_grid) == 0 # Should keep all trafo ('t') switches when buses are included hv_buses = set(net.trafo.hv_bus) lv_buses = set(net.trafo.lv_bus) trafo_switch_buses = set(net.switch[net.switch.et == 't'].bus) subnet = pp.select_subnet(net, hv_buses | lv_buses | trafo_switch_buses) assert net.switch[net.switch.et == 't'].index.isin(subnet.switch.index).all() # Should keep all line ('l') switches when buses are included from_bus = set(net.line.from_bus) to_bus = set(net.line.to_bus) line_switch_buses = set(net.switch[net.switch.et == 'l'].bus) subnet = pp.select_subnet(net, from_bus | to_bus | line_switch_buses) assert net.switch[net.switch.et == 'l'].index.isin(subnet.switch.index).all() # This network has switches of type 'b' net2 = nw.create_cigre_network_lv() # Should keep all bus-to-bus ('b') switches when buses are included buses = set(net2.switch[net2.switch.et == 'b'].bus) elements = set(net2.switch[net2.switch.et == 'b'].element) subnet = pp.select_subnet(net2, buses | elements) assert net2.switch[net2.switch.et == 'b'].index.isin(subnet.switch.index).all()
def test_nets_equal(): tb.logger.setLevel(40) original = nw.create_cigre_network_lv() net = copy.deepcopy(original) # should be equal assert tb.nets_equal(original, net) assert tb.nets_equal(net, original) # detecting additional element pp.create_bus(net, vn_kv=.4) assert not tb.nets_equal(original, net) assert not tb.nets_equal(net, original) net = copy.deepcopy(original) # detecting removed element net["bus"].drop(net.bus.index[0], inplace=True) assert not tb.nets_equal(original, net) assert not tb.nets_equal(net, original) net = copy.deepcopy(original) # detecting alternated value net["load"]["p_kw"][net["load"].index[0]] += 0.1 assert not tb.nets_equal(original, net) assert not tb.nets_equal(net, original) net = copy.deepcopy(original) # detecting added column net["load"]["new_col"] = 0.1 assert not tb.nets_equal(original, net) assert not tb.nets_equal(net, original) net = copy.deepcopy(original) # not detecting alternated value if difference is beyond tolerance net["load"]["p_kw"][net["load"].index[0]] += 0.0001 assert tb.nets_equal(original, net, tol=0.1) assert tb.nets_equal(net, original, tol=0.1)
load_df.at[bus, 'p_mw'] = row['Load'] #modifies load_df in place ''' Plot the line loading %, transformer loading %, and cost over 24 hours. ''' def plot_results(): pass #Load IEEE 57 bus system (default) #net = nw.case57(vn_kv_area1=115, vn_kv_area2=500, vn_kv_area3=138, vn_kv_area4=345, vn_kv_area5=230, vn_kv_area6=161) #net = nw.example_multivoltage() net = nw.create_cigre_network_lv() #gen_df = net.gen #gen_df.insert(8, 'max_p_mw',[100],True) #gen_df.insert(8, 'min_p_mw',[0],True) #sgen_df = net.sgen #sgen_df.insert(8, 'max_p_mw',[20,.5,.5,15,2,.006,.005,.005,.005,.005,.005]) #sgen_df.insert(8, 'min_p_mw',[0,0,0,0,0,0,0,0,0,0,0],True) #Create cost functions #costeg = pp.create_poly_cost(net, 0, 'ext_grid', cp1_eur_per_mw=10) #costgen1 = pp.create_poly_cost(net, 0, 'gen', cp1_eur_per_mw=10) #costgen2 = pp.create_poly_cost(net, 0, 'sgen', cp1_eur_per_mw=10) #costgen3 = pp.create_poly_cost(net, 1, 'sgen', cp1_eur_per_mw=10) #costgen4 = pp.create_poly_cost(net, 2, 'sgen', cp1_eur_per_mw=10) #costgen5 = pp.create_poly_cost(net, 3, 'sgen', cp1_eur_per_mw=10)
import pandapower as pp import pandapower.networks as pn import numpy as np import pandapower.plotting as plot import matplotlib.pyplot as plt from pandapower.plotting.plotly import vlevel_plotly import pandas as pd net = pn.create_cigre_network_lv() net plot.simple_plot(net, show_plot=True) vlevel_plotly(net) #del net.bus_geodata pp.convert_format(net) pp.to_excel(net, "examplecigrelow.xlsx") netcoords = net.bus_geodata netcoords.to_excel('cigrecoords.xlsx') netlv = pp.from_excel("final code/examplecigrelow.xlsx") #lv.bus_geodata #del netlv.bus_geodata netlv plot.simple_plot(netlv, show_plot=True) vlevel_plotly(netlv) #vlevel_plotly(net) netlv net
def create_network(): # carga la red de cigre de baja tensión y la modifica acrode a nuestros interese # retorna un objeto pandapower y la matriz de resistencias r y de reactancias x net = pn.create_cigre_network_lv() # Eliminar cargas que no se usarán for index in net.load.index: if not net.load['name'][index][5] == 'R': net.load.drop(index, inplace=True) net.load.drop(0, inplace=True) # Eliminar todos los switches y crear uno nuevo for index in net.switch.index: net.switch.drop(index, inplace=True) pp.create_switch(net, bus=2, element=0, et='l', closed=True, type='CB', z_ohm=0.0) pp.create_switch(net, bus=5, element=3, et='l', closed=True, type='CB', z_ohm=0.0) # Eliminar trafos que no se usarán for index in net.trafo.index: if not net.trafo['name'][index] == 'Trafo R0-R1': net.trafo.drop(index, inplace=True) # Eliminar lineas que no se usarán for index in net.line.index: if not net.line['name'][index][5] == 'R': net.line.drop(index, inplace=True) # Eliminar buses que no se usarán for index in net.bus.index: if not net.bus['name'][index][4] == 'R': net.bus.drop(index, inplace=True) net.bus_geodata.drop(index, inplace=True) # Cambio de lugar de la external grid net.ext_grid['bus'] = 1 # Agregar nodo 20 y linea respectiva pp.create_bus(net, vn_kv=0.4, index=20, type='m', zone='CIGRE_LV', in_service=True, geodata=(7, -1)) pp.create_line_from_parameters(net, from_bus=5, to_bus=20, std_type='UG3', length_km=0.030, r_ohm_per_km=0.822, x_ohm_per_km=0.0847, c_nf_per_km=0.0, g_us_per_km=0.0, max_i_ka=1.0) # Agregar GD pp.create_sgen(net, bus=16, p_mw=0.030, q_mvar=0.0, name='Microturbina', scaling=1.0, type='CHP', index=1, in_service=False) pp.create_sgen(net, bus=17, p_mw=0.010, q_mvar=0.0, name='WT', scaling=1.0, type='WP', index=2, in_service=False) pp.create_sgen(net, bus=17, p_mw=0.010, q_mvar=0.0, name='PV1', scaling=1.0, type='PV', index=3, in_service=True) pp.create_sgen(net, bus=18, p_mw=0.003, q_mvar=0.0, name='PV2', scaling=1.0, type='PV', index=4, in_service=True) pp.create_sgen(net, bus=19, p_mw=0.010, q_mvar=0.0, name='Celda combustible', scaling=1.0, type='CHP', index=5, in_service=False) pp.create_storage(net, bus=20, p_mw=0.03, max_e_mwh=0.060, q_mvar=0, min_e_mwh=0.012, in_service=False) # Cambiar consumos S_loads = [0.015, 0.072, 0.050, 0.015, 0.047] cos_phi = 0.85 for i in net.load.index: net.load['p_mw'][i] = S_loads[i - 1] * cos_phi net.load['q_mvar'][i] = S_loads[i - 1] * np.sqrt(1 - np.square(cos_phi)) # Modificar Geodata de los buses para graficar y = np.array( [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 7, 7, 6, 5, 2, 1, 7]) x = np.array( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, 2, 3, 3, -1, 1, -1, -1]) net.bus_geodata['x'] = 0.3 * x net.bus_geodata['y'] = 0.3 * y Zn = ((0.4 * 1e3)**2) / (net.sn_mva * 1e6) r = np.zeros((len(net.bus), len(net.bus))) x = np.zeros((len(net.bus), len(net.bus))) for index in net.line.index: r_line = net.line['r_ohm_per_km'][index] * net.line['length_km'][ index] / Zn x_line = net.line['x_ohm_per_km'][index] * net.line['length_km'][ index] / Zn r[net.line['from_bus'][index] - 1, net.line['to_bus'][index] - 1] = r_line x[net.line['from_bus'][index] - 1, net.line['to_bus'][index] - 1] = x_line r[net.line['to_bus'][index] - 1, net.line['from_bus'][index] - 1] = r_line x[net.line['to_bus'][index] - 1, net.line['from_bus'][index] - 1] = x_line return net, r, x