def calc_distance_to_bus(net, bus, respect_switches=True, nogobuses=None, notravbuses=None, weight='weight'): """ Calculates the shortest distance between a source bus and all buses connected to it. INPUT: **net** (pandapowerNet) - Variable that contains a pandapower network. **bus** (integer) - Index of the source bus. OPTIONAL: **respect_switches** (boolean, True) - True: open line switches are being considered (no edge between nodes) False: open line switches are being ignored **nogobuses** (integer/list, None) - nogobuses are not being considered **notravbuses** (integer/list, None) - lines connected to these buses are not being considered **weight** (string, None) – Edge data key corresponding to the edge weight OUTPUT: **dist** - Returns a pandas series with containing all distances to the source bus in km. If weight=None dist is the topological distance (int). EXAMPLE: import pandapower.topology as top dist = top.calc_distance_to_bus(net, 5) """ g = create_nxgraph(net, respect_switches=respect_switches, nogobuses=nogobuses, notravbuses=notravbuses) return pd.Series(nx.single_source_dijkstra_path_length(g, bus, weight=weight))
def unsupplied_buses(net, mg=None, in_service_only=False, slacks=None): """ Finds buses, that are not connected to an external grid. INPUT: **net** (pandapowerNet) - variable that contains a pandapower network OPTIONAL: **mg** (NetworkX graph) - NetworkX Graph or MultiGraph that represents a pandapower network. OUTPUT: **ub** (set) - unsupplied buses EXAMPLE: import pandapower.topology as top top.unsupplied_buses(net) """ mg = mg or create_nxgraph(net) slacks = slacks or set(net.ext_grid[net.ext_grid.in_service==True].bus.values) not_supplied = set() for cc in nx.connected_components(mg): if not set(cc) & slacks: not_supplied.update(set(cc)) buses_remove = set() if in_service_only: for bus in not_supplied: if not net.bus.loc[bus, 'in_service']: buses_remove.add(bus) not_supplied = not_supplied - buses_remove return not_supplied
def unsupplied_buses(net, mg=None, in_service_only=False, slacks=None, respect_switches=True): """ Finds buses, that are not connected to an external grid. INPUT: **net** (pandapowerNet) - variable that contains a pandapower network OPTIONAL: **mg** (NetworkX graph) - NetworkX Graph or MultiGraph that represents a pandapower network. **in_service_only** (boolean, False) - Defines whether only in service buses should be included in unsupplied_buses. **slacks** (set, None) - buses which are considered as root / slack buses. If None, all existing slack buses are considered. **respect_switches** (boolean, True) - Fixes how to consider switches - only in case of no given mg. OUTPUT: **ub** (set) - unsupplied buses EXAMPLE: import pandapower.topology as top top.unsupplied_buses(net) """ mg = mg or create_nxgraph(net, respect_switches=respect_switches) if slacks is None: slacks = set(net.ext_grid[net.ext_grid.in_service].bus.values) not_supplied = set() for cc in nx.connected_components(mg): if not set(cc) & slacks: not_supplied.update(set(cc)) buses_remove = set() if in_service_only: for bus in not_supplied: if not net.bus.loc[bus, 'in_service']: buses_remove.add(bus) not_supplied = not_supplied - buses_remove return not_supplied
def estimate_voltage_vector(net): """ Function initializes the voltage vector of net with a rough estimation. All buses are set to the slack bus voltage. Transformer differences in magnitude and phase shifting are accounted for. :param net: pandapower network :return: pandas dataframe with estimated vm_pu and va_degree """ res_bus = pd.DataFrame(index=net.bus.index, columns=["vm_pu", "va_degree"]) net_graph = create_nxgraph(net, include_trafos=False) for _, ext_grid in net.ext_grid.iterrows(): area = list(connected_component(net_graph, ext_grid.bus)) res_bus.vm_pu.loc[area] = ext_grid.vm_pu res_bus.va_degree.loc[area] = ext_grid.va_degree trafos = net.trafo[net.trafo.in_service == 1] trafo_index = trafos.index.tolist() while len(trafo_index): for tix in trafo_index: trafo = trafos.ix[tix] if pd.notnull(res_bus.vm_pu.at[trafo.hv_bus]) \ and pd.isnull(res_bus.vm_pu.at[trafo.lv_bus]): try: area = list(connected_component(net_graph, trafo.lv_bus)) shift = trafo.shift_degree if "shift_degree" in trafo else 0 ratio = (trafo.vn_hv_kv / trafo.vn_lv_kv) / ( net.bus.vn_kv.at[trafo.hv_bus] / net.bus.vn_kv.at[trafo.lv_bus]) res_bus.vm_pu.loc[area] = res_bus.vm_pu.at[ trafo.hv_bus] * ratio res_bus.va_degree.loc[area] = res_bus.va_degree.at[ trafo.hv_bus] - shift except KeyError: raise UserWarning( "An out-of-service bus is connected to an in-service " "transformer. Please set the transformer out of service or" "put the bus into service. Treat results with caution!" ) trafo_index.remove(tix) elif pd.notnull(res_bus.vm_pu.at[trafo.hv_bus]): # parallel transformer, lv buses are already set from previous transformer trafo_index.remove(tix) if len(trafo_index) == len(trafos): # after the initial run we could not identify any areas correctly, it's probably a transmission grid # with slack on the LV bus and multiple transformers/gens. do flat init and return res_bus.vm_pu.loc[res_bus.vm_pu.isnull()] = 1. res_bus.va_degree.loc[res_bus.va_degree.isnull()] = 0. return res_bus return res_bus
def determine_stubs(net, roots=None, mg=None, respect_switches=False): """ Finds stubs in a network. Open switches are being ignored. Results are being written in a new column in the bus table ("on_stub") and line table ("is_stub") as True/False value. INPUT: **net** (pandapowerNet) - Variable that contains a pandapower network. OPTIONAL: **roots** (integer/list, None) - indices of buses that should be excluded (by default, the ext_grid buses will be set as roots) EXAMPLE: import pandapower.topology as top top.determine_stubs(net, roots = [0, 1]) """ if mg is None: mg = create_nxgraph(net, respect_switches=respect_switches) # remove buses with degree lower 2 until none left if roots is None: roots = set(net.ext_grid.bus) # mg.add_edges_from((a, b) for a, b in zip(list(roots)[:-1], list(roots)[1:])) # while True: # dgo = {g for g, d in list(mg.degree().items()) if d < 2} #- roots # if not dgo: # break # mg.remove_nodes_from(dgo) # n1_buses = mg.nodes() _, n1_buses = get_2connected_buses(mg, roots) net.bus["on_stub"] = True net.bus.loc[n1_buses, "on_stub"] = False net.line["is_stub"] = ~((net.line.from_bus.isin(n1_buses)) & (net.line.to_bus.isin(n1_buses))) stubs = set(net.bus.index) - set(n1_buses) return stubs