<jupyter_start><jupyter_text>Cut by TI<jupyter_code>turbclasses = np.linspace(0,50,6)
turbcol, probe_heights, _ = utils.get_vertical_locations(catinfo['columns']['ti'], 87)

metdat['turbclass'] = pd.cut(metdat[turbcol], turbclasses, include_lowest=False).astype(str)
metdat['turbclass'].value_counts()

temp = metdat.groupby('turbclass')
turbclasses = list(temp.groups.keys())[:-1]
lowTI = temp.get_group(turbclasses[0])
plotcats = ['air density',
            'air pressure',
            'air temperature',
            'direction',
            'relative humidity',
            'speed',
            'wind shear',
            'wind veer']
lowtifigpath = '../../figs/lowTI'
try:
    os.makedirs(lowtifigpath)
except:
    pass<jupyter_output><empty_output><jupyter_text>Full data histograms<jupyter_code>catinfo['labels']['direction']
nrelcolors = utils.get_nrelcolors()

for cat in ['direction']:#plotcats:
    
    height = 87
    if 'shear' in cat.lower():
        height = 110

    plotvar, probe_height, _ = utils.get_vertical_locations(catinfo['columns'][cat], height)

    fulldat = metdat[plotvar].dropna().sort_values()
    fulldat = MET.reject_outliers(fulldat,m=4)

    fig, ax = plt.subplots(figsize=(5,3))
    
    binwidth = np.round((fulldat.max()-fulldat.min())/35.0,decimals=3)
    bins = np.arange(fulldat.min(), fulldat.max(), binwidth)
    
    fulldat.plot.hist(bins = bins, 
                        color=nrelcolors['blue'][0],
                        edgecolor='k',
                        alpha=1,
                        ax=ax,
                        weights=np.ones(len(fulldat))/len(fulldat)*100,
                        legend=False)

    ax.set_xlabel(catinfo['labels'][cat])
    ax.set_ylabel('Frequency [%]')

    fig.savefig(os.path.join(figPath,'M5_{}_hist_comp_{}m.png'.format(catinfo['save'][cat],probe_height)),dpi=200,bbox_inches='tight')
    
    plt.clf()<jupyter_output><empty_output><jupyter_text>Low TI histograms comparisons<jupyter_code>nrelcolors = utils.get_nrelcolors()

for cat in ['direction']:#plotcats:
    
    height = 87
    if 'shear' in cat.lower():
        height = 110

    plotvar, _, _ = utils.get_vertical_locations(catinfo['columns'][cat], height)

    fulldat = metdat[plotvar].dropna().sort_values()
    fulldat = MET.reject_outliers(fulldat,m=4)
    lowtidat = lowTI[plotvar].dropna().sort_values()
    lowtidat = MET.reject_outliers(lowtidat,m=4)
    
    result = pd.concat([fulldat, lowtidat], axis=1)
    fig, ax = plt.subplots(figsize=(5,3))
    
    binwidth = np.round((fulldat.max()-fulldat.min())/35.0,decimals=3)
    bins = np.arange(fulldat.min(), fulldat.max(), binwidth)
    
    fulldat.plot.hist(bins = bins, 
                        color=nrelcolors['blue'][0],
                        edgecolor='k',
                        alpha=0.5,
                        ax=ax,
                        weights=np.ones(len(fulldat))/len(fulldat)*100,
                        legend=False)

    lowtidat.plot.hist(bins = bins, 
                        color=nrelcolors['red'][0],
                        edgecolor='k',
                        alpha=0.5,
                        ax=ax,
                        weights=np.ones(len(lowtidat))/len(lowtidat)*100, 
                        legend=False)

    ax.set_xlabel(catinfo['labels'][cat])
    ax.set_ylabel('Frequency [%]')
    leg = ax.legend(['Full Data', 'Low TI'], frameon=False)

    fig.savefig(os.path.join(lowtifigpath,'LOWTI_{}_hist_comp.png'.format(catinfo['save'][cat])),dpi=200,bbox_inches='tight')
    
    plt.clf()
    
