Ejemplo n.º 1
0
def plot_zones():
    net = get_net_118_with_zones()
    areas = get_subnets(net)

    fig, axes = plt.subplots(1, len(areas.keys()))

    keys = areas.keys()
    keys = sorted(keys)
    for i, zone in enumerate(keys):
        net = areas[zone]
        collections = list()
        ax = axes[i]
        sizes = pplt.get_collection_sizes(net)
        collections.append(pplt.create_bus_collection(net, size=sizes["bus"]))
        collections.append(pplt.create_line_collection(net))
        collections.append(
            pplt.create_trafo_collection(net, size=sizes["trafo"]))
        if zone == 3:
            collections.append(
                pplt.create_bus_collection(net,
                                           net.bus.loc[net.bus.toy_zone].index,
                                           color="g",
                                           size=2 * sizes["bus"],
                                           zorder=11))
        pplt.draw_collections(collections, ax=ax)

    plt.show()
Ejemplo n.º 2
0
def plot_feeder():
    net = nw.case118()
    fig, ax = plt.subplots(1, 1)
    mg = top.create_nxgraph(net, nogobuses=set(net.trafo.lv_bus.values))
    colors = sns.color_palette()
    collections = list()
    sizes = pplt.get_collection_sizes(net)
    voltage_levels = net.bus.vn_kv.unique()
    voltage_level_colors = dict(zip(voltage_levels, colors))
    legend_entries = dict()
    gens = set(net.gen.loc[:, "bus"].values)
    for area, color in zip(top.connected_components(mg), colors):
        vn_area = net.bus.loc[list(area)[0], "vn_kv"]
        color = voltage_level_colors[vn_area]
        legend_entries[vn_area] = color
        area_gens = gens - area
        other = area - gens

        collections.append(
            pplt.create_bus_collection(net,
                                       area_gens,
                                       color=color,
                                       size=sizes["bus"],
                                       zorder=11,
                                       patch_type="rect"))
        collections.append(
            pplt.create_bus_collection(net,
                                       other,
                                       color=color,
                                       size=sizes["bus"],
                                       zorder=11))
        line_ind = net.line.loc[:, "from_bus"].isin(
            area) | net.line.loc[:, "to_bus"].isin(area)
        lines = net.line.loc[line_ind].index
        collections.append(pplt.create_line_collection(net, lines,
                                                       color=color))

    eg_vn = net.bus.at[net.ext_grid.bus.values[0], "vn_kv"]
    collections.append(
        pplt.create_ext_grid_collection(net,
                                        size=sizes["ext_grid"],
                                        color=voltage_level_colors[eg_vn]))
    collections.append(
        pplt.create_trafo_collection(net, size=sizes["trafo"], zorder=1))
    pplt.draw_collections(collections, ax=ax)
    custom_legend(fig, entries=legend_entries)
    legend_entries = {"gen": "grey"}
    custom_legend(fig, entries=legend_entries, loc='center right', marker="s")
    print_info(net, fig)
    plt.show()
def plot_network(net):
    #  función que recibe una red y la grafica.
    colors = ["k", "b", "g", "r", "c", "y"]
    buses = net.bus.index.tolist()
    coords = zip(net.bus_geodata.x.loc[buses].values + 0.02,
                 net.bus_geodata.y.loc[buses].values + 0.02)
    lc = plot.create_line_collection(net,
                                     net.line.index,
                                     color=colors[0],
                                     use_bus_geodata=True,
                                     zorder=1)
    bc = plot.create_bus_collection(net,
                                    net.bus.index,
                                    size=0.02,
                                    bus_geodata=None,
                                    color=colors[0],
                                    zorder=2)
    bic = plot.create_annotation_collection(size=0.07,
                                            texts=np.char.mod('%d', buses),
                                            coords=coords,
                                            zorder=3,
                                            color=colors[0])
    tf = plot.create_trafo_collection(net,
                                      trafos=net.trafo.index,
                                      color=colors[0],
                                      size=0.04,
                                      zorder=4)
    sc = plot.create_bus_collection(net,
                                    net.ext_grid.bus.values,
                                    patch_type="rect",
                                    size=0.03,
                                    color=colors[2],
                                    zorder=5)
    ld = plot.create_load_collection(net, size=0.03)
    sg = plot.create_sgen_collection(net,
                                     sgens=net.sgen.index[1:],
                                     size=0.05,
                                     orientation=0)
    sg1 = plot.create_sgen_collection(net,
                                      sgens=[net.sgen.index[0]],
                                      size=0.05,
                                      orientation=np.pi / 2)
    sw = plot.create_line_switch_collection(net,
                                            size=0.04,
                                            distance_to_bus=0.08)
    return plot.draw_collections([lc, bc, bic, tf, sc, ld, sg, sg1, sw],
                                 figsize=(7, 10))
