# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## Supplementary Figure - 2019 Operations
# <NAME>, 2021.

import os
os.chdir('../')

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Patch
from matplotlib.lines import Line2D

# Note: for 2019, only ran with storage before but dropped that from the naming

# +
scens1 = ['_Timers9pm_noWPcontrol', '_Timers12am_noWPcontrol', '_TimersRandom_noWPcontrol', '_TimersNone_noWPcontrol', '_TimersNone_WPcontrol_minpeak', '_TimersNone_WPcontrol_avgem']
scens2 = ['UniversalHome', 'HighHome', 'LowHome_HighWork', 'LowHome_LowWork']

vals1 = np.zeros((7, 5)) # overgeneration
tables_dfs1 = pd.DataFrame(np.zeros((7, 5)), 
                          index=['_Timers9pm_noWPcontrol', '_Timers12am_noWPcontrol','_TimersRandom_noWPcontrol', '_TimersNone_noWPcontrol', '_TimersNone_WPcontrol_minpeak', '_TimersNone_WPcontrol_avgem', '_TimersMixed_WPcontrol_minpeak'], 
                          columns=['UniversalHome', 'HighHome', 'LowHome_HighWork', 'LowHome_LowWork', 'BusinessAsUsual'])

vals2 = np.zeros((7, 5)) # ramping
tables_dfs2 = pd.DataFrame(np.zeros((7, 5)), 
                          index=['_Timers9pm_noWPcontrol', '_Timers12am_noWPcontrol','_TimersRandom_noWPcontrol', '_TimersNone_noWPcontrol', '_TimersNone_WPcontrol_minpeak', '_TimersNone_WPcontrol_avgem', '_TimersMixed_WPcontrol_minpeak'], 
                          columns=['UniversalHome', 'HighHome', 'LowHome_HighWork', 'LowHome_LowWork', 'BusinessAsUsual'])

for i, scen1 in enumerate(scens1):
    for j, scen2 in enumerate(scens2):
        penlevel = 1.0
        overgen = None
        dpdf = pd.read_csv('Results/Run2019/fuel1_solar1_wind1_'+scen2+scen1+'_penlevel'+str(penlevel)+'_withstorage_dpdf_20220506.csv')                
        try: 
            overgen = pd.read_csv('Results/Run2019/fuel1_solar1_wind1_'+scen2+scen1+'_penlevel'+str(penlevel)+'_withstorage_overgeneration.csv')
        except:
            print('No overgeneration for ', scen1, scen2)
                    
        if overgen is not None:
            vals1[i, j] = np.abs(overgen.demand.sum())
            tables_dfs1.loc[scen1, scen2] = np.abs(overgen.demand.sum())
        
        prof1 = np.zeros((25, ))
        prof1[np.arange(0, 24)] = dpdf['demand'].values.reshape(-1, 24).mean(axis=0) # in original 
        prof1[24] = prof1[0]
        vals2[i, j] = np.max(prof1[1:] - prof1[:-1])
        tables_dfs2.loc[scen1, scen2] = np.max(prof1[1:] - prof1[:-1])
        
        
scen2 = 'BusinessAsUsual'
scen1 =  '_TimersMixed_WPcontrol_minpeak'
i = i+1
j = j+1
overgen = None
dpdf = pd.read_csv('Results/Run2019/fuel1_solar1_wind1_'+scen2+scen1+'_penlevel'+str(penlevel)+'_withstorage_dpdf_20220506.csv')
try: 
    overgen = pd.read_csv('Results/Run2019/fuel1_solar1_wind1_'+scen2+scen1+'_penlevel'+str(penlevel)+'_withstorage_overgeneration.csv')
except:
    print('No overgeneration for ', scen1, scen2)        
        
if overgen is not None:
    vals1[i, j] = np.abs(overgen.demand.sum())
    tables_dfs1.loc[scen1, scen2] = np.abs(overgen.demand.sum())

prof = np.zeros((25, ))
prof[np.arange(0, 24)] = dpdf['demand'].values.reshape(-1, 24).mean(axis=0)
prof[24] = prof[0]
vals2[i, j] = np.max(prof[1:] - prof[:-1])
tables_dfs2.loc[scen1, scen2] = np.max(prof[1:] - prof[:-1])        



# -

tables_dfs1*(1/1000)

tables_dfs2*(1/1000)

# +
# (tables_dfs2*(1/1000)).round(2).to_csv('MainPlotting/Tables/fig5a_ramping.csv')
# (tables_dfs1*(1/1000)).round(2).to_csv('MainPlotting/Tables/fig5a_overgeneration.csv')
# -

np.round((1/1000)*vals2, 2)

# +
plt.figure(figsize=(10, 4))
titles = ['UH', 'HH', 'LHHW', 'LHLW']

colors = ['#d7301f', '#fc8d59','#91cf60',  '#737373', '#9ebcda', '#88419d']
control_labels = ['9pm SFH Timers', '12am SFH Timers', 'Random SFH Timers', 'Uncontrolled', 'Min(Peak) Work Control', 'Max(Avg Em) Work Control']

plt.subplot(121)
plt.xlabel('Access Scenario', fontsize=14)
plt.ylabel('Ramping [GW]', fontsize=14)
plt.xticks(np.arange(0, 4), labels=titles, fontsize=12)

ms = [8, 8, 8, 14, 8, 8]
lines = ['-P', '-X', '-d', '-*', '-^','-v']
for control_idx in range(6):
    plt.plot(np.arange(0, 4), (1/1000)*vals2[control_idx, np.arange(0, 4)], lines[control_idx], color=colors[control_idx], label=control_labels[control_idx], zorder=1, markersize=ms[control_idx])
plt.scatter(np.array([1]), np.array((1/1000)*tables_dfs2.loc['_TimersMixed_WPcontrol_minpeak', 'BusinessAsUsual']), marker='o', color='#ffffbf', edgecolors='k', s=100, zorder=2, label='Business As Usual')
plt.xlim([-0.5, 3.5])
plt.yticks(np.arange(2, 11, 2), fontsize=14)
plt.gca().set_axisbelow(True)        
plt.gca().grid(axis='y')


plt.subplot(122)


plt.xticks(np.arange(0, 4), labels=titles, fontsize=12)
plt.xlabel('Access Scenario', fontsize=14)
plt.yticks([20, 40, 60, 80, 100], fontsize=12)
plt.xlim([-0.5, 3.5])


lines = ['-P', '-X', '-d', '-*', '-^','-v']
ms = [8, 8, 8, 14, 8, 8]
edgecolors=[colors[0], colors[1],'k', colors[2], colors[3]]
for control_idx in range(6):
    plt.plot(np.arange(0, 4), (1/1000)*vals1[control_idx, np.arange(0, 4)], lines[control_idx], color=colors[control_idx], label=control_labels[control_idx], zorder=1, markersize=ms[control_idx])
plt.ylabel('Overgeneration [GWh]', fontsize=14)
plt.scatter(np.array([1]), np.array((1/1000)*tables_dfs1.loc['_TimersMixed_WPcontrol_minpeak', 'BusinessAsUsual']), marker='o', color='#ffffbf', edgecolors='k', s=100, zorder=2, label='Business As Usual')
            
plt.legend(fontsize=12)
plt.yticks(np.arange(20, 110, 20), fontsize=14)
plt.gca().set_axisbelow(True)        
plt.gca().grid(axis='y')

plt.tight_layout()
plt.savefig('SupplementPlotting/Plots/supfig23_v2.pdf', bbox_inches='tight')
plt.show()

StarcoderdataJupyterScriptsDedupFiltered