Esempio n. 1
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 = self._line_color_scheme[
            color_idx] if connected and rho > 0.0 else "black"
        line_style = "-" if connected else "--"
        self._draw_powerline_line(pos_or_x, pos_or_y, pos_ex_x, pos_ex_y,
                                  color, line_style)
        if line_value is not None:
            txt = pltu.format_value_unit(line_value, line_unit)
            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)
Esempio n. 2
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):

        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)
        gen_text = ""
        if gen_value is not None:
            txt_x = pos_x + nd_x * (self._gen_radius / 2)
            txt_y = pos_y + nd_y * (self._gen_radius / 2)
            text_pos = self._textpos_from_dir(dir_x, dir_y)
            gen_text = gen_name + "<br>"
            gen_text += pltu.format_value_unit(gen_value, gen_unit)
            if self.show_gen_txt:
                trace1 = self._draw_gen_txt(gen_name,
                                            txt_x, txt_y,
                                            gen_text, text_pos)
                figure.add_trace(trace1)
        trace2 = self._draw_gen_line(pos_x, pos_y, sub_x, sub_y)
        figure.add_trace(trace2)
        trace3 = self._draw_gen_circle(pos_x, pos_y, gen_name, gen_text)
        figure.add_trace(trace3)
        trace4 = self._draw_gen_bus(sub_x, sub_y, dir_x, dir_y, gen_bus, gen_name)
        figure.add_trace(trace4)
Esempio n. 3
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):

        color_scheme = self.line_color_scheme
        capacity = observation.rho[line_id]
        color = color_scheme[int(capacity * float(len(color_scheme) - 1))]
        if capacity == 0.0:
            color = "black"
        line_style = dict(dash=None if connected else "dash", color=color)
        if line_value is not None:
            line_text = pltu.format_value_unit(line_value, line_unit)
            trace1 = self._draw_powerline_txt(line_name, pos_or_x, pos_or_y,
                                              pos_ex_x, pos_ex_y, line_text)
            figure.add_trace(trace1)
        trace2 = self._draw_powerline_line(line_name, pos_or_x, pos_or_y,
                                           pos_ex_x, pos_ex_y, line_style)
        figure.add_trace(trace2)
        dir_x, dir_y = pltu.norm_from_points(pos_or_x, pos_or_y, pos_ex_x,
                                             pos_ex_y)
        trace3 = self._draw_powerline_bus(pos_or_x, pos_or_y, dir_x, dir_y,
                                          or_bus, line_name, self._or_prefix)
        trace4 = self._draw_powerline_bus(pos_ex_x, pos_ex_y, -dir_x, -dir_y,
                                          ex_bus, line_name, self._ex_prefix)
        figure.add_trace(trace3)
        figure.add_trace(trace4)
        watt_sign = observation.p_or[line_id]
        trace5 = self._draw_powerline_arrow(pos_or_x, pos_or_y, pos_ex_x,
                                            pos_ex_y, watt_sign, line_name,
                                            color)
        figure.add_trace(trace5)
Esempio n. 4
0
    def _draw_powerline_arrow(self, pos_or_x, pos_or_y, pos_ex_x, pos_ex_y,
                              watts_value, line_name, line_color):
        cx, cy = pltu.middle_from_points(pos_or_x, pos_or_y, pos_ex_x,
                                         pos_ex_y)
        dx, dy = pltu.norm_from_points(pos_or_x, pos_or_y, pos_ex_x, pos_ex_y)
        sym = self._plotly_tri_from_line_dir_and_sign(dx, dy, watts_value)
        marker_dict = dict(size=self._line_arrow_radius,
                           color=line_color,
                           showscale=False,
                           symbol=sym)

        sub_offx = dx * self._sub_radius
        sub_offy = dy * self._sub_radius
        or_offx = dx * self._line_arrow_len
        or_offy = dy * self._line_arrow_len
        arrx_or = pos_or_x + sub_offx + or_offx
        arrx_ex = pos_or_x + sub_offx
        arry_or = pos_or_y + sub_offy + or_offy
        arry_ex = pos_or_y + sub_offy
        trace_name = self._line_prefix + self._arrow_prefix + line_name
        return go.Scatter(x=[arrx_or, arrx_ex],
                          y=[arry_or, arry_ex],
                          hoverinfo='skip',
                          showlegend=False,
                          marker=marker_dict,
                          name=trace_name)
