diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index a34611de..48f064b0 100644 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -21,7 +21,7 @@ Description import os import logging -from _helpers import configure_logging +from _helpers import configure_logging, retrieve_snakemake_keys import pandas as pd import matplotlib.pyplot as plt @@ -55,7 +55,7 @@ def rename_techs(label): preferred_order = pd.Index(["transmission lines","hydroelectricity","hydro reservoir","run of river","pumped hydro storage","onshore wind","offshore wind ac", "offshore wind dc","solar PV","solar thermal","OCGT","hydrogen storage","battery storage"]) -def plot_costs(infn, fn=None): +def plot_costs(infn, config, fn=None): ## For now ignore the simpl header cost_df = pd.read_csv(infn,index_col=list(range(3)),header=[1,2,3]) @@ -67,7 +67,7 @@ def plot_costs(infn, fn=None): df = df.groupby(df.index.map(rename_techs)).sum() - to_drop = df.index[df.max(axis=1) < snakemake.config['plotting']['costs_threshold']] + to_drop = df.index[df.max(axis=1) < config['plotting']['costs_threshold']] print("dropping") @@ -84,7 +84,7 @@ def plot_costs(infn, fn=None): fig, ax = plt.subplots() fig.set_size_inches((12,8)) - df.loc[new_index,new_columns].T.plot(kind="bar",ax=ax,stacked=True,color=[snakemake.config['plotting']['tech_colors'][i] for i in new_index]) + df.loc[new_index,new_columns].T.plot(kind="bar",ax=ax,stacked=True,color=[config['plotting']['tech_colors'][i] for i in new_index]) handles,labels = ax.get_legend_handles_labels() @@ -92,7 +92,7 @@ def plot_costs(infn, fn=None): handles.reverse() labels.reverse() - ax.set_ylim([0,snakemake.config['plotting']['costs_max']]) + ax.set_ylim([0,config['plotting']['costs_max']]) ax.set_ylabel("System Cost [EUR billion per year]") @@ -109,7 +109,7 @@ def plot_costs(infn, fn=None): fig.savefig(fn, transparent=True) -def plot_energy(infn, fn=None): +def plot_energy(infn, config, fn=None): energy_df = pd.read_csv(infn, index_col=list(range(2)),header=[1,2,3]) @@ -120,7 +120,7 @@ def plot_energy(infn, fn=None): df = df.groupby(df.index.map(rename_techs)).sum() - to_drop = df.index[df.abs().max(axis=1) < snakemake.config['plotting']['energy_threshold']] + to_drop = df.index[df.abs().max(axis=1) < config['plotting']['energy_threshold']] print("dropping") @@ -137,7 +137,7 @@ def plot_energy(infn, fn=None): fig, ax = plt.subplots() fig.set_size_inches((12,8)) - df.loc[new_index,new_columns].T.plot(kind="bar",ax=ax,stacked=True,color=[snakemake.config['plotting']['tech_colors'][i] for i in new_index]) + df.loc[new_index,new_columns].T.plot(kind="bar",ax=ax,stacked=True,color=[config['plotting']['tech_colors'][i] for i in new_index]) handles,labels = ax.get_legend_handles_labels() @@ -145,7 +145,7 @@ def plot_energy(infn, fn=None): handles.reverse() labels.reverse() - ax.set_ylim([snakemake.config['plotting']['energy_min'],snakemake.config['plotting']['energy_max']]) + ax.set_ylim([config['plotting']['energy_min'], config['plotting']['energy_max']]) ax.set_ylabel("Energy [TWh/a]") @@ -170,10 +170,12 @@ if __name__ == "__main__": attr='', ext='png', country='all') configure_logging(snakemake) - summary = snakemake.wildcards.summary + paths, config, wildcards, logs, out = retrieve_snakemake_keys(snakemake) + + summary = wildcards.summary try: func = globals()[f"plot_{summary}"] except KeyError: raise RuntimeError(f"plotting function for {summary} has not been defined") - func(os.path.join(snakemake.input[0], f"{summary}.csv"), snakemake.output[0]) + func(os.path.join(paths[0], f"{summary}.csv"), config, out[0])