<jupyter_start><jupyter_text>Sustainable Energy TransitionsA project by <NAME> and <NAME> at Masdar Institute of Science and TechnologyPlotting notebook for social media images 2 This workbook will guide you through the mining, processing, formatting and saving the input data for the SET 2.0 model.This is document has been created using  IPython Notebook in the Anaconda distribution and it can be edited and run in active mode by clicking download in top right corner of this page. The code is partitioned into sections, called cells. When you are using this workbook in active mode, double-click on a cell to edit it and then run using Ctrl + Enter. Hitting Shift + Enter runs the code and steps into the next cell, while Alt + Enter runs the code and adds a new, empty cell. If you are running this notebook on a presonal computer, you will need a machine with at least 1GB of memory (2GB recommended) and a processor of 1GHz.DataThe major data sources for this work are the outputs generated by the SET 2.0 model.ProcessingThe data processing has been done using the Anaconda distribution of Python 2.7 using the IPython Notebook editor. If you have not generated your own data, please download all results files, and run this Iptyhon notebook in the same folder. Then the data is loaded into a pandas dataframe, which represents the backbone of the data analysis. Numerical processing is done with NumPy and for plotting we use matplotlib. Please make sure you have all of these compoents set up in your Python installation. The workbook generates .jpg files to be inlcuded on the main data presentation site. Code Import dependencies.<jupyter_code>import pandas as pd, numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.font_manager as font_manager
%matplotlib inline
mycolors=['#dd1c77','#df65b0','#980043']
abc='abcdefghijklmnopqrstuvwxyz' #for plot labeling
#for plot styling - not necessary
plt.style.use('fivethirtyeight')
#plt.style.use('classic')<jupyter_output><empty_output><jupyter_text>Set up save path on your local computer.<jupyter_code>path="E:\Skydrive\GitHub\set"
titless=[['Fossil phase-out: 2015 - 2050',\
        'Fossil phase-out: 2015 - 2080',\
        'Fossil phase-out: 2020 - 2040'],\
        ['Fossil phase-out: 2020 - 2075',\
        'Fossil phase-out: 2020 - 2100',\
        'Fossil phase-out: 2030 - 2060'],\
        ['Fossil phase-out: 2025 - 2100',\
        'Fossil phase-out: 2025 - 2130',\
        'Fossil phase-out: 2040 - 2080']]
peaks=[[2015,\
        2015,\
        2020],\
        [2020,\
         2020,\
         2030],\
        [2025,\
         2025,\
         2040]]
caps=[r"Emissions cap: 510 GtCO$_2$",r"Emissions cap: 990 GtCO$_2$",r"Emissions cap: 1505 GtCO$_2$"]
trans=["Early","Fuel switch","Late"]<jupyter_output><empty_output><jupyter_text>Sensitivity<jupyter_code>#plots setup

demand=10 #demand bracket
eroei=9 #eroei bracket
D=(int)(np.round(pd.read_excel('data/parameters/params7.xlsx').set_index('Run').loc['final demand'].values[demand*21]))
E=(int)(np.round(pd.read_excel('data/parameters/params7.xlsx').set_index('Run').loc['wind EROEI'].values[eroei]))

colors='Spectral_r'
bases=[7,10,13]
shares=["6.1","3.2","10.1"]

order=[3,5,4,0,2,1,6,8,7]

lifetime=25
moving_window=10<jupyter_output><empty_output><jupyter_text>Read data<jupyter_code>DF={}
DF2={}
DF3={}
DF4={}
for k in range(len(order)):
    i=order[k]+7
    DF[k]=pd.read_excel('data/results/results'+repr(i)+'.xlsx',sheetname=1,header=None)
    DF2[k]=pd.read_excel('data/results/results'+repr(i)+'.xlsx',sheetname=2,header=None)
    DF3[k]=pd.read_excel('data/results/results'+repr(i)+'.xlsx',sheetname=0,header=None)
    DF4[k]=pd.read_excel('data/results/results'+repr(i)+'.xlsx',sheetname=3,header=None)<jupyter_output><empty_output><jupyter_text>Demand plots Demand Rates<jupyter_code>fpath = 'Comfortaa.ttf'
prop = font_manager.FontProperties(fname=fpath)
for eroei in range(21):
    #eroei=9 #eroei bracket
    E=(int)(np.round(pd.read_excel('data/parameters/params7.xlsx').set_index('Run').loc['wind EROEI'].values[eroei]))

    vi=0
    vx=15.0
    vx2=35.0
    lev=vx/2.5+1
    lev2=(vx2-vx)/2.5+1
    fig = plt.figure(figsize=(8,5))                                                               
    ax=[]
    ax.append(plt.subplot2grid((2,2), (0,0), rowspan=2, colspan=2, axisbg=None, axisbelow=True))
    fig.tight_layout()  
    fig.subplots_adjust(wspace=0.35)

    for k in [3]:#+range(len(order)):
        title=titless[k/3][k%3]
        base=bases[k/3]
        cap=caps[k/3]
        tran=trans[k%3]
        share=shares[k/3]
        i=order[k]+7

        df=DF[k].copy()
        df=df[df.columns[eroei::21]]
        df.index=range(1950,2111)
        df2=DF2[k].copy()
        df2.index=range(1950,2111)
        df2=df2[df2.columns[eroei::21]]
        df+=df2/lifetime
        df=pd.rolling_mean(df,moving_window,center=True) 
        df=df.loc[2001:2101]

        a2=ax[0].contourf(df.T,levels=np.linspace(vx,vx2,lev2),cmap=colors,extend='max',vmin=-100,vmax=vx2)
        a=ax[0].contourf(df.T,levels=np.linspace(vi,vx,(lev-1)*5+1),cmap=colors,extend='both')
        b=ax[0].contour(df.T,linewidths=1,levels=np.linspace(vi,vx*2,(lev-1)*2+1).astype(float),colors='#222222')
        ax[0].set_ylim(1,21)
        ax[0].set_xlim(0,100)
        ax[0].clabel(b, fmt = '%r',inline=1, fontsize=14,fontproperties=prop)
        ax[0].set_xticklabels([2000,2020,2040,2060,2080,2100],size=14,fontproperties=prop)
        ticks=np.array([0,4.5,7.8,10,14.2,16.9,20])+1
        ax[0].set_yticks(ticks)
        tick1=[667,1000,1500,2000,3000,4000,6000]
        ax[0].set_yticklabels(tick1,size=14,fontproperties=prop)
        ax[0].set_xlabel('Year',fontproperties=prop)
        ax[0].set_ylabel('Demand in year 2100 [W / person]',labelpad=15,fontproperties=prop)
        ax[0].text(0.5, 1.02, r"Fossil phase-out 2020-2075  |   Emissions cap: 990 GtCO$_2$",
            horizontalalignment='center',
            verticalalignment='bottom',fontproperties=prop,
            transform=ax[0].transAxes,size=14,color='k')
        ax[0].text(0.5, 1.1, r"EROEI = "+repr(E)+" in year 2014   |   Demand = 667-6000 W / person in year 2100",
            horizontalalignment='center',
            verticalalignment='bottom',fontproperties=prop,
            transform=ax[0].transAxes,size=14,color='k')

        fig.subplots_adjust(right=0.85)
        cbar_ax = fig.add_axes([0.9, 0.05, 0.03, 0.930])
        fig.colorbar(a, cmap=colors, cax=cbar_ax, ticks=[0,2.5,5.0,7.5,10.0,12.5,15.0])
        cbar_ax.set_yticklabels([0,2.5,5,7.5,10,12.5,15],fontproperties=prop)

        ax[0].text(1.21, 0.5, 'Renewable Capacity Installation Rate [TWp / year]',
        horizontalalignment='center',
        verticalalignment='center',rotation=90,
        transform=ax[0].transAxes,fontproperties=prop)

    ax[0].plot([11 for i in range(1,101)],linewidth=2,color='k',linestyle='--')
    plt.suptitle('Demand Sensitivity of Renewable Capacity Installation Rate',fontproperties=prop,size=17,y=1.14,x=0.46)    
    plt.savefig(path+'/twitter/Demand_Sensitivity_Rates_EROEI_nosmooth'+repr(E)+'.png',bbox_inches = 'tight', pad_inches = 0.1, dpi=150)
    plt.close()