Esempio n. 5
0
    def draw_storage(self, figure, observation, load_id, load_name, load_bus,
                     load_value, load_unit, pos_x, pos_y, sub_x, sub_y):
        self.xlim[0] = min(self.xlim[0], pos_x - self._load_radius)
        self.xlim[1] = max(self.xlim[1], pos_x + self._load_radius)
        self.ylim[0] = min(self.ylim[0], pos_y - self._load_radius)
        self.ylim[1] = max(self.ylim[1], pos_y + self._load_radius)
        self._draw_storage_line(
            pos_x, pos_y, sub_x,
            sub_y)  # line from the storage to the substation
        self._draw_storage_circle(pos_x, pos_y)  # storage element

        load_txt = ""
        if self._storage_name:
            load_txt += "\"{}\":\n".format(load_name)
        if self._storage_id:
            load_txt += "id: {}\n".format(load_id)
        if load_value is not None:
            load_txt += pltu.format_value_unit(load_value, load_unit)
        if load_txt:
            self._draw_load_txt(pos_x, pos_y, sub_x, sub_y, load_txt)
        if self._display_load_name:
            self._draw_load_name(pos_x, pos_y, str(load_id))
        load_dir_x, load_dir_y = pltu.norm_from_points(sub_x, sub_y, pos_x,
                                                       pos_y)
        self._draw_storage_bus(sub_x, sub_y, load_dir_x, load_dir_y, load_bus)
Esempio n. 6
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
        hide = False
        if np.isfinite(rho):
            color_idx = max(0, min(n_colors, int(rho * n_colors)))
        else:
            color_idx = 0
            hide = True

        color = "black"
        if not hide:
            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)
Esempio n. 7
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)
        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)
            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)
        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)
Esempio n. 8
0
 def _draw_load_txt(self, pos_x, pos_y, sub_x, sub_y, text):
     dir_x, dir_y = pltu.vec_from_points(sub_x, sub_y, pos_x, pos_y)
     off_x, off_y = pltu.norm_from_points(sub_x, sub_y, pos_x, pos_y)
     txt_x = pos_x + off_x * self._gen_radius
     txt_y = pos_y + off_y * self._gen_radius
     ha = self._h_textpos_from_dir(dir_x, dir_y)
     va = self._v_textpos_from_dir(dir_x, dir_y)
     self.ax.text(txt_x,
                  txt_y,
                  text,
                  color=self._load_txt_color,
                  horizontalalignment=ha,
                  fontsize='small',
                  verticalalignment=va)
Esempio n. 9
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.xlim[1] = max(self.xlim[1], pos_x)
     self.ylim[0] = min(self.ylim[0], pos_y)
     self.ylim[1] = max(self.ylim[1], pos_y)
     self._draw_gen_line(pos_x, pos_y, sub_x, sub_y)
     self._draw_gen_circle(pos_x, pos_y)
     if gen_value is not None:
         gen_txt = gen_name + ":\n"
         gen_txt += pltu.format_value_unit(gen_value, gen_unit)
         self._draw_gen_txt(pos_x, pos_y, sub_x, sub_y, gen_txt)
     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)
Esempio n. 10
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):
     self.xlim[0] = min(self.xlim[0], pos_x)
     self.xlim[1] = max(self.xlim[1], pos_x)
     self.ylim[0] = min(self.ylim[0], pos_y)
     self.ylim[1] = max(self.ylim[1], pos_y)
     self._draw_load_line(pos_x, pos_y, sub_x, sub_y)
     self._draw_load_circle(pos_x, pos_y)
     if load_value is not None:
         load_txt = load_name + ":\n"
         load_txt += pltu.format_value_unit(load_value, load_unit)
         self._draw_load_txt(pos_x, pos_y, sub_x, sub_y, load_txt)
     self._draw_load_name(pos_x, pos_y, str(load_id))
     load_dir_x, load_dir_y = pltu.norm_from_points(sub_x, sub_y, pos_x,
                                                    pos_y)
     self._draw_load_bus(sub_x, sub_y, load_dir_x, load_dir_y, load_bus)
Esempio n. 11
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)
Esempio n. 12
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)
     self._draw_gen_line(pos_x, pos_y, sub_x, sub_y)
     self._draw_gen_circle(pos_x, pos_y)
     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:
         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)
     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)
Esempio n. 13
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)
Esempio n. 14
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))