Repository navigation
Expand file tree
/
Copy pathplot_parallel.py
More file actions
146 lines (127 loc) · 7.12 KB
/
Copy pathplot_parallel.py
File metadata and controls
146 lines (127 loc) · 7.12 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""PNG plots for the parallel (3DC_4CH) model. Every time series is plotted hour by hour."""
from __future__ import annotations
from pathlib import Path
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt # noqa: E402
import pandas as pd # noqa: E402
BLUE, ORANGE, AQUA, YELLOW, GREY = "#2a78d6", "#eb6834", "#1baf7a", "#eda100", "#8a8984"
MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
MONTH_END_H = [744, 1416, 2160, 2880, 3624, 4344, 5088, 5832, 6552, 7296, 8016, 8760]
TEMPS = (("T_Water_Ret", BLUE, "T_Water_Ret (tee outlet)"),
("T_DryCooler", ORANGE, "T_DryCooler (Flow Mixer 1)"),
("T_Air", AQUA, "T_Air (ambient used by the model)"),
("T_Chiller", YELLOW, "T_Chiller (Flow Mixer 2)"))
def _style(ax, title: str, ylabel: str, xlabel: str = "Hour of year [h]") -> None:
ax.set_title(title, fontsize=10, loc="left")
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.grid(True, color="#e4e3df", linewidth=0.6)
ax.set_axisbelow(True)
for side in ("top", "right"):
ax.spines[side].set_visible(False)
def _month(hourly: pd.DataFrame) -> pd.Series:
return pd.Series([next((i for i, e in enumerate(MONTH_END_H) if x <= e), 11) for x in hourly["TIME"]],
index=hourly.index)
def _save(fig, path: Path, paths: list[Path]) -> None:
fig.tight_layout()
fig.savefig(path)
plt.close(fig)
paths.append(path)
def make_plots(hourly: pd.DataFrame, out: Path, name: str, daily: pd.DataFrame | None = None,
currency: str = "currency") -> list[Path]:
paths: list[Path] = []
h = hourly.copy()
h["month"] = _month(h)
# 1. Full year, hourly temperatures
fig, ax = plt.subplots(figsize=(11, 4.6), dpi=150)
for col, c, lab in TEMPS:
ax.plot(h["TIME"], h[col], color=c, lw=0.35, label=lab)
ax.axhline(50, color=GREY, lw=1, ls="--")
ax.text(8700, 46.5, "50 °C return target", color="#52514e", fontsize=8, ha="right")
_style(ax, f"{name}: hourly temperatures, full year", "Temperature [°C]")
ax.set_xlim(0, 8760)
leg = ax.legend(frameon=False, fontsize=8, ncol=4, loc="upper center", bbox_to_anchor=(0.5, -0.16))
for line in leg.get_lines():
line.set_linewidth(2)
_save(fig, out / f"{name}_temperatures_hourly.png", paths)
# 2. Hourly temperatures, one panel per month
fig, axes = plt.subplots(4, 3, figsize=(12, 11), dpi=150, sharey=True)
for m, ax in enumerate(axes.flat):
mm = h[h["month"] == m]
day = (mm["TIME"] - 1) / 24 - (MONTH_END_H[m - 1] / 24 if m else 0) + 1
for col, c, lab in TEMPS:
ax.plot(day, mm[col], color=c, lw=0.7, label=lab)
ax.axhline(50, color=GREY, lw=0.8, ls="--")
_style(ax, MONTHS[m], "°C" if m % 3 == 0 else "", "Day of month" if m >= 9 else "")
ax.set_xlim(1, day.max() + 1 / 24)
fig.legend(*axes.flat[0].get_legend_handles_labels(), frameon=False, fontsize=9, ncol=4,
loc="lower center", bbox_to_anchor=(0.5, 0.0))
fig.suptitle(f"{name}: hourly temperatures by month (dashed line = 50 °C target)", x=0.01, ha="left", fontsize=11)
fig.tight_layout(rect=(0, 0.03, 1, 0.98))
p = out / f"{name}_temperatures_monthly_hourly.png"
fig.savefig(p)
plt.close(fig)
paths.append(p)
# 3. Hourly heat removed and electricity, one quantity per panel
fig, axes = plt.subplots(3, 1, figsize=(11, 8), dpi=150, sharex=True)
axes[0].plot(h["TIME"], h["Cooling_Power_DC"] / 1000, color=BLUE, lw=0.35, label="Dry coolers")
axes[0].plot(h["TIME"], h["Load_Met_Chiller"] / 1000, color=ORANGE, lw=0.35, label="Chillers (load met)")
_style(axes[0], "Heat removed, hourly", "Heat rate [MW]", "")
leg = axes[0].legend(frameon=False, fontsize=8, ncol=2, loc="upper right")
for line in leg.get_lines():
line.set_linewidth(2)
axes[1].plot(h["TIME"], h["Chiller_Power"], color=ORANGE, lw=0.35)
_style(axes[1], "Chiller electricity (all chillers), hourly", "Power [kW]", "")
axes[2].plot(h["TIME"], h["Fan_Power"], color=BLUE, lw=0.5)
_style(axes[2], "Dry-cooler fan electricity (all fans), hourly", "Power [kW]")
axes[2].set_xlim(0, 8760)
_save(fig, out / f"{name}_power_hourly.png", paths)
# 4. Control behaviour (hourly)
fig, axes = plt.subplots(2, 1, figsize=(11, 5), dpi=150, sharex=True)
axes[0].step(h["TIME"], h["Fan_signal"], where="post", color=BLUE, lw=0.6)
_style(axes[0], "Fan_signal from Controller 30C/40C (levels 0.65, 0.80, 1.00)", "Fan signal [-]", "")
axes[0].set_ylim(0.6, 1.05)
axes[1].plot(h["TIME"], h["PLR_Chiller"], color=ORANGE, lw=0.5)
_style(axes[1], "Chiller part-load ratio (each of the identical chillers)", "PLR [-]")
axes[1].set_xlim(0, 8760)
_save(fig, out / f"{name}_control.png", paths)
# 5. Monthly totals
m = h.groupby("month")[["Cooling_Power_DC", "Load_Met_Chiller", "Chiller_Power", "Fan_Power"]].sum() / 1000.0
fig, axes = plt.subplots(1, 2, figsize=(10, 4), dpi=150)
x = list(range(len(m)))
w = 0.38
axes[0].bar([i - w / 2 for i in x], m["Cooling_Power_DC"], w, color=BLUE, label="Dry coolers")
axes[0].bar([i + w / 2 for i in x], m["Load_Met_Chiller"], w, color=ORANGE, label="Chillers (load met)")
_style(axes[0], "Cooling delivered per month", "Heat removed [MWh]", "")
axes[1].bar([i - w / 2 for i in x], m["Chiller_Power"], w, color=ORANGE, label="Chiller compressors")
axes[1].bar([i + w / 2 for i in x], m["Fan_Power"], w, color=BLUE, label="Dry-cooler fans")
_style(axes[1], "Electricity per month", "Electricity [MWh]", "")
for ax in axes:
ax.set_xticks(x, [MONTHS[i] for i in m.index], fontsize=8)
ax.legend(frameon=False, fontsize=8)
_save(fig, out / f"{name}_monthly_energy.png", paths)
# 6. Hottest week, hourly
roll = h["T_Air"].rolling(168).mean()
end = int(roll.idxmax())
wk = h.iloc[max(0, end - 167): end + 1]
fig, ax = plt.subplots(figsize=(9, 4), dpi=150)
for col, c, lab in TEMPS:
ax.plot(wk["TIME"], wk[col], color=c, lw=1.6, label=lab)
ax.axhline(50, color=GREY, lw=1, ls="--")
_style(ax, f"Hottest week (hours {int(wk['TIME'].iloc[0])}-{int(wk['TIME'].iloc[-1])})", "Temperature [°C]")
ax.legend(frameon=False, fontsize=8, ncol=2, loc="upper center", bbox_to_anchor=(0.5, -0.16))
_save(fig, out / f"{name}_hottest_week.png", paths)
# 7. Daily price and daily electricity cost
if daily is not None:
dates = pd.to_datetime(daily["date"])
fig, axes = plt.subplots(2, 1, figsize=(11, 6), dpi=150, sharex=True)
axes[0].step(dates, daily["Price_mean_per_kWh"], where="post", color=BLUE, lw=1.4)
_style(axes[0], "Electricity price per day", f"Price [{currency}/kWh]", "")
lo, hi = daily["Price_min_per_kWh"].min(), daily["Price_max_per_kWh"].max()
pad = max(0.1 * hi, 1e-3)
axes[0].set_ylim(max(0, lo - pad), hi + pad)
axes[1].bar(dates, daily["Cost_pump_in_kW"] / 1000, width=0.9, color=ORANGE)
_style(axes[1], "Electricity cost per day (pump power in kW)", f"Cost [thousand {currency}]", "Date")
_save(fig, out / f"{name}_daily_price_cost.png", paths)
return paths