/
Plotting.py
129 lines (115 loc) · 3.6 KB
/
Plotting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright (c) 2019-2020, RTE (https://www.rte-france.com)
# See AUTHORS.txt
# This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0.
# If a copy of the Mozilla Public License, version 2.0 was not distributed with this file,
# you can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems.
from grid2op.Exceptions import PlotError
from grid2op.Plot.PlotPlotly import PlotPlotly
from grid2op.Plot.PlotMatplotlib import PlotMatplotlib
from grid2op.Plot.PlotPyGame import PlotPyGame
from grid2op.Exceptions.plotExceptions import PyGameQuit
class Plotting:
"""
INTERNAL
.. warning:: /!\\\\ This class is deprecated /!\\\\
"""
allwed_display_mod = {
"pygame": PlotPyGame,
"plotly": PlotPlotly,
"matplotlib": PlotMatplotlib,
}
def __init__(
self,
observation_space,
display_mod="plotly",
substation_layout=None,
radius_sub=20.0,
load_prod_dist=70.0,
bus_radius=6.0,
):
if display_mod not in self.allwed_display_mod:
raise PlotError(
'Only avaible plot mod are "{}". You specified "{}" which is not supported.'
"".format(self.allwed_display_mod, display_mod)
)
cls_ = self.allwed_display_mod[display_mod]
self.displ_backend = cls_(
observation_space,
substation_layout=substation_layout,
radius_sub=radius_sub,
load_prod_dist=load_prod_dist,
bus_radius=bus_radius,
)
self.display_mod = display_mod
def _display_fig(self, fig, display):
if display:
if self.display_mod == "plotly":
fig.show()
elif self.display_mod == "matplotlib":
fig, ax = fig
fig.show()
def plot_layout(
self, fig=None, reward=None, done=None, timestamp=None, display=True
):
try:
fig = self.displ_backend.plot_layout(
fig=fig, reward=reward, done=done, timestamp=timestamp
)
self._display_fig(fig, display=display)
except PyGameQuit:
pass
return fig
def plot_info(
self,
fig=None,
line_info=None,
load_info=None,
gen_info=None,
sub_info=None,
colormap=None,
display=True,
):
try:
fig = self.displ_backend.plot_info(
fig=fig,
line_info=line_info,
load_info=load_info,
gen_info=gen_info,
sub_info=sub_info,
colormap=colormap,
)
self._display_fig(fig, display=display)
except PyGameQuit:
pass
return fig
def plot_obs(
self,
observation,
fig=None,
reward=None,
done=None,
timestamp=None,
line_info="rho",
load_info="p",
gen_info="p",
colormap="line",
display=True,
):
try:
fig = self.displ_backend.plot_obs(
observation,
fig=fig,
reward=reward,
done=done,
timestamp=timestamp,
line_info=line_info,
load_info=load_info,
gen_info=gen_info,
colormap=colormap,
)
self._display_fig(fig, display=display)
except PyGameQuit:
pass
return fig