jmquintana79
9/6/2017 - 2:24 AM

Wind Hourly Analysis Plot

Plot distribution per hour of the most relevant variables.

It is required that the Pandas DF has got this column names: hws, devhws, hwd, devhwd,power

"""
ANALYSIS WIND HOURLY

Plot distribution per hour of the most relevant variables.

It is required that the Pandas DF has got this column names:
hws, devhws, hwd, devhwd,power 

"""
def analysis_wind_hourly(WIND,stitle=''):
    import pandas as pd
    import numpy as np


    ## WIND SPEED HOURLY 

    # format index
    WIND.index = pd.to_datetime(WIND.index) 
    # include hour field
    WIND['hour'] = [i.hour for i in WIND.index.tolist()]
    # calculate turbulence
    WIND['turbulence'] = [idevhws*1000.//ihws for idevhws,ihws in zip(WIND.devhws.tolist(),WIND.hws.tolist())]


    ## PLOT

    import matplotlib.pyplot as plt
    # create object
    fig= plt.figure(figsize=(20,15))


    ## AXIS1

    # set axis1
    ax1 = plt.subplot2grid((3,2),(0,0)) 
    # df with hws per hours
    HOUR = pd.DataFrame(np.array([WIND[WIND.hour==ihour]['hws'].tolist() for ihour in sorted(list(set(WIND.hour.values)))]).transpose(),columns=list(range(24)))
    # plot
    HOUR.plot(kind='box',ax=ax1)
    # set title
    if len(stitle)>0: title = ': %s'%stitle
    else: title = stitle
    ax1.set_title("HWS Distribution per Hour%s"%title,fontsize=18)
    # axes labels
    ax1.set_xlabel("Hour")
    ax1.set_ylabel("HWS(m/s)")
    # clean
    del(HOUR)


    ## AXIS2

    # set axis2
    ax2 = plt.subplot2grid((3,2),(0,1))
    # df with hws per hours
    HOUR = pd.DataFrame(np.array([WIND[WIND.hour==ihour]['devhws'].tolist() for ihour in sorted(list(set(WIND.hour.values)))]).transpose(),columns=list(range(24)))
    # plot
    HOUR.plot(kind='box',ax=ax2)
    # set title
    if len(stitle)>0: title = ': %s'%stitle
    else: title = stitle
    ax2.set_title("std(HWS) Distribution per Hour%s"%title,fontsize=18)
    # axes labels
    ax2.set_xlabel("Hour")
    ax2.set_ylabel("std(HWS)(m/s)")
    # clean
    del(HOUR)


    ## AXIS3

    # set axis3
    ax3 = plt.subplot2grid((3,2),(1,0))
    # df with hws per hours
    HOUR = pd.DataFrame(np.array([WIND[WIND.hour==ihour]['hwd'].tolist() for ihour in sorted(list(set(WIND.hour.values)))]).transpose(),columns=list(range(24)))
    # plot
    HOUR.plot(kind='box',ax=ax3)
    # set title
    if len(stitle)>0: title = ': %s'%stitle
    else: title = stitle
    ax3.set_title("HWD Distribution per Hour%s"%title,fontsize=18)
    # axes labels
    ax3.set_xlabel("Hour")
    ax3.set_ylabel("HWD(degrees)")
    # clean
    del(HOUR)


    ## AXIS4

    # set axis4
    ax4 = plt.subplot2grid((3,2),(1,1))
    # df with hws per hours
    HOUR = pd.DataFrame(np.array([WIND[WIND.hour==ihour]['devhwd'].tolist() for ihour in sorted(list(set(WIND.hour.values)))]).transpose(),columns=list(range(24)))
    # plot
    HOUR.plot(kind='box',ax=ax4)
    # set title    
    if len(stitle)>0: title = ': %s'%stitle
    else: title = stitle
    ax4.set_title("std(HWD) Distribution per Hour%s"%title,fontsize=18)
    # axes labels
    ax4.set_xlabel("Hour")
    ax4.set_ylabel("std(HWD)(degrees)")
    # clean
    del(HOUR)


    ## AXIS5

    # set axis5
    ax5 = plt.subplot2grid((3,2),(2,0))
    # df with hws per hours
    HOUR = pd.DataFrame(np.array([WIND[WIND.hour==ihour]['turbulence'].tolist() for ihour in sorted(list(set(WIND.hour.values)))]).transpose(),columns=list(range(24)))
    # plot
    HOUR.plot(kind='box',ax=ax5)
    # set title    
    if len(stitle)>0: title = ': %s'%stitle
    else: title = stitle
    ax5.set_title("Turbulence Int. Distribution per Hour%s"%title,fontsize=18)
    # axes labels
    ax5.set_xlabel("Hour")
    ax5.set_ylabel("Turbulence Int. (*10**-3)")
    # clean
    del(HOUR)


    ## AXIS6

    # set axis6
    ax6 = plt.subplot2grid((3,2),(2,1))
    # df with hws per hours
    HOUR = pd.DataFrame(np.array([WIND[WIND.hour==ihour]['power'].tolist() for ihour in sorted(list(set(WIND.hour.values)))]).transpose(),columns=list(range(24)))
    # plot
    HOUR.plot(kind='box',ax=ax6)
    # set title 
    if len(stitle)>0: title = ': %s'%stitle
    else: title = stitle
    ax6.set_title("POWER Distribution per Hour%s"%title,fontsize=18)
    # axes labels
    ax6.set_xlabel("Hour")
    ax6.set_ylabel("Power(kW)")
    # clean
    del(HOUR)


    # setup space(height) between subplots
    plt.subplots_adjust(hspace = 0.3)

    # show
    plt.show()
    
    # return
    return None