turbcol,_,_ = utils.get_vertical_locations(catinfo['columns']['ti'], 87)
nrelcolors= utils.get_nrelcolors()
colors = utils.get_colors(5, basecolor='span')

# test = metdat.groupby([metdat.index.weekofyear,'turbclass'])
test = metdat.groupby([metdat.index.dayofyear,'turbclass'])
test2 = test[turbcol].count().unstack().drop('nan',axis=1).transpose()
test2 = test2/test2.sum()
test2 = test2.transpose()
test2.mean()*100
test2.std()*100
test3 = test2[test2.columns[-1::-1]]
colors = utils.get_colors(5, basecolor='span',reverse=True)

fig, ax = plt.subplots(figsize=(5,3))

for ii,turb in enumerate(turbclasses[-1::-1]):
    data = test3[turb].dropna()
    plt.hist(data, bins=np.arange(data.min(),data.max(),0.01), 
                    color=colors[ii],
                    edgecolor='k',
                    alpha=0.9,
                    weights= np.ones(len(data))/len(data), density=False)
ax.set_xlabel('Daily Contribution [%]')
ax.set_ylabel('Frequency [%]')
leg = ax.legend(turbclasses[-1::-1], loc=6, bbox_to_anchor = (1,0.5), frameon=False)
leg.set_title(catinfo['labels']['ti'])
# fig.savefig(os.path.join(lowtifigpath,'TI_frequency_hist.png'),dpi=200,bbox_inches='tight')
test3 = test2[test2.columns[-1::-1]]
colors = utils.get_colors(5, basecolor='span',reverse=True)

fig, ax = plt.subplots(figsize=(5,3))

for ii,turb in enumerate(turbclasses[-1::-1]):
    data = test3[turb]
    ax.hist(data, bins=np.arange(data.min(),data.max(),0.02), 
                    color=colors[ii],
                    edgecolor='k',
                    alpha=0.85,
                    weights= 100*np.ones(len(data))/len(data), density=False)
#     data.plot.kde(color=colors[ii], ax=ax)
ax.set_xlim(0,0.65)
ax.set_xlabel('Daily Contribution [%]')
ax.set_ylabel('Frequency [%]')
leg = ax.legend(turbclasses[-1::-1], loc=6, bbox_to_anchor = (1,0.5), frameon=False)
leg.set_title(catinfo['labels']['ti'])
fig.savefig(os.path.join(lowtifigpath,'LOWTI_frequency_hist.png'),dpi=200,bbox_inches='tight')
test3 = test2[test2.columns[-1::-1]]
times = pd.to_datetime(test3.index, format='%j')
pd.DatetimeIndex(times, format='%m-%d')
import matplotlib.dates as mdates

test3 = test2[test2.columns[-1::-1]]
times = pd.to_datetime(test3.index, format='%j')
test3 = test3.set_index(times.format('%m'))

fig, ax = plt.subplots(figsize=(5,3))
ax = test3.plot(x=test3.index, color=colors, ax=ax)
leg = ax.legend(turbclasses[-1::-1], loc=6, bbox_to_anchor=(1,0.5), frameon=False)
leg.set_title(catinfo['labels']['ti'])
ax.set_ylabel('Daily Contribution [%]')
ax.set_xlabel('Day of Year')
ax.format_xdata = mdates.DateFormatter('%m')
# fig.savefig(os.path.join(lowtifigpath,'LOWTI_plot_by_day.png'),dpi=200,bbox_inches='tight')<jupyter_output><empty_output><jupyter_text>Low TI figs<jupyter_code>categories = list(catinfo['columns'].keys())

for cat in ['speed']:#categories:
    if 'stability flag' in cat.lower():
        continue
    
#     # savepath for new figs
#     savecat = catinfo['save'][cat]
#     catfigpath = os.makedirs(os.path.join(figPath,savecat), mode=0o777, exist_ok=True)
#     catfigpath = os.path.join(figPath,savecat)
    
    # Profiles
    ## cumulative profile
    fig, ax = vis.cumulative_profile(lowTI, catinfo, cat)
