-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_plots.py
More file actions
132 lines (100 loc) · 4.73 KB
/
main_plots.py
File metadata and controls
132 lines (100 loc) · 4.73 KB
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
130
131
132
import matplotlib.pyplot as plt
from pathlib import Path
import pytz
from cosimos.simulator.history import History
from bems.config import EMSConfig
#plt.style.use('tj_style.mplstyle')
plt.rcParams['figure.dpi'] = 150
plt.rcParams['axes.grid'] = True
plt.rcParams['figure.figsize'] = [8, 4.8]
timezone = pytz.timezone('Europe/Berlin')
def plot_all(history: History, results_path: Path, store_figs: bool = False) -> None:
plots = [
plot_zone_temperatures,
plot_heating_cooling,
plot_electrical_power,
plot_individual_heating,
plot_individual_cooling,
plot_battery
]
# don't plot if simulation stopped immediately
if len(history.time) == 1:
return
store_figs = store_figs and results_path is not None
if store_figs:
results_path.joinpath('plots').mkdir(exist_ok=True, parents=True)
for plot in plots:
plot(history, results_path, store_figs)
def plot_zone_temperatures(history: History, results_path: Path, store_figs: bool = False) -> None:
data = history.to_dataframe()
fig, ax = plt.subplots() # type: plt.Figure, plt.Axes
data.state[[f"theta_{i}" for i in range(1, 10)]].plot(ax=ax, drawstyle='steps-post')
ax.legend([rf"$\theta_{i}$" for i in range(1, 10)])
ax.set_ylim([15, 25])
ax.set_ylabel('Zone temperature in °C')
ax2 = ax.twinx()
data.model_parameters['theta_air'].plot(ax=ax2, label=None, drawstyle='steps-post', linestyle=':')
ax2.set_ylabel('Ambient temperature in °C')
ax2.set_ylim([-10, 35])
fig.tight_layout()
if store_figs:
fig.savefig(results_path.joinpath('plots/zone_temperatures.png'), dpi=300)
plt.show()
def plot_heating_cooling(history: History, results_path: Path, store_figs: bool = False) -> None:
data = history.to_dataframe()
fig, ax = plt.subplots()
data.applied_controller_output['Q_cool_b'].plot(ax=ax, label=r"$Q_\mathrm{cool,b}$", drawstyle='steps-post')
data.applied_controller_output['Q_cool_s'].plot(ax=ax, label=r"$Q_\mathrm{cool,s}$", drawstyle='steps-post')
data.applied_controller_output['Q_chp'].plot(ax=ax, label=r"$Q_\mathrm{chp}$", drawstyle='steps-post')
data.applied_controller_output['Q_rad'].plot(ax=ax, label=r"$Q_\mathrm{rad}$", drawstyle='steps-post')
ax.set_ylim([-500, 500])
ax.legend()
ax.set_ylabel('Power in kW')
fig.tight_layout()
if store_figs:
fig.savefig(results_path.joinpath('plots/heating_cooling.png'), dpi=300)
plt.show()
def plot_electrical_power(history: History, results_path: Path, store_figs: bool = False) -> None:
data = history.to_dataframe()
fig, ax = plt.subplots()
data.applied_controller_output['P_grid'].plot(ax=ax, label=r"$P_\mathrm{grid}$", drawstyle='steps-post')
data.applied_controller_output['P_bat'].plot(ax=ax, label=r"$P_\mathrm{bat}$", drawstyle='steps-post')
data.applied_controller_output['P_chp'].plot(ax=ax, label=r"$P_\mathrm{chp}$", drawstyle='steps-post')
data.model_parameters['P_dem'].plot(ax=ax, label=r"$P_\mathrm{dem}$", drawstyle='steps-post')
data.model_parameters['P_ren'].plot(ax=ax, label=r"$P_\mathrm{ren}$", drawstyle='steps-post')
ax.set_ylim([-700, 700])
ax.legend()
fig.tight_layout()
if store_figs:
fig.savefig(results_path.joinpath('plots/electrical_power.png'), dpi=300)
plt.show()
def plot_individual_heating(history: History, results_path: Path, store_figs: bool = False) -> None:
data = history.to_dataframe()
fig, ax = plt.subplots()
data.applied_controller_output[[f'Q_heat_{i}' for i in range(1, 8)]].plot(ax=ax, drawstyle='steps-post')
ax.legend([rf"$Q_\mathrm{{heat, {i} }}$" for i in range(1, 10)])
ax.set_ylim([0, 500])
fig.tight_layout()
if store_figs:
fig.savefig(results_path.joinpath('plots/individual_heating.png'), dpi=300)
plt.show()
def plot_individual_cooling(history: History, results_path: Path, store_figs: bool = False) -> None:
data = history.to_dataframe()
fig, ax = plt.subplots()
data.applied_controller_output[[f'Q_cool_{i}' for i in range(1, 10)]].plot(ax=ax, drawstyle='steps-post')
ax.legend([rf"$Q_\mathrm{{cool, {i} }}$" for i in range(1, 10)])
ax.set_ylim([-500, 0])
fig.tight_layout()
if store_figs:
fig.savefig(results_path.joinpath('plots/individual_cooling.png'), dpi=300)
plt.show()
def plot_battery(history: History, results_path: Path, store_figs: bool = False) -> None:
data = history.to_dataframe()
fig, ax = plt.subplots()
data.state['E_bat'].plot(ax=ax, label=r"$E_\mathrm{bat}$", drawstyle='steps-post')
ax.set_ylim([-700, 700])
ax.legend()
fig.tight_layout()
if store_figs:
fig.savefig(results_path.joinpath('plots/battery.png'), dpi=300)
plt.show()