-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_entsoe_data.py
More file actions
251 lines (225 loc) · 8.16 KB
/
Copy pathplot_entsoe_data.py
File metadata and controls
251 lines (225 loc) · 8.16 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
"""Plotting functions for ENTSO-E market data visualization."""
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
def setup_subplot(ax, title, ylabel, add_legend=False, add_dates=True):
"""
Setup common subplot elements: title, grid, legend, date formatting.
Parameters:
-----------
ax : matplotlib.axes.Axes
Subplot axes to configure
title : str
Plot title
ylabel : str
Y-axis label
add_legend : bool
Whether to add a legend
add_dates : bool
Whether to format x-axis as dates
"""
ax.set_title(title, fontweight="bold", fontsize=11)
ax.set_ylabel(ylabel, fontsize=10)
ax.grid(True, alpha=0.2, linestyle="--")
if add_legend:
ax.legend(fontsize=9, loc="best", framealpha=0.9)
if add_dates:
ax.xaxis.set_major_formatter(mdates.DateFormatter("%m-%d"))
ax.xaxis.set_major_locator(mdates.DayLocator(interval=2))
plt.setp(ax.xaxis.get_majorticklabels(), rotation=45, ha="right", fontsize=8)
def plot_entsoe_overview(
data, zone, start, end, output_file="entsoe_data_overview.png"
):
"""
Create clean overview plots for ENTSO-E market data.
Parameters:
-----------
data : pd.DataFrame
DataFrame with ENTSO-E data indexed by timestamp
zone : str
ENTSO-E zone code (e.g., '10Y1001A1001A82H')
start : pd.Timestamp
Start date of data
end : pd.Timestamp
End date of data
gfs_data : pd.DataFrame (ignored, for compatibility)
GFS data (not used in this plot anymore)
output_file : str
Output filename for the plot
Returns:
--------
str : Path to saved plot file
"""
# Fixed 2x3 layout for ENTSO-E data only
fig, axes = plt.subplots(2, 3, figsize=(18, 10))
zone_name = "Germany-Luxembourg" if "82H" in zone else zone
title = f"ENTSO-E Market Data - {zone_name}\n{start.date()} to {end.date()}"
fig.suptitle(title, fontsize=14, fontweight="bold")
# Plot 1: Day-Ahead Prices (target variable)
ax = axes[0, 0]
# Filter out NaN values for plotting (prices are hourly, not 15-min)
price_data = data["price_eur_mwh"].dropna()
if len(price_data) > 0:
ax.plot(
price_data.index,
price_data.values,
linewidth=2,
color="#c0392b",
marker="o",
markersize=2,
)
ax.axhline(y=0, color="black", linestyle="-", linewidth=0.5, alpha=0.5)
mean_price = price_data.mean()
ax.axhline(
y=mean_price, color="#c0392b", linestyle="--", linewidth=1, alpha=0.5
)
setup_subplot(ax, "Day-Ahead Electricity Prices", "EUR/MWh")
# Plot 2: Load Actual
ax = axes[0, 1]
ax.plot(
data.index,
data["load_actual_mw"],
linewidth=1.5,
color="#2c3e50",
label="Actual",
alpha=0.8,
)
setup_subplot(ax, "Load Demand", "MW", add_legend=True)
# Plot 3: Generation Mix (Fossil vs Renewable)
ax = axes[0, 2]
renewable_cols = [
"gen_actual_wind_onshore_actual_aggregated_mw",
"gen_actual_wind_offshore_actual_aggregated_mw",
"gen_actual_solar_actual_aggregated_mw",
"gen_actual_hydro_run_of_river_and_poundage_actual_aggregated_mw",
]
fossil_cols = [
"gen_actual_fossil_gas_actual_aggregated_mw",
"gen_actual_fossil_hard_coal_actual_aggregated_mw",
"gen_actual_fossil_brown_coal_lignite_actual_aggregated_mw",
]
renewable_gen = sum(data[col] for col in renewable_cols if col in data.columns)
fossil_gen = sum(data[col] for col in fossil_cols if col in data.columns)
ax.plot(
data.index,
renewable_gen,
linewidth=1.5,
color="#27ae60",
label="Renewable",
alpha=0.8,
)
ax.plot(
data.index,
fossil_gen,
linewidth=1.5,
color="#7f8c8d",
label="Fossil",
alpha=0.8,
)
if "gen_actual_nuclear_actual_aggregated_mw" in data.columns:
ax.plot(
data.index,
data["gen_actual_nuclear_actual_aggregated_mw"],
linewidth=1.5,
color="#e67e22",
label="Nuclear",
alpha=0.8,
)
setup_subplot(ax, "Generation Mix", "MW", add_legend=True)
# Plot 4: Cross-Border Flows (Top flows by magnitude)
ax = axes[1, 0]
flow_countries = [
("flow_fr_mw", "France"),
("flow_nl_mw", "Netherlands"),
("flow_at_mw", "Austria"),
("flow_pl_mw", "Poland"),
("flow_cz_mw", "Czechia"),
("flow_ch_mw", "Switzerland"),
("flow_se4_mw", "Sweden"),
("flow_dk1_mw", "Denmark-W"),
("flow_dk2_mw", "Denmark-E"),
]
# Calculate average absolute flow for each country and sort by magnitude
flows_with_magnitude = []
for col, label in flow_countries:
if col in data.columns:
avg_magnitude = data[col].abs().mean()
if not pd.isna(avg_magnitude):
flows_with_magnitude.append((col, label, avg_magnitude))
# Sort by magnitude and take top 5
flows_with_magnitude.sort(key=lambda x: x[2], reverse=True)
top_flows = flows_with_magnitude[:5]
for col, label, _ in top_flows:
# Plot only non-NaN values to handle different time resolutions
flow_data = data[col].dropna()
if len(flow_data) > 0:
ax.plot(
flow_data.index,
flow_data.values,
linewidth=1.3,
label=label,
alpha=0.75,
)
ax.axhline(y=0, color="black", linestyle="-", linewidth=0.5, alpha=0.5)
setup_subplot(ax, "Cross-Border Flows (Top 5)", "MW", add_legend=True)
# Plot 5: Hourly Price Pattern
ax = axes[1, 1]
if "price_eur_mwh" in data.columns:
# Use only non-NaN price values
price_data = data[data["price_eur_mwh"].notna()]
if len(price_data) > 0:
hour = price_data.index.hour
hourly_price = price_data.groupby(hour)["price_eur_mwh"].mean()
ax.bar(
hourly_price.index,
hourly_price.values,
alpha=0.7,
color="#e74c3c",
edgecolor="#c0392b",
linewidth=0.5,
)
ax.set_xlabel("Hour of Day", fontsize=10)
ax.set_xticks([0, 6, 12, 18, 23])
setup_subplot(ax, "Average Hourly Price Pattern", "EUR/MWh", add_dates=False)
else:
ax.text(0.5, 0.5, "No data", transform=ax.transAxes, ha="center", va="center")
setup_subplot(ax, "Hourly Price Pattern", "EUR/MWh", add_dates=False)
# Plot 6: Renewable Percentage
ax = axes[1, 2]
if "load_actual_mw" in data.columns:
# Calculate renewable generation from actual generation columns
renewable_cols = [
"gen_actual_wind_onshore_actual_aggregated_mw",
"gen_actual_wind_offshore_actual_aggregated_mw",
"gen_actual_solar_actual_aggregated_mw",
"gen_actual_hydro_run_of_river_and_poundage_actual_aggregated_mw",
]
renewable_mw = sum(data[col] for col in renewable_cols if col in data.columns)
renewable_pct = (renewable_mw / data["load_actual_mw"]) * 100
ax.plot(data.index, renewable_pct, linewidth=1.5, color="#27ae60", alpha=0.8)
ax.axhline(
y=renewable_pct.mean(),
color="#27ae60",
linestyle="--",
linewidth=1,
alpha=0.5,
)
ax.text(
0.98,
0.98,
f"Avg: {renewable_pct.mean():.1f}%",
transform=ax.transAxes,
ha="right",
va="top",
fontsize=9,
bbox=dict(boxstyle="round", facecolor="white", alpha=0.8, pad=0.3),
)
setup_subplot(ax, "Renewable Generation Share", "% of Load")
else:
ax.text(0.5, 0.5, "No data", transform=ax.transAxes, ha="center", va="center")
setup_subplot(ax, "Renewable Share", "% of Load")
# Adjust layout to prevent label overlap
plt.tight_layout(rect=[0, 0.02, 1, 0.98])
plt.savefig(output_file, dpi=150, bbox_inches="tight")
plt.close(fig)
return output_file