* rewrite mocksnakemake for parsing real Snakefile * continue add function to scripts * going through all scripts, setting new mocksnakemake * fix plotting scripts * fix build_country_flh * fix build_country_flh II * adjust config files * fix make_summary for tutorial network * create dir also for output * incorporate suggestions * consistent import of mocksnakemake * consistent import of mocksnakemake II * Update scripts/_helpers.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/_helpers.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/_helpers.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/_helpers.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/plot_network.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/plot_network.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/retrieve_databundle.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * use pathlib for mocksnakemake * rename mocksnakemake into mock_snakemake * revert change in data * Update scripts/_helpers.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * remove setting logfile in mock_snakemake, use Path in configure_logging * fix fallback path and base_dir fix return type of make_io_accessable * reformulate mock_snakemake * incorporate suggestion, fix typos * mock_snakemake: apply absolute paths again, add assertion error *.py: make hard coded io path accessable for mock_snakemake * retrieve_natura_raster: use snakemake.output for fn_out * include suggestion * Apply suggestions from code review Co-Authored-By: Jonas Hörsch <jonas.hoersch@posteo.de> * linting, add return ad end of file * Update scripts/plot_p_nom_max.py Co-Authored-By: Jonas Hörsch <jonas.hoersch@posteo.de> * Update scripts/plot_p_nom_max.py fixes #112 Co-Authored-By: Jonas Hörsch <jonas.hoersch@posteo.de> * plot_p_nom_max: small correction * config.tutorial.yaml fix snapshots end * use techs instead of technology * revert try out from previous commit, complete replacing * change clusters -> clusts in plot_p_nom_max due to wildcard constraints of clusters * change clusters -> clusts in plot_p_nom_max due to wildcard constraints of clusters II
80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
"""
|
|
Plots renewable installation potentials per capacity factor.
|
|
|
|
Relevant Settings
|
|
-----------------
|
|
|
|
Inputs
|
|
------
|
|
|
|
Outputs
|
|
-------
|
|
|
|
Description
|
|
-----------
|
|
|
|
"""
|
|
import logging
|
|
logger = logging.getLogger(__name__)
|
|
from _helpers import configure_logging
|
|
|
|
import pypsa
|
|
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
import logging
|
|
|
|
def cum_p_nom_max(net, tech, country=None):
|
|
carrier_b = net.generators.carrier == tech
|
|
|
|
generators = \
|
|
pd.DataFrame(dict(
|
|
p_nom_max=net.generators.loc[carrier_b, 'p_nom_max'],
|
|
p_max_pu=net.generators_t.p_max_pu.loc[:,carrier_b].mean(),
|
|
country=net.generators.loc[carrier_b, 'bus'].map(net.buses.country)
|
|
)).sort_values("p_max_pu", ascending=False)
|
|
|
|
if country is not None:
|
|
generators = generators.loc[generators.country == country]
|
|
|
|
generators["cum_p_nom_max"] = generators["p_nom_max"].cumsum() / 1e6
|
|
|
|
return generators
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if 'snakemake' not in globals():
|
|
from _helpers import mock_snakemake
|
|
snakemake = mock_snakemake('plot_p_nom_max', network='elec', simpl='',
|
|
techs='solar,onwind,offwind-dc', ext='png',
|
|
clusts= '5,full', country= 'all')
|
|
configure_logging(snakemake)
|
|
|
|
plot_kwds = dict(drawstyle="steps-post")
|
|
|
|
clusters = snakemake.wildcards.clusts.split(',')
|
|
techs = snakemake.wildcards.techs.split(',')
|
|
country = snakemake.wildcards.country
|
|
if country == 'all':
|
|
country = None
|
|
else:
|
|
plot_kwds['marker'] = 'x'
|
|
|
|
fig, axes = plt.subplots(1, len(techs))
|
|
|
|
for j, cluster in enumerate(clusters):
|
|
net = pypsa.Network(snakemake.input[j])
|
|
|
|
for i, tech in enumerate(techs):
|
|
cum_p_nom_max(net, tech, country).plot(x="p_max_pu", y="cum_p_nom_max",
|
|
label=cluster, ax=axes[i], **plot_kwds)
|
|
|
|
for i, tech in enumerate(techs):
|
|
ax = axes[i]
|
|
ax.set_xlabel(f"Capacity factor of {tech}")
|
|
ax.set_ylabel("Cumulative installable capacity / TW")
|
|
|
|
plt.legend(title="Cluster level")
|
|
|
|
fig.savefig(snakemake.output[0], transparent=True, bbox_inches='tight')
|