Skip to content

Commit 35e1625

Browse files
committed
change historical price error horizons
1 parent e0a25d3 commit 35e1625

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

price-characterisation/historical-price-errors.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@
5151
# ## Getting Data
5252
# define price error dir
5353
data_dir = Path("price-error")
54+
nemosis_cache = Path("nemosis_cache/")
5455

5556
# %% [markdown]
5657
# ### Obtaining actual price data from `NEMOSIS`
5758
# We will download `DISPATCHPRICE` to access the `RRP` (energy price) field and cache it so that it's ready for computation.
5859

5960
# %%
6061
if not data_dir.exists():
61-
nemosis_cache = Path("nemosis_cache/")
6262
if not nemosis_cache.exists():
6363
nemosis_cache.mkdir(parents=True)
6464
nemosis.cache_compiler(
@@ -251,6 +251,7 @@ def process_price_error(
251251
fname = f"price-error-{start.year}.parquet"
252252
if Path(data_dir, fname).exists():
253253
print(f"Price error {analysis_start_dt.year + i} file exists, continuing")
254+
continue
254255
else:
255256
end = datetime(
256257
start.year + 1,
@@ -260,11 +261,12 @@ def process_price_error(
260261
start.minute,
261262
start.second,
262263
)
263-
print(f"Calculating price errors for year {start.year}")
264-
price_error = calculate_price_error(
265-
start.strftime(dt_str_format), end.strftime(dt_str_format)
266-
)
267-
price_error.to_parquet(Path(data_dir, fname))
264+
265+
print(f"Calculating price errors for year {start.year}")
266+
price_error = calculate_price_error(
267+
start.strftime(dt_str_format), end.strftime(dt_str_format)
268+
)
269+
price_error.to_parquet(Path(data_dir, fname))
268270

269271
# %% [markdown]
270272
# ## Price Error Count by Severity and Year
@@ -299,7 +301,7 @@ def plot_counts_within_horizon(
299301
i = 0
300302
price_errors_lazy = pl.scan_parquet(price_errors_dir / Path("*.parquet"))
301303
price_errors_lazy = price_errors_lazy.filter(
302-
pl.col("ahead_time") < pl.duration(minutes=horizon_minutes)
304+
pl.col("ahead_time") <= pl.duration(minutes=horizon_minutes)
303305
)
304306
price_errors_df = price_errors_lazy.collect().to_pandas()
305307
price_errors_df.set_index("forecasted_time", inplace=True)
@@ -379,16 +381,18 @@ def annotate_ax(
379381

380382

381383
fig, axes = plt.subplots(
382-
2, 1, sharex=True, sharey=True,
384+
3, 1, sharex=True,
383385
)
384-
for horizon, ax in zip((24 * 60, 1 * 60), axes.flatten()):
386+
for horizon, ax in zip((24*60, 2 * 60, 15), axes.flatten()):
385387
plot_counts_within_horizon(ax, data_dir, horizon)
386388

387389
annotate_ax(axes[0], annotate=True, vline_ymax=1.1, y_annot=29e3, annot_fontsize=6)
388390
annotate_ax(axes[1], annotate=False, vline_ymax=1.1, y_annot=29e3, annot_fontsize=6)
391+
annotate_ax(axes[2], annotate=False, vline_ymax=1.1, y_annot=29e3, annot_fontsize=6)
389392
fig.suptitle("NEM-wide Monthly Count of Price Forecast Errors", fontsize=16)
390-
axes[0].set_title("Within day-ahead horizon (30MPD & 5MPD)", loc="left", fontsize=10)
391-
axes[1].set_title("Within hour-ahead horizon (5MPD)", loc="left", fontsize=10)
393+
axes[0].set_title("Up to a day ahead (30MPD & 5MPD)", loc="left", fontsize=10)
394+
axes[1].set_title("Up to two hours ahead (30MPD & 5MPD)", loc="left", fontsize=10)
395+
axes[2].set_title("Up to 15 minutes ahead (5MPD)", loc="left", fontsize=10)
392396
for ax in axes.flatten():
393397
ax.set_ylabel("Count", fontsize=7)
394398
handles, labels = axes[0].get_legend_handles_labels()

0 commit comments

Comments
 (0)