Skip to content

Commit

Permalink
Additional patches for plotter (#1998)
Browse files Browse the repository at this point in the history
* Ground work for different sgen patches

* Updated patch_maker with sgen WT (line based single blade)

* Updated patch_maker for sgen type WT (3 blade design)

* Added support for PV patch & reworked WT patch

* Added support for PV patch orientation

* Added support for WT patch orientation

* Removed unwanted imports

* Fixed a bug where only 1 type of sgen patch was plotted on all nodes

* mutiple patches on same node partial fix

* multiple patches hardcoded positions

* unique patch count implementation

* resolved arguments

* multiple patches v0.9

* multiple patches v0.91

* multiple patches v0.92

* multiple patches v0.93

* multiple patches v0.95

* multiple patches v0.95 (updated changelog and doc-string)

* Update CHANGELOG.rst

* removed unused argument (patch_count)

* fixed simple_plot bugs to adapt to tutorial

* fixed tutorial bug #2

* Fixed tutorial internal_datastructure bug

* fixed tutorial distributed_slack bug

* Fixed -sgen patches not appearing in some cases

---------

Co-authored-by: Jan Wiemer <[email protected]>
  • Loading branch information
hzraja and jwiemer112 authored Aug 8, 2023
1 parent 0cffae0 commit bb687d7
Show file tree
Hide file tree
Showing 8 changed files with 967 additions and 171 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Change Log

[upcoming release] - 2023-..-..
-------------------------------
- [ADDED] patches for PV-plants (:code:`sgen.type = "PV"`) and Windturbines (:code:`sgen.type = "WT"`) to :code:`simple_plot`
- [ADDED] Documentation for running powerflow using power-grid-model
- [ADDED] exporting to :code:`GeoJSON` with all properties from :code:`bus`, :code:`res_bus` and :code:`line`, :code:`res_line`
- [ADDED] function to run powerflow using the power-grid-model library
Expand All @@ -23,6 +24,7 @@ Change Log
- [CHANGED] always convert RATE_A to ppc in build_branch (not only when mode == 'opf' as before)



[2.13.1] - 2023-05-12
-------------------------------
- [FIXED] missing test files for CIM converter test in the release files
Expand Down
38 changes: 23 additions & 15 deletions pandapower/plotting/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _create_line2d_collection(coords, indices, infos=None, picker=False, **kwarg
return lc


def _create_node_element_collection(node_coords, patch_maker, size=1., infos=None,
def _create_node_element_collection(node_coords, patch_maker, size=1., unique_angles=None, infos=None,
repeat_infos=(1, 1), orientation=np.pi, picker=False,
patch_facecolor="w", patch_edgecolor="k", line_color="k",
**kwargs):
Expand All @@ -238,6 +238,8 @@ def _create_node_element_collection(node_coords, patch_maker, size=1., infos=Non
:type patch_maker: function
:param size: patch size
:type size: float, default 1
:param unique_angles: angles for patches
:type size: dict
:param infos: list of infos belonging to each of the elements (can be displayed when hovering \
over them)
:type infos: iterable, default None
Expand Down Expand Up @@ -277,9 +279,8 @@ def _create_node_element_collection(node_coords, patch_maker, size=1., infos=Non
linewidths = kwargs.pop("linewidths", 2.)
linewidths = kwargs.pop("linewidth", linewidths)
linewidths = kwargs.pop("lw", linewidths)

lines, polys, popped_keywords = patch_maker(
node_coords, size, angles, patch_facecolor=patch_facecolor, patch_edgecolor=patch_edgecolor,
node_coords, size, angles, unique_angles=unique_angles, patch_facecolor=patch_facecolor, patch_edgecolor=patch_edgecolor,
**kwargs)
for kw in set(popped_keywords) & set(kwargs.keys()):
kwargs.pop(kw)
Expand Down Expand Up @@ -960,7 +961,7 @@ def create_busbar_collection(net, buses=None, infofunc=None, cmap=None, norm=Non
return lc


def create_load_collection(net, loads=None, size=1., infofunc=None, orientation=np.pi, picker=False,
def create_load_collection(net, loads=None, size=1., unique_angles={}, infofunc=None, orientation=None, picker=False,
**kwargs):
"""
Creates a matplotlib patch collection of pandapower loads.
Expand All @@ -973,6 +974,8 @@ def create_load_collection(net, loads=None, size=1., infofunc=None, orientation=
**size** (float, 1) - patch size
**unique_angles** {dict} angles for patches
**infofunc** (function, None) - infofunction for the patch element
**orientation** (float, np.pi) - orientation of load collection. pi is directed downwards,
Expand All @@ -987,19 +990,21 @@ def create_load_collection(net, loads=None, size=1., infofunc=None, orientation=
**load_lc** - line collection
"""
# sgens = get_index_array(sgens, net.sgen.index)

loads = get_index_array(loads, net.load.index)
infos = [infofunc(i) for i in range(len(loads))] if infofunc is not None else []
node_coords = net.bus_geodata.loc[net.load.loc[loads, "bus"].values, ["x", "y"]].values
node_coords = net.bus_geodata.loc[:, ["x", "y"]]

color = kwargs.pop("color", "k")

load_pc, load_lc = _create_node_element_collection(
node_coords, load_patches, size=size, infos=infos, orientation=orientation,
node_coords, load_patches, size=size, unique_angles=unique_angles, infos=infos, orientation=orientation,
picker=picker, line_color=color, **kwargs)
return load_pc, load_lc


def create_gen_collection(net, gens=None, size=1., infofunc=None, orientation=np.pi, picker=False,
def create_gen_collection(net, gens=None, size=1., unique_angles=None, infofunc=None, orientation=None, picker=False,
**kwargs):
"""
Creates a matplotlib patch collection of pandapower gens.
Expand All @@ -1012,6 +1017,8 @@ def create_gen_collection(net, gens=None, size=1., infofunc=None, orientation=np
**size** (float, 1) - patch size
**unique_angles** {dict} angles for patches
**infofunc** (function, None) - infofunction for the patch element
**orientation** (float or list of floats, np.pi) - orientation of gen collection. pi is\
Expand All @@ -1028,17 +1035,17 @@ def create_gen_collection(net, gens=None, size=1., infofunc=None, orientation=np
"""
gens = get_index_array(gens, net.gen.index)
infos = [infofunc(i) for i in range(len(gens))] if infofunc is not None else []
node_coords = net.bus_geodata.loc[net.gen.loc[gens, "bus"].values, ["x", "y"]].values
node_coords = net.bus_geodata.loc[:, ["x", "y"]]

color = kwargs.pop("color", "k")

gen_pc, gen_lc = _create_node_element_collection(
node_coords, gen_patches, size=size, infos=infos, orientation=orientation,
node_coords, gen_patches, size=size, unique_angles=unique_angles, infos=infos, orientation=orientation,
picker=picker, line_color=color, **kwargs)
return gen_pc, gen_lc


def create_sgen_collection(net, sgens=None, size=1., infofunc=None, orientation=np.pi, picker=False,
def create_sgen_collection(net, sgens=None, size=1., unique_angles=None, infofunc=None, orientation=None, picker=False,
**kwargs):
"""
Creates a matplotlib patch collection of pandapower sgen.
Expand All @@ -1051,6 +1058,8 @@ def create_sgen_collection(net, sgens=None, size=1., infofunc=None, orientation=
**size** (float, 1) - patch size
**unique_angles** {dict} angles for patches
**infofunc** (function, None) - infofunction for the patch elem
**picker** (bool, False) - picker argument passed to the patch collectionent
Expand All @@ -1065,14 +1074,14 @@ def create_sgen_collection(net, sgens=None, size=1., infofunc=None, orientation=
**sgen_lc** - line collection
"""
sgens = get_index_array(sgens, net.sgen.index)

infos = [infofunc(i) for i in range(len(sgens))] if infofunc is not None else []
node_coords = net.bus_geodata.loc[net.sgen.loc[sgens, "bus"].values, ["x", "y"]].values
node_coords = net.bus_geodata.loc[:, ["x", "y"]]

color = kwargs.pop("color", "k")

color = kwargs.pop("color", "k")
sgen_pc, sgen_lc = _create_node_element_collection(
node_coords, sgen_patches, size=size, infos=infos, orientation=orientation,
node_coords, sgen_patches, size=size, unique_angles=unique_angles, infos=infos, orientation=orientation,
picker=picker, line_color=color, **kwargs)
return sgen_pc, sgen_lc

Expand Down Expand Up @@ -1154,7 +1163,6 @@ def create_ext_grid_collection(net, size=1., infofunc=None, orientation=0, picke
infos = [infofunc(ext_grid_idx) for ext_grid_idx in ext_grids] if infofunc is not None else []

node_coords = net.bus_geodata.loc[ext_grid_buses, ["x", "y"]].values

color = kwargs.pop("color", "k")

ext_grid_pc, ext_grid_lc = _create_node_element_collection(
Expand Down
Loading

0 comments on commit bb687d7

Please sign in to comment.