Interactive plot with plotly

class grid2op.Plot.BasePlot(observation_space, substation_layout=None, radius_sub=20.0, load_prod_dist=70.0, bus_radius=6.0)[source]

Utility class that allows to compute the position of the objects of the powergrid.

Deriving from this class allows to perform the display of the powergrid.

NB this class only performs the computation of the position, but does not display anything.

observation_space

The observation space used.

Type

grid2op.Observation.HelperObservation

__init__(observation_space, substation_layout=None, radius_sub=20.0, load_prod_dist=70.0, bus_radius=6.0)[source]

Initialize self. See help(type(self)) for accurate signature.

class grid2op.Plot.PlotMatplotlib(observation_space, substation_layout=None, radius_sub=25.0, load_prod_dist=70.0, bus_radius=4.0, alpha_obj=0.3)[source]

This class aims at simplifying the representation of the grid using matplotlib graphical libraries.

It can be used to inspect position of elements, or to project some static data on this plot. It can be usefull to have a look at the thermal limit or the maximum value produced by generators etc.

__init__(observation_space, substation_layout=None, radius_sub=25.0, load_prod_dist=70.0, bus_radius=4.0, alpha_obj=0.3)[source]

Initialize self. See help(type(self)) for accurate signature.

plot_info(line_info=None, load_info=None, gen_info=None, sub_info=None, colormap=None)[source]

Plot some information on the powergrid. For now, only numeric data are supported.

Parameters
  • line_info (list) – information to be displayed in the powerlines, in place of their name and id (for example their thermal limit) [must have the same size as the number of powerlines]

  • load_info (list) – information to display in the generators, in place of their name and id [must have the same size as the number of loads]

  • gen_info (list) – information to display in the generators, in place of their name and id (for example their pmax) [must have the same size as the number of generators]

  • sub_info (list) – information to display in the substation, in place of their name and id (for example the number of different topologies possible at this substation) [must have the same size as the number of substations]

  • colormap (str) – If not None, one of “line”, “load”, “gen” or “sub”. If None, default colors will be used for each elements (default color is the coloring of If not None, all elements will be black, and the selected element will be highlighted.

plot_layout(figsize=(15, 15))[source]

This function plot the layout of the grid, as well as the object. You will see the name of each elements and their id.

class grid2op.Plot.PlotPlotly(observation_space, substation_layout=None, radius_sub=25.0, load_prod_dist=70.0, bus_radius=4.0)[source]

This class aims at simplifying the representation of an observation as a plotly object given a layout of a given powergrid substation. It “automatically” handles the positionning of the powerlines, loads and generators based on that.

This class is just here as an inspection tool. The results can be of course improved, epsecially the label of the powerlines, or the ppositioning of the loads and generators.

_layout

Initial layout of the powergrid.

Type

dict

subs_elements

For each substation, it gives a representation of all the object connected to it. So, for each substation, it has a dictionnary with:

  • key: the name of the objects

  • value: a dictionnary representing this object containing:

    • “type” : its type, among “load”, “gen” and “line”

    • “sub_pos” (int) and index representing which element of the substation represents this object

    • “pos” : its position as a tuple

    • “z”: its position as a complex number

Type

list

cols

A color palette, this should not be changed for now.

Type

object

radius_sub

The radius of each substation. The bigger this number, the better the topology will be visible, but the more space taken on the overall plot

Type

float

load_prod_dist

The distance between a load and a generator from the center of the substation. This must be higher than PlotObs.radius_sub

Type

float

bus_radius

The radius of the bus. When multiple buses are present in a substation, they are materialized by a filled circle. This number represents the size of these circles.

Type

float

__init__(observation_space, substation_layout=None, radius_sub=25.0, load_prod_dist=70.0, bus_radius=4.0)[source]
Parameters
  • substation_layout (list) – List of tupe given the position of each of the substation of the powergrid.

  • observation_space (grid2op.Observation.ObservationSpace) – BaseObservation space

get_plot_observation(observation, fig=None)[source]

Plot the given observation in the given figure.

For now it represents information about load and generator active values. It also display dashed powerlines when they are disconnected and the color of each powerlines depends on its relative flow (its flow in amperes divided by its maximum capacity).

If a substation counts only 1 bus, nothing specific is display. If it counts more, then buses are materialized by colored dot and lines will connect every object to its appropriate bus (with the proper color).

Names of substation and objects are NOT displayed on this figure to lower the amount of information.

Parameters
  • observation (grid2op.Observation.Observation) – The observation to plot

  • fig (plotly.graph_objects.Figure) – The figure on which to plot the observation. Possibly None, in this case a new figure is made.

Returns

res – The figure updated with the data from the new observation.

Return type

plotly.graph_objects.Figure

class grid2op.Plot.PlotPyGame(observation_space, substation_layout=None, radius_sub=20.0, load_prod_dist=70.0, bus_radius=5.0, timestep_duration_seconds=1.0, fontsize=20)[source]

This renderer should be used only for “online” representation of a powergrid.

__init__(observation_space, substation_layout=None, radius_sub=20.0, load_prod_dist=70.0, bus_radius=5.0, timestep_duration_seconds=1.0, fontsize=20)[source]
Parameters
  • substation_layout (list) – List of tupe given the position of each of the substation of the powergrid.

  • observation_space (grid2op.Observation.ObservationSpace) – BaseObservation space used for the display

  • radius_sub (int) – radius (in pixel) of the substations representation.

  • load_prod_dist (int) – distance (in pixels) between the substation and the load or the generator.

  • bus_radius (int) – The buses are represented by small circles. This is the radius (in pixel) for the pixels representing the buses.

  • timestep_duration_seconds (float) – Currently not implemented.

  • fontsize (int) – size of the font used to display the texts.

close()[source]

This method is called when the renderer should be close.

get_rgb(obs, reward=None, done=None, timestamp=None)[source]

Computes and returns the rgb 3d array from an observation, and potentially other informations.

Parameters
  • obs (grid2op.Observation.Observation) – The observation to converte into a 3d array

  • reward (float) – The current reward

  • done (bool) – Whether this is the last frame of the episode.

  • timestamp (datetime.datetime) – The curent datetime corresponding to the observation

Returns

res – The 3d representation of the observation that can then be converted to a gif, or an image using appropriate softwares.

Return type

numpy.ndarray

render(obs, reward=None, done=None, timestamp=None)[source]

This function is called when the human renderer mode is called. It displays the observation on the screen, and allows for basic interactions, such as pausing or exiting.

NB pressing “escape” key or the “exit” screen button will quit the game. It will end the current episode, and won’t start any other episode.

Parameters
  • obs (grid2op.Observation.Observation) – The observation to converte into a 3d array

  • reward (float) – The current reward

  • done (bool) – Whether this is the last frame of the episode.

  • timestamp (datetime.datetime) – The curent datetime corresponding to the observation

Returns

res – Whether the human decided to quit the window. If True then it will completly quit the game, ending all steps of this episode and all episode afterwards.

Return type

bool

reset(env)[source]

Reset the runner in a consistent state, equivalent to a state where it has not run at all.

Parameters

env (grid2op.Environment.Environment) – The used environment.

If you still can’t find what you’re looking for, try in one of the following pages: