Пример #1
0
def edit_layout(ds_name, test=False):
    env = grid2op.make(ds_name, test=test)

    plotter = PlotMatplot(env.observation_space)
    fig = plotter.plot_layout()
    fig.show()

    user_input = ""
    while True:
        # Select a substation or exit
        user_input = input("exit or sub id: ")
        if "exit" in user_input:
            break
        sub_id = int(user_input)

        # Get substation infos
        sub_name = env.name_sub[sub_id]
        x = plotter._grid_layout[sub_name][0]
        y = plotter._grid_layout[sub_name][1]
        print("{} [{};{}]".format(sub_name, x, y))

        # Update x coord
        user_input = input("{} new x: ".format(sub_name))
        if len(user_input) == 0:
            new_x = x
        else:
            new_x = float(user_input)

        # Update Y coord
        user_input = input("{} new y: ".format(sub_name))
        if len(user_input) == 0:
            new_y = y
        else:
            new_y = float(user_input)

        # Apply to layout
        plotter._grid_layout[sub_name][0] = new_x
        plotter._grid_layout[sub_name][1] = new_y

        # Redraw
        plotter.plot_info(figure=fig)
        fig.canvas.draw()

    # Done editing, print subs result
    subs_layout = {}
    for k, v in plotter._grid_layout.items():
        if k in env.name_sub:
            subs_layout[k] = v
    print(json.dumps(subs_layout, indent=2))
Пример #2
0
class PlotErrorOnGrid:
    """
    TODO move this class in this own file
    this class is used to "project" on the grid the metrics / errors of some proxies.

    it just ensure the projection, and as of creation (October, 26th 2020) it requires a development version
    of grid2op found at https://github.com/BDonnot/Grid2Op

    """
    def __init__(self, env):
        from grid2op.PlotGrid import PlotMatplot
        self.plot_helper = PlotMatplot(env.observation_space)
        self._line_attr = {
            "a_or", "a_ex", "p_or", "p_ex", "q_or", "q_ex", "v_or", "v_ex"
        }
        self._load_attr = {"load_p", "load_q", "load_v"}
        self._prod_attr = {"prod_p", "prod_q", "prod_v"}

    def get_fig(self, attr_nm, metrics):
        fig = None
        try:
            # only floating point values are supported at the moment
            metrics = metrics.astype(np.float)
        except Exception as exc_:
            return None

        if np.all(~np.isfinite(metrics)):
            # no need to plot a "all nan" vector
            return None

        if attr_nm in self._prod_attr:
            # deals generator attributes
            self.plot_helper.assign_gen_palette(increase_gen_size=1.5)
            fig = self.plot_helper.plot_info(gen_values=metrics,
                                             coloring="gen")
            self.plot_helper.restore_gen_palette()
        elif attr_nm in self._line_attr:
            # deals with lines attributes
            self.plot_helper.assign_line_palette()
            fig = self.plot_helper.plot_info(line_values=metrics,
                                             coloring="line")
            self.plot_helper.restore_line_palette()
        return fig