Toolbox
The pandapower toolbox is a collection of helper functions that are implemented for the pandapower framework. It is designed for functions of common application that fit nowhere else. Have a look at the available functions to save yourself the effort of maybe implementing something twice. If you develop some functionality which could be interesting to other users as well and do not fit into one of the specialized packages, feel welcome to add your contribution. To improve overview functions are loosely grouped by functionality, please adhere to this notion when adding your own functions and feel free to open new groups as needed.
Comparison
- pandapower.toolbox.dataframes_equal(df1, df2, ignore_index_order=True, **kwargs)
Returns a boolean whether the given two dataframes are equal or not.
- pandapower.toolbox.compare_arrays(x, y)
Returns an array of bools whether array x is equal to array y. Strings are allowed in x or y. NaN values are assumed as equal.
- pandapower.toolbox.nets_equal(net1, net2, check_only_results=False, check_without_results=False, exclude_elms=None, name_selection=None, **kwargs)
Returns a boolean whether the two given pandapower networks are equal.
pandapower net keys starting with “_” are ignored. Same for the key “et” (elapsed time).
If the element tables contain JSONSerializableClass objects, they will also be compared: attributes are compared but not the addresses of the objects.
- INPUT:
net1 (pandapowerNet)
net2 (pandapowerNet)
- OPTIONAL:
check_only_results (bool, False) - if True, only result tables (starting with
res_
) are comparedcheck_without_results (bool, False) - if True, result tables (starting with
res_
) are ignored for comparisonexclude_elms (list, None) - list of element tables which should be ignored in the comparison
name_selection (list, None) - list of element tables which should be compared
kwargs - key word arguments for dataframes_equal()
- pandapower.toolbox.nets_equal_keys(net1, net2, check_only_results, check_without_results, exclude_elms, name_selection, **kwargs)
Returns a lists of keys which are 1) not equal and 2) not checked. Used within nets_equal().
Power Factor
- pandapower.toolbox.signing_system_value(element_type)
Returns a 1 for all bus elements using the consumver viewpoint and a -1 for all bus elements using the generator viewpoint.
- pandapower.toolbox.pq_from_cosphi(s, cosphi, qmode, pmode)
Calculates P/Q values from rated apparent power and cosine(phi) values.
s: rated apparent power
cosphi: cosine phi of the
qmode: “underexcited” (Q absorption, decreases voltage) or “overexcited” (Q injection, increases voltage)
pmode: “load” for load or “gen” for generation
As all other pandapower functions this function is based on the consumer viewpoint. For active power, that means that loads are positive and generation is negative. For reactive power, underexcited behavior (Q absorption, decreases voltage) is modeled with positive values, overexcited behavior (Q injection, increases voltage) with negative values.
- pandapower.toolbox.cosphi_from_pq(p, q)
Analog to pq_from_cosphi, but the other way around. In consumer viewpoint (pandapower): “underexcited” (Q absorption, decreases voltage) and “overexcited” (Q injection, increases voltage)
Result Information
- pandapower.toolbox.lf_info(net, numv=1, numi=2)
Prints some basic information of the results in a net (max/min voltage, max trafo load, max line load).
OPTIONAL:
numv (integer, 1) - maximal number of printed maximal respectively minimal voltages
numi (integer, 2) - maximal number of printed maximal loading at trafos or lines
- pandapower.toolbox.opf_task(net, delta_pq=0.001, keep=False, log=True)
Collects some basic inforamtion of the optimal powerflow task und prints them.
- pandapower.toolbox.switch_info(net, sidx)
Prints what buses and elements are connected by a certain switch.
- pandapower.toolbox.overloaded_lines(net, max_load=100)
Returns the results for all lines with loading_percent > max_load or None, if there are none.
- pandapower.toolbox.violated_buses(net, min_vm_pu, max_vm_pu)
Returns all bus indices where vm_pu is not within min_vm_pu and max_vm_pu or returns None, if there are none of those buses.
- pandapower.toolbox.clear_result_tables(net)
Clears all
res_
DataFrames in net.
- pandapower.toolbox.res_power_columns(element_type, side=0)
Returns columns names of result tables for active and reactive power
- Parameters:
- element_typestr
name of element table, e.g. “gen”
- sidetyping.Union[int, str], optional
Defines for branch elements which branch side is considered, by default 0
- Returns:
- list[str]
columns names of result tables for active and reactive power
Examples
>>> res_power_columns("gen") ["p_mw", "q_mvar"] >>> res_power_columns("line", "from") ["p_from_mw", "q_from_mvar"] >>> res_power_columns("line", 0) ["p_from_mw", "q_from_mvar"] >>> res_power_columns("line", "all") ["p_from_mw", "q_from_mvar", "p_to_mw", "q_to_mvar"]
Item/Element Selection
- pandapower.toolbox.get_element_index(net, element_type, name, exact_match=True)
Returns the element(s) identified by a name or regex and its element-table.
- INPUT:
net - pandapower network
element_type - Table to get indices from (“line”, “bus”, “trafo” etc.)
name - Name of the element to match.
- OPTIONAL:
- exact_match (boolean, True) -
True: Expects exactly one match, raises UserWarning otherwise. False: returns all indices containing the name
- OUTPUT:
index - The index (or indices in case of exact_match=False) of matching element(s).
- pandapower.toolbox.get_element_indices(net, element_type, name, exact_match=True)
Returns a list of element(s) identified by a name or regex and its element-table -> Wrapper function of get_element_index()
- INPUT:
net - pandapower network
element_type (str, string iterable) - Element table to get indices from (“line”, “bus”, “trafo” etc.).
name (str) - Name of the element to match.
- OPTIONAL:
exact_match (boolean, True)
True: Expects exactly one match, raises UserWarning otherwise.
False: returns all indices containing the name
- OUTPUT:
index (list) - List of the indices of matching element(s).
- EXAMPLE:
>>> import pandapower.networks as pn >>> import pandapower as pp >>> net = pn.example_multivoltage() >>> # get indices of only one element type (buses in this example): >>> pp.get_element_indices(net, "bus", ["Bus HV%i" % i for i in range(1, 4)]) [32, 33, 34] >>> # get indices of only two element type (first buses, second lines): >>> pp.get_element_indices(net, ["bus", "line"], "HV", exact_match=False) [Int64Index([32, 33, 34, 35], dtype='int64'), Int64Index([0, 1, 2, 3, 4, 5], dtype='int64')] >>> pp.get_element_indices(net, ["bus", "line"], ["Bus HV3", "MV Line6"]) [34, 11]
- pandapower.toolbox.next_bus(net, bus, element_id, et='line', **kwargs)
Returns the index of the second bus an element is connected to, given a first one. E.g. the from_bus given the to_bus of a line.
- Parameters:
- netpandapowerNet
pandapower net
- busint
index of bus
- element_idint
index of element
- etstr, optional
which branch element type to consider, by default ‘line’
- Returns:
- int
index of next connected bus
- pandapower.toolbox.get_connected_elements(net, element_type, buses, respect_switches=True, respect_in_service=False)
Returns elements connected to a given buses.
- INPUT:
net (pandapowerNet)
element_type (string, name of the element table)
buses (single integer or iterable of ints)
- OPTIONAL:
respect_switches (boolean, True)
True: open switches will be respected
False: open switches will be ignored
respect_in_service (boolean, False)
True: in_service status of connected lines will be respected
False: in_service status will be ignored
- OUTPUT:
connected_elements (set) - Returns connected elements.
- pandapower.toolbox.get_connected_elements_dict(net, buses, respect_switches=True, respect_in_service=False, include_empty_lists=False, element_types=None, **kwargs)
Returns a dict of lists of connected elements.
- Parameters:
- net_type_
_description_
- busesiterable of buses
buses as origin to search for connected elements
- respect_switchesbool, optional
_description_, by default True
- respect_in_servicebool, optional
_description_, by default False
- include_empty_listsbool, optional
if True, the output doesn’t have values of empty lists but may lack of element types as keys, by default False
- element_typesiterable of strings, optional
types elements which are analyzed for connection. If not given, all pandapower element types are analyzed. That list of all element types can also be restricted by key word arguments “connected_buses”, “connected_bus_elements”, “connected_branch_elements” and “connected_other_elements”, by default None
- Returns:
- dict[str,list]
elements connected to given buses
- pandapower.toolbox.get_connected_buses(net, buses, consider=('l', 's', 't', 't3', 'i'), respect_switches=True, respect_in_service=False)
Returns buses connected to given buses. The source buses will NOT be returned.
- INPUT:
net (pandapowerNet)
buses (single integer or iterable of ints)
- OPTIONAL:
respect_switches (boolean, True)
True: open switches will be respected
False: open switches will be ignored
respect_in_service (boolean, False)
True: in_service status of connected buses will be respected
False: in_service status will be ignored
consider (iterable, (“l”, “s”, “t”, “t3”, “i”)) - Determines, which types of connections will be considered.
l: lines
s: switches
t: trafos
t3: trafo3ws
i: impedances
- OUTPUT:
cl (set) - Returns connected buses.
- pandapower.toolbox.get_connected_buses_at_element(net, element_index, element_type, respect_in_service=False)
Returns buses connected to a given branch element. In case of a bus switch, two buses will be returned, else one.
- INPUT:
net (pandapowerNet)
element_index (integer)
element_type (string) - Type of the source element:
l, line: line
s, switch: switch
t, trafo: trafo
t3, trafo3w: trafo3w
i, impedance: impedance
- OPTIONAL:
respect_in_service (boolean, False)
True: in_service status of connected buses will be respected
False: in_service status will be ignored
- OUTPUT:
cl (set) - Returns connected switches.
- pandapower.toolbox.get_connected_switches(net, buses, consider=('b', 'l', 't', 't3', 'i'), status='all', include_element_connections=False)
Returns switches connected to given buses.
- INPUT:
net (pandapowerNet)
buses (single integer or iterable of ints)
- OPTIONAL:
- consider (iterable, (“l”, “s”, “t”, “t3)) - Determines, which types of connections
will be considered. l: lines b: bus-bus-switches t: transformers t3: 3W transformers i: impedance
- status (string, (“all”, “closed”, “open”)) - Determines, which switches will
be considered
include_element_connections (bool, False) - If True, also the other bus of the connected element, e.g. the other line ending, is included
- OUTPUT:
cl (set) - Returns connected switches.
- pandapower.toolbox.get_connecting_branches(net, buses1, buses2, branch_elements=None)
Gets/Drops branches that connects any bus of buses1 with any bus of buses2.
- pandapower.toolbox.false_elm_links(net, element_type, col, target_element_type)
Returns which indices have links to elements of other element tables which does not exist in the net.
Examples
>>> false_elm_links(net, "line", "to_bus", "bus") # exemplary input 1 >>> false_elm_links(net, "poly_cost", "element", net["poly_cost"]["et"]) # exemplary input 2
- pandapower.toolbox.false_elm_links_loop(net, element_types=None)
Returns a dict of elements which indices have links to elements of other element tables which does not exist in the net. This function is an outer loop for get_false_links() applications.
- pandapower.toolbox.element_bus_tuples(bus_elements=True, branch_elements=True, res_elements=False)
Utility function Provides the tuples of elements and corresponding columns for buses they are connected to :param bus_elements: whether tuples for bus elements e.g. load, sgen, … are included :param branch_elements: whether branch elements e.g. line, trafo, … are included :param res_elements: whether result table names e.g. res_sgen, res_line, … are included :param return_type: which type the output has :return: list of tuples with element names and column names
- pandapower.toolbox.pp_elements(bus=True, bus_elements=True, branch_elements=True, other_elements=True, cost_tables=False, res_elements=False)
Returns a set of pandapower elements.
- pandapower.toolbox.branch_element_bus_dict(include_switch=False, sort=None)
Returns a dict with keys of branch elements and values of bus column names as list.
- pandapower.toolbox.count_elements(net, return_empties=False, **kwargs)
Counts how much elements of which element type exist in the pandapower net
- Parameters:
- netpandapowerNet
pandapower net
- return_emptiesbool, optional
whether element types should be listed if no element exist, by default False
- Returns:
- pd.Series
number of elements per element type existing in the net
- Other Parameters:
- kwargsdict[str,bool], optional
arguments (passed to pp_elements()) to narrow considered element types. If nothing is passed, an empty dict is passed to pp_elements(), by default None
See also
count_group_elements
Examples
>>> import pandapower as pp >>> import pandapower.networks as nw >>> pp.count_elements(nw.case9(), bus_elements=False) bus 9 line 9 dtype: int32
- pandapower.toolbox.get_gc_objects_dict()
This function is based on the code in mem_top module Summarize object types that are tracket by the garbage collector in the moment. Useful to test if there are memoly leaks. :return: dictionary with keys corresponding to types and values to the number of objects of the type
Data Modification
- pandapower.toolbox.add_column_from_node_to_elements(net, column, replace, elements=None, branch_bus=None, verbose=True)
Adds column data to elements, inferring them from the column data of buses they are connected to.
- INPUT:
net (pandapowerNet) - the pandapower net that will be changed
column (string) - name of column that should be copied from the bus table to the element table
replace (boolean) - if True, an existing column in the element table will be overwritten
elements (list) - list of elements that should get the column values from the bus table
branch_bus (list) - defines which bus should be considered for branch elements. ‘branch_bus’ must have the length of 2. One entry must be ‘from_bus’ or ‘to_bus’, the other ‘hv_bus’ or ‘lv_bus’
- EXAMPLE:
compare to add_zones_to_elements()
- pandapower.toolbox.add_column_from_element_to_elements(net, column, replace, elements=None, continue_on_missing_column=True)
Adds column data to elements, inferring them from the column data of the elements linked by the columns “element” and “element_type” or “et”.
- INPUT:
net (pandapowerNet) - the pandapower net that will be changed
column (string) - name of column that should be copied from the tables of the elements.
replace (boolean) - if True, an existing column will be overwritten
elements (list) - list of elements that should get the column values from the linked element tables. If None, all elements with the columns “element” and “element_type” or “et” are considered (these are currently “measurement” and “switch”).
continue_on_missing_column (Boolean, True) - If False, a error will be raised in case of an element table has no column ‘column’ although this element is refered in ‘elements’. E.g. ‘measurement’ is in ‘elements’ and in net.measurement is a trafo measurement but in net.trafo there is no column ‘name’ although column==’name’ - ni this case ‘continue_on_missing_column’ acts.
- EXAMPLE:
import pandapower as pp import pandapower.networks as pn net = pn.create_cigre_network_mv() pp.create_measurement(net, “i”, “trafo”, 5, 3, 0, side=”hv”) pp.create_measurement(net, “i”, “line”, 5, 3, 0, side=”to”) pp.create_measurement(net, “p”, “bus”, 5, 3, 2) print(net.measurement.name.values, net.switch.name.values) pp.add_column_from_element_to_elements(net, “name”, True) print(net.measurement.name.values, net.switch.name.values)
- pandapower.toolbox.add_zones_to_elements(net, replace=True, elements=None, **kwargs)
Adds zones to elements, inferring them from the zones of buses they are connected to.
- pandapower.toolbox.reindex_buses(net, bus_lookup)
Changes the index of net.bus and considers the new bus indices in all other pandapower element tables.
- INPUT:
net - pandapower network
bus_lookup (dict) - the keys are the old bus indices, the values the new bus indices
- pandapower.toolbox.create_continuous_bus_index(net, start=0, store_old_index=False)
Creates a continuous bus index starting at ‘start’ and replaces all references of old indices by the new ones.
- INPUT:
net - pandapower network
- OPTIONAL:
start - index begins with “start”
store_old_index - if True, stores the old index in net.bus[“old_index”]
- OUTPUT:
bus_lookup - mapping of old to new index
- pandapower.toolbox.reindex_elements(net, element_type, new_indices=None, old_indices=None, lookup=None)
Changes the index of the DataFrame net[element_type].
- Parameters:
- netpp.pandapowerNet
net with elements to reindex
- element_typestr
name of element type to rename, e.g. “gen” or “load”
- new_indicestyping.Union[list[int], pandas.Index[int]], optional
new indices to set, by default None
- old_indicestyping.Union[list[int], pandas.Index[int]], optional
old indices to be replaced. If not given, all indices are assumed in case of given new_indices, and all lookup keys are assumed in case of given lookup, by default None
- lookupdict[int,int], optional
lookup to assign new indices to old indices, by default None
Notes
Either new_indices or lookup must be given. old_indices can be given to limit the indices to be replaced. In case of given new_indices, both must have the same length. If element_type is “group”, be careful to give new_indices without passing old_indices because group indices do not need to be unique.
Examples
>>> net = pp.create_empty_network() >>> idx0 = pp.create_bus(net, 110) >>> idx1 = 4 >>> idx2 = 7 >>> # Reindex using 'new_indices': >>> pp.reindex_elements(net, "bus", [idx1]) # passing old_indices=[idx0] is optional >>> net.bus.index Int64Index([4], dtype='int64') >>> # Reindex using 'lookup': >>> pp.reindex_elements(net, "bus", lookup={idx1: idx2}) Int64Index([7], dtype='int64')
- pandapower.toolbox.create_continuous_elements_index(net, start=0, add_df_to_reindex={})
Creating a continuous index for all the elements, starting at zero and replaces all references of old indices by the new ones.
- INPUT:
net - pandapower network with unodered indices
- OPTIONAL:
start - index begins with “start”
add_df_to_reindex - by default all useful pandapower elements for power flow will be selected. Customized DataFrames can also be considered here.
- OUTPUT:
net - pandapower network with odered and continuous indices
- pandapower.toolbox.set_scaling_by_type(net, scalings, scale_load=True, scale_sgen=True)
Sets scaling of loads and/or sgens according to a dictionary mapping type to a scaling factor. Note that the type-string is case sensitive. E.g. scaling = {“pv”: 0.8, “bhkw”: 0.6}
- Parameters:
net
scalings – A dictionary containing a mapping from element type to
scale_load
scale_sgen
- pandapower.toolbox.set_data_type_of_columns_to_default(net)
Overwrites dtype of DataFrame columns of PandapowerNet elements to default dtypes defined in pandapower. The function “convert_format” does that authomatically for nets saved with pandapower versions below 1.6. If this is required for versions starting with 1.6, it should be done manually with this function.
- INPUT:
net - pandapower network with unodered indices
- OUTPUT:
No output; the net passed as input has pandapower-default dtypes of columns in element tables.
- pandapower.toolbox.get_inner_branches(net, buses, branch_elements=None)
Returns indices of branches that connects buses within ‘buses’ at all branch sides (e.g. ‘from_bus’ and ‘to_bus’).
Electric Grid Modification
- pandapower.toolbox.select_subnet(net, buses, include_switch_buses=False, include_results=False, keep_everything_else=False)
Selects a subnet by a list of bus indices and returns a net with all elements connected to them.
- pandapower.toolbox.merge_nets(net1, net2, validate=True, merge_results=True, tol=1e-09, **kwargs)
Function to concatenate two nets into one data structure. The elements keep their indices unless both nets have the same indices. In that case, net2 elements get reindexed. The reindex lookup of net2 elements can be retrieved by passing return_net2_reindex_lookup=True.
- Parameters:
- net1pp.pandapowerNet
first net to concatenate
- net2pp.pandapowerNet
second net to concatenate
- validatebool, optional
whether power flow results should be compared against the results of the input nets, by default True
- merge_resultsbool, optional
whether results tables should be concatenated, by default True
- tolfloat, optional
tolerance which is allowed to pass the results validate check (relevant if validate is True), by default 1e-9
- std_prio_on_net1bool, optional
whether net1 standard type should be kept if net2 has types with same names, by default True
- return_net2_reindex_lookupbool, optional
if True, the merged net AND a dict of lookups is returned, by default False
- net2_reindex_log_levelstr, optional
logging level of the message which element types of net2 got reindexed elements. Options are, for example “debug”, “info”, “warning”, “error”, or None, by default “info”
- Returns:
- pp.pandapowerNet
net with concatenated element tables
- Raises:
- UserWarning
if validate is True and power flow results of the merged net deviate from input nets results
- pandapower.toolbox.set_element_status(net, buses, in_service)
Sets buses and all elements connected to them in or out of service.
- pandapower.toolbox.set_isolated_areas_out_of_service(net, respect_switches=True)
Set all isolated buses and all elements connected to isolated buses out of service.
- pandapower.toolbox.repl_to_line(net, idx, std_type, name=None, in_service=False, **kwargs)
creates a power line in parallel to the existing power line based on the values of the new std_type. The new parallel line has an impedance value, which is chosen so that the resulting impedance of the new line and the already existing line is equal to the impedance of the replaced line. Or for electrical engineers:
Z0 = impedance of the existing line
Z1 = impedance of the replaced line
Z2 = impedance of the created line
sketch:
--- Z2 --- ---| |--- = --- Z1 --- --- Z0 ---
- Parameters:
- net - pandapower net
- idx (int) - idx of the existing line
- std_type (str) - pandapower standard type
- name (str, None) - name of the new power line
- in_service (bool, False) - if the new power line is in service
- **kwargs - additional line parameters you want to set for the new line
- Returns:
- new_idx (int) - index of the created power line
- pandapower.toolbox.merge_parallel_line(net, idx)
Changes the impedances of the parallel line so that it equals a single line.
Z0 = impedance of the existing parallel lines
Z1 = impedance of the respective single line
sketch:
--- Z0 --- ---| |--- = --- Z1 --- --- Z0 ---
- Parameters:
- net - pandapower net
- idx (int) - idx of the line to merge
- Returns:
- net
- pandapower.toolbox.merge_same_bus_generation_plants(net, add_info=True, error=True, gen_elms=('ext_grid', 'gen', 'sgen'))
Merge generation plants connected to the same buses so that a maximum of one generation plants per node remains.
- ATTENTION:
gen_elms should always be given in order of slack (1.), PV (2.) and PQ (3.) elements.
- INPUT:
net - pandapower net
- OPTIONAL:
add_info (bool, True) - If True, the column ‘includes_other_plants’ is added to the elements dataframes. This column informs about which element table rows are the result of a merge of generation plants.
error (bool, True) - If True, raises an Error, if vm_pu values differ with same buses.
gen_elms (list, [“ext_grid”, “gen”, “sgen”]) - list of elements to be merged by same buses. Should be in order of slack (1.), PV (2.) and PQ (3.) elements.
- pandapower.toolbox.close_switch_at_line_with_two_open_switches(net)
Finds lines that have opened switches at both ends and closes one of them. Function is usually used when optimizing section points to prevent the algorithm from ignoring isolated lines.
- pandapower.toolbox.fuse_buses(net, b1, b2, drop=True, fuse_bus_measurements=True)
Reroutes any connections to buses in b2 to the given bus b1. Additionally drops the buses b2, if drop=True (default).
Dropping Elements
- pandapower.toolbox.drop_elements(net, element_type, element_index, **kwargs)
Drops element, result and group entries, as well as, associated elements from the pandapower net.
- pandapower.toolbox.drop_elements_simple(net, element_type, element_index)
Drops element, result and group entries from the pandapower net.
See also
drop_elements
providing more generic usage (inter-element connections considered)
- pandapower.toolbox.drop_buses(net, buses, drop_elements=True)
Drops specified buses, their bus_geodata and by default drops all elements connected to them as well.
- pandapower.toolbox.drop_trafos(net, trafos, table='trafo')
Deletes all trafos and in the given list of indices and removes any switches connected to it.
- pandapower.toolbox.drop_lines(net, lines)
Deletes all lines and their geodata in the given list of indices and removes any switches connected to it.
- pandapower.toolbox.drop_elements_at_buses(net, buses, bus_elements=True, branch_elements=True, drop_measurements=True)
drop elements connected to given buses
- pandapower.toolbox.drop_switches_at_buses(net, buses)
- pandapower.toolbox.drop_measurements_at_elements(net, element_type, idx=None, side=None)
Drop measurements of given element_type and (if given) given elements (idx) and side.
- pandapower.toolbox.drop_controllers_at_elements(net, element_type, idx=None)
Drop all the controllers for the given elements (idx).
- pandapower.toolbox.drop_controllers_at_buses(net, buses)
Drop all the controllers for the elements connected to the given buses.
- pandapower.toolbox.drop_duplicated_measurements(net, buses=None, keep='first')
Drops duplicated measurements at given set of buses. If buses is None, all buses are considered.
- pandapower.toolbox.drop_inner_branches(net, buses, branch_elements=None)
Drops branches that connects buses within ‘buses’ at all branch sides (e.g. ‘from_bus’ and ‘to_bus’).
- pandapower.toolbox.drop_out_of_service_elements(net)
Drop all elements (including corresponding dataframes such as switches, measurements, result tables, geodata) with “in_service” is False. Buses that are connected to in-service branches are not deleted.
- pandapower.toolbox.drop_inactive_elements(net, respect_switches=True)
Drops any elements not in service AND any elements connected to inactive buses.
Replacing Elements
- pandapower.toolbox.create_replacement_switch_for_branch(net, element_type, element_index)
Creates a switch parallel to a branch, connecting the same buses as the branch. The switch is closed if the branch is in service and open if the branch is out of service. The in_service status of the original branch is not affected and should be set separately, if needed.
- Parameters:
net – pandapower network
element_type – element_type table e. g. ‘line’, ‘impedance’
element_index – index of the branch e. g. 0
- Returns:
None
- pandapower.toolbox.replace_zero_branches_with_switches(net, elements=('line', 'impedance'), zero_length=True, zero_impedance=True, in_service_only=True, min_length_km=0, min_r_ohm_per_km=0, min_x_ohm_per_km=0, min_c_nf_per_km=0, min_rft_pu=0, min_xft_pu=0, min_rtf_pu=0, min_xtf_pu=0, drop_affected=False)
Creates a replacement switch for branches with zero impedance (line, impedance) and sets them out of service.
- Parameters:
net – pandapower network
elements – a tuple of names of element tables e. g. (‘line’, ‘impedance’) or (line)
zero_length – whether zero length lines will be affected
zero_impedance – whether zero impedance branches will be affected
in_service_only – whether the branches that are not in service will be affected
drop_affected – wheter the affected branch elements are dropped
min_length_km – threshhold for line length for a line to be considered zero line
min_r_ohm_per_km – threshhold for line R’ value for a line to be considered zero line
min_x_ohm_per_km – threshhold for line X’ value for a line to be considered zero line
min_c_nf_per_km – threshhold for line C’ for a line to be considered zero line
min_rft_pu – threshhold for R from-to value for impedance to be considered zero impedance
min_xft_pu – threshhold for X from-to value for impedance to be considered zero impedance
min_rtf_pu – threshhold for R to-from value for impedance to be considered zero impedance
min_xtf_pu – threshhold for X to-from value for impedance to be considered zero impedance
- Returns:
- pandapower.toolbox.replace_impedance_by_line(net, index=None, only_valid_replace=True, max_i_ka=nan)
Creates lines by given impedances data, while the impedances are dropped.
- INPUT:
net - pandapower net
- OPTIONAL:
index (index, None) - Index of all impedances to be replaced. If None, all impedances will be replaced.
only_valid_replace (bool, True) - If True, impedances will only replaced, if a replacement leads to equal power flow results. If False, unsymmetric impedances will be replaced by symmetric lines.
max_i_ka (value(s), False) - Data/Information how to set max_i_ka. If ‘imp.sn_mva’ is given, the sn_mva values of the impedances are considered.
- pandapower.toolbox.replace_line_by_impedance(net, index=None, sn_mva=None, only_valid_replace=True)
Creates impedances by given lines data, while the lines are dropped.
- INPUT:
net - pandapower net
- OPTIONAL:
index (index, None) - Index of all lines to be replaced. If None, all lines will be replaced.
sn_kva (list or array, None) - Values of sn_kva for creating the impedances. If None, the net.sn_kva is assumed
only_valid_replace (bool, True) - If True, lines will only replaced, if a replacement leads to equal power flow results. If False, capacitance and dielectric conductance will be neglected.
- pandapower.toolbox.replace_ext_grid_by_gen(net, ext_grids=None, gen_indices=None, slack=False, cols_to_keep=None, add_cols_to_keep=None)
Replaces external grids by generators.
- INPUT:
net - pandapower net
- OPTIONAL:
ext_grids (iterable) - indices of external grids which should be replaced
gen_indices (iterable) - required indices of new generators
slack (bool, False) - indicates which value is set to net.gen.slack for the new generators
cols_to_keep (list, None) - list of column names which should be kept while replacing ext_grids. If None these columns are kept if values exist: “max_p_mw”, “min_p_mw”, “max_q_mvar”, “min_q_mvar”. However cols_to_keep is given, these columns are always set: “bus”, “vm_pu”, “p_mw”, “name”, “in_service”, “controllable”
add_cols_to_keep (list, None) - list of column names which should be added to ‘cols_to_keep’ to be kept while replacing ext_grids.
- pandapower.toolbox.replace_gen_by_ext_grid(net, gens=None, ext_grid_indices=None, cols_to_keep=None, add_cols_to_keep=None)
Replaces generators by external grids.
- INPUT:
net - pandapower net
- OPTIONAL:
gens (iterable) - indices of generators which should be replaced
ext_grid_indices (iterable) - required indices of new external grids
cols_to_keep (list, None) - list of column names which should be kept while replacing gens. If None these columns are kept if values exist: “max_p_mw”, “min_p_mw”, “max_q_mvar”, “min_q_mvar”. However cols_to_keep is given, these columns are alway set: “bus”, “vm_pu”, “va_degree”, “name”, “in_service”
add_cols_to_keep (list, None) - list of column names which should be added to ‘cols_to_keep’ to be kept while replacing gens.
- pandapower.toolbox.replace_gen_by_sgen(net, gens=None, sgen_indices=None, cols_to_keep=None, add_cols_to_keep=None)
Replaces generators by static generators.
- INPUT:
net - pandapower net
- OPTIONAL:
gens (iterable) - indices of generators which should be replaced
sgen_indices (iterable) - required indices of new static generators
cols_to_keep (list, None) - list of column names which should be kept while replacing gens. If None these columns are kept if values exist: “max_p_mw”, “min_p_mw”, “max_q_mvar”, “min_q_mvar”. However cols_to_keep is given, these columns are always set: “bus”, “p_mw”, “q_mvar”, “name”, “in_service”, “controllable”
add_cols_to_keep (list, None) - list of column names which should be added to ‘cols_to_keep’ to be kept while replacing gens.
- pandapower.toolbox.replace_sgen_by_gen(net, sgens=None, gen_indices=None, cols_to_keep=None, add_cols_to_keep=None)
Replaces static generators by generators.
- INPUT:
net - pandapower net
- OPTIONAL:
sgens (iterable) - indices of static generators which should be replaced
gen_indices (iterable) - required indices of new generators
cols_to_keep (list, None) - list of column names which should be kept while replacing sgens. If None these columns are kept if values exist: “max_p_mw”, “min_p_mw”, “max_q_mvar”, “min_q_mvar”. However cols_to_keep is given, these columns are always set: “bus”, “vm_pu”, “p_mw”, “name”, “in_service”, “controllable”
add_cols_to_keep (list, None) - list of column names which should be added to ‘cols_to_keep’ to be kept while replacing sgens.
- pandapower.toolbox.replace_pq_elmtype(net, old_element_type, new_element_type, old_indices=None, new_indices=None, cols_to_keep=None, add_cols_to_keep=None)
Replaces e.g. static generators by loads or loads by storages and so forth.
- INPUT:
net - pandapower net
- old_element_type (str) - element type of which elements should be replaced. Should be in [
“sgen”, “load”, “storage”]
- new_element_type (str) - element type of which elements should be created. Should be in [
“sgen”, “load”, “storage”]
- OPTIONAL:
old_indices (iterable) - indices of the elements which should be replaced
new_indices (iterable) - required indices of the new elements
cols_to_keep (list, None) - list of column names which should be kept while replacing. If None these columns are kept if values exist: “max_p_mw”, “min_p_mw”, “max_q_mvar”, “min_q_mvar”. Independent whether cols_to_keep is given, these columns are always set: “bus”, “p_mw”, “q_mvar”, “name”, “in_service”, “controllable”
add_cols_to_keep (list, None) - list of column names which should be added to ‘cols_to_keep’ to be kept while replacing.
- OUTPUT:
new_idx (list) - list of indices of the new elements
- pandapower.toolbox.replace_ward_by_internal_elements(net, wards=None, log_level='warning')
Replaces wards by loads and shunts.
- INPUT:
net - pandapower net
- OPTIONAL:
wards (iterable) - indices of xwards which should be replaced
- OUTPUT:
No output - the given wards in pandapower net are replaced by loads and shunts
- pandapower.toolbox.replace_xward_by_internal_elements(net, xwards=None, set_xward_bus_limits=False, log_level='warning')
Replaces xward by loads, shunts, impedance and generators
- Parameters:
- netpandapowerNet
pandapower net
- xwardsiterable, optional
indices of xwards which should be replaced. If None, all xwards are replaced, by default None
- set_xward_bus_limitsbool, optional
if True, the buses internal in xwards get vm limits from the connected buses
- log_levelstr, optional
logging level of the message which element types of net2 got reindexed elements. Options are, for example “debug”, “info”, “warning”, “error”, or None, by default “info”
- Returns:
- None
the given xwards in pandapower are replaced by buses, loads, shunts, impadance and generators