コード例 #1
0
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()
コード例 #2
0
def test_cmap_continuous():
    cmap_list = [(0.97, "blue"), (1.0, "green"), (1.03, "red")]
    cmap, norm = plot.cmap_continuous(cmap_list)

    assert np.allclose(cmap(0.99), (0.984313725490196, 0.007873894655901603, 0.0, 1.0))
    assert np.allclose(cmap(1.02), (1.0, 0.0, 0.0, 1.0))
    assert np.allclose([norm(0.97 + 0.01 * n) for n in range(7)],
                       [0.16666666666666666 * n for n in range(7)])
コード例 #3
0
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()
コード例 #4
0
import pandapower as pp
import pandapower.networks as nw
import pandapower.plotting as plot
import matplotlib.pyplot as plt

# load network case
# 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