示例#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()
示例#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_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()
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()