Skip to content

Commit

Permalink
plotting scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisol Garrouste (INL) committed Aug 29, 2023
1 parent f2b2df0 commit 6eaed8e
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 2,222 deletions.
10 changes: 5 additions & 5 deletions use_cases/LWR_FT_2023/run/plot_cashflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def plot_lifetime_cashflows(lifetime_cashflows, axis, plant, dispatch_dir, title
df = df.sort_values(by='value', axis=0, ascending=False)
df.reset_index(inplace=True)

# In $M/NPP capacity (MWe)
df['value'] = df['value'].div(1e6*NPP_CAPACITIES[plant])
# In $bn
df['value'] = df['value'].div(1e9)#*NPP_CAPACITIES[plant])

# Waterfall calculations
# calculate running totals
Expand Down Expand Up @@ -134,10 +134,10 @@ def plot_lifetime_cashflows(lifetime_cashflows, axis, plant, dispatch_dir, title
ax.text(i-.15, mid[i], f"{df[y][i]:,.2f}")
# Baseline case as horizontal line
baseline_NPV, std_NPV = get_baseline_NPV(plant)
baseline_NPV /=1e6
baseline_NPV /= NPP_CAPACITIES[plant]
baseline_NPV /=1e9
#baseline_NPV /= NPP_CAPACITIES[plant]
ax.axhline(baseline_NPV, color='b', linewidth=2)
bau_text = 'BAU NPV: '+str(np.round(baseline_NPV,3))+" M$/MWe"
bau_text = 'BAU NPV: $'+str(np.round(baseline_NPV,3))+" bn"
ax.text(5, baseline_NPV+0.1, bau_text, color='b')

# Rename cashflows
Expand Down
3 changes: 3 additions & 0 deletions use_cases/LWR_FT_2023/run/plot_comp_ft_meoh.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import numpy as np
import seaborn as sns
import matplotlib

locations_names = {'braidwood':'Braidwood', 'cooper':'Cooper', 'davis_besse':'Davis-Besse', 'prairie_island':'Prairie Island',
'stp':'South Texas Project'}
Expand Down Expand Up @@ -33,6 +34,8 @@ def plot_hist(df_dic):
ax.set_xlabel('')
ax.legend(["FT", "MeOH"])

ax.yaxis.set_major_locator(matplotlib.ticker.MultipleLocator(100))
ax.set_ylim(-100+min(merged_df['delta_NPV_ft']), 100+max(merged_df['delta_NPV_meoh']))
sns.despine(ax=ax, trim=True)

fig.tight_layout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<produces resource="naphtha,diesel,jet_fuel" dispatch="fixed">
<consumes>h2,electricity</consumes>
<capacity resource="h2">
<sweep_values debug_value="-24167.0">-24583.0,-12291.5</sweep_values>
<sweep_values debug_value="-24583">-24583.0,-12291.5</sweep_values>
</capacity>
<transfer>
<linear>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<produces resource="naphtha,diesel,jet_fuel" dispatch="fixed">
<consumes>h2,electricity</consumes>
<capacity resource="h2">
<sweep_values debug_value="-18584">-18905.0,-9452.5</sweep_values>
<sweep_values debug_value="-18905">-18905.0,-9452.5</sweep_values>
</capacity>
<transfer>
<linear>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<produces resource="naphtha,diesel,jet_fuel" dispatch="fixed">
<consumes>h2,electricity</consumes>
<capacity resource="h2">
<sweep_values debug_value="-21605">-21978.0,-10989.0</sweep_values>
<sweep_values debug_value="-21978">-21978.0,-10989.0</sweep_values>
</capacity>
<transfer>
<linear>
Expand Down
60 changes: 54 additions & 6 deletions use_cases/LWR_MeOH_2023/run/modif_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np


STORAGE_INIT = 0.01 # 1% filled at the beginning of the day
STORAGE_INIT = 0.0 # 0% filled at the beginning of the day
steps_data = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'data', 'HERON_data.xlsx')


Expand Down Expand Up @@ -181,7 +181,53 @@ def add_elec_consumption_meoh(case):
with open(os.path.join(case, 'heron_input.xml'), 'wb') as f:
tree.write(f)

def get_opt_config(location):
"""Get the optimal configuration of the location for SA inputs"""
dir = os.path.dirname(os.path.abspath(__file__))
sweep_results = pd.read_csv(os.path.join(dir,location+'_sweep', 'gold', 'sweep.csv'))
sweep_results = sweep_results[['htse_capacity', 'meoh_capacity', 'h2_storage_capacity']].iloc[0,:]
sweep_results = sweep_results.to_dict()
return sweep_results


def sa_sweep_values(case):
tree = ET.parse(os.path.join(case, 'heron_input.xml'))
root = tree.getroot().find('Components')

case_name = case.split('/')[-1]
if 'davis_besse' in case_name:
location='davis_besse'
elif 'prairie_island' in case_name:
location='prairie_island'
else:
location = case.split('/')[-1].split('_')[0]
opt_dict = get_opt_config(location)

for comp in root.findall('Component'):
# Storage
if comp.get('name') =='h2_storage':
sweep_val_node = comp.find('stores').find('capacity').find('sweep_values')
sweep_values = [opt_dict['h2_storage_capacity'], opt_dict['h2_storage_capacity']/2]
sweep_values = [str(v) for v in sweep_values]
sweep_values = ','.join(sweep_values)
sweep_val_node.text = sweep_values
# FT
if comp.get('name') =='meoh':
sweep_val_node = comp.find('produces').find('capacity').find('sweep_values')
sweep_values = [opt_dict['meoh_capacity'], opt_dict['meoh_capacity']/2]
sweep_values = [str(v) for v in sweep_values]
sweep_values = ','.join(sweep_values)
sweep_val_node.text = sweep_values
# HTSE
if comp.get('name') =='htse':
sweep_val_node = comp.find('produces').find('capacity').find('sweep_values')
sweep_values = [opt_dict['htse_capacity'], opt_dict['htse_capacity']/2]
sweep_values = [str(v) for v in sweep_values]
sweep_values = ','.join(sweep_values)
sweep_val_node.text = sweep_values

with open(os.path.join(case, 'heron_input.xml'), 'wb') as f:
tree.write(f)

def main():
parser = argparse.ArgumentParser()
Expand All @@ -201,18 +247,20 @@ def main():
print("Cases to modify: {}\n".format(cases))
for case in cases:
init_storage(case)
#meoh_ratios(case)
meoh_ratios(case)
reduced_arma_samples = True
if '_sweep' in case:
reduced_arma_samples = False
if '_baseline' in case:
reduced_arma_samples = False
if reduced_arma_samples:
arma_samples(case)
sweep_values_htse(case)
sweep_values_meoh(case)
add_elec_consumption_meoh(case)
sweep_values_storage(case)
#sweep_values_htse(case)
#sweep_values_meoh(case)
#add_elec_consumption_meoh(case)
#sweep_values_storage(case)
if ('sweep' not in case) and ('baseline' not in case):
sa_sweep_values(case)



Expand Down
14 changes: 7 additions & 7 deletions use_cases/LWR_MeOH_2023/run/plot_cashflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def plot_lifetime_cashflows(lifetime_cashflows, axis, plant, dispatch_dir, title
df = df.sort_values(by='value', axis=0, ascending=False)
df.reset_index(inplace=True)

# In $M/NPP capacity (MWe)
df['value'] = df['value'].div(1e6*NPP_CAPACITIES[plant])
# In $bn
df['value'] = df['value'].div(1e9)#*NPP_CAPACITIES[plant])

# Waterfall calculations
# calculate running totals
Expand Down Expand Up @@ -134,10 +134,10 @@ def plot_lifetime_cashflows(lifetime_cashflows, axis, plant, dispatch_dir, title
ax.text(i-.15, mid[i], f"{df[y][i]:,.2f}")
# Baseline case as horizontal line
baseline_NPV, std_NPV = get_baseline_NPV(plant)
baseline_NPV /=1e6
baseline_NPV /= NPP_CAPACITIES[plant]
baseline_NPV /=1e9
#baseline_NPV /= NPP_CAPACITIES[plant]
ax.axhline(baseline_NPV, color='b', linewidth=2)
bau_text = 'BAU NPV: '+str(np.round(baseline_NPV,3))+" M$/MWe"
bau_text = 'BAU NPV: $'+str(np.round(baseline_NPV,3))+" bn"
ax.text(5, baseline_NPV+0.1, bau_text, color='b')

# Rename cashflows
Expand All @@ -156,7 +156,7 @@ def plot_all_locations():
all_to_csv = pd.DataFrame()

fig, axs = plt.subplots(3,2, figsize = (11,13), sharey= True,layout='constrained')
fig.supylabel('M$ 2020(USD) / MWe')
fig.supylabel('bn$ 2020(USD)')
title_letters = ['(a)', '(b)', '(c)', '(d)', '(e)']
#title_letters = ['Braidwood', 'Cooper', 'Davis-Besse', 'Prairie-Island', 'South Texas Project']

Expand All @@ -183,7 +183,7 @@ def plot_all_locations():
all_to_csv.to_csv(os.path.join(dir, 'lwr_meoh_cashflow_breakdown.csv'))
axs.flat[-1].axis('tight')
axs.flat[-1].axis('off')
plt.savefig(os.path.join(dir, "total_cashflow_breakdown.png"))
plt.savefig(os.path.join(dir, "lwr_meoh_total_cashflow_breakdown.png"))



Expand Down
2 changes: 1 addition & 1 deletion use_cases/LWR_MeOH_2023/run/plot_sweeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def main():
dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(dir)
df = get_results()
df.to_csv(os.path.join(dir,'sweep_results.csv'))
df.to_csv(os.path.join(dir,'lwr_meoh_sweep_results.csv'))
plot_hist(df)

if __name__ == "__main__":
Expand Down
22 changes: 13 additions & 9 deletions use_cases/LWR_MeOH_2023/run/pp_SA.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ def plot_SA_locations(loc_dic, type='regular'):
ind = np.arange(len(val_dic['low_values']))
width=0.35
if type=='regular':
p1 = ax[i].bar(ind, val_dic['low_values'], width, yerr=val_dic['low_values_sd'], label='Low (Ref x0.75)')
p2 = ax[i].bar(ind, val_dic['high_values'], width, yerr=val_dic['high_values_sd'], label='High (Ref x1.25)')
p1 = ax[i].bar(ind, val_dic['low_values'], width, yerr=val_dic['low_values_sd'], label='Low (Ref x0.75)',
error_kw=dict(ecolor='black',elinewidth=1, capthick=1, capsize=3))
p2 = ax[i].bar(ind, val_dic['high_values'], width, yerr=val_dic['high_values_sd'], label='High (Ref x1.25)',
error_kw=dict(ecolor='black',elinewidth=1, capthick=1, capsize=3))
ax[i].set_xticks(ind)
ax[i].set_xticklabels(reg_variables)
elif type=='ptc':
Expand Down Expand Up @@ -133,7 +135,7 @@ def plot_SA_locations(loc_dic, type='regular'):
fig.legend(lines, labels, bbox_to_anchor=(0,1), ncol=1)

fig.tight_layout()
fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SA_results_location_"+type+".png"))
fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lwr_meoh_SA_results_location_"+type+".png"))



Expand All @@ -146,8 +148,10 @@ def plot_SA_one_location(loc_dic, location, type='regular'):
ind = np.arange(len(val_dic['low_values']))
width=0.35
if type=='regular':
p1 = ax.bar(ind, val_dic['low_values'], width, yerr=val_dic['low_values_sd'], label='Low (Ref x0.75)')
p2 = ax.bar(ind, val_dic['high_values'], width, yerr=val_dic['high_values_sd'], label='High (Ref x1.25)')
p1 = ax.bar(ind, val_dic['low_values'], width, yerr=val_dic['low_values_sd'], label='Low (Ref x0.75)',
error_kw=dict(ecolor='black',elinewidth=1, capthick=1, capsize=3))
p2 = ax.bar(ind, val_dic['high_values'], width, yerr=val_dic['high_values_sd'], label='High (Ref x1.25)',
error_kw=dict(ecolor='black',elinewidth=1, capthick=1, capsize=3))
ax.set_xticks(ind)
ax.set_xticklabels(reg_variables)
elif type=='ptc':
Expand All @@ -172,7 +176,7 @@ def plot_SA_one_location(loc_dic, location, type='regular'):
fig.legend(lines, labels, bbox_to_anchor=(1,1), ncol=1)

fig.tight_layout()
fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SA_results_location_"+location+'_'+type+".png"))
fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lwr_meoh_SA_results_location_"+location+'_'+type+".png"))

def plot_SA_variable_v2(var_dic):
ptc_df = pd.DataFrame()
Expand Down Expand Up @@ -214,7 +218,7 @@ def plot_SA_variable_v2(var_dic):

sns.despine()
fig.tight_layout()
fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SA_results_variable.png"))
fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lwr_meoh_SA_results_variable.png"))

def plot_SA_variable_v3(var_dic):
ptc_df = pd.DataFrame()
Expand Down Expand Up @@ -295,7 +299,7 @@ def plot_SA_variable_v3(var_dic):
#ax_stp[1].legend( [r'$CO_2\; (\$30/ton)$', r'$CO_2 (\$60/ton)$'])
sns.despine()

fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SA_results_variable.png"))
fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lwr_meoh_SA_results_variable.png"))


def plot_SA_variable(var_dic):
Expand Down Expand Up @@ -323,7 +327,7 @@ def plot_SA_variable(var_dic):
lines, labels = [sum(lol, []) for lol in zip(*lines_labels)]
fig.legend(lines, labels, loc='lower right', ncol=1)
fig.tight_layout()
fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SA_results_variable.png"))
fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lwr_meoh_SA_results_variable.png"))



Expand Down
4 changes: 2 additions & 2 deletions use_cases/LWR_MeOH_2023/run/pp_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def plot_configurations(df_list):
# Labels
ax.set_ylabel('Change in profitability (%)')
ax.set_xlabel(f'{dic_var_names[var]} capacity ({dic_var_units[var]})')
sns.despine(ax=ax, trim=True)
sns.despine(ax=ax)
ax.legend(title=dic_var_names[leg_var]+'\n('+dic_var_units[leg_var]+')',bbox_to_anchor=(1,1) )

fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "SA_results_configurations.png"))
fig.savefig(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lwr_meoh_SA_results_configurations.png"))


def load_sweep_data(location):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<produces resource="naphtha,diesel,jet_fuel" dispatch="fixed">
<consumes>h2,electricity</consumes>
<capacity resource="h2">
<sweep_values debug_value="-12615">-12833.0,-6416.5</sweep_values>
<sweep_values debug_value="-12833">-12833.0,-6416.5</sweep_values>
</capacity>
<transfer>
<linear>
Expand Down
Binary file modified use_cases/SMR_FT_2023/data/HERON_model_data.xlsx
Binary file not shown.
Loading

0 comments on commit 6eaed8e

Please sign in to comment.