for year in range(2001,2101):
    #year=2030
    eroei=9 #eroei bracket
    E=(int)(np.round(pd.read_excel('data/parameters/params7.xlsx').set_index('Run').loc['wind EROEI'].values[eroei]))

    vi=0
    vx=15.0
    vx2=35.0
    lev=vx/2.5+1
    lev2=(vx2-vx)/2.5+1
    fig = plt.figure(figsize=(8,5))                                                               
    ax=[]
    ax.append(plt.subplot2grid((2,2), (0,0), rowspan=2, colspan=2, axisbg=None, axisbelow=True))
    fig.tight_layout()  
    fig.subplots_adjust(wspace=0.35)

    for k in [3]:#+range(len(order)):
        title=titless[k/3][k%3]
        base=bases[k/3]
        cap=caps[k/3]
        tran=trans[k%3]
        share=shares[k/3]
        i=order[k]+7

        df=DF[k].copy()
        df.index=range(1950,2111)
        df2=DF2[k].copy()
        df2.index=range(1950,2111)
        df+=df2/lifetime
        df=pd.rolling_mean(df,moving_window,center=True) 
        df=df.loc[2001:2101]

        dk=pd.DataFrame()
        break_after=21
        for i in range(len(df.loc[year])/break_after):
            dl=pd.DataFrame(df.loc[year][i*break_after:(i+1)*break_after]).T
            dl.columns=range(break_after)
            dk=pd.concat([dk,dl])

        a2=ax[0].contourf(dk.T,levels=np.linspace(vx,vx2,lev2),cmap=colors,extend='max',vmin=-100,vmax=vx2)
        a=ax[0].contourf(dk.T,levels=np.linspace(vi,vx,(lev-1)*5+1),cmap=colors,extend='both')
        b=ax[0].contour(dk.T,linewidths=1,levels=np.linspace(vi,vx*2,(lev-1)*2+1).astype(float),colors='#222222')
        ax[0].set_ylim(1,21)
        ax[0].set_xlim(0,20)
        ax[0].clabel(b, fmt = '%r',inline=1, fontsize=14,fontproperties=prop)
        ax[0].set_xticks(np.array([0,4.5,7.8,10,14.2,16.9,20])+1)
        ax[0].set_xticklabels([667,1000,1500,2000,3000,4000,6000],size=14)
        ax[0].set_yticks([0,4.5,7.8,10,14.2,16.9,20])
        ax[0].set_yticklabels([6.67,10,15,20,30,40,60],size=14)
        ax[0].set_xlabel('Demand in year 2100 [W / person]',fontproperties=prop,labelpad=13)
        ax[0].set_ylabel('Renewable EROEI in year 2014 [ratio]',labelpad=2,fontproperties=prop)
        ax[0].text(0.5, 1.02, r"Fossil phase-out 2020-2075  |   Emissions cap: 990 GtCO$_2$",
            horizontalalignment='center',
            verticalalignment='bottom',fontproperties=prop,
            transform=ax[0].transAxes,size=14,color='k')
        ax[0].text(0.5, 1.1, r"EROEI = 6.67-60 in year 2014   |   Demand = 667-6000 W / person in year 2100",
            horizontalalignment='center',
            verticalalignment='bottom',fontproperties=prop,
            transform=ax[0].transAxes,size=14,color='k')

        fig.subplots_adjust(right=0.85)
        cbar_ax = fig.add_axes([0.9, 0.05, 0.03, 0.930])
        fig.colorbar(a, cmap=colors, cax=cbar_ax, ticks=[0,2.5,5.0,7.5,10.0,12.5,15.0])
        cbar_ax.set_yticklabels([0,2.5,5,7.5,10,12.5,15],fontproperties=prop)

        ax[0].text(1.21, 0.5, 'Renewable Capacity Installation Rate [TWp / year]',
        horizontalalignment='center',
        verticalalignment='center',rotation=90,
        transform=ax[0].transAxes,fontproperties=prop)

    ax[0].plot([11 for i in range(1,101)],linewidth=2,color='k',linestyle='--')
    plt.suptitle('Demand/EROEI sensitivity of Installation Rates in year '+repr(year),fontproperties=prop,size=17,y=1.14,x=0.46)    
    plt.savefig(path+'/twitter/Surface_Year'+repr(year)+'_Rates.png',bbox_inches = 'tight', pad_inches = 0.1, dpi=150)
    plt.close()<jupyter_output>C:\Anaconda\envs\py27\lib\site-packages\ipykernel\__main__.py:30: FutureWarning: pd.rolling_mean is deprecated for DataFrame and will be removed in a future version, replace with 
	DataFrame.rolling(window=10,center=True).mean()
{'fraction_non_alphanumeric': 0.15862258448575878, 'fraction_numerical': 0.0769301218060262, 'mean_word_length': 3.66866182129115, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '350693', 'license': 'MIT', 'n_tokens_mistral': 4568, 'n_tokens_neox': 4049, 'n_words': 700, 'path': '.ipynb_checkpoints/twitterplotter2-checkpoint.ipynb', 'repo_name': 'csaladenes/sustainable-energy-transitions', 'size': '10935'}