Beispiel #1
0
    def draw_gen(self, figure, observation, gen_id, gen_name, gen_bus,
                 gen_value, gen_unit, pos_x, pos_y, sub_x, sub_y):
        self.xlim[0] = min(self.xlim[0], pos_x - self._gen_radius)
        self.xlim[1] = max(self.xlim[1], pos_x + self._gen_radius)
        self.ylim[0] = min(self.ylim[0], pos_y - self._gen_radius)
        self.ylim[1] = max(self.ylim[1], pos_y + self._gen_radius)
        hide = False
        if isinstance(self._gen_edge_color, str):
            # case where the color of the generator is a string (same color for all generators)
            gen_color = self._gen_edge_color
        else:
            my_val = observation.prod_p[gen_id]
            n_colors = len(self._gen_edge_color) - 1
            if np.isfinite(my_val):
                color_idx = max(0, min(n_colors, int(my_val * n_colors)))
            else:
                color_idx = 0
                hide = True
            gen_color = self._gen_edge_color[color_idx]

        if not hide:
            self._draw_gen_line(pos_x, pos_y, sub_x, sub_y)
            self._draw_gen_circle(pos_x, pos_y, gen_color)
            gen_txt = ""
            if self._gen_name:
                gen_txt += "\"{}\":\n".format(gen_name)
            if self._gen_id:
                gen_txt += "id: {}\n".format(gen_id)
            if gen_value is not None and self._display_gen_value:
                gen_txt += pltu.format_value_unit(gen_value, gen_unit)
            if gen_txt:
                self._draw_gen_txt(pos_x, pos_y, sub_x, sub_y, gen_txt)
            if self._display_gen_name:
                self._draw_gen_name(pos_x, pos_y, str(gen_id))
            gen_dir_x, gen_dir_y = pltu.norm_from_points(
                sub_x, sub_y, pos_x, pos_y)
            self._draw_gen_bus(sub_x, sub_y, gen_dir_x, gen_dir_y, gen_bus)
Beispiel #2
0
    def draw_powerline(self, figure, observation, line_id, line_name,
                       connected, line_value, line_unit, or_bus, pos_or_x,
                       pos_or_y, ex_bus, pos_ex_x, pos_ex_y):
        rho = observation.rho[line_id]
        n_colors = len(self._line_color_scheme) - 1
        color_idx = max(0, min(n_colors, int(rho * n_colors)))
        color = "black"
        if connected and rho > 0.0:
            color = self._line_color_scheme[color_idx]
        line_style = "-" if connected else "--"
        self._draw_powerline_line(pos_or_x, pos_or_y, pos_ex_x, pos_ex_y,
                                  color, line_style)
        # Deal with line text configurations
        txt = ""
        if self._line_name:
            txt += "\"{}\"\n".format(line_name)
        if self._line_id:
            txt += "id: {}\n".format(str(line_id))
        if line_value is not None:
            txt += pltu.format_value_unit(line_value, line_unit)
        if txt:
            self._draw_powerline_txt(pos_or_x, pos_or_y, pos_ex_x, pos_ex_y,
                                     txt)

        or_dir_x, or_dir_y = pltu.norm_from_points(pos_or_x, pos_or_y,
                                                   pos_ex_x, pos_ex_y)
        self._draw_powerline_bus(pos_or_x, pos_or_y, or_dir_x, or_dir_y,
                                 or_bus)
        ex_dir_x, ex_dir_y = pltu.norm_from_points(pos_ex_x, pos_ex_y,
                                                   pos_or_x, pos_or_y)
        self._draw_powerline_bus(pos_ex_x, pos_ex_y, ex_dir_x, ex_dir_y,
                                 ex_bus)
        watt_value = observation.p_or[line_id]
        if rho > 0.0 and watt_value != 0.0:
            self._draw_powerline_arrow(pos_or_x, pos_or_y, pos_ex_x, pos_ex_y,
                                       color, watt_value)
Beispiel #3
0
    def update_powerline(self, figure, observation, line_id, line_name,
                         connected, line_value, line_unit, or_bus, pos_or_x,
                         pos_or_y, ex_bus, pos_ex_x, pos_ex_y):
        color_scheme = self.line_color_scheme
        capacity = min(observation.rho[line_id], 1.0)
        color_idx = int(capacity * (len(color_scheme) - 1))
        color = color_scheme[color_idx]
        if capacity == 0.0:
            color = "black"
        if line_value is not None:
            line_text = pltu.format_value_unit(line_value, line_unit)
            figure.update_traces(text=line_text, selector=dict(name=line_name))

        line_style = dict(dash=None if connected else "dash", color=color)
        figure.update_traces(line=line_style,
                             selector=dict(name=self._line_prefix + line_name))

        or_bus = or_bus if or_bus > 0 else 0
        ex_bus = ex_bus if ex_bus > 0 else 0
        or_marker = dict(color=self._line_bus_colors[or_bus])
        ex_marker = dict(color=self._line_bus_colors[ex_bus])
        or_select_name = self._line_prefix + self._bus_prefix + self._or_prefix + line_name
        ex_select_name = self._line_prefix + self._bus_prefix + self._ex_prefix + line_name
        figure.update_traces(marker=or_marker,
                             selector=dict(name=or_select_name))
        figure.update_traces(marker=ex_marker,
                             selector=dict(name=ex_select_name))
        arrow_select_name = self._line_prefix + self._arrow_prefix + line_name
        watt_value = observation.p_or[line_id]
        dx, dy = pltu.norm_from_points(pos_or_x, pos_or_y, pos_ex_x, pos_ex_y)
        arrow_sym = self._plotly_tri_from_line_dir_and_sign(dx, dy, watt_value)
        arrow_display = True if capacity > 0.0 else False
        arrow_marker = dict(color=color, symbol=arrow_sym)
        figure.update_traces(marker=arrow_marker,
                             visible=arrow_display,
                             selector=dict(name=arrow_select_name))
Beispiel #4
0
    def draw_load(self, figure, observation, load_id, load_name, load_bus,
                  load_value, load_unit, pos_x, pos_y, sub_x, sub_y):
        dir_x, dir_y = pltu.norm_from_points(sub_x, sub_y, pos_x, pos_y)
        nd_x, nd_y = pltu.norm_from_points(sub_x, sub_y, pos_x, pos_y)
        load_text = ""
        if load_value is not None:
            txt_x = pos_x + nd_x * (self._load_radius / 2)
            txt_y = pos_y + nd_y * (self._load_radius / 2)
            text_pos = self._textpos_from_dir(dir_x, dir_y)
            load_text = load_name + "<br>"
            load_text += pltu.format_value_unit(load_value, load_unit)
            if self.show_load_txt:
                trace1 = self._draw_load_txt(load_name, txt_x, txt_y,
                                             load_text, text_pos)
                figure.add_trace(trace1)

        trace2 = self._draw_load_line(pos_x, pos_y, sub_x, sub_y)
        figure.add_trace(trace2)
        trace3 = self._draw_load_circle(pos_x, pos_y, load_name, load_text)
        figure.add_trace(trace3)

        trace4 = self._draw_load_bus(sub_x, sub_y, dir_x, dir_y, load_bus,
                                     load_name)
        figure.add_trace(trace4)
Beispiel #5
0
 def update_gen(self, figure, observation, gen_id, gen_name, gen_bus,
                gen_value, gen_unit, pos_x, pos_y, sub_x, sub_y):
     gen_text = ""
     if gen_value is not None:
         gen_text = gen_name + "<br>"
         gen_text += pltu.format_value_unit(gen_value, gen_unit)
         if self.show_gen_txt:
             figure.update_traces(text=gen_text,
                                  selector=dict(name=gen_name))
         circle_name = self._gen_prefix + gen_name
         figure.update_traces(text=gen_text,
                              selector=dict(name=circle_name))
     gen_marker = dict(color=self._line_bus_colors[gen_bus])
     gen_select_name = self._gen_prefix + self._bus_prefix + gen_name
     figure.update_traces(marker=gen_marker,
                          selector=dict(name=gen_select_name))
Beispiel #6
0
 def update_load(self, figure, observation, load_id, load_name, load_bus,
                 load_value, load_unit, pos_x, pos_y, sub_x, sub_y):
     load_text = ""
     if load_value is not None:
         load_text = load_name + "<br>"
         load_text += pltu.format_value_unit(load_value, load_unit)
         if self.show_load_txt:
             figure.update_traces(text=load_text,
                                  selector=dict(name=load_name))
         circle_name = self._load_prefix + load_name
         figure.update_traces(text=load_text,
                              selector=dict(name=circle_name))
     load_marker = dict(color=self._line_bus_colors[load_bus])
     load_select_name = self._load_prefix + self._bus_prefix + load_name
     figure.update_traces(marker=load_marker,
                          selector=dict(name=load_select_name))
Beispiel #7
0
 def _draw_powerline_arrow(self, pos_or_x, pos_or_y, pos_ex_x, pos_ex_y,
                           color, watt_value):
     sign = 1.0 if watt_value > 0.0 else -1.0
     off = 1.0 if watt_value > 0.0 else 2.0
     dx, dy = pltu.norm_from_points(pos_or_x, pos_or_y, pos_ex_x, pos_ex_y)
     lx = dx * self._line_arrow_len
     ly = dy * self._line_arrow_len
     arr_x = pos_or_x + dx * self._sub_radius + off * lx
     arr_y = pos_or_y + dy * self._sub_radius + off * ly
     patch = patches.FancyArrow(arr_x,
                                arr_y,
                                sign * lx,
                                sign * ly,
                                length_includes_head=True,
                                head_length=self._line_arrow_len,
                                head_width=self._line_arrow_width,
                                edgecolor=color,
                                facecolor=color)
     self.ax.add_patch(patch)