def _plot_lines(self, figure, observation, line_values, line_unit, redraw): draw_fn = self.draw_powerline if not redraw: draw_fn = self.update_powerline topo = observation.topo_vect line_or_pos = observation.line_or_pos_topo_vect line_ex_pos = observation.line_ex_pos_topo_vect for line_idx in range(observation.n_line): line_or_sub = observation.line_or_to_subid[line_idx] line_or_sub_name = observation.name_sub[line_or_sub] line_ex_sub = observation.line_ex_to_subid[line_idx] line_ex_sub_name = observation.name_sub[line_ex_sub] line_name = observation.name_line[line_idx] line_status = True line_status = observation.line_status[line_idx] line_value = None if line_values is not None: lv = line_values[line_idx] if isinstance(lv, (float, dt_float)): line_value = np.round(float(lv), 2) elif isinstance(lv, (int, dt_int)): line_value = int(lv) else: line_value = lv line_or_bus = topo[line_or_pos[line_idx]] line_or_bus = line_or_bus if line_or_bus > 0 else 0 line_or_x = self._grid_layout[line_or_sub_name][0] line_or_y = self._grid_layout[line_or_sub_name][1] line_ex_bus = topo[line_ex_pos[line_idx]] line_ex_bus = line_ex_bus if line_ex_bus > 0 else 0 line_ex_x = self._grid_layout[line_ex_sub_name][0] line_ex_y = self._grid_layout[line_ex_sub_name][1] # Special case for parralel lines tmp = self.observation_space.get_lines_id(from_=line_or_sub, to_=line_ex_sub) if len(tmp) > 1: ox, oy = pltu.orth_norm_from_points(line_or_x, line_or_y, line_ex_x, line_ex_y) if line_idx == tmp[0]: line_or_x += ox * self._parallel_spacing line_or_y += oy * self._parallel_spacing line_ex_x += ox * self._parallel_spacing line_ex_y += oy * self._parallel_spacing else: line_or_x -= ox * self._parallel_spacing line_or_y -= oy * self._parallel_spacing line_ex_x -= ox * self._parallel_spacing line_ex_y -= oy * self._parallel_spacing draw_fn(figure, observation, line_idx, line_name, line_status, line_value, line_unit, line_or_bus, line_or_x, line_or_y, line_ex_bus, line_ex_x, line_ex_y)
def _draw_powerline_txt(self, pos_or_x, pos_or_y, pos_ex_x, pos_ex_y, text): pos_x, pos_y = pltu.middle_from_points(pos_or_x, pos_or_y, pos_ex_x, pos_ex_y) off_x, off_y = pltu.orth_norm_from_points(pos_or_x, pos_or_y, pos_ex_x, pos_ex_y) txt_x = pos_x + off_x * (self._load_radius / 2) txt_y = pos_y + off_y * (self._load_radius / 2) ha = self._h_textpos_from_dir(off_x, off_y) va = self._v_textpos_from_dir(off_x, off_y) self.ax.text(txt_x, txt_y, text, color=self._gen_txt_color, fontsize='small', horizontalalignment=ha, verticalalignment=va)