Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jkisse authored Nov 10, 2021
2 parents c30b0f4 + f89fb39 commit 1586943
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
tutorials/* linguist-vendored
*.rst text eol=lf
*.rst text=auto eol=lf
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Log
- [ADDED] "results" initialization for runopp()
- [CHANGED] toolbox function nets_equal()
- [ADDED] toolbox function merge_same_bus_generation_plants()
- [ADDED] TapDependentImpedance controller that adjusts the transformer parameters (e.g. vk_percent, vkr_percent) according to the tap position, based on a specified characteristic

[2.7.1]- 2021-07-22
----------------------
Expand Down
1 change: 1 addition & 0 deletions pandapower/control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pandapower.control.controller.trafo.ContinuousTapControl import ContinuousTapControl
from pandapower.control.controller.trafo.DiscreteTapControl import DiscreteTapControl
from pandapower.control.controller.trafo.USetTapControl import USetTapControl
from pandapower.control.controller.trafo.TapDependentImpedance import TapDependentImpedance
from pandapower.control.controller.trafo_control import TrafoController

# --- Other ---
Expand Down
2 changes: 1 addition & 1 deletion pandapower/control/controller/characteristic_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def _read_from_object_attribute(self, net, element, object_attribute, index):
if hasattr(index, '__iter__') and len(index) > 1:
values = np.array(shape=index.shape)
for i, idx in enumerate(index):
values[i] = setattr(net[element]["object"].at[idx], object_attribute)
values[i] = getattr(net[element]["object"].at[idx], object_attribute)
else:
values = getattr(net[element]["object"].at[index], object_attribute)
return values
Expand Down
46 changes: 46 additions & 0 deletions pandapower/control/controller/trafo/TapDependentImpedance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2016-2021 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.

from pandapower.control.controller.characteristic_control import CharacteristicControl
from pandapower.control.util.characteristic import Characteristic

class TapDependentImpedance(CharacteristicControl):
"""
Controller that adjusts the impedance of a transformer (or multiple transformers) depending to the actual tap position and
according to a defined characteristic.
INPUT:
**net** (attrdict) - Pandapower net
**tid** (int or list or numpy array) - ID of the transformer or multiple transfromers
**characteristic** (object of class Characteristic) - Characteristic that describes the relationship between transformer tap
position and transformer impedance
OPTIONAL:
**in_service** (bool, True) - Indicates if the controller is currently in_service
**drop_same_existing_ctrl** (bool, False) - Indicates if already existing controllers of the same type and with the same matching parameters (e.g. at same element) should be dropped
"""

def __init__(self, net, transformer_index, characteristic, trafotable="trafo", output_variable="vk_percent", tol=1e-3, restore=True,
in_service=True, order=0, level=0, drop_same_existing_ctrl=False, matching_params=None, **kwargs):
if matching_params is None:
matching_params = {"transformer_index": transformer_index, 'output_variable': output_variable}
super().__init__(net, output_element=trafotable, output_variable=output_variable, output_element_index=transformer_index,
input_element=trafotable, input_variable="tap_pos", input_element_index=transformer_index,
characteristic=characteristic, tol=tol, in_service=in_service, order=order,
level=level, drop_same_existing_ctrl=drop_same_existing_ctrl, matching_params=matching_params, **kwargs)
self.restore=restore
self.initial_values = net[trafotable].loc[transformer_index, output_variable].copy()

def initialize_control(self, net):
if self.restore:
self.initial_values = net[self.output_element].loc[self.output_element_index, self.output_variable].copy()

def finalize_control(self, net):
if self.restore:
net[self.output_element].loc[self.output_element_index, self.output_variable] = self.initial_values
94 changes: 0 additions & 94 deletions pandapower/control/controller/trafo/u_setofp.py

This file was deleted.

3 changes: 2 additions & 1 deletion pandapower/plotting/generic_geodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def build_igraph_from_pp(net, respect_switches=False, buses=None):
mask = net.switch.et.values == "b"
if respect_switches:
mask &= ~open_switches
for switch in net.switch[mask].itertuples():
bus_mask = _get_element_mask_from_nodes(net, "switch", ["element", "bus"], buses)
for switch in net.switch[mask & bus_mask].itertuples():
g.add_edge(pp_bus_mapping[switch.element],
pp_bus_mapping[switch.bus], weight=0.001)

Expand Down
2 changes: 1 addition & 1 deletion pandapower/plotting/powerflow_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def plot_loading(net, element="line", boxcolor="b", mediancolor="r", whiskercolo
if index_subset is None:
index_subset = net[element].index
loadings = net["res_%s" % element].loading_percent.values[net["res_%s" % element].index.isin(index_subset)]
boxplot = ax.boxplot(loadings[~np.isnan(loadings)], whis="range")
boxplot = ax.boxplot(loadings[~np.isnan(loadings)], whis=[0, 100])
for l in list(boxplot.keys()):
plt.setp(boxplot[l], lw=3)
if l == "medians":
Expand Down
13 changes: 7 additions & 6 deletions pandapower/plotting/simple_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pandapower.plotting.plotting_toolbox import get_collection_sizes
from pandapower.plotting.collections import create_bus_collection, create_line_collection, \
create_trafo_collection, create_trafo3w_collection, \
create_line_switch_collection, draw_collections, create_bus_bus_switch_collection, create_sgen_collection, \
create_line_switch_collection, draw_collections, create_bus_bus_switch_collection, create_ext_grid_collection, create_sgen_collection, \
create_gen_collection, create_load_collection
from pandapower.plotting.generic_geodata import create_generic_coordinates

Expand Down Expand Up @@ -128,10 +128,11 @@ def simple_plot(net, respect_switches=False, line_width=1.0, bus_size=1.0, ext_g
collections = [bc, lc]

# create ext_grid collections
eg_buses_with_geo_coordinates = set(net.ext_grid.bus.values) & set(net.bus_geodata.index)
if len(eg_buses_with_geo_coordinates) > 0:
sc = create_bus_collection(net, eg_buses_with_geo_coordinates, patch_type="rect",
size=ext_grid_size, color=ext_grid_color, zorder=11)
# eg_buses_with_geo_coordinates = set(net.ext_grid.bus.values) & set(net.bus_geodata.index)
if len(net.ext_grid) > 0:
sc = create_ext_grid_collection(net, size=ext_grid_size, orientation=0,
ext_grids=net.ext_grid.index, patch_edgecolor=ext_grid_color,
zorder=11)
collections.append(sc)

# create trafo collection if trafo is available
Expand Down Expand Up @@ -159,7 +160,7 @@ def simple_plot(net, respect_switches=False, line_width=1.0, bus_size=1.0, ext_g
collections.append(sc)

if plot_sgens and len(net.sgen):
sgc = create_sgen_collection(net, size=sgen_size)
sgc = create_sgen_collection(net, size=sgen_size, orientation=0)
collections.append(sgc)
if plot_gens and len(net.gen):
gc = create_gen_collection(net, size=gen_size)
Expand Down
75 changes: 75 additions & 0 deletions pandapower/test/control/test_tap_dependent_impedance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2016-2021 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.

import pytest
import pandapower as pp
from pandapower.control import Characteristic, TapDependentImpedance


def test_tap_dependent_impedance_control():
net = pp.create_empty_network()
b1 = pp.create_bus(net, 110)
b2 = pp.create_bus(net, 20)
pp.create_ext_grid(net, b1)
pp.create_transformer_from_parameters(net, b1, b2, 40, 110, 21, 0.5, 12.3, 25, 0.11, 0, 'hv', 10, 20, 0, 1.8, 180, 10)

characteristic_vk = Characteristic.from_points(((0, 13.5), (10, 12.3), (20, 11.1)))
characteristic_vkr = Characteristic.from_points(((0, 0.52), (10, 0.5), (20, 0.53)))
TapDependentImpedance(net, 0, characteristic_vk, output_variable='vk_percent', restore=False)
TapDependentImpedance(net, 0, characteristic_vkr, output_variable='vkr_percent', restore=False)

pp.runpp(net, run_control=True)
assert net.trafo.vk_percent.at[0] == 12.3
assert net.trafo.vkr_percent.at[0] == 0.5

net.trafo.tap_pos = 0
pp.runpp(net, run_control=True)
assert net.trafo.vk_percent.at[0] == 13.5
assert net.trafo.vkr_percent.at[0] == 0.52

net.trafo.tap_pos = 20
pp.runpp(net, run_control=True)
assert net.trafo.vk_percent.at[0] == 11.1
assert net.trafo.vkr_percent.at[0] == 0.53


def test_tap_dependent_impedance_restore():
net = pp.create_empty_network()
b1 = pp.create_bus(net, 110)
b2 = pp.create_bus(net, 20)
pp.create_ext_grid(net, b1)
pp.create_load(net, b2, 20)
pp.create_transformer_from_parameters(net, b1, b2, 40, 110, 21, 0.5, 12.3, 25, 0.11, 0, 'hv', 10, 20, 0, 1.8, 180, 10)

characteristic_vk = Characteristic.from_points(((0, 13.5), (10, 12.3), (20, 11.1)))
characteristic_vkr = Characteristic.from_points(((0, 0.52), (10, 0.5), (20, 0.53)))
TapDependentImpedance(net, 0, characteristic_vk, output_variable='vk_percent', restore=True)
TapDependentImpedance(net, 0, characteristic_vkr, output_variable='vkr_percent', restore=True)

pp.runpp(net, run_control=True)
# remember the losses for the neutral position
pl_mw_neutral = net.res_trafo.pl_mw.at[0]
assert net.trafo.vk_percent.at[0] == 12.3
assert net.trafo.vkr_percent.at[0] == 0.5

net.trafo.tap_pos = 0
pp.runpp(net, run_control=True)
# check if the impedance has been restored
assert net.trafo.vk_percent.at[0] == 12.3
assert net.trafo.vkr_percent.at[0] == 0.5
# check if the losses are different than at the neutral position -> the tap-dependent impedance has been conbsidered
assert abs(net.res_trafo.pl_mw.at[0] - pl_mw_neutral) > 0.015

net.trafo.tap_pos = 20
pp.runpp(net, run_control=True)
# check if the impedance has been restored
assert net.trafo.vk_percent.at[0] == 12.3
assert net.trafo.vkr_percent.at[0] == 0.5
# check if the losses are different than at the neutral position -> the tap-dependent impedance has been conbsidered
assert abs(net.res_trafo.pl_mw.at[0] - pl_mw_neutral) > 0.002


if __name__ == '__main__':
pytest.main(['-xs', __file__])
3 changes: 2 additions & 1 deletion pandapower/topology/create_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def create_nxgraph(net, respect_switches=True, include_lines=True, include_imped
# remove out of service buses
if not include_out_of_service:
for b in net.bus.index[~net.bus.in_service.values]:
mg.remove_node(b)
if b in mg:
mg.remove_node(b)

return mg

Expand Down

0 comments on commit 1586943

Please sign in to comment.