2023-07-05 13:50:57 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2024-02-19 15:21:48 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors
|
2023-07-05 13:50:57 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import pandas as pd
|
|
|
|
import pypsa
|
|
|
|
import seaborn as sns
|
2023-08-15 13:02:41 +00:00
|
|
|
from _helpers import configure_logging, set_scenario_config
|
2023-07-05 13:50:57 +00:00
|
|
|
|
|
|
|
sns.set_theme("paper", style="whitegrid")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if "snakemake" not in globals():
|
|
|
|
from _helpers import mock_snakemake
|
|
|
|
|
|
|
|
snakemake = mock_snakemake(
|
|
|
|
"plot_electricity_prices",
|
|
|
|
opts="Ept-12h",
|
|
|
|
clusters="37",
|
|
|
|
ll="v1.0",
|
|
|
|
)
|
|
|
|
configure_logging(snakemake)
|
2023-08-15 13:02:41 +00:00
|
|
|
set_scenario_config(snakemake)
|
2023-07-05 13:50:57 +00:00
|
|
|
|
|
|
|
n = pypsa.Network(snakemake.input.network)
|
|
|
|
n.loads.carrier = "load"
|
|
|
|
|
|
|
|
historic = pd.read_csv(
|
|
|
|
snakemake.input.electricity_prices,
|
|
|
|
index_col=0,
|
2023-07-05 17:06:32 +00:00
|
|
|
header=0,
|
2023-07-05 13:50:57 +00:00
|
|
|
parse_dates=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(historic.index) > len(n.snapshots):
|
|
|
|
historic = historic.resample(n.snapshots.inferred_freq).mean().loc[n.snapshots]
|
|
|
|
|
|
|
|
optimized = n.buses_t.marginal_price.groupby(n.buses.country, axis=1).mean()
|
|
|
|
|
|
|
|
data = pd.concat([historic, optimized], keys=["Historic", "Optimized"], axis=1)
|
|
|
|
data.columns.names = ["Kind", "Country"]
|
|
|
|
|
|
|
|
fig, ax = plt.subplots(figsize=(6, 6))
|
|
|
|
|
|
|
|
df = data.mean().unstack().T
|
|
|
|
df.plot.barh(ax=ax, xlabel="Electricity Price [€/MWh]", ylabel="")
|
|
|
|
ax.grid(axis="y")
|
|
|
|
fig.savefig(snakemake.output.price_bar, bbox_inches="tight")
|
|
|
|
|
2023-07-19 08:11:54 +00:00
|
|
|
fig, ax = plt.subplots()
|
|
|
|
|
|
|
|
df = data.groupby(level="Kind", axis=1).mean()
|
|
|
|
df.plot(ax=ax, xlabel="", ylabel="Electricity Price [€/MWh]", alpha=0.8)
|
|
|
|
ax.grid(axis="x")
|
|
|
|
fig.savefig(snakemake.output.price_line, bbox_inches="tight")
|
|
|
|
|
2023-07-05 13:50:57 +00:00
|
|
|
# touch file
|
|
|
|
with open(snakemake.output.plots_touch, "a"):
|
|
|
|
pass
|