#     fig.savefig(os.path.join(catfigpath,'{}_{}_profile.png'.format(towerID, savecat)), dpi=200, bbox_inches='tight')
    
    ## monthly profile
    fig, ax = vis.monthly_profile(lowTI, catinfo, cat)
#     fig.savefig(os.path.join(catfigpath,'{}_{}_profile_monthly.png'.format(towerID, savecat)), dpi=200, bbox_inches='tight')
    
    ## stability profile
    fig,ax = vis.stability_profile(lowTI, catinfo, cat)
#     fig.savefig(os.path.join(catfigpath,'{}_{}_profile_stability.png'.format(towerID, savecat)), dpi=200, bbox_inches='tight')
    
    ## monthly stability profile
    fig,ax = vis.monthly_stability_profiles(lowTI, catinfo, cat)
#     fig.savefig(os.path.join(catfigpath,'{}_{}_profile_monthly_stability.png'.format(towerID, savecat)), dpi=200, bbox_inches='tight')
    
    # Diurnal cycle
    ## cumulative hourly plot
    fig,ax = vis.hourlyplot(lowTI, catinfo, cat)
#     fig.savefig(os.path.join(catfigpath,'{}_{}_hourly.png'.format(towerID, savecat)), dpi=200, bbox_inches='tight')
    
    ## monthly hourly plot
    fig,ax = vis.monthlyhourlyplot(lowTI, catinfo, cat)
#     fig.savefig(os.path.join(catfigpath,'{}_{}_hourly_monthly.png'.format(towerID, savecat)), dpi=200, bbox_inches='tight')

    plt.close('all')
    
    
temp = lowTI.copy()
temp = temp.groupby(temp.index.month)
fig,ax = vis.monthlyhourlyplot(lowTI,catinfo,'direction')
fig.savefig(os.path.join(lowtifigpath,'TI_hourly_monthly.png'),dpi=200,bbox_inches='tight')
fig, ax, leg = vis.monthly_rose_fig(lowTI,catinfo,'speed',vertloc=90, bins=[0,3,5,7,12], ylim=12)
fig.savefig(os.path.join(lowtifigpath,'TI_monthly_wind_rose.png'),dpi=200,bbox_inches='tight')
dircol, probe_heights, _ = utils.get_vertical_locations(catinfo['columns']['direction'], 87)
spdcol, probe_heights, _ = utils.get_vertical_locations(catinfo['columns']['speed'], 87)
colors = utils.get_colors(5,basecolor='span')

fig,ax = plt.subplots(figsize=(8,3))
for ii, tclass in enumerate(turbclasses):
    test.get_group((1,tclass)).plot.scatter(dircol, spdcol, color=colors[ii], alpha = 0.35, edgecolor='k', ax=ax)
ax.legend(turbclasses)
dircol, probe_heights, _ = utils.get_vertical_locations(catinfo['columns']['direction'], 87)

fig, ax = plt.subplots(figsize=(8,3))
cat = 'gradient richardson'
stabcol, probe_heights, _ = utils.get_vertical_locations(catinfo['columns'][cat], 87)
test.get_group((1,turbclasses[0])).plot.scatter(dircol, stabcol, color=colors[0], alpha = 0.35, edgecolor='k', ax=ax)
ax.set_title(catinfo['labels'][cat])

fig, ax = plt.subplots(figsize=(8,3))
cat = 'stability parameter z/l'
stabcol, probe_heights, _ = utils.get_vertical_locations(catinfo['columns'][cat], 87)
test.get_group((1,turbclasses[0])).plot.scatter(dircol, stabcol, color=colors[0], alpha = 0.35, edgecolor='k', ax=ax)
ax.set_title(catinfo['labels'][cat])

