2023-07-03 15:13:16 +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-03 15:13:16 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import pypsa
|
|
|
|
import seaborn as sns
|
2023-08-15 13:02:41 +00:00
|
|
|
from _helpers import configure_logging, set_scenario_config
|
2023-07-03 15:13:16 +00:00
|
|
|
|
|
|
|
sns.set_theme("paper", style="whitegrid")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if "snakemake" not in globals():
|
|
|
|
from _helpers import mock_snakemake
|
|
|
|
|
|
|
|
snakemake = mock_snakemake(
|
2023-08-04 14:20:39 +00:00
|
|
|
"plot_elec_statistics",
|
2023-07-05 09:07:36 +00:00
|
|
|
opts="Ept-12h",
|
|
|
|
clusters="37",
|
2023-07-03 15:13:16 +00:00
|
|
|
ll="v1.0",
|
|
|
|
)
|
2023-07-05 09:07:36 +00:00
|
|
|
configure_logging(snakemake)
|
2023-08-15 13:02:41 +00:00
|
|
|
set_scenario_config(snakemake)
|
2023-07-05 09:07:36 +00:00
|
|
|
|
|
|
|
n = pypsa.Network(snakemake.input.network)
|
|
|
|
|
|
|
|
n.loads.carrier = "load"
|
|
|
|
n.carriers.loc["load", ["nice_name", "color"]] = "Load", "darkred"
|
|
|
|
colors = n.carriers.set_index("nice_name").color.where(
|
|
|
|
lambda s: s != "", "lightgrey"
|
|
|
|
)
|
|
|
|
|
|
|
|
def rename_index(ds):
|
2023-07-11 12:25:32 +00:00
|
|
|
specific = ds.index.map(lambda x: f"{x[1]}\n({x[0]})")
|
2023-07-11 10:40:25 +00:00
|
|
|
generic = ds.index.get_level_values("carrier")
|
|
|
|
duplicated = generic.duplicated(keep=False)
|
|
|
|
index = specific.where(duplicated, generic)
|
|
|
|
return ds.set_axis(index)
|
2023-07-05 09:07:36 +00:00
|
|
|
|
|
|
|
def plot_static_per_carrier(ds, ax, drop_zero=True):
|
|
|
|
if drop_zero:
|
|
|
|
ds = ds[ds != 0]
|
|
|
|
ds = ds.dropna()
|
|
|
|
c = colors[ds.index.get_level_values("carrier")]
|
|
|
|
ds = ds.pipe(rename_index)
|
|
|
|
label = f"{ds.attrs['name']} [{ds.attrs['unit']}]"
|
|
|
|
ds.plot.barh(color=c.values, xlabel=label, ax=ax)
|
|
|
|
ax.grid(axis="y")
|
|
|
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ds = n.statistics.capacity_factor().dropna()
|
|
|
|
plot_static_per_carrier(ds, ax)
|
|
|
|
fig.savefig(snakemake.output.capacity_factor_bar)
|
|
|
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ds = n.statistics.installed_capacity().dropna()
|
|
|
|
ds = ds.drop("Line")
|
2023-08-17 10:56:34 +00:00
|
|
|
ds = ds.drop(("Generator", "Load"), errors="ignore")
|
2023-07-05 09:07:36 +00:00
|
|
|
ds = ds / 1e3
|
|
|
|
ds.attrs["unit"] = "GW"
|
|
|
|
plot_static_per_carrier(ds, ax)
|
|
|
|
fig.savefig(snakemake.output.installed_capacity_bar)
|
|
|
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ds = n.statistics.optimal_capacity()
|
|
|
|
ds = ds.drop("Line")
|
2023-08-17 10:56:34 +00:00
|
|
|
ds = ds.drop(("Generator", "Load"), errors="ignore")
|
2023-07-05 09:07:36 +00:00
|
|
|
ds = ds / 1e3
|
|
|
|
ds.attrs["unit"] = "GW"
|
|
|
|
plot_static_per_carrier(ds, ax)
|
|
|
|
fig.savefig(snakemake.output.optimal_capacity_bar)
|
|
|
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ds = n.statistics.capex()
|
|
|
|
plot_static_per_carrier(ds, ax)
|
|
|
|
fig.savefig(snakemake.output.capital_expenditure_bar)
|
|
|
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ds = n.statistics.opex()
|
|
|
|
plot_static_per_carrier(ds, ax)
|
|
|
|
fig.savefig(snakemake.output.operational_expenditure_bar)
|
|
|
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ds = n.statistics.curtailment()
|
|
|
|
plot_static_per_carrier(ds, ax)
|
|
|
|
fig.savefig(snakemake.output.curtailment_bar)
|
|
|
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ds = n.statistics.supply()
|
|
|
|
ds = ds.drop("Line")
|
|
|
|
ds = ds / 1e6
|
|
|
|
ds.attrs["unit"] = "TWh"
|
|
|
|
plot_static_per_carrier(ds, ax)
|
|
|
|
fig.savefig(snakemake.output.supply_bar)
|
|
|
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ds = n.statistics.withdrawal()
|
|
|
|
ds = ds.drop("Line")
|
|
|
|
ds = ds / -1e6
|
|
|
|
ds.attrs["unit"] = "TWh"
|
|
|
|
plot_static_per_carrier(ds, ax)
|
|
|
|
fig.savefig(snakemake.output.withdrawal_bar)
|
|
|
|
|
|
|
|
fig, ax = plt.subplots()
|
|
|
|
ds = n.statistics.market_value()
|
|
|
|
plot_static_per_carrier(ds, ax)
|
|
|
|
fig.savefig(snakemake.output.market_value_bar)
|
|
|
|
|
|
|
|
# touch file
|
|
|
|
with open(snakemake.output.barplots_touch, "a"):
|
|
|
|
pass
|