plot_p_nom_max: Add plots for the cumulative renewable expansion potential
The wildcards `clusters` and `technology` accept lists of values separated by ','
This commit is contained in:
parent
a069bef380
commit
60dda9f909
@ -275,6 +275,15 @@ rule plot_summary:
|
||||
output: "results/plots/summary_{summary}_{network}_s{simpl}_{clusters}_l{ll}_{opts}_{country}.{ext}"
|
||||
script: "scripts/plot_summary.py"
|
||||
|
||||
def input_plot_p_nom_max(wildcards):
|
||||
return [('networks/{network}_s{simpl}{maybe_cluster}.nc'
|
||||
.format(maybe_cluster=('' if c == 'full' else ('_' + c)), **wildcards))
|
||||
for c in wildcards.clusters.split(",")]
|
||||
rule plot_p_nom_max:
|
||||
input: input_plot_p_nom_max
|
||||
output: "results/plots/{network}_s{simpl}_cum_p_nom_max_{clusters}_{technology}_{country}.{ext}"
|
||||
script: "scripts/plot_p_nom_max.py"
|
||||
|
||||
# Local Variables:
|
||||
# mode: python
|
||||
# End:
|
||||
|
70
scripts/plot_p_nom_max.py
Normal file
70
scripts/plot_p_nom_max.py
Normal file
@ -0,0 +1,70 @@
|
||||
import pypsa
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
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__:
|
||||
# Detect running outside of snakemake and mock snakemake for testing
|
||||
if 'snakemake' not in globals():
|
||||
from vresutils.snakemake import MockSnakemake, Dict
|
||||
snakemake = MockSnakemake(
|
||||
path='..',
|
||||
wildcards={'clusters': '45,90,181,full',
|
||||
'country': 'all'},
|
||||
params=dict(techs=['onwind', 'offwind-ac', 'offwind-dc', 'solar']),
|
||||
input=Dict(
|
||||
**{
|
||||
'full': 'networks/elec_s.nc',
|
||||
'45': 'networks/elec_s_45.nc',
|
||||
'90': 'networks/elec_s_90.nc',
|
||||
'181': 'networks/elec_s_181.nc',
|
||||
}
|
||||
),
|
||||
output=['results/plots/cum_p_nom_max_{clusters}_{country}.pdf']
|
||||
)
|
||||
|
||||
logging.basicConfig(level=snakemake.config['logging_level'])
|
||||
|
||||
plot_kwds = dict(drawstyle="steps-post")
|
||||
|
||||
clusters = snakemake.wildcards.clusters.split(',')
|
||||
techs = snakemake.params.techs
|
||||
country = snakemake.wildcards.country
|
||||
if country == 'all':
|
||||
country = None
|
||||
else:
|
||||
plot_kwds['marker'] = 'x'
|
||||
|
||||
fig, axes = plt.subplots(1, len(techs))
|
||||
|
||||
for cluster in clusters:
|
||||
net = pypsa.Network(getattr(snakemake.input, cluster))
|
||||
|
||||
for i, tech in enumerate(techs):
|
||||
cum_p_nom_max(net, tech, country).plot(x="p_max_pu", y="c_p_nom_max", label=cluster, ax=axes[0][i], **plot_kwds)
|
||||
|
||||
for i, tech in enumerate(techs):
|
||||
ax = axes[0][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')
|
Loading…
Reference in New Issue
Block a user