def plot_network(net):
    # create buses ID
    buses = net.bus.index.tolist()  # list of all bus indices
    coords = zip(net.bus_geodata.x.loc[buses].values + 0.15,
                 net.bus_geodata.y.loc[buses].values +
                 0.07)  # tuples of all bus coords
    bic = plot.create_annotation_collection(size=0.2,
                                            texts=np.char.mod('%d', buses),
                                            coords=coords,
                                            zorder=3,
                                            color="black")
    # creating a color function to get a linear a colormap with color centers green at 30%, yellow at 50% and red at 60%
    # line loading
    cmap_list_lines = [(20, "green"), (50, "yellow"), (60, "red")]
    cmap_lines, norm_lines = plot.cmap_continuous(cmap_list_lines)
    # create a collection for colouring each line according to a line color range.
    lc = plot.create_line_collection(net,
                                     net.line.index,
                                     zorder=2,
                                     cmap=cmap_lines,
                                     norm=norm_lines,
                                     linewidths=2)
    # create discrete map for node pu magnitude
    cmap_list_nodes = [(0.975, "blue"), (1.0, "green"), (1.03, "red")]
    cmap_nodes, norm_nodes = plot.cmap_continuous(cmap_list_nodes)
    bc = plot.create_bus_collection(
        net,
        net.bus.index,
        size=0.07,
        zorder=2,
        cmap=cmap_nodes,
        norm=norm_nodes)  #80 of mv obherreim and 0.07 for ieee
    tlc, tpc = plot.create_trafo_collection(net, net.trafo.index, color="g")
    sc = plot.create_bus_collection(net,
                                    net.ext_grid.bus.values,
                                    patch_type="rect",
                                    size=.08,
                                    color="y",
                                    zorder=11)
    # draw the different collections
    plot.draw_collections([lc, bc, tlc, tpc, sc, bic], figsize=(8, 6))
    plt.show()
 def updateBusCollection(self, redraw=False):
     bc = plot.create_bus_collection(self.net,
                                     size=self.scale * 0.01,
                                     zorder=2,
                                     picker=True,
                                     color="black",
                                     patch_type="rect",
                                     infofunc=lambda x: ("bus", x))
     self.collections["bus"] = bc
     if redraw:
         self.drawCollections()
def plot_net(net, ax=None):
    if ax is None:
        fig, ax = mpl.subplots(1, 1, figsize=(10, 7))
    mean_distance_between_buses = sum(
        (net['bus_geodata'].max() - net['bus_geodata'].min()).dropna() / 200)

    bus_size = mean_distance_between_buses * 1.
    ext_grid_size = mean_distance_between_buses * 1.
    trafo_size = mean_distance_between_buses * .1

    collections = list()
    if ax is None:
        fig, ax = plt.subplots(1, 1)

    # create plot collection to visualize results
    cmap, norm = plt.cmap_continuous([(0.9, "blue"), (1.0, "green"),
                                      (1.1, "red")])
    collections.append(
        plt.create_bus_collection(net, size=bus_size, cmap=cmap, norm=norm))
    cmap, norm = plt.cmap_continuous([(0., "green"), (50., "yellow"),
                                      (100., "red")])
    collections.append(
        plt.create_line_collection(net,
                                   use_bus_geodata=True,
                                   linewidth=1.,
                                   cmap=cmap,
                                   norm=norm))
    collections.append(
        plt.create_trafo_collection(net,
                                    size=trafo_size,
                                    color="green",
                                    alpha=.5))
    collections.append(
        plt.create_ext_grid_collection(net,
                                       size=ext_grid_size,
                                       orientation=1.5))

    for idx in net.bus_geodata.index:
        x = net.bus_geodata.loc[idx, "x"]
        y = net.bus_geodata.loc[idx, "y"] + bus_size * 1.
        ax.text(x + 0.01, y, str(idx), fontsize=8, color="k")

    plt.draw_collections(collections, ax=ax)
    mpl.tight_layout()
    ax.axis('off')
    mpl.show()

    mpl.close()
