def test_distance(feeder_network): net = feeder_network dist = top.calc_distance_to_bus(net, 0) assert np.allclose(dist.sort_index().values, [0, 12, 13, 5]) dist = top.calc_distance_to_bus(net, 0, notravbuses={3}) assert np.allclose(dist.sort_index().values, [0, 12, 18, 5]) pp.create_switch(net, bus=3, element=2, et="l", closed=False) dist = top.calc_distance_to_bus(net, 0) assert np.allclose(dist.sort_index().values, [0, 12, 18, 5])
def get_farther_bus(net, zone=None): b0 = net.ext_grid.bus[0] distance_bus = ppt.calc_distance_to_bus(net, b0) if zone is None: return distance_bus.idxmax() return distance_bus[net.bus[net.bus.zone == zone].index].idxmax()
def plot_voltage_profile(net, plot_transformers=True, ax=None, xlabel="Distance from Slack [km]", ylabel="Voltage [pu]", x0=0, trafocolor="r", bus_colors=None, **kwargs): if ax is None: plt.figure(facecolor="white", dpi=120) ax = plt.gca() if not net.converged: raise ValueError("no results in this pandapower network") for eg in net.ext_grid[net.ext_grid.in_service == True].bus: d = top.calc_distance_to_bus(net, eg) for _, line in net.line[net.line.in_service == True].iterrows(): if not line.from_bus in d.index: continue if not ((net.switch.element == line.name) & (net.switch.closed == False) & (net.switch.et == 'l')).any(): fbus = line.from_bus tbus = line.to_bus x = [x0 + d.at[fbus], x0 + d.at[tbus]] try: y = [ net.res_bus.vm_pu.at[fbus], net.res_bus.vm_pu.at[tbus] ] except: raise UserWarning ax.plot(x, y, **kwargs) if bus_colors is not None: for bus, x, y in zip((fbus, tbus), x, y): if bus in bus_colors: ax.plot(x, y, 'or', color=bus_colors[bus], ms=3) kwargs = {k: v for k, v in kwargs.items() if not k == "label"} if plot_transformers: if hasattr(plot_transformers, "__iter__"): # if is a list for example trafos = net.trafo.loc[list(plot_transformers)] else: trafos = net.trafo[net.trafo.in_service == True] for _, trafo in trafos.iterrows(): if trafo.hv_bus not in d.index: continue ax.plot( [x0 + d.loc[trafo.hv_bus], x0 + d.loc[trafo.lv_bus]], [ net.res_bus.vm_pu.loc[trafo.hv_bus], net.res_bus.vm_pu.loc[trafo.lv_bus] ], color=trafocolor, **{k: v for k, v in kwargs.items() if not k == "color"}) if xlabel: ax.set_xlabel(xlabel, fontweight="bold", color=(.4, .4, .4)) if ylabel: ax.set_ylabel(ylabel, fontweight="bold", color=(.4, .4, .4)) return ax
def plot_voltage_profile(net, plot_transformers=True, ax=None, xlabel="Distance from Slack [km]", ylabel="Voltage [pu]", x0=0, trafocolor="r", bus_colors=None, line_loading_weight=False, voltage_column=None, bus_size=3, lines=None, **kwargs): if ax is None: plt.figure(facecolor="white", dpi=120) ax = plt.gca() if not net.converged: raise ValueError("no results in this pandapower network") if voltage_column is None: voltage_column = net.res_bus.vm_pu if lines is None: lines = net.line.index for eg in net.ext_grid[net.ext_grid.in_service == True].bus: d = top.calc_distance_to_bus(net, eg) for lix, line in net.line[(net.line.in_service == True) & net.line.index.isin(lines)].iterrows(): if line.from_bus not in d.index: continue if not ((net.switch.element == line.name) & ~net.switch.closed & (net.switch.et == 'l')).any(): from_bus = line.from_bus to_bus = line.to_bus x = [x0 + d.at[from_bus], x0 + d.at[to_bus]] try: y = [ voltage_column.at[from_bus], voltage_column.at[to_bus] ] except: raise UserWarning if "linewidth" in kwargs or not line_loading_weight: ax.plot(x, y, **kwargs) else: ax.plot(x, y, linewidth=0.4 * np.sqrt(net.res_line.loading_percent.at[lix]), **kwargs) if bus_colors is not None: for bus, x, y in zip((from_bus, to_bus), x, y): if bus in bus_colors: ax.plot(x, y, 'or', color=bus_colors[bus], ms=bus_size) kwargs = {k: v for k, v in kwargs.items() if not k == "label"} # if plot_transformers: # if hasattr(plot_transformers, "__iter__"): # if is a list for example # transformers = net.trafo.loc[list(plot_transformers)] # else: # transformers = net.trafo[net.trafo.in_service == True] # for _, transformer in transformers.iterrows(): # if transformer.hv_bus not in d.index: # continue # ax.plot([x0 + d.loc[transformer.hv_bus], # x0 + d.loc[transformer.lv_bus]], # [voltage_column.loc[transformer.hv_bus], # voltage_column.loc[transformer.lv_bus]], color=trafocolor, # **{k: v for k, v in kwargs.items() if not k == "color"}) # trafo geodata if plot_transformers: for trafo_table in ['trafo', 'trafo3w']: if trafo_table not in net.keys(): continue transformers = net[trafo_table].query('in_service') for tid, tr in transformers.iterrows(): t_buses = [ tr[b_col] for b_col in ('lv_bus', 'mv_bus', 'hv_bus') if b_col in tr.index ] if any([ b not in d.index.values or b not in net.res_bus.index.values for b in t_buses ]): # logger.info('cannot add trafo %d to plot' % tid) continue for bi, bj in combinations(t_buses, 2): tr_coords = ([x0 + d.loc[bi], x0 + d.loc[bj]], [ net.res_bus.at[bi, 'vm_pu'], net.res_bus.at[bj, 'vm_pu'] ]) ax.plot(*tr_coords, color=trafocolor, **{ k: v for k, v in kwargs.items() if not k == "color" }) if xlabel: ax.set_xlabel(xlabel, fontweight="bold", color=(.4, .4, .4)) if ylabel: ax.set_ylabel(ylabel, fontweight="bold", color=(.4, .4, .4)) return ax
def plot_v_profile(net, ax=None, vmin=0.95, vmax=1.05): """ Plots voltage profile of a Pandapower grid """ b0 = net.ext_grid.bus[0] distance_bus = ppt.calc_distance_to_bus(net, b0) if ax is None: fig, ax = plt.subplots() # Draw lines lines_c = [[(dbf, vbf), (dbt, vbt)] for dbt, vbt, dbf, vbf in zip( distance_bus[net.line.from_bus], net.res_bus.vm_pu[net.line.from_bus], distance_bus[net.line.to_bus], net.res_bus.vm_pu[net.line.to_bus], )] lc = LineCollection(lines_c, linestyle='--', color='k', label='Lines') ax.add_collection(lc) # Draw trafos trafos_c = [[(dbf, vbf), (dbt, vbt)] for dbt, vbt, dbf, vbf in zip( distance_bus[net.trafo.hv_bus], net.res_bus.vm_pu[net.trafo.hv_bus], distance_bus[net.trafo.lv_bus], net.res_bus.vm_pu[net.trafo.lv_bus], )] lt = LineCollection(trafos_c, linestyle='--', color='b', label='Tranformers') ax.add_collection(lt) plt.autoscale() if 'Feeder' in net.bus: fs = net.bus.Feeder.unique() # Writes Feeder name at the end of it for f in fs: if not ((f is None) or not (f == f)): if not 'SS' in f: bm = distance_bus[net.bus[net.bus.Feeder == f].index].idxmax() dm = distance_bus[bm] vm = net.res_bus.vm_pu[bm] ax.text(x=dm + 0.5, y=vm, s=f) #Draws horizontal line at min and max V (in pu) ax.axhline(vmin, linestyle='dashed', color='red') ax.axhline(vmax, linestyle='dashed', color='red') # Plot nodes ok = (net.res_bus.vm_pu >= vmin) & (net.res_bus.vm_pu <= vmax) dok, vok = distance_bus[net.res_bus[ok].index], net.res_bus.vm_pu[ net.res_bus[ok].index] dnok, vnok = distance_bus[net.res_bus[~ok].index], net.res_bus.vm_pu[ net.res_bus[~ok].index] ax.plot(dok, vok, '*', color='b', markersize=3, picker=8, gid='ok1', label='_') ax.plot(dnok, vnok, '*', color='red', markersize=3, picker=8, gid='nok1', label='_') #plot ext_grid node n_eg = net.ext_grid.bus ax.plot(distance_bus[n_eg], net.res_bus.vm_pu[n_eg], 's', color='magenta', label='HV grid') # ax.set_xlabel('Distance [km]') ax.set_ylabel('Voltage (pu)') ax.legend()
if not (te in notfrem): # print('removing', t.get_text()) t.remove() continue t.remove() plt.savefig( r'c:\user\U546416\Pictures\Boriette\Voltages\Synergies_high_{}.pdf'.format( case)) plt.savefig( r'c:\user\U546416\Pictures\Boriette\Voltages\Synergies_high_{}.jpg'.format( case), dpi=300) #%% Identifying key nodes b0 = net.ext_grid.bus[0] distance_bus = ppt.calc_distance_to_bus(net, b0) fbus = pd.DataFrame([distance_bus, net.bus.Feeder]).T.groupby('Feeder').idxmax().squeeze() feeders = ['F06', 'F17'] week = 9 idxi = (week - 1) * 7 * 2 * 24 idxf = idxi + 7 * 2 * 24 x = np.arange(0, 24 * 7, 0.5) f, ax = plt.subplots() for f in feeders: plt.plot(x, volts[str(fbus[f])].iloc[idxi:idxf], label=f) plt.axhline(1.05, color='r', linestyle='--') plt.axhline(0.95, color='r', linestyle='--')