From 3e64599c4caf6606dff98620c955a758323700b5 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 5 Jul 2023 19:06:32 +0200 Subject: [PATCH] plot_electricity_prices: fix header spec --- scripts/plot_validation_cross_border_flows.py | 57 +++++++++++++++++++ scripts/plot_validation_electricity_prices.py | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 scripts/plot_validation_cross_border_flows.py diff --git a/scripts/plot_validation_cross_border_flows.py b/scripts/plot_validation_cross_border_flows.py new file mode 100644 index 00000000..1340376f --- /dev/null +++ b/scripts/plot_validation_cross_border_flows.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors +# +# SPDX-License-Identifier: MIT + +import matplotlib.pyplot as plt +import pandas as pd +import pypsa +import seaborn as sns +from _helpers import configure_logging +from pypsa.statistics import get_bus_and_carrier + +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", + simpl="", + opts="Ept-12h", + clusters="37", + ll="v1.0", + ) + configure_logging(snakemake) + + n = pypsa.Network(snakemake.input.network) + n.loads.carrier = "load" + + historic = pd.read_csv( + snakemake.input.cross_border_flows, + index_col=0, + header=0, + 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"] + + # # %% total production per carrier + # 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") + + # touch file + with open(snakemake.output.plots_touch, "a"): + pass diff --git a/scripts/plot_validation_electricity_prices.py b/scripts/plot_validation_electricity_prices.py index c03addda..85735789 100644 --- a/scripts/plot_validation_electricity_prices.py +++ b/scripts/plot_validation_electricity_prices.py @@ -32,7 +32,7 @@ if __name__ == "__main__": historic = pd.read_csv( snakemake.input.electricity_prices, index_col=0, - header=[0, 1], + header=0, parse_dates=True, )