Ejemplo n.º 7
0
 def __init__(self, net):
     super(SliderWidget, self).__init__()
     self.setupUi(self)
     self.net = net
     self.net.line_geodata.drop(set(net.line_geodata.index) - set(net.line.index), inplace=True)
     cmap, norm = plot.cmap_continous([(0.97, "blue"), (1.0, "green"), (1.03, "red")])
     self.bc = plot.create_bus_collection(net, size=90, zorder=2, cmap=cmap, norm=norm, picker=True,
                                          infofunc=lambda x: "This is bus %s"%net.bus.name.at[x])
     cmap, norm = plot.cmap_continous([(20, "green"), (50, "yellow"), (60, "red")])
     self.lc = plot.create_line_collection(net, zorder=1, cmap=cmap, norm=norm, linewidths=2,
                                           infofunc=lambda x: "This is line %s"%net.line.name.at[x])
     self.fig, self.ax = plt.subplots()
     plot.draw_collections([self.bc, self.lc], ax=self.ax)
     plt.close()
     self.canvas = FigureCanvas(self.fig)
     self.canvas.mpl_connect('pick_event', self.pick_event)
     self.gridLayout.addWidget(self.canvas)
     self.canvas.draw()
     self.LoadSlider.valueChanged.connect(self.slider_changed)
     self.SgenSlider.valueChanged.connect(self.slider_changed)
     self.setWindowTitle("PyQt with pandapower Demo")
Ejemplo n.º 8
0
    def network_plot(self, data: GridData, mode="topological_graph", pause=5):
        """
        plot the network using matplotlib

        * mode = topological_graph or color_map
        """

        if mode == "topological_graph":
            self.net.bus_geodata.drop(self.net.bus_geodata.index, inplace=True)
            self.net.line_geodata.drop(self.net.line_geodata.index,
                                       inplace=True)
            pplot.create_generic_coordinates(self.net)
            pplot.fuse_geodata(self.net)
            buses = self.net.bus.index.tolist()
            coords = zip(self.net.bus_geodata.x.loc[buses].values,
                         self.net.bus_geodata.y.loc[buses].values)
            bus_layer = pplot.create_bus_collection(self.net,
                                                    self.net.bus.index,
                                                    size=.05,
                                                    color="black",
                                                    zorder=1)
            sub_layer = pplot.create_bus_collection(
                self.net,
                self.net.ext_grid.bus.values,
                patch_type="rect",
                size=.2,
                color="yellow",
                zorder=2)
            busid_layer = pplot.create_annotation_collection(size=0.2,
                                                             texts=np.char.mod(
                                                                 '%d', buses),
                                                             coords=coords,
                                                             zorder=3,
                                                             color="blue")
            line_layer = pplot.create_line_collection(self.net,
                                                      self.net.line.index,
                                                      color="grey",
                                                      linestyles="dashed",
                                                      linewidths=0.2,
                                                      use_bus_geodata=True,
                                                      zorder=4)
            lines_ergized = self.net.line[self.net.line.in_service ==
                                          True].index
            line_ergized_layer = pplot.create_line_collection(self.net,
                                                              lines_ergized,
                                                              color="red",
                                                              zorder=5)
            pplot.draw_collections([
                line_layer, bus_layer, sub_layer, busid_layer,
                line_ergized_layer
            ],
                                   figsize=(8, 6))
            pass

        if mode == "color_map":
            self.net.bus_geodata.drop(self.net.bus_geodata.index, inplace=True)
            self.net.line_geodata.drop(self.net.line_geodata.index,
                                       inplace=True)
            voltage_map = [((0.00, 0.90), "lime"), ((0.90, 0.950), "g"),
                           ((0.950, 1.05), "b"), ((1.05, 1.1), "m"),
                           ((1.1, 1.5), "r")]
            cmap, norm = pplot.cmap_discrete(voltage_map)
            pplot.create_generic_coordinates(self.net)
            pplot.fuse_geodata(self.net)
            buses = self.net.bus.index.tolist()
            coords = zip(self.net.bus_geodata.x.loc[buses].values,
                         self.net.bus_geodata.y.loc[buses].values)
            bus_layer = pplot.create_bus_collection(self.net,
                                                    self.net.bus.index,
                                                    size=.05,
                                                    cmap=cmap,
                                                    norm=norm,
                                                    color="black",
                                                    zorder=1)
            sub_layer = pplot.create_bus_collection(
                self.net,
                self.net.ext_grid.bus.values,
                patch_type="rect",
                size=.2,
                color="yellow",
                zorder=2)
            busid_layer = pplot.create_annotation_collection(size=0.2,
                                                             texts=np.char.mod(
                                                                 '%d', buses),
                                                             coords=coords,
                                                             zorder=3,
                                                             color="blue")
            line_layer = pplot.create_line_collection(self.net,
                                                      self.net.line.index,
                                                      color="grey",
                                                      linestyles="dashed",
                                                      linewidths=0.2,
                                                      use_bus_geodata=True,
                                                      zorder=4)
            lines_ergized = self.net.line[self.net.line.in_service ==
                                          True].index
            line_ergized_layer = pplot.create_line_collection(self.net,
                                                              lines_ergized,
                                                              color="red",
                                                              zorder=5)
            pplot.draw_collections([
                line_layer, bus_layer, sub_layer, busid_layer,
                line_ergized_layer
            ],
                                   figsize=(8, 6))
            pass

        plt.ion()
        plt.plot()
        # put the fault lines list in the figure
        plt.annotate("fault lines: %s" % data.list_fault_line, (-2.3, -2.8))
        if pause == 0:
            plt.show()
        else:
            plt.pause(pause)
            plt.close()
        pass
