1
# Copyright (c) 2020 by Fraunhofer Institute for Energy Economics
2
# and Energy System Technology (IEE), Kassel. All rights reserved.
3
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4

5 1
import numpy as np
6 1
from matplotlib.patches import RegularPolygon, Rectangle, Circle, PathPatch
7 1
from matplotlib.path import Path
8 1
from pandapower.plotting.plotting_toolbox import get_color_list, _rotate_dim2, get_angle_list, \
9
    get_list
10

11

12 1
def get_filled_list(filled, number_entries, name_entries="valves"):
13 1
    return get_list(filled, number_entries, "filled", name_entries)
14

15

16 1
def valve_patches(coords, size, **kwargs):
17 1
    polys, lines = list(), list()
18 1
    facecolor = kwargs.pop('patch_facecolor')
19 1
    colors = get_color_list(facecolor, len(coords))
20 1
    lw = kwargs.get("linewidths", 2.)
21 1
    filled = kwargs.pop("filled", np.full(len(coords), 0, dtype=np.bool))
22 1
    filled = get_filled_list(filled, len(coords))
23 1
    for geodata, col, filled_ind in zip(coords, colors, filled):
24 1
        p1, p2 = np.array(geodata[0]), np.array(geodata[-1])
25 1
        diff = p2 - p1
26 1
        angle = np.arctan2(*diff)
27 1
        vec_size = _rotate_dim2(np.array([0, size]), angle)
28 1
        centroid_tri1 = p1 + diff / 2 - vec_size
29 1
        centroid_tri2 = p1 + diff / 2 + vec_size
30 1
        face_col = "w" if not filled_ind else col
31 1
        polys.append(RegularPolygon(centroid_tri1, numVertices=3, radius=size, orientation=-angle,
32
                                    ec=col, fc=face_col, lw=lw))
33 1
        polys.append(RegularPolygon(centroid_tri2, numVertices=3, radius=size,
34
                                    orientation=-angle+np.pi/3, ec=col, fc=face_col, lw=lw))
35 1
        lines.append([p1, p1 + diff / 2 - vec_size / 2 * 3])
36 1
        lines.append([p2, p1 + diff / 2 + vec_size / 2 * 3])
37 1
    return lines, polys, {"filled"}
38

39

40 1
def heat_exchanger_patches(coords, size, **kwargs):
41 1
    polys, lines = list(), list()
42 1
    facecolor = kwargs.pop('patch_facecolor')
43 1
    colors = get_color_list(facecolor, len(coords))
44 1
    lw = kwargs.get("linewidths", 2.)
45 1
    for geodata, col in zip(coords, colors):
46 1
        p1, p2 = np.array(geodata[0]), np.array(geodata[-1])
47 1
        diff = p2 - p1
48 1
        m = 3*size/4
49 1
        direc= diff/np.sqrt(diff[0]**2+diff[1]**2)
50 1
        normal = np.array([-direc[1], direc[0]])
51 1
        path1 = (p1 + diff / 2+ direc *m/2) + normal * (size * 9 / 8)
52 1
        path2 = p1 + diff / 2 + direc *m / 2
53 1
        path3 = p1 + diff / 2 + normal * size / 3
54 1
        path4 = p1 + diff / 2 - direc *m/2
55 1
        path5 = (p1 + diff / 2- direc *m/2)  + normal * (size * 9 / 8)
56 1
        path =[path1, path2, path3, path4, path5]
57 1
        radius = size #np.sqrt(diff[0]**2+diff[1]**2)/15
58

59 1
        pa = Path(path)
60 1
        polys.append(Circle(p1 + diff / 2, radius=radius, edgecolor=col, facecolor="w", lw=lw))
61 1
        polys.append(PathPatch(pa, fill=False, lw=lw, edgecolor=col))
62 1
        lines.append([p1, p1 + diff / 2 - direc * radius])
63 1
        lines.append([p2, p1 + diff / 2 + direc * radius])
64 1
    return lines, polys, {}
65

66

67 1
def source_patches(node_coords, size, angles, **kwargs):
68
    """Creation function of patches for sources.
69

70
    :param node_coords: coordinates of the nodes that the sources belong to.
71
    :type node_coords: iterable
72
    :param size: size of the patch
73
    :type size: float
74
    :param angles: angles by which to rotate the patches (in radians)
75
    :type angles: iterable(float), float
76
    :param kwargs: additional keyword arguments (might contain parameter "offset")
77
    :type kwargs:
78
    :return: Return values are: \
79
        - lines (list) - list of coordinates for lines leading to source patches and diagonals\
80
        - polys (list of RegularPolygon) - list containing the load patches\
81
        - keywords (set) - set of keywords removed from kwargs
82
    """
83 1
    offset = kwargs.get("offset", size * 2)
84 1
    all_angles = get_angle_list(angles, len(node_coords))
85 1
    facecolor = kwargs.get("patch_faceolor", "w")
86 1
    edgecolor = kwargs.get("patch_edgecolor", "k")
87 1
    facecolors = get_color_list(facecolor, len(node_coords))
88 1
    edgecolors = get_color_list(edgecolor, len(node_coords))
89 1
    polys, lines = list(), list()
90 1
    for i, node_geo in enumerate(node_coords):
91 1
        p2 = node_geo + _rotate_dim2(np.array([0, offset]), all_angles[i])
92 1
        p_edge_left = p2 + _rotate_dim2(np.array([size, size]), all_angles[i])
93 1
        p_edge_right = p2 + _rotate_dim2(np.array([- size, size]), all_angles[i])
94 1
        p_ll = p2 + _rotate_dim2(np.array([-size, 0]), all_angles[i])
95 1
        polys.append(Rectangle(p_ll, 2 * size, 2 * size, angle=(- all_angles[i] / np.pi * 180),
96
                               fc=facecolors[i], ec=edgecolors[i]))
97 1
        lines.append((node_geo, p2))
98 1
        lines.append((p2, p_edge_left))
99 1
        lines.append((p2, p_edge_right))
100 1
    return lines, polys, {"offset"}
101

102

103 1
def pump_patches(coords, size, **kwargs):
104 1
    polys, lines = list(), list()
105 1
    edgecolor = kwargs.pop('patch_edgecolor')
106 1
    colors = get_color_list(edgecolor, len(coords))
107 1
    lw = kwargs.get("linewidths", 2.)
108 1
    for geodata, col in zip(coords, colors):
109 1
        p1, p2 = np.array(geodata[0]), np.array(geodata[-1])
110 1
        diff = p2 - p1
111 1
        angle = np.arctan2(*diff)
112 1
        vec_size = _rotate_dim2(np.array([0, size]), angle)
113 1
        line1 = _rotate_dim2(np.array([0, size * np.sqrt(2)]), angle - np.pi/4)
114 1
        line2 = _rotate_dim2(np.array([0, size * np.sqrt(2)]), angle + np.pi/4)
115 1
        radius = size
116

117 1
        polys.append(Circle(p1 + diff / 2, radius=radius, edgecolor=col, facecolor='w', lw=lw))
118

119 1
        lines.append([p1+diff/2+vec_size, p1+diff/2-vec_size+line1])
120 1
        lines.append([p1+diff/2+vec_size, p1+diff/2-vec_size+line2])
121

122 1
        lines.append([p1, p1 + diff / 2 - vec_size])
123 1
        lines.append([p2, p1 + diff / 2 + vec_size])
124 1
    return lines, polys, {}

Read our documentation on viewing source code .

Loading