plot_summary: Plot energy / CO2 balances for each carrier

Take data from supply_energy.csv and plot the balances for each
carrier.

One summary for energy excludes CO2 flows (unlike graphs/energy.pdf).
This commit is contained in:
Tom Brown 2020-05-13 13:40:00 +02:00
parent eb34356722
commit 2bee13fe40
3 changed files with 79 additions and 6 deletions

View File

@ -279,10 +279,12 @@ rule make_summary:
rule plot_summary:
input:
costs=config['summary_dir'] + '/' + config['run'] + '/csvs/costs.csv',
energy=config['summary_dir'] + '/' + config['run'] + '/csvs/energy.csv'
energy=config['summary_dir'] + '/' + config['run'] + '/csvs/energy.csv',
balances=config['summary_dir'] + '/' + config['run'] + '/csvs/supply_energy.csv'
output:
costs=config['summary_dir'] + '/' + config['run'] + '/graphs/costs.pdf',
energy=config['summary_dir'] + '/' + config['run'] + '/graphs/energy.pdf'
energy=config['summary_dir'] + '/' + config['run'] + '/graphs/energy.pdf',
balances=config['summary_dir'] + '/' + config['run'] + '/graphs/balances-energy.pdf'
threads: 2
resources: mem_mb=10000
script:

View File

@ -70,7 +70,7 @@ sector:
'tes' : True
'tes_tau' : 3.
'boilers' : True
'oil_boilers': True
'oil_boilers': False
'chp' : True
'solar_thermal' : True
'solar_cf_correction': 0.788457 # = >>> 1/1.2683
@ -252,8 +252,8 @@ plotting:
"gas for industry co2 to atmosphere": "#654321"
"gas for industry co2 to stored": "#654321"
"Fischer-Tropsch" : "#44DD33"
"kerosene for aviation": "#44DD33"
"naphtha for industry" : "#44DD33"
"kerosene for aviation": "#44BB11"
"naphtha for industry" : "#44FF55"
"nuclear" : "#303030"
"water tanks" : "#BBBBBB"
"hot water storage" : "#BBBBBB"

View File

@ -169,6 +169,75 @@ def plot_energy():
fig.savefig(snakemake.output.energy,transparent=True)
def plot_balances():
co2_carriers = ["co2","co2 stored","process emissions"]
balances_df = pd.read_csv(snakemake.input.balances,index_col=list(range(3)),header=[0,1,2])
balances = {i.replace(" ","_") : [i] for i in balances_df.index.levels[0]}
balances["energy"] = balances_df.index.levels[0]^co2_carriers
for k,v in balances.items():
df = balances_df.loc[v]
df = df.groupby(df.index.get_level_values(2)).sum()
#convert MWh to TWh
df = df/1e6
#remove trailing link ports
df.index = [i[:-1] if i[-1:] in ["0","1","2","3"] else i for i in df.index]
df = df.groupby(df.index.map(rename_techs)).sum()
to_drop = df.index[df.abs().max(axis=1) < snakemake.config['plotting']['energy_threshold']]
print("dropping")
print(df.loc[to_drop])
df = df.drop(to_drop)
print(df.sum())
if df.empty:
continue
new_index = (preferred_order&df.index).append(df.index.difference(preferred_order))
new_columns = df.columns.sort_values()
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])
handles,labels = ax.get_legend_handles_labels()
handles.reverse()
labels.reverse()
if v[0] in co2_carriers:
ax.set_ylabel("CO2 [MtCO2/a]")
else:
ax.set_ylabel("Energy [TWh/a]")
ax.set_xlabel("")
ax.grid(axis="y")
ax.legend(handles,labels,ncol=4,loc="upper left")
fig.tight_layout()
fig.savefig(snakemake.output.balances[:-10] + k + ".pdf",transparent=True)
if __name__ == "__main__":
# Detect running outside of snakemake and mock snakemake for testing
if 'snakemake' not in globals():
@ -180,10 +249,12 @@ if __name__ == "__main__":
snakemake.input = Dict()
snakemake.output = Dict()
for item in ["costs","energy"]:
for item in ["costs", "energy", "balances"]:
snakemake.input[item] = snakemake.config['summary_dir'] + '/{name}/csvs/{item}.csv'.format(name=snakemake.config['run'],item=item)
snakemake.output[item] = snakemake.config['summary_dir'] + '/{name}/graphs/{item}.pdf'.format(name=snakemake.config['run'],item=item)
plot_costs()
plot_energy()
plot_balances()