Groups
With pandapower version > 2.10.1, functionality to group network elements is available. Basically, these are helper functions to better handle and interact with multiple elements, even of different element types, such as buses, generators and lines, at once.
For first steps with group functionality, as often, it is recommended to have a look to the tutorial.
Plenty of group related functions are presented in the following.
Create and delete groups
- pandapower.create_group(net, element_types, element_indices, name='', reference_columns=None, index=None, **kwargs)
Add a new group to net[‘group’] dataframe.
Attention
If you declare a group but forget to declare all connected elements although you wants to (e.g. declaring lines but forgetting to mention the connected switches), you may get problems after using
drop_elements_and_group()or other functions. There are different pandapower toolbox functions which may help you to define ‘elements_dict’, such asget_connecting_branches(),get_inner_branches(),get_connecting_elements_dict().- Parameters:
net (pandapowerNet) – pandapower net
element_types (str or list of strings) – defines, together with ‘elements’, which net elements belong to the group
element_indices (list of list of indices) – defines, together with ‘element_types’, which net elements belong to the group
name (str, optional) – name of the group, by default “”
reference_columns (string or list of strings, optional) – If given, the elements_dict should not refer to DataFrames index but to another column. It is highly relevant that the reference_column exists in all DataFrames of the grouped elements and have the same dtype, by default None
index (int, optional) – index for the dataframe net.group, by default None
Example
>>> create_group(net, ["bus", "gen"], [[10, 12], [1, 2]]) >>> create_group(net, ["bus", "gen"], [["Berlin", "Paris"], ["Wind_1", "Nuclear1"]], reference_columns="name")
- pandapower.create_group_from_dict(net, elements_dict, name='', reference_column=None, index=None, **kwargs)
Wrapper function of
create_group().- Parameters:
name (str)
index (int | None)
- pandapower.drop_group(net, index)
Drops the group of given index.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the group which should be dropped
- pandapower.drop_group_and_elements(net, index)
Drops all elements of the group and in net.group the group itself.
Adapt group members
- pandapower.attach_to_group(net, index, element_types, element_indices, reference_columns=None, take_existing_reference_columns=True)
Appends the group by the elements given.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the considered group
element_types (str or list of strings) – defines, together with ‘elements’, which net elements belong to the group
element_indices (list of list of indices) – defines, together with ‘element_types’, which net elements belong to the group
reference_columns (string or list of strings, optional) – If given, the elements_dict should not refer to DataFrames index but to another column. It is highly relevant that the reference_column exists in all DataFrames of the grouped elements and have the same dtype, by default False
take_existing_reference_columns (bool, optional) – Determines the behavior if the given reference_columns does not match the reference_column existing in net.group. If True, the existing reference_column is taken for both. If False, an error is raised.
- pandapower.attach_to_groups(net, index, element_types, element_indices, reference_columns=None)
Appends the groups by the elements given.
- Parameters:
net (pandapowerNet) – pandapower net
index (list[int]) – index of the considered group
element_types (str or list of strings) – defines, together with ‘elements’, which net elements belong to the group
element_indices (list of list of indices) – defines, together with ‘element_types’, which net elements belong to the group
reference_columns (string or list of strings, optional) – If given, the elements_dict should not refer to DataFrames index but to another column. It is highly relevant that the reference_column exists in all DataFrames of the grouped elements and have the same dtype, by default None
See also
- pandapower.detach_from_group(net, index, element_type, element_index)
Detaches elements from the group with the given group index ‘index’. No errors are raised if elements are passed to be drop from groups which alread don’t have these elements as members. A reverse function is available -> pp.group.attach_to_group().
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – Index of the group from which the element should be dropped
element_type (str) – The element type of which elements should be dropped from the group(s), e.g. “bus”
element_index (int or list of integers) – indices of the elements which should be dropped from the group
- pandapower.detach_from_groups(net, element_type, element_index, index=None)
Detaches elements from one or multiple groups, defined by ‘index’. No errors are raised if elements are passed to be dropped from groups which alread don’t have these elements as members. A reverse function is available -> pp.group.attach_to_group().
- Parameters:
net (pandapowerNet) – pandapower net
element_type (str) – The element type of which elements should be dropped from the group(s), e.g. “bus”
element_index (int or list of integers) – indices of the elements which should be dropped from the group
index (int or list of integers, optional) – Indices of the group(s) from which the element should be dropped. If None, the elements are dropped from all groups, by default None
Access group data and evaluate membership
- pandapower.group_name(net, index)
Returns the name of the group and checks that all group rows include the same name
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the group
verbose (bool, optional) – Setting to False, accelerate the code but don’t check inconsistent names, by default True
See also
group_indexrecursive function
- pandapower.group_index(net, name)
Returns the index of the group named as given
- Parameters:
net (pandapowerNet) – pandapower net
name (str) – name of the requested group
See also
group_namerecursive function
- pandapower.group_element_index(net, index, element_type)
Returns the indices of the elements of the group in the element table net[element_type]. This function considers net.group.reference_column.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – Index of the group
element_type (str) – name of the element table to which the returned indices of the elements of the group belong to
- Returns:
indices of the elements of the group in the element table net[element_type]
- Return type:
pd.Index
- pandapower.group_row(net, index, element_type)
Returns the row which consists the data of the requested group index and element type.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the group
element_type (str) – element type (defines which row of the data of the group should be returned)
- Returns:
data of net.group, defined by the index of the group and the element type
- Return type:
pandas.Series
- Raises:
KeyError – Now row exist for the requested group and element type
ValueError – Multiple rows exist for the requested group and element type
- pandapower.element_associated_groups(net, element_type, element_index, return_empties=True, drop_empty_lines=True)
Returns to which groups given elements belong to.
- Parameters:
net (pandapowerNet) – pandapower net
element_type (str) – element type of the elements to be found in the groups, e.g. “gen” or “load”
element_index (str) – indices of the element table which should be found in the groups
return_empties (bool, optional) – whether entries with an empty list of assiciated groups should be returned, by default True
drop_empty_lines (bool, optional) – This parameter decides whether empty entries should be removed (the complete row in net.group), by default True
- Returns:
for each element index a list of associated group indices is returned as a dict
- Return type:
dict[int, list[int]]
- pandapower.isin_group(net, element_type, element_index, index=None, drop_empty_lines=True)
Returns whether elements are in group(s).
- Parameters:
net (pandapowerNet) – pandapower net
element_type (str) – element type of the elements to be found in the groups, e.g. “gen” or “load”
element_index (int or list of integers) – indices of the element table which should be found in the groups
index (int or list of integers, optional) – Can narrow the number of groups in which the elements are searched, by default None
drop_empty_lines (bool, optional) – This parameter decides whether empty entries should be removed (the complete row in net.group), by default True
- Returns:
Information whether the element are in any group
- Return type:
boolean or boolean numpy.array
- pandapower.count_group_elements(net, index)
Returns a Series concluding the number of included elements in self.elements_dict
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the considered group
- Returns:
number of elements per element type existing in the group
- Return type:
pd.Series
See also
count_elements
Compare groups
- pandapower.groups_equal(net, index1, index2, **kwargs)
Returns a boolean whether both group are equal.
- Parameters:
net (pandapowerNet) – pandapower net
index1 (int) – index of the first group to compare
index2 (int) – index of the second group to compare
- pandapower.compare_group_elements(net, index1, index2)
allow_cross_reference_column_comparison
- Parameters:
net (pandapowerNet) – pandapower net
index1 (int) – index of the first group to compare
index2 (int) – index of the second group to compare
Fix group data
- pandapower.check_unique_group_rows(net, raise_error=True, log_level='warning')
Checks whether all groups have unique names. raise_error decides whether duplicated names lead to error or log message.
- Parameters:
net (pandapowerNet) – pandapower net
raise_error (bool, optional) – decides whether duplicated names lead to error or log message., by default False
log_level (str, optional) – the level for logs, relevant if raise_error is False
Notes
Using different reference_columns for the same group and element_type is not supported.
- pandapower.remove_not_existing_group_members(net, verbose=True)
Remove group members from net.group that do not exist in the elements tables.
- Parameters:
net (pandapowerNet) – pandapower net
verbose (bool, optional) – Steers amount of logging messages, by default True
- pandapower.ensure_lists_in_group_element_column(net, drop_empty_lines=True)
Ensure that all entries in net.group.element are of type list.
- Parameters:
net (pandapowerNet) – pandapower net
drop_empty_lines (bool, optional) – This parameter decides whether empty entries should be removed (the complete row in net.group), by default True
- pandapower.group_entries_exist_in_element_table(net, index, element_type)
Returns an array of booleans whether the entries in net.group.element exist in net[element_type], also considering reference_column
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – Index of the group
element_type (str) – element type which entries should be checked, e.g. “bus”
- Returns:
Whether the entries in net.group.element exist in net[element_type]
- Return type:
array of booleans
Further group functions
- pandapower.set_group_in_service(net, index)
Sets all elements of the group in service.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the considered group
- pandapower.set_group_out_of_service(net, index)
Sets all elements of the group out of service.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the considered group
- pandapower.set_value_to_group(net, index, value, column, replace=True, append_column=True)
Sets the same value to the column of the element tables of all elements/members of the group.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the considered group
value (int/float/object) – value to be written to all group members into the element tables
column (str) – column to be manipulated
replace (bool, optional) – If False, value is only written to places where no value exist before (column doesn’t exist before or value is nan), by default True
append_column (bool, optional) – Decides whether the column should be added to element tables where this doesn’t exist before, by default True
- pandapower.group_res_p_mw(net, index)
Sums all result table values p_mw of group members.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the considered group
Examples
>>> from pandapower import runpp, create_group, group_res_p_mw >>> from pandapower.networks import create_cigre_network_mv >>> net = create_cigre_network_mv(with_der="all") >>> runpp(net) >>> gr_idx = create_group(net, ["sgen", "line"], [[0, 1], [0, 1]], name="test group") >>> net.res_line.pl_mw.loc[[0, 1]].sum() - net.res_sgen.p_mw.loc[[0, 1]].sum() # expected value 0.057938 >>> group_res_p_mw(net, gr_idx) 0.057938
- pandapower.group_res_q_mvar(net, index)
Sums all result table values q_mvar of group members.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the considered group
Examples
>>> from pandapower import runpp, create_group, group_res_q_mvar >>> from pandapower.networks import create_cigre_network_mv >>> net = create_cigre_network_mv(with_der="all") >>> runpp(net) >>> gr_idx = create_group(net, ["sgen", "line"], [[0, 1], [0, 1]], name="test group") >>> net.res_line.ql_mvar.loc[[0, 1]].sum() - net.res_sgen.q_mvar.loc[[0, 1]].sum() # expected value 0.010114 >>> group_res_q_mvar(net, gr_idx) 0.010114
- pandapower.group_res_power_per_bus(net, index)
Returns active and reactive power consumptions of given group per bus
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – _description_
- Returns:
power consumption of the group per bus (index=bus, columns=[“p_mw”, “q_mvar”])
- Return type:
pd.DataFrame
Examples
>>> from pandapower import runpp, create_group, group_res_power_per_bus >>> from pandapower.networks import create_cigre_network_mv >>> net = create_cigre_network_mv(with_der="all") >>> runpp(net) >>> gr_idx = create_group(net, ["sgen", "line"], [[0, 1], [0, 1]], name="test group") >>> group_res_power_per_bus(net, gr_idx) p_mw q_mvar bus 1 2.953004e+00 1.328978e+00 2 -3.641532e-14 4.618528e-14 3 -2.875066e+00 -1.318864e+00 4 -2.000000e-02 0.000000e+00
- pandapower.set_group_reference_column(net, index, reference_column, element_type=None)
Set a reference_column to the group of given index. The values in net.group.element get updated.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – Index of the group
reference_column (str) – column in the elemt tables which should be used as reference to link the group members. If no column but the index should be used as the link (is the default), reference_column should be None.
element_type (str, optional) – Type of element which should get a new column to reference. If None, all element types are considered, by default None
- Raises:
ValueError – net[element_type][reference_column] has duplicated values.
- pandapower.return_group_as_net(net, index, keep_everything_else=False, verbose=True, **kwargs)
Returns a pandapower net consisting of the members of this group.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the considered group
keep_everything_else (bool, optional) – Decides whether other data than element tables are kept, by default False
verbose (bool, optional) – Decides whether logging messages are triggered, by default True
- Returns:
pandapower net, only with elements that are members of the group
- Return type:
pandapowerNet