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()
Esempio n. 3
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