예제 #1
0
def compare_with_windprof(SYNTH,**kwargs):

    loc=kwargs['location']
    U = SYNTH.U
    V = SYNTH.V
    LAT=SYNTH.LAT
    LON=SYNTH.LON
    Z=SYNTH.Z
    st=SYNTH.start
    en=SYNTH.end

    ''' synthesis '''
    # lat_idx=cm.find_index_recursively(array=LAT,value=loc['lat'],decimals=2)
    # lon_idx=cm.find_index_recursively(array=LON,value=loc['lon'],decimals=2)

    f=interp1d(LAT,range(len(LAT)))
    latx=int(np.ceil(f(loc['lat'])))
    f=interp1d(LON,range(len(LON)))
    lonx=int(np.ceil(f(loc['lon'])))

    uprof = U[lonx,latx,:]
    vprof = V[lonx,latx,:]
    sprofspd=np.sqrt(uprof**2+vprof**2)
    sprofdir=270. - ( np.arctan2(vprof,uprof) * 180./np.pi )

    ''' wind profiler '''
    case=kwargs['case']
    wspd,wdir,time,hgt = wp.make_arrays(case= str(case),
                                        resolution='coarse',
                                        surface=False)
    idx = time.index(datetime.datetime(st.year, st.month, st.day, st.hour, 0))
    wprofspd = wspd[:,idx]
    wprofdir = wdir[:,idx]

    ''' profile '''
    with sns.axes_style("darkgrid"):
        fig,ax=plt.subplots(1,2, figsize=(9,9), sharey=True)
        
        n=0
        hl1=ax[n].plot(sprofspd,Z,'-o',label='P3-SYNTH (250 m)')
        hl2=ax[n].plot(wprofspd,hgt,'-o',label='WPROF-COARSE (100 m)')
        ax[n].set_xlabel('wind speed [m s-1]')
        ax[n].set_ylabel('height AGL [km]')
        lns = hl1 + hl2
        labs = [l.get_label() for l in lns]
        ax[n].legend(lns, labs, loc=0)

        n=1
        ax[n].plot(sprofdir,Z,'-o',label='P3-SYNTH')
        ax[n].plot(wprofdir,hgt,'-o',label='WPROF')
        ax[n].set_xlabel('wind direction [deg]')
        ax[n].invert_xaxis()
        t1='Comparison between P3-synthesis and ' +loc['name']+' wind profiler'
        t2='\nDate: ' + st.strftime('%Y-%m-%d')
        t3='\nSynthesis time: ' + st.strftime('%H:%M') + ' to ' + en.strftime('%H:%M UTC') 
        t4='\nWind profiler time: ' + time[idx].strftime('%H:%M') + ' to ' + time[idx+1].strftime('%H:%M UTC') 
        fig.suptitle(t1+t2+t3+t4)
        plt.ylim([0,5])
        plt.draw()
예제 #2
0
def get_windprof(case, gapflow_time=None,
                 top_hgt_km=None,
                 homedir=None):

    " return layer average values; layer is defined \
    by top_hgt_km"

    import Windprof2 as wp
    from scipy.interpolate import interp1d
    from datetime import timedelta

    out = wp.make_arrays(resolution='coarse',
                         surface=False, case=str(case), period=False,
                         homedir=homedir)
    wspd, wdir, time, hgt = out
    time = np.array(time)

    ' match surface obs timestamp'
    time2 = time - timedelta(minutes=5)

    ' get corresponding target time index '
    index_dict = dict((value, idx) for idx, value in enumerate(time2))
    target_idx = [index_dict[x] for x in gapflow_time]

    ' wp time equivalent to gapflow time '
    target_time = time2[target_idx] + timedelta(minutes=5)

    wspd_target = []
    wdir_target = []

    for tt in target_time:
        idx = np.where(time == tt)[0]
        # ws = np.squeeze(wspd[:, idx])
        # wd = np.squeeze(wdir[:, idx])
        # ' interpolate at target altitude '
        # fws = interp1d(hgt, ws)
        # fwd = interp1d(hgt, wd)
        # new_ws = fws(target_hgt_km)
        # new_wd = fwd(target_hgt_km)

        hidx = np.where(hgt <= top_hgt_km)[0]
        ws = np.squeeze(wspd[hidx, idx])
        wd = np.squeeze(wdir[hidx, idx])
        u = -ws*np.sin(np.radians(wd))
        v = -ws*np.cos(np.radians(wd))
        ubar = np.nanmean(u)
        vbar = np.nanmean(v)
        new_ws = np.sqrt(ubar**2+vbar**2)
        new_wd = 270-np.arctan2(vbar,ubar)*180/np.pi
        if new_wd > 360:
            new_wd -= 360

        wspd_target.append(new_ws)
        wdir_target.append(new_wd)

    return np.array(wspd_target), np.array(wdir_target)
import Windprof2 as wp
import matplotlib.pyplot as plt
# import numpy as np


