Toolbox
The pandapipes toolbox is a collection of helper functions that are implemented for the pandapipes 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.
There are many similarities to the pandapower toolbox functions (c.f. this chapter in the pandapower documentation), but not all functions are transferred to pandapipes. If you want to extend the toolbox, feel free to open a new pull request.
Note
If you implement a function that might be useful for others, it is mandatory to add a short docstring to make browsing the toolbox practical. Ideally further comments if appropriate and a reference of authorship should be added as well.
General Issues
- element_junction_tuples(include_node_elements=True, include_branch_elements=True, include_res_elements=False, net=None)
Utility function Provides the tuples of elements and corresponding columns for junctions they are connected to
- Parameters:
include_node_elements (bool) – whether tuples for junction elements e.g. sink, source, are included
include_branch_elements (bool) – whether branch elements e.g. pipe, pumps, … are included
include_res_elements (bool) – whether to include result tables
net (pandapipesNet) – pandapipes net from which to derive component names
- Returns:
set of tuples with element names and column names
- Return type:
set
- pp_elements(junction=True, include_node_elements=True, include_branch_elements=True, include_res_elements=False, net=None)
Provides a list of all pandapipes elements belonging to the desired element types. If a net is given, the elements are derived from the component list.
- Parameters:
junction (bool, default True) – if True, return junction table name
include_node_elements (bool, default True) – if True, return node element table names
include_branch_elements (bool, default True) – if True, return branch element table names
include_res_elements (bool, default False) – if True, return result table names for all the elements
net (pandapipesNet) – if a pandapipes network is given, the table names will be derived from its component list
- Returns:
pp_elms - set of table names for the desired element types
- Return type:
set
Result and Net Information
- nets_equal(net1, net2, check_only_results=False, exclude_elms=None, **kwargs)
Compares the DataFrames of two networks.
The networks are considered equal if they share the same keys and values, except of the ‘et’ (elapsed time) entry which differs depending on runtime conditions and entries stating with ‘_’.
- Parameters:
net1 (pandapipesNet) – first net for comparison
net2 (pandapipesNet) – second net for comparison
check_only_results (bool, default False)
exclude_elms (list of strings, default None) – element types that should be skipped in the comparison
kwargs – key word arguments
- Returns:
True, if nets are equal
- Return type:
Bool
Simulation Setup and Preparation
- reindex_junctions(net, junction_lookup)
Changes the index of net.junction and considers the new junction indices in all other pandapipes element tables.
- Parameters:
net (pandapipesNet) – pandapipes network
junction_lookup (dict) – the keys are the old junction indices, the values the new junction indices
- Returns:
junction_lookup - the finally reindexed junction lookup (with corrections if necessary)
- Return type:
dict
- create_continuous_junction_index(net, start=0, store_old_index=False)
Creates a continuous junction index starting at ‘start’ and replaces all references of old indices by the new ones.
- Parameters:
net (pandapipesNet) – pandapipes network
start (int, default 0) – index begins with “start”
store_old_index (bool, default False) – if True, stores the old index in net.junction[“old_index”]
- Returns:
junction_lookup - mapping of old to new index
- Return type:
dict
- reindex_elements(net, element, new_indices, old_indices=None)
Changes the index of net[element].
- Parameters:
net (pandapipesNet) – pandapipes network
element (str) – name of the element table
new_indices (iterable) – list of new indices
old_indices (iterable, default None) – list of old/previous indices which will be replaced. If None, all indices are considered.
- Returns:
No output.
- create_continuous_elements_index(net, start=0, add_df_to_reindex=None)
Creating a continuous index for all the elements, starting at zero and replaces all references of old indices by the new ones.
- Parameters:
net (pandapipesNet) – pandapipes network with unodered indices
start (int) – new index begins with “start”
add_df_to_reindex (iterable, default None) – by default all useful pandapower elements for power flow will be selected. Customized DataFrames can also be considered here.
- Returns:
net - pandapipes network with odered and continuous indices
- Return type:
pandapipesNet
Topology Modification
- fuse_junctions(net, j1, j2, drop=True)
Reroutes any connections to junctions in j2 to the given junction j1. Additionally drops the junctions j2, if drop=True (default).
- Parameters:
net (pandapipesNet) – pandapipes network
j1 (int) – junction into which to fuse the other junction(s)
j2 (Iterable or int) – junction(s) that shall be fused into junction 1
drop (boolean, default True) – if True, junction(s) j2 will be dropped after fusing all elements
- Returns:
net - the new pandapipes network
- Return type:
pandapipesNet
- drop_junctions(net, junctions, drop_elements=True)
Drops specified junctions, their junction_geodata and by default drops all elements connected to them as well.
- Parameters:
net (pandapipesNet) – pandapipes network
junctions (Iterable) – junctions to drop
drop_elements (bool, default True) – if True, all elements connected to the junction will be dropped as well
- Returns:
No output.
- drop_elements_at_junctions(net, junctions, node_elements=True, branch_elements=True)
drop elements connected to given junctions
- Parameters:
net (pandapipesNet) – pandapipes network
junctions (Iterable) – junctions from which to remove all elements
node_elements (bool, default True) – flag stating if node elements (such as sinks or sources) shall be dropped
branch_elements (bool, default True) – flag stating if branch elements (such as pipes or valves) shall be dropped
- Returns:
No output.
- drop_pipes(net, pipes)
Deletes all pipes and their geodata in the given list of indices.
- Parameters:
net (pandapipesNet) – pandapipes network
pipes (Iterable) – pipes to be dropped from the network
- Returns:
No output.
pandapower toolbox functions
Some toolbox functions can be used directly from pandapower, for example:
- clear_result_tables(net)
Clears all
res_
DataFrames in net.
- 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.
- dataframes_equal(df1, df2, ignore_index_order=True, **kwargs)
Returns a boolean whether the given two dataframes are equal or not.
- 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)
- 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).
- 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]
- ensure_iterability(var, len_=None)
Ensures iterability of a variable (and also the length if given).
Examples
>>> ensure_iterability([1, 2]) [1, 2] >>> ensure_iterability(1) [1] >>> ensure_iterability("Hi") ["Hi"] >>> ensure_iterability([1, 2], len_=2) [1, 2] >>> ensure_iterability([1, 2], len_=3) ValueError("Length of variable differs from 3.")