Skip to content

Commit

Permalink
Merge branch 'develop' of gitlab:pp/pandapower into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenMeinecke committed Dec 18, 2017
2 parents 0ceda2b + 7777bf5 commit 003ab4a
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions pandapower/plotting/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def create_line_switch_symbol_collection(net, size=1, distance_to_bus=3, use_lin
**size** (float, 1) - Size of the switch patches
**distance_to_bus** (float, 5) - Distance of the switch patch from the bus patch
**distance_to_bus** (float, 3) - Distance of the switch patch from the bus patch
**use_line_geodata** (bool, False) - If True, line coordinates are used to identify the
switch position
Expand All @@ -508,12 +508,9 @@ def create_line_switch_symbol_collection(net, size=1, distance_to_bus=3, use_lin
logger.warning("Bus coordinates for switch %s not found, skipped switch!" % switch)
continue

# switch bus coordinates
x_sb = net.bus_geodata.x.loc[sb]
y_sb = net.bus_geodata.y.loc[sb]

x_ta = 0
y_ta = 0
# switch bus and target coordinates
pos_sb = net.bus_geodata.loc[sb, ["x", "y"]].values
pos_ta = np.zeros(2)

use_bus_geodata = False

Expand All @@ -522,41 +519,33 @@ def create_line_switch_symbol_collection(net, size=1, distance_to_bus=3, use_lin
line_coords = net.line_geodata.coords.loc[line.name]
# check, which end of the line is nearer to the switch bus
if len(line_coords) > 2:
if abs(line_coords[0][0] - x_sb) < 0.01:
x_ta = line_coords[1][0]
y_ta = line_coords[1][1]
if abs(line_coords[0][0] - pos_sb[0]) < 0.01 and \
abs(line_coords[0][1] - pos_sb[1]) < 0.01:
pos_ta = np.array([line_coords[1][0], line_coords[1][1]])
else:
x_ta = line_coords[-2][0]
y_ta = line_coords[-2][1]
pos_ta = np.array([line_coords[-2][0], line_coords[-2][1]])
else:
use_bus_geodata = True
else:
use_bus_geodata = True

if not use_line_geodata or use_bus_geodata:
x_ta = net.bus_geodata.x.loc[target_bus]
y_ta = net.bus_geodata.y.loc[target_bus]

# vector from switch bus to target bus
vec_x = x_ta - x_sb
vec_y = y_ta - y_sb

# distance of vector
dist = np.sqrt(vec_x**2 + vec_y**2)
pos_ta = net.bus_geodata.loc[target_bus, ["x", "y"]]

# position of switch symbol
pos_x = x_sb + vec_x/dist * distance_to_bus
pos_y = y_sb + vec_y/dist * distance_to_bus
vec = pos_ta - pos_sb
mag = np.linalg.norm(vec)
pos_sw = pos_sb + vec / mag * distance_to_bus

# rotation of switch symbol
angle = np.arctan2(vec_y, vec_x)
rotation = Affine2D().rotate_around(pos_x, pos_y, angle)
angle = np.arctan2(vec[1], vec[0])
rotation = Affine2D().rotate_around(pos_sw[0], pos_sw[1], angle)

# color switch by state
col = color if net.switch.closed.loc[switch] else "white"

# create switch patch (switch size is respected to center the switch on the line)
patch = Rectangle((pos_x - size/2, pos_y - size/2), size, size, facecolor=col,
patch = Rectangle((pos_sw[0] - size/2, pos_sw[1] - size/2), size, size, facecolor=col,
edgecolor=color)
# apply rotation
patch.set_transform(rotation)
Expand Down

0 comments on commit 003ab4a

Please sign in to comment.