pandapower/toolbox.py
changed.
Showing 2 of 2 files from the diff.
@@ -32,7 +32,7 @@
Loading
32 | 32 | EXAMPLE: |
|
33 | 33 | import pandapower.topology as top |
|
34 | 34 | ||
35 | - | mg = top.create_nx_graph(net) |
|
35 | + | mg = top.create_nxgraph(net) |
|
36 | 36 | ||
37 | 37 | cc = top.connected_component(mg, 5) |
|
38 | 38 |
@@ -68,7 +68,7 @@
Loading
68 | 68 | EXAMPLE: |
|
69 | 69 | import pandapower.topology as top |
|
70 | 70 | ||
71 | - | mg = top.create_nx_graph(net) |
|
71 | + | mg = top.create_nxgraph(net) |
|
72 | 72 | ||
73 | 73 | cc = top.connected_components(net, 5) |
|
74 | 74 |
@@ -959,7 +959,7 @@
Loading
959 | 959 | element_in_cost_df = net[cost_df].et == element |
|
960 | 960 | if sum(element_in_cost_df): |
|
961 | 961 | net[cost_df].element.loc[element_in_cost_df] = get_indices(net[cost_df].element[ |
|
962 | - | element_in_cost_df], lookup) |
|
962 | + | element_in_cost_df], lookup) |
|
963 | 963 | ||
964 | 964 | ||
965 | 965 | def create_continuous_elements_index(net, start=0, add_df_to_reindex=set()): |
@@ -1238,10 +1238,32 @@
Loading
1238 | 1238 | net.measurement.drop(idx_to_drop, inplace=True) |
|
1239 | 1239 | ||
1240 | 1240 | ||
1241 | + | def get_connecting_branches(net, buses1, buses2, branch_elements=None): |
|
1242 | + | """ |
|
1243 | + | Gets/Drops branches that connects any bus of buses1 with any bus of buses2. |
|
1244 | + | """ |
|
1245 | + | branch_dict = branch_element_bus_dict(include_switch=True) |
|
1246 | + | if branch_elements is not None: |
|
1247 | + | branch_dict = {key: branch_dict[key] for key in branch_elements} |
|
1248 | + | if "switch" in branch_dict: |
|
1249 | + | branch_dict["switch"].append("element") |
|
1250 | + | ||
1251 | + | found = {elm: set() for elm in branch_dict.keys()} |
|
1252 | + | for elm, bus_types in branch_dict.items(): |
|
1253 | + | for bus1 in bus_types: |
|
1254 | + | for bus2 in bus_types: |
|
1255 | + | if bus2 != bus1: |
|
1256 | + | idx = net[elm].index[net[elm][bus1].isin(buses1) & net[elm][bus2].isin(buses2)] |
|
1257 | + | if elm == "switch": |
|
1258 | + | idx = idx.intersection(net[elm].index[net[elm].et == "b"]) |
|
1259 | + | found[elm] |= set(idx) |
|
1260 | + | return {key: val for key, val in found.items() if len(val)} |
|
1261 | + | ||
1262 | + | ||
1241 | 1263 | def _inner_branches(net, buses, task, branch_elements=None): |
|
1242 | 1264 | """ |
|
1243 | - | Drops branches that connects buses within 'buses' at all branch sides (e.g. 'from_bus' and |
|
1244 | - | 'to_bus'). |
|
1265 | + | Drops or finds branches that connects buses within 'buses' at all branch sides (e.g. 'from_bus' |
|
1266 | + | and 'to_bus'). |
|
1245 | 1267 | """ |
|
1246 | 1268 | branch_dict = branch_element_bus_dict(include_switch=True) |
|
1247 | 1269 | if branch_elements is not None: |
@@ -1319,18 +1341,21 @@
Loading
1319 | 1341 | tr3w_buses = net.trafo3w.loc[tr3w, ['hv_bus', 'mv_bus', 'lv_bus']].values |
|
1320 | 1342 | if not all(net.bus.loc[tr3w_buses, 'in_service'].values): |
|
1321 | 1343 | net.trafo3w.at[tr3w, 'in_service'] = False |
|
1322 | - | open_tr3w_switches = net.switch.loc[(net.switch.et == 't3') & ~net.switch.closed & (net.switch.element == tr3w)] |
|
1344 | + | open_tr3w_switches = net.switch.loc[(net.switch.et == 't3') & ~net.switch.closed & ( |
|
1345 | + | net.switch.element == tr3w)] |
|
1323 | 1346 | if len(open_tr3w_switches) == 3: |
|
1324 | 1347 | net.trafo3w.at[tr3w, 'in_service'] = False |
|
1325 | 1348 | ||
1326 | 1349 | for element, et in zip(["line", "trafo"], ["l", "t"]): |
|
1327 | 1350 | oos_elements = net[element].query("not in_service").index |
|
1328 | - | oos_switches = net.switch[(net.switch.et == et) & net.switch.element.isin(oos_elements)].index |
|
1351 | + | oos_switches = net.switch[(net.switch.et == et) & net.switch.element.isin( |
|
1352 | + | oos_elements)].index |
|
1329 | 1353 | ||
1330 | 1354 | closed_switches.update([i for i in oos_switches.values if not net.switch.at[i, 'closed']]) |
|
1331 | 1355 | net.switch.loc[oos_switches, "closed"] = True |
|
1332 | 1356 | ||
1333 | - | for idx, bus in net.switch.loc[~net.switch.closed & (net.switch.et == et)][["element", "bus"]].values: |
|
1357 | + | for idx, bus in net.switch.loc[~net.switch.closed & (net.switch.et == et)][[ |
|
1358 | + | "element", "bus"]].values: |
|
1334 | 1359 | if not net.bus.in_service.at[next_bus(net, bus, idx, element)]: |
|
1335 | 1360 | net[element].at[idx, "in_service"] = False |
|
1336 | 1361 | if len(closed_switches) > 0: |
@@ -1745,7 +1770,7 @@
Loading
1745 | 1770 | Zni = vn ** 2 / sn_mva[i] |
|
1746 | 1771 | new_index.append(create_impedance( |
|
1747 | 1772 | net, line_.from_bus, line_.to_bus, line_.r_ohm_per_km * line_.length_km / Zni, |
|
1748 | - | line_.x_ohm_per_km * line_.length_km / Zni, sn_mva[i], name=line_.name, |
|
1773 | + | line_.x_ohm_per_km * line_.length_km / Zni, sn_mva[i], name=line_.name, |
|
1749 | 1774 | in_service=line_.in_service)) |
|
1750 | 1775 | i += 1 |
|
1751 | 1776 | drop_lines(net, index) |
@@ -2150,9 +2175,9 @@
Loading
2150 | 2175 | to_add_shunt = net.res_ward.loc[wards, ["p_mw", "q_mvar", "vm_pu"]] |
|
2151 | 2176 | to_add_shunt.index = new_shunt_idx |
|
2152 | 2177 | to_add_shunt.p_mw = net.res_ward.vm_pu[wards].values ** 2 * net.ward.pz_mw[wards].values * \ |
|
2153 | - | sign_in_service * sign_not_isolated |
|
2154 | - | to_add_shunt.q_mvar = net.res_ward.vm_pu[wards].values ** 2 * net.ward.qz_mvar[wards].values * \ |
|
2155 | - | sign_in_service * sign_not_isolated |
|
2178 | + | sign_in_service * sign_not_isolated |
|
2179 | + | to_add_shunt.q_mvar = net.res_ward.vm_pu[wards].values ** 2 * net.ward.qz_mvar[ |
|
2180 | + | wards].values * sign_in_service * sign_not_isolated |
|
2156 | 2181 | to_add_shunt.vm_pu = net.res_ward.vm_pu[wards].values |
|
2157 | 2182 | net.res_shunt = pd.concat([net.res_shunt, to_add_shunt]) |
|
2158 | 2183 |
@@ -2193,8 +2218,9 @@
Loading
2193 | 2218 | in_service=xward.in_service, name=xward.name) |
|
2194 | 2219 | create_gen(net, bus_idx, 0, xward.vm_pu, in_service=xward.in_service, |
|
2195 | 2220 | name=xward.name) |
|
2196 | - | create_impedance(net, xward.bus, bus_idx, xward.r_ohm / (bus_v ** 2), xward.x_ohm / (bus_v ** 2), |
|
2197 | - | net.sn_mva, in_service=xward.in_service, name=xward.name) |
|
2221 | + | create_impedance(net, xward.bus, bus_idx, xward.r_ohm / (bus_v ** 2), |
|
2222 | + | xward.x_ohm / (bus_v ** 2), net.sn_mva, in_service=xward.in_service, |
|
2223 | + | name=xward.name) |
|
2198 | 2224 | ||
2199 | 2225 | # --- result data |
|
2200 | 2226 | if net.res_xward.shape[0]: |
@@ -2395,8 +2421,8 @@
Loading
2395 | 2421 | will be respected |
|
2396 | 2422 | False: in_service status will be |
|
2397 | 2423 | ignored |
|
2398 | - | **consider** (iterable, ("l", "s", "t", "t3", "i")) - Determines, which types of connections will |
|
2399 | - | be considered. |
|
2424 | + | **consider** (iterable, ("l", "s", "t", "t3", "i")) - Determines, which types of |
|
2425 | + | connections will be considered. |
|
2400 | 2426 | l: lines |
|
2401 | 2427 | s: switches |
|
2402 | 2428 | t: trafos |
@@ -2412,12 +2438,13 @@
Loading
2412 | 2438 | cb = set() |
|
2413 | 2439 | if "l" in consider or 'line' in consider: |
|
2414 | 2440 | in_service_constr = net.line.in_service if respect_in_service else True |
|
2415 | - | opened_lines = set(net.switch.loc[(~net.switch.closed) & |
|
2416 | - | (net.switch.et == "l")].element.unique()) if respect_switches else set() |
|
2417 | - | connected_fb_lines = set(net.line.index[(net.line.from_bus.isin(buses)) & |
|
2418 | - | ~net.line.index.isin(opened_lines) & in_service_constr]) |
|
2419 | - | connected_tb_lines = set(net.line.index[(net.line.to_bus.isin(buses)) & |
|
2420 | - | ~net.line.index.isin(opened_lines) & in_service_constr]) |
|
2441 | + | opened_lines = set(net.switch.loc[(~net.switch.closed) & ( |
|
2442 | + | net.switch.et == "l")].element.unique()) if respect_switches else set() |
|
2443 | + | connected_fb_lines = set(net.line.index[( |
|
2444 | + | net.line.from_bus.isin(buses)) & ~net.line.index.isin(opened_lines) & |
|
2445 | + | in_service_constr]) |
|
2446 | + | connected_tb_lines = set(net.line.index[( |
|
2447 | + | net.line.to_bus.isin(buses)) & ~net.line.index.isin(opened_lines) & in_service_constr]) |
|
2421 | 2448 | cb |= set(net.line[net.line.index.isin(connected_tb_lines)].from_bus) |
|
2422 | 2449 | cb |= set(net.line[net.line.index.isin(connected_fb_lines)].to_bus) |
|
2423 | 2450 |
@@ -2429,12 +2456,14 @@
Loading
2429 | 2456 | ||
2430 | 2457 | if "t" in consider or 'trafo' in consider: |
|
2431 | 2458 | in_service_constr = net.trafo.in_service if respect_in_service else True |
|
2432 | - | opened_trafos = set(net.switch.loc[(~net.switch.closed) & |
|
2433 | - | (net.switch.et == "t")].element.unique()) if respect_switches else set() |
|
2434 | - | connected_hvb_trafos = set(net.trafo.index[(net.trafo.hv_bus.isin(buses)) & |
|
2435 | - | ~net.trafo.index.isin(opened_trafos) & in_service_constr]) |
|
2436 | - | connected_lvb_trafos = set(net.trafo.index[(net.trafo.lv_bus.isin(buses)) & |
|
2437 | - | ~net.trafo.index.isin(opened_trafos) & in_service_constr]) |
|
2459 | + | opened_trafos = set(net.switch.loc[(~net.switch.closed) & ( |
|
2460 | + | net.switch.et == "t")].element.unique()) if respect_switches else set() |
|
2461 | + | connected_hvb_trafos = set(net.trafo.index[( |
|
2462 | + | net.trafo.hv_bus.isin(buses)) & ~net.trafo.index.isin(opened_trafos) & |
|
2463 | + | in_service_constr]) |
|
2464 | + | connected_lvb_trafos = set(net.trafo.index[( |
|
2465 | + | net.trafo.lv_bus.isin(buses)) & ~net.trafo.index.isin(opened_trafos) & |
|
2466 | + | in_service_constr]) |
|
2438 | 2467 | cb |= set(net.trafo.loc[connected_lvb_trafos].hv_bus.values) |
|
2439 | 2468 | cb |= set(net.trafo.loc[connected_hvb_trafos].lv_bus.values) |
|
2440 | 2469 |
@@ -2442,28 +2471,34 @@
Loading
2442 | 2471 | if "t3" in consider or 'trafo3w' in consider: |
|
2443 | 2472 | in_service_constr3w = net.trafo3w.in_service if respect_in_service else True |
|
2444 | 2473 | if respect_switches: |
|
2445 | - | opened_buses_hv = set(net.switch.loc[~net.switch.closed & (net.switch.et == "t3") & |
|
2446 | - | net.switch.bus.isin(net.trafo3w.hv_bus)].bus.unique()) |
|
2447 | - | opened_buses_mv = set(net.switch.loc[~net.switch.closed & (net.switch.et == "t3") & |
|
2448 | - | net.switch.bus.isin(net.trafo3w.mv_bus)].bus.unique()) |
|
2449 | - | opened_buses_lv = set(net.switch.loc[~net.switch.closed & (net.switch.et == "t3") & |
|
2450 | - | net.switch.bus.isin(net.trafo3w.lv_bus)].bus.unique()) |
|
2474 | + | opened_buses_hv = set(net.switch.loc[ |
|
2475 | + | ~net.switch.closed & (net.switch.et == "t3") & |
|
2476 | + | net.switch.bus.isin(net.trafo3w.hv_bus)].bus.unique()) |
|
2477 | + | opened_buses_mv = set(net.switch.loc[ |
|
2478 | + | ~net.switch.closed & (net.switch.et == "t3") & |
|
2479 | + | net.switch.bus.isin(net.trafo3w.mv_bus)].bus.unique()) |
|
2480 | + | opened_buses_lv = set(net.switch.loc[ |
|
2481 | + | ~net.switch.closed & (net.switch.et == "t3") & |
|
2482 | + | net.switch.bus.isin(net.trafo3w.lv_bus)].bus.unique()) |
|
2451 | 2483 | else: |
|
2452 | 2484 | opened_buses_hv = opened_buses_mv = opened_buses_lv = set() |
|
2453 | 2485 | ||
2454 | - | hvb_trafos3w = set(net.trafo3w.index[net.trafo3w.hv_bus.isin(buses) & |
|
2455 | - | ~net.trafo3w.hv_bus.isin(opened_buses_hv) & in_service_constr3w]) |
|
2456 | - | mvb_trafos3w = set(net.trafo3w.index[net.trafo3w.mv_bus.isin(buses) & |
|
2457 | - | ~net.trafo3w.mv_bus.isin(opened_buses_mv) & in_service_constr3w]) |
|
2458 | - | lvb_trafos3w = set(net.trafo3w.index[net.trafo3w.lv_bus.isin(buses) & |
|
2459 | - | ~net.trafo3w.lv_bus.isin(opened_buses_lv) & in_service_constr3w]) |
|
2460 | - | ||
2461 | - | cb |= (set(net.trafo3w.loc[hvb_trafos3w].mv_bus) | set(net.trafo3w.loc[hvb_trafos3w].lv_bus) - |
|
2462 | - | opened_buses_mv - opened_buses_lv) |
|
2463 | - | cb |= (set(net.trafo3w.loc[mvb_trafos3w].hv_bus) | set(net.trafo3w.loc[mvb_trafos3w].lv_bus) - |
|
2464 | - | opened_buses_hv - opened_buses_lv) |
|
2465 | - | cb |= (set(net.trafo3w.loc[lvb_trafos3w].hv_bus) | set(net.trafo3w.loc[lvb_trafos3w].mv_bus) - |
|
2466 | - | opened_buses_hv - opened_buses_mv) |
|
2486 | + | hvb_trafos3w = set(net.trafo3w.index[ |
|
2487 | + | net.trafo3w.hv_bus.isin(buses) & ~net.trafo3w.hv_bus.isin(opened_buses_hv) & |
|
2488 | + | in_service_constr3w]) |
|
2489 | + | mvb_trafos3w = set(net.trafo3w.index[ |
|
2490 | + | net.trafo3w.mv_bus.isin(buses) & ~net.trafo3w.mv_bus.isin(opened_buses_mv) & |
|
2491 | + | in_service_constr3w]) |
|
2492 | + | lvb_trafos3w = set(net.trafo3w.index[ |
|
2493 | + | net.trafo3w.lv_bus.isin(buses) & ~net.trafo3w.lv_bus.isin(opened_buses_lv) & |
|
2494 | + | in_service_constr3w]) |
|
2495 | + | ||
2496 | + | cb |= (set(net.trafo3w.loc[hvb_trafos3w].mv_bus) | set( |
|
2497 | + | net.trafo3w.loc[hvb_trafos3w].lv_bus) - opened_buses_mv - opened_buses_lv) |
|
2498 | + | cb |= (set(net.trafo3w.loc[mvb_trafos3w].hv_bus) | set( |
|
2499 | + | net.trafo3w.loc[mvb_trafos3w].lv_bus) - opened_buses_hv - opened_buses_lv) |
|
2500 | + | cb |= (set(net.trafo3w.loc[lvb_trafos3w].hv_bus) | set( |
|
2501 | + | net.trafo3w.loc[lvb_trafos3w].mv_bus) - opened_buses_hv - opened_buses_mv) |
|
2467 | 2502 | ||
2468 | 2503 | if "i" in consider or 'impedance' in consider: |
|
2469 | 2504 | in_service_constr = net.impedance.in_service if respect_in_service else True |
@@ -2571,7 +2606,8 @@
Loading
2571 | 2606 | for et in consider: |
|
2572 | 2607 | if et == 'b': |
|
2573 | 2608 | cs |= set(net['switch'].index[ |
|
2574 | - | (net['switch']['bus'].isin(buses) | net['switch']['element'].isin(buses)) & |
|
2609 | + | (net['switch']['bus'].isin(buses) | |
|
2610 | + | net['switch']['element'].isin(buses)) & |
|
2575 | 2611 | (net['switch']['et'] == 'b') & switch_selection]) |
|
2576 | 2612 | else: |
|
2577 | 2613 | cs |= set(net['switch'].index[(net['switch']['bus'].isin(buses)) & |
@@ -2610,7 +2646,8 @@
Loading
2610 | 2646 | This function is based on the code in mem_top module |
|
2611 | 2647 | Summarize object types that are tracket by the garbage collector in the moment. |
|
2612 | 2648 | Useful to test if there are memoly leaks. |
|
2613 | - | :return: dictionary with keys corresponding to types and values to the number of objects of the type |
|
2649 | + | :return: dictionary with keys corresponding to types and values to the number of objects of the |
|
2650 | + | type |
|
2614 | 2651 | """ |
|
2615 | 2652 | objs = gc.get_objects() |
|
2616 | 2653 | nums_by_types = dict() |
@@ -2623,9 +2660,10 @@
Loading
2623 | 2660 | ||
2624 | 2661 | def repl_to_line(net, idx, std_type, name=None, in_service=False, **kwargs): |
|
2625 | 2662 | """ |
|
2626 | - | creates a power line in parallel to the existing power line based on the values of the new std_type. |
|
2627 | - | The new parallel line has an impedance value, which is chosen so that the resulting impedance of the new line |
|
2628 | - | and the already existing line is equal to the impedance of the replaced line. Or for electrical engineers: |
|
2663 | + | creates a power line in parallel to the existing power line based on the values of the new |
|
2664 | + | std_type. The new parallel line has an impedance value, which is chosen so that the resulting |
|
2665 | + | impedance of the new line and the already existing line is equal to the impedance of the |
|
2666 | + | replaced line. Or for electrical engineers: |
|
2629 | 2667 | ||
2630 | 2668 | Z0 = impedance of the existing line |
|
2631 | 2669 | Z1 = impedance of the replaced line |
@@ -2682,14 +2720,13 @@
Loading
2682 | 2720 | max_i_ka = i_ka1 - i_ka0 |
|
2683 | 2721 | name = "repl_" + str(idx) if name is None else name |
|
2684 | 2722 | ||
2685 | - | # if this line is in service to the existing line, the power flow result should be the same as when replacing the |
|
2686 | - | # existing line with the desired standard type |
|
2687 | - | new_idx = create_line_from_parameters(net, from_bus=net.line.at[idx, "from_bus"], |
|
2688 | - | to_bus=net.line.at[idx, "to_bus"], |
|
2689 | - | length_km=net.line.at[idx, "length_km"], r_ohm_per_km=r_ohm_per_km, |
|
2690 | - | x_ohm_per_km=x_ohm_per_km, |
|
2691 | - | c_nf_per_km=c_nf_per_km, max_i_ka=max_i_ka, g_us_per_km=g_us_per_km, |
|
2692 | - | in_service=in_service, name=name, **kwargs) |
|
2723 | + | # if this line is in service to the existing line, the power flow result should be the same as |
|
2724 | + | # when replacing the existing line with the desired standard type |
|
2725 | + | new_idx = create_line_from_parameters( |
|
2726 | + | net, from_bus=net.line.at[idx, "from_bus"], to_bus=net.line.at[idx, "to_bus"], |
|
2727 | + | length_km=net.line.at[idx, "length_km"], r_ohm_per_km=r_ohm_per_km, |
|
2728 | + | x_ohm_per_km=x_ohm_per_km, c_nf_per_km=c_nf_per_km, max_i_ka=max_i_ka, |
|
2729 | + | g_us_per_km=g_us_per_km, in_service=in_service, name=name, **kwargs) |
|
2693 | 2730 | # restore the previous line parameters before changing the standard type |
|
2694 | 2731 | net.line.loc[idx, :] = bak |
|
2695 | 2732 | return new_idx |
Files | Coverage |
---|---|
pandapower | 87.60% |
setup.py | 0.00% |
Project Totals (162 files) | 87.52% |
610742562
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.