fig, ax = plt.subplots(figsize=(8,3))
cat = 'monin-obukhov length'
stabcol, probe_heights, _ = utils.get_vertical_locations(catinfo['columns'][cat], 87)
test.get_group((1,turbclasses[0])).plot.scatter(dircol, stabcol, color=colors[0], alpha = 0.35, edgecolor='k', ax=ax)
ax.set_title(catinfo['labels'][cat])<jupyter_output><empty_output><jupyter_text>Weibull distribution<jupyter_code>import windrose
import scipy.stats as stats
speedcols, _, _ = utils.get_vertical_locations(catinfo['columns']['speed'])

for plotvar in speedcols[0:1]:
    fulldat = metdat[plotvar].dropna()
    fulldat = MET.reject_outliers(fulldat,m=4)
    lowtidat = lowTI[plotvar].dropna()
    lowtidat = MET.reject_outliers(lowtidat,m=4)

    binwidth = np.round((lowtidat.max()-lowtidat.min())/35.0,decimals=3)
    bins = np.arange(lowtidat.min(), lowtidat.max(), binwidth)

    nrecolors = utils.get_nrelcolors()

    binwidth = np.round((lowtidat.max()-lowtidat.min())/35.0,decimals=3)
    bins = np.arange(lowtidat.min(), lowtidat.max(), binwidth)

    fig, ax = plt.subplots(figsize = (5,3))
    
    lowtiparams = stats.exponweib.fit(lowtidat, fc=1)
    ax.plot(bins, stats.exponweib.pdf(bins, *lowtiparams), color=nrecolors['red'][0])

    # thing,stuff = 
    output = ax.hist(lowtidat, 
                bins = bins, 
                facecolor=nrecolors['red'][0], 
                edgecolor='k',
                alpha=0.3,
                normed=True)

    fullparams = stats.exponweib.fit(fulldat, fc=1)
    pdf = stats.exponweib.pdf(bins, *fullparams)
    ax.plot(bins, pdf, color=nrecolors['blue'][0])

    fullparams = stats.weibull_min.fit(fulldat)
    pdf = stats.weibull_min.pdf(bins, *fullparams)
    ax.plot(bins, pdf)

    # thing,stuff = 
    output = ax.hist(fulldat, 
                bins = bins, 
                facecolor=nrecolors['blue'][0], 
                edgecolor='k',
                alpha=0.3,
                normed=True)
    
    leg = fig.legend()
#     fig.savefig(os.path.join(lowtifigpath,'TI_monthly_wind_rose.png'),dpi=200,bbox_inches='tight')
plotvar, _, _ = utils.get_vertical_locations(catinfo['columns']['speed'], height)
fulldat = metdat[plotvar].dropna().sort_values()
fulldat = MET.reject_outliers(fulldat,m=4)

binwidth = np.round((fulldat.max()-fulldat.min())/35.0,decimals=3)
bins = np.arange(fulldat.min(), fulldat.max(), binwidth)

fullparams = stats.rayleigh.fit(fulldat)

plt.plot(bins, stats.rayleigh.pdf(bins, *fullparams), color=nrecolors['blue'][0])

output = plt.hist(fulldat, 
            bins = bins, 
            facecolor=nrecolors['blue'][0], 
            edgecolor='k',
            alpha=0.3,
            normed=True)
fullparams = stats.weibull_min.fit(lowtidat, floc=1)
pdf = stats.weibull_min.pdf(bins, *fullparams)
plt.plot(bins, pdf, color=nrecolors['blue'][0])

# thing,stuff = 
output = plt.hist(lowtidat, 
            bins = bins, 
            facecolor=nrecolors['blue'][0], 
            edgecolor='k',
            alpha=0.3,
            normed=True)
fullparams<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17024479125406006, 'fraction_numerical': 0.022419393171195436, 'mean_word_length': 3.783630162940508, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '14302', 'license': 'Apache-2.0', 'n_tokens_mistral': 4913, 'n_tokens_neox': 4671, 'n_words': 599, 'path': 'notebooks/.ipynb_checkpoints/Low_turb_conditions-checkpoint.ipynb', 'repo_name': 'NREL/MetMastVis', 'size': '12623'}