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
- Return type:
None
- pandapower.drop_group_and_elements(net, index)
Drops all elements of the group and in net.group the group itself.
- Parameters:
net (pandapowerNet) – pandapower net
index (int) – index of the group which should be dropped
- Return type:
None
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 | list[str]) – defines, together with ‘elements’, which net elements belong to the group
element_indices (list[list[int]] | list[int]) – defines, together with ‘element_types’, which net elements belong to the group
reference_columns (str | list[str] | None) – 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
take_existing_reference_columns (bool) – 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.
- Return type:
None
- 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 | list[str]) – defines, together with ‘elements’, which net elements belong to the group
element_indices (list[list[int]] | list[int]) – together with ‘element_types’ defines which net elements belong to the group
reference_columns (str | list[str] | None) – 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
- Return type:
None
See also
- pandapower.detach_from_group(net, index, element_type, element_index)
- pandapower.detach_from_groups(net, element_type, element_index, index=None)
Detaches elements from the group with the given group index ‘index’. No errors are raised if elements are passed to be dropped from groups which already don’t have these elements as members. A reverse function is available ->
group.attach_to_group()- Parameters:
net (pandapowerNet) – pandapower net
index (int | None) – 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 | list[int]) – indices of the elements which should be dropped from the group
- Return type:
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
- Returns:
The name of the group
- Raises:
ValueError – if any row of the group has incorrect name set
- Return type:
str
See also
- pandapower.group_index(net, name)
Returns the index of the group named as given
- Parameters:
net (pandapowerNet) – pandapower net
name (str) – the group to get the index from
- Returns:
The index of the group
- Raises:
ValueError – if multiple group index are found for the name
- Return type:
int
See also
- 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:
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
- Raises:
KeyError – Now row exist for the requested group and element type
ValueError – Multiple rows exist for the requested group and element type
- Return type:
Series
- 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 (Iterable[int] | int) – indices of the element table which should be found in the groups
return_empties (bool) – whether entries with an empty list of associated groups should be returned
drop_empty_lines (bool) – This parameter decides whether empty entries should be removed (the complete row in net.group)
- 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 | list[int]) – indices of the element table which should be found in the groups
index (int | list[int] | None) – Can narrow the number of groups in which the elements are searched
drop_empty_lines (bool) – This parameter decides whether empty entries should be removed (the complete row in net.group)
- Returns:
Information whether the element are in any group
- Return type:
bool | ndarray[tuple[Any, …], dtype[bool]]
- 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:
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
:keyword These are passed to
pandas.testing.assert_frame_equal():
- 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
- Raises:
ValueError – If group has duplicate element types.
- Return type:
bool
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) – decides whether duplicated names lead to error or log message.
log_level (Literal['error', 'warning', 'info', 'debug', 'UserWarning']) – 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) – Additional logging messages
- 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) – This parameter decides whether empty entries should be removed (the complete row in net.group)
- 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:
ndarray[tuple[Any, …], dtype[bool]]
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 (Any) – value to be written to all group members into the element tables
column (str) – column to be manipulated
replace (bool) – If False, value is only written to places where no value exist before (column doesn’t exist before or value is nan)
append_column (bool) – Decides whether the column should be added to element tables where this doesn’t exist before
- 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
Example
>>> 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
Example
>>> 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) – index of the group
- Returns:
power consumption of the group per bus (index=bus, columns=[“p_mw”, “q_mvar”])
- Return type:
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 element 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 | None) – Type of element which should get a new column to reference. If None, all element types are considered
- 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) – Decides whether other data than element tables are kept
verbose (bool) – Decides whether logging messages are triggered
- Returns:
pandapower net, only with elements that are members of the group
- Return type:
pandapowerNet