fig, axes = plt.subplots(3, 3, figsize=(11, 9), sharex=True, sharey=True)
axes = axes.flatten()
wd_lim_surf = 125
wd_lim_aloft = 170
mAGL, color = [120, 'navy']
# mAGL,color=[500,'green']
for c, ax in zip(range(12, 13), axes):

    wspd, wdir, time, hgt = wp.make_arrays(
        resolution='coarse', surface=True, case=str(c))
    wp.plot_scatter2(ax=ax, wdir=wdir, hgt=hgt, time=time, mAGL=mAGL,
                     lim_surf=wd_lim_surf, lim_aloft=wd_lim_aloft, color=color)
    ax.text(0., 0.05, 'Case '+str(c).zfill(2), transform=ax.transAxes)


axes[0].text(
    0, 1.05, 'Altitude: '+str(mAGL) + 'm AGL', transform=axes[0].transAxes)
axes[6].set_xlabel('wind direction surface')
axes[6].text(wd_lim_surf, -20, str(wd_lim_surf), ha='center')
axes[6].text(0, -20, '0', ha='center')
axes[0].set_ylabel('wind direction aloft')
axes[0].text(380, wd_lim_aloft, str(wd_lim_aloft), va='center', rotation=90)
axes[0].text(380, 0, '0', va='center', rotation=90)
plt.subplots_adjust(bottom=0.05, top=0.95, hspace=0.05, wspace=0.05)
fig.delaxes(axes[7])
fig.delaxes(axes[8])
예제 #4
0
                        transform=ax.transAxes)

    return gapflow


def get_windprof(case, gapflow_time=None, top_hgt_km=None, homedir=None):

    " return layer average values; layer is defined \
    by top_hgt_km"

    import Windprof2 as wp
    from scipy.interpolate import interp1d
    from datetime import timedelta

    out = wp.make_arrays(resolution='coarse',
                         surface=False,
                         case=str(case),
                         period=False,
                         homedir=homedir)
    wspd, wdir, time, hgt = out
    time = np.array(time)

    ' match surface obs timestamp'
    time2 = time - timedelta(minutes=5)

    ' get corresponding target time index '
    index_dict = dict((value, idx) for idx, value in enumerate(time2))
    target_idx = [index_dict[x] for x in gapflow_time]

    ' wp time equivalent to gapflow time '
    target_time = time2[target_idx] + timedelta(minutes=5)
예제 #5
0
import Windprof2 as wp
import matplotlib.pyplot as plt
# import numpy as np

fig, axes = plt.subplots(3, 3, figsize=(11, 9), sharex=True, sharey=True)
axes = axes.flatten()
wd_lim_surf = 125
wd_lim_aloft = 170
mAGL, color = [120, 'navy']
# mAGL,color=[500,'green']
for c, ax in zip(range(12, 13), axes):

    wspd, wdir, time, hgt = wp.make_arrays(resolution='coarse',
                                           surface=True,
                                           case=str(c))
    wp.plot_scatter2(ax=ax,
                     wdir=wdir,
                     hgt=hgt,
                     time=time,
                     mAGL=mAGL,
                     lim_surf=wd_lim_surf,
                     lim_aloft=wd_lim_aloft,
                     color=color)
    ax.text(0., 0.05, 'Case ' + str(c).zfill(2), transform=ax.transAxes)

axes[0].text(0,
             1.05,
             'Altitude: ' + str(mAGL) + 'm AGL',
             transform=axes[0].transAxes)
axes[6].set_xlabel('wind direction surface')
axes[6].text(wd_lim_surf, -20, str(wd_lim_surf), ha='center')
# 										surface=True,
# 										case=str(case),
# 										period=False)

# wp.plot_scatter(wdir=wdir,hgt=hgt,title='Case '+str(case).zfill(2))
# plt.show(block=False)

fig, axes = plt.subplots(5,3, figsize=(11,15), sharex=True, sharey=True)
axes=axes.flatten()
vline=130
hline=170
mAGL,color=[120,'navy']
# mAGL,color=[500,'green']
for c, ax in zip(range(1,15), axes):
	
	wspd,wdir,time,hgt = wp.make_arrays(resolution='fine', surface=True,
										case=str(c),period=False)
	wp.plot_scatter2(ax=ax,wdir=wdir,hgt=hgt,mAGL=mAGL,vline=vline,hline=hline,color=color)
	ax.text(0.,0.05,'Case '+str(c).zfill(2),transform=ax.transAxes)



axes[0].text(0,1.05,'Altitude: '+str(mAGL) +'m AGL',transform=axes[0].transAxes)
axes[13].set_xlabel('wind direction surface')
axes[13].text(vline,-20,str(vline),ha='center')
axes[13].text(0,-20,'0',ha='center')
axes[6].set_ylabel('wind direction aloft')
axes[6].text(380,hline,str(hline),va='center',rotation=90)
axes[6].text(380,0,'0',va='center', rotation=90)
plt.subplots_adjust(bottom=0.05,top=0.95,hspace=0.05,wspace=0.05)
fig.delaxes(axes[-1])
plt.show(block=False)