Ejemplo n.º 9
0
# net = nw.mv_oberrhein()
net=nw.case33bw()
# net = nw.create_synthetic_voltage_control_lv_network(network_class='rural_1')
# run pf
pp.runpp(net)

# creating a color function to get a linear a colormap with color centers green at 30%, yellow at 50% and red at 60%
# line loading
cmap_list_lines=[(20, "green"), (50, "yellow"), (60, "red")]
cmap_lines, norm_lines = plot.cmap_continuous(cmap_list_lines)
# create a collection for colouring each line according to a line color range.
lc = plot.create_line_collection(net, net.line.index, zorder=2, cmap=cmap_lines, norm=norm_lines, linewidths=2)
# create discrete map for node pu magnitude
cmap_list_nodes=[(0.975, "blue"), (1.0, "green"), (1.03, "red")]
cmap_nodes, norm_nodes = plot.cmap_continuous(cmap_list_nodes)
bc = plot.create_bus_collection(net, net.bus.index, size=0.07, zorder=2, cmap=cmap_nodes, norm=norm_nodes) #80 of mv obherreim and 0.07 for ieee
# tlc, tpc = plot.create_trafo_collection(net, net.trafo.index, color="g")
sc = plot.create_bus_collection(net, net.ext_grid.bus.values, patch_type="rect", size=.08, color="y", zorder=11)
# plot.draw_collections([lc, bc, sc], figsize=(8,6))
# plt.show()

net_generic = nw.case33bw()
net_generic.bus_geodata.drop(net_generic.bus_geodata.index, inplace=True)
net_generic.line_geodata.drop(net_generic.line_geodata.index, inplace=True)
plot.create_generic_coordinates(net_generic, respect_switches=True) #create artificial coordinates with the igraph package
colors = ["b", "g", "r", "c", "y"]
plot.fuse_geodata(net_generic)
bc = plot.create_bus_collection(net_generic, net_generic.bus.index, size=.08, color=colors[0], zorder=10)
lcd = plot.create_line_collection(net_generic, net_generic.line.index, color="grey", linewidths=0.5, use_bus_geodata=True)
sc = plot.create_bus_collection(net_generic, net_generic.ext_grid.bus.values, patch_type="rect", size=.08, color="y", zorder=11)
plot.draw_collections([lcd, bc, sc], figsize=(8,6))
Ejemplo n.º 10
0
import pandapower.networks as nw
import pandapower.plotting as plot
import matplotlib.pyplot as plt
import seaborn

colours = seaborn.color_palette()

net = nw.mv_oberrhein()
bc = plot.create_bus_collection(net,
                                buses=net.bus.index,
                                color=colours[0],
                                size=80,
                                zorder=1)
lc = plot.create_line_collection(net,
                                 lines=net.line.index,
                                 color='grey',
                                 zorder=2)

long_lines = net.line.loc[net.line.length_km > 2.].index
lc1 = plot.create_line_collection(net,
                                  lines=long_lines,
                                  color=colours[2],
                                  zorder=2)
plot.draw_collections([lc, bc, lc1])
plt.show()
net = nw.mv_oberrhein()
#net = nw.create_cigre_network_mv(with_der="pv_wind")

#lc = plot.create_line_collection(net, net.line.index, color="grey", zorder=1) #create lines
#bc = plot.create_bus_collection(net, net.bus.index, size=80, color=colors[0], zorder=2) #create buses
#plot.draw_collections([lc, bc], figsize=(8,6)) # plot lines and buses

long_lines = net.line[net.line.length_km > 2.].index
lc = plot.create_line_collection(net, net.line.index, color="grey", zorder=1)
lcl = plot.create_line_collection(net, long_lines, color=(.3, 1, .3), zorder=2)

pp.runpp(net)
low_voltage_buses = net.res_bus[net.res_bus.vm_pu < 0.98].index
bc = plot.create_bus_collection(net,
                                net.bus.index,
                                size=90,
                                color=(.2, .2, 1),
                                zorder=10)
bch = plot.create_bus_collection(net,
                                 low_voltage_buses,
                                 size=90,
                                 color=(1, 0, 0),
                                 zorder=11)
plot.draw_collections([lc, lcl, bc, bch], figsize=(8, 6))

im = plt.imread("")

plt.savefig('test', dpi=300)
###############################################################################

###############################################################################
Ejemplo n.º 12
0
# identify overvoltage
vm_max = 1.00
overvoltage_bus = net.res_bus[net.res_bus['vm_pu']>vm_max]
for i_overvoltage in  overvoltage_bus.index:
    overvoltage_bus_value = overvoltage_bus['vm_pu'][i_overvoltage]
    overvoltage_bus_id = i_overvoltage
    print(f"Bus with overvoltage:{overvoltage_bus_id}, load_percentage:{overvoltage_bus_value}")

# visualize network
colors = seaborn.color_palette()
if 1==0:
    plot.simple_plot(net, show_plot=True)
if 1==0:
    low_voltage_buses = net.res_bus[net.res_bus.vm_pu < 0.98].index
    lc = plot.create_line_collection(net, net.line.index, color="grey", zorder=1)
    bc = plot.create_bus_collection(net, net.bus.index, size=90, color=colors[0], zorder=10)
    bch = plot.create_bus_collection(net, low_voltage_buses, size=90, color=colors[2], zorder=11)
    plot.draw_collections([lc, bc, bch], figsize=(8, 6))
    plt.show()

# OPF Part--------------------------------------------------------------
# creating virtual generators and virtual loads for OPF execution
print("OPF part. Creation of flexible sources")
# add virtual demands and generators to quantify the flexibility request
net_opf = pp.pandapowerNet(net)
flex_source_1_up = pp.create_gen(net_opf,bus4, name='Flex_1_UP', min_p_mw=0, p_mw=0, max_p_mw=100, min_q_mvar=0, max_q_mvar=200, controllable=True)
flex_source_1_down = pp.create_load(net_opf, bus4,name='Flex_1_DOWN', p_mw=0, min_p_mw=0, max_p_mw=100, min_q_mvar=0, max_q_mvar=200, controllable=True)
dummy = 1

# costs parameters for flexibility activation
# pp.create_poly_cost(net, 0, 'ext_grid', cp1_eur_per_mw=0)
Ejemplo n.º 13
0
import pandapower as pp
import pandapower.networks as nw
import pandapower.plotting as plot
import matplotlib.pyplot as plt

from matplotlib.pyplot import get_cmap
from matplotlib.colors import Normalize

# load the network - test case118 from MATPOWER and run power flow to retrieve results
net = nw.case118()
pp.runpp(net)

# create common colorbars and norms for the branches (lines) e.g. 20% line loading in green, 50% line loading in yellow
cmap = get_cmap('PuBu_r')
norm = Normalize(vmin=0, vmax=5)

# initialize the line and bus collections
lc = plot.create_line_collection(net, net.line.index, zorder=1, cmap=cmap, norm=norm) #, norm=norm, linewidths=2)
bc = plot.create_bus_collection(net, net.bus.index, size=0.1, zorder=2, cmap=cmap) #, norm=norm)

plot.draw_collections([lc, bc], figsize=(8,6), plot_colorbars=False)

plt.show()
# Youtube Tutorial: https://www.youtube.com/watch?v=QYDp_-TX7C4
import pandapower as pp
import pandapower.plotting as pplt
import pandapower.topology as top
import pandapower.networks as nw
import matplotlib.pyplot as plt
import seaborn as sns

net = nw.mv_oberrhein()
pplt.simple_plot(net)

mg = top.create_nxgraph(net, nogobuses=set(net.trafo.lv_bus.values) | set(net.trafo.hv_bus.values))
colors = sns.color_palette()
collections = list()
sizes = pplt.get_collection_sizes(net)
for area, color in zip(top.connected_components(mg), colors):
    collections.append(pplt.create_bus_collection(net, area, color=color, size=sizes["bus"]))
    line_ind = net.line.loc[:, "from_bus"].isin(area) | net.line.loc[:, "to_bus"].isin(area)
    lines = net.line.loc[line_ind].index
    collections.append(pplt.create_line_collection(net, lines, color=color))
collections.append(pplt.create_ext_grid_collection(net, size=sizes["ext_grid"]))
pplt.draw_collections(collections)
plt.show()