Example #1
0
def tta_precip():

    import Windprof2 as wp

    print "BBY-tta    | BBY-notta | CZD-tta   | CZD-notta | FRS-tta | FRS-notta "
    o = "{:11.1f} {:11.1f} {:11.1f} {:11.1f} {:11.1f} {:11.1f}"
    for case in range(8, 15):
        bby, czd, frs, _ = get_data(str(case))
        tta_times = wp.get_tta_times(case=str(case), continuous=True)
        if len(tta_times) > 0:
            tta_idx_bby = (bby.index >= tta_times[0]) & (bby.index <= tta_times[-1])
            tta_idx_czd = (czd.index >= tta_times[0]) & (czd.index <= tta_times[-1])
            tta_idx_frs = (frs.index >= tta_times[0]) & (frs.index <= tta_times[-1])
            bby_tta = bby.precip[tta_idx_bby].sum()
            bby_notta = bby.precip[~tta_idx_bby].sum()
            czd_tta = czd.precip[tta_idx_czd].sum()
            czd_notta = czd.precip[~tta_idx_czd].sum()
            frs_tta = frs.precip[tta_idx_frs].sum()
            frs_notta = frs.precip[~tta_idx_frs].sum()
        else:
            bby_tta = -999
            bby_notta = bby.precip.sum()
            czd_tta = -999
            czd_notta = czd.precip.sum()
            frs_tta = -999
            frs_notta = frs.precip.sum()
        print o.format(bby_tta, bby_notta, czd_tta, czd_notta, frs_tta, frs_notta)
Example #2
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()
Example #3
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)
for tta, time in zip(tta_range, times):
    drange = pd.date_range(start=wp_st, end=wp_en, freq='1H')
    time['tta'][0] = np.where(drange == tta[0])[0]
    time['tta'][1] = np.where(drange == tta[1])[0]

params = [
    'WD$<140$, nh$\geq1\,(2,4)$',
    'WD$<150$, nh$\geq1$',
    'WD$<160$, nh$\geq1$',
    'WD$<150$, nh$\geq2$',
]

for c, ax in zip(case, axes):

    wspd, wdir, time, hgt = wp.make_arrays2(
        resolution=res,
        add_surface=True,
        case=str(c),
    )
    cbar_inv = False

    wspdMerid = -wspd * cosd(wdir)

    if c == 13:
        foo = wspdMerid

    ax, hcbar, im = wp.plot_time_height(ax=ax,
                                        wspd=wspdMerid,
                                        time=time,
                                        height=hgt,
                                        spd_range=[0, 30],
                                        spd_delta=2,
Example #5
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)
Example #6
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')
Example #7
0
# 										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)
}

labend = {
    8: '15\n00',
    9: '24\n00',
    10: '17\n00',
    11: '11\n00',
    12: '04\n00',
    13: '19\n00',
    14: '27\n00'
}

for c, ax in zip(case, axes):

    wspd, wdir, time, hgt = wp.make_arrays2(resolution=res,
                                            surface=True,
                                            case=str(c),
                                            homedir=homedir)

    if c == 14:
        cbar = ax
    else:
        cbar = False

    wspdMerid = -wspd * cosd(wdir)

    ax, hcbar = wp.plot_time_height(ax=ax,
                                    wspd=wspdMerid,
                                    time=time,
                                    height=hgt,
                                    spd_range=[0, 30],
topdf = False

case = range(13, 14)
res = 'coarse'
o = 'case{}_total_wind_{}.pdf'
t = 'Total wind speed - {} resolution - Case {} - Date: {}'

for c in case:

    ''' creates plot with seaborn style '''
    with sns.axes_style("white"):
        scale=0.8
        f, ax1 = plt.subplots(figsize=(11*scale, 8.5*scale))

    wspd, wdir, time, hgt = wp.make_arrays2(resolution=res,
                                           surface=True,
                                           case=str(c),
                                           homedir=homedir)

    wspdMerid=-wspd*cosd(wdir);

    wp.plot_colored_staff(ax=ax1, wspd=wspdMerid, wdir=wdir, time=time,
                          height=hgt, spd_range=[0, 36], spd_delta=2,
                          vdensity=0, hdensity=0, cmap='nipy_spectral',
                          title=t.format(res.title(), str(c).zfill(2),
                          time[1].strftime('%Y-%b')),cbar=ax1)

    # wp.add_soundingTH('bvf_moist', str(c), ax=ax1, wptime=time,
                      # wphgt=hgt, sigma=1, homedir=homedir)

    if topdf:
        savename = o.format(str(c).zfill(2), res)
    gs0 = gridspec.GridSpec(2, 1, hspace=0.15)

    axes = range(2)
    axes[0] = plt.subplot(gs0[0], gid='(a) 23-24Jan01')
    axes[1] = plt.subplot(gs0[1], gid='(b) 17Feb01')

labend = {
    3: '25\n00',
    7: '18\n08',
}

for c, ax in zip(case, axes):

    out = wp.make_arrays2(resolution=res,
                          add_surface=True,
                          case=str(c),
                          interp_hgts=np.linspace(0.160, 3.74, 40))

    wspd, wdir, time, hgt = out

    if ax.get_gid() == '(a) 23-24Jan01':
        cbar = ax
        cbarinvi = False
    else:
        cbar = True
        cbarinvi = True
    ''' wind speed target '''
    ucomp = -wspd * sind(wdir)
    vcomp = -wspd * cosd(wdir)
    x = ucomp * sind(230)
        time['tta'][1] = np.where(drange == tta[1])[0]

''' last xlabel '''
labend = {8: '15\n00',
          9: '24\n00',
          10: '17\n00',
          11: '10\n00',
          12: '03\n00',
          13: '19\n00',
          14: '26\n00'
          }

for c, ax in zip(case, axes):

    wspd, wdir, time, hgt = wp.make_arrays2(resolution=res,
                                            add_surface=True,
                                            case=str(c),
                                            )
    #    print [time[0],time[-1]]
    if c == 14:
        cbar_inv = False
    else:
        cbar_inv = True

    wspdMerid = -wspd * cosd(wdir)

    if c == 13:
        foo = wspdMerid


    ax, hcbar, img = wp.plot_time_height(ax=ax,
        time['tta'][1] = np.where(drange == tta[1])[0]

''' last xlabel '''
labend = {8: '15\n00',
          9: '24\n00',
          10: '17\n00',
          11: '10\n00',
          12: '03\n00',
          13: '19\n00',
          14: '26\n00'
          }

for c, ax in zip(case, axes):

    wspd, wdir, time, hgt = wp.make_arrays2(resolution=res,
                                            add_surface=True,
                                            case=str(c),
                                            )
    #    print [time[0],time[-1]]
    if c == 14:
        cbar_inv = False
    else:
        cbar_inv = True

    wspdMerid = -wspd * cosd(wdir);

    if c == 13:
        foo = wspdMerid

    ax, hcbar = wp.plot_time_height(ax=ax,
                                    wspd=wspdMerid,
                                    time=time,
    drange = pd.date_range(start=wp_st,end=wp_en,freq='1H')
    time['tta'][0] = np.where(drange == tta[0])[0]
    time['tta'][1] = np.where(drange == tta[1])[0]

params = [
            '$\overline{WDIR}_{500}<140$, nh$\geq1\,(2,4)$',
            '$\overline{WDIR}_{500}<150$, nh$\geq1$',
            '$\overline{WDIR}_{500}<160$, nh$\geq1$',
            '$\overline{WDIR}_{500}<150$, nh$\geq2$',
         ]


for c, ax in zip(case, axes):

    wspd, wdir, time, hgt = wp.make_arrays2(resolution=res,
                                            add_surface=True,
                                            case=str(c),
                                            )
    cbar_inv = False

    wspdMerid = -wspd*cosd(wdir)

    if c == 13:
        foo = wspdMerid

    ax, hcbar, im = wp.plot_time_height(ax=ax,
                                        wspd=wspdMerid,
                                        time=time,
                                        height=hgt,
                                        spd_range=[0, 30],
                                        spd_delta=2,
                                        cmap='jet',
Example #14
0
topdf = False

case = range(13, 14)
res = 'coarse'
o = 'case{}_total_wind_{}.pdf'
t = 'Total wind speed - {} resolution - Case {} - Date: {}'

for c in case:
    ''' creates plot with seaborn style '''
    with sns.axes_style("white"):
        scale = 0.8
        f, ax1 = plt.subplots(figsize=(11 * scale, 8.5 * scale))

    wspd, wdir, time, hgt = wp.make_arrays2(resolution=res,
                                            surface=True,
                                            case=str(c),
                                            homedir=homedir)

    wspdMerid = -wspd * cosd(wdir)

    wp.plot_colored_staff(ax=ax1,
                          wspd=wspdMerid,
                          wdir=wdir,
                          time=time,
                          height=hgt,
                          spd_range=[0, 36],
                          spd_delta=2,
                          vdensity=0,
                          hdensity=0,
                          cmap='nipy_spectral',
    
    axes = range(2)    
    axes[0] = plt.subplot(gs0[0],gid='(a) 23-24Jan01')
    axes[1] = plt.subplot(gs0[1],gid='(b) 17Feb01')


labend={3:'25\n00',
        7: '18\n08',
       }



for c, ax in zip(case, axes):

    out = wp.make_arrays2(resolution=res,
                          add_surface=True,
                          case=str(c),
                          interp_hgts=np.linspace(0.160, 3.74, 40))

    wspd, wdir, time, hgt = out


    if ax.get_gid() == '(a) 23-24Jan01':
        cbar = ax
        cbarinvi=False
    else:
        cbar = True
        cbarinvi=True

    ''' wind speed target '''
    ucomp = -wspd*sind(wdir)
    vcomp = -wspd*cosd(wdir)
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])
       14:{'tta':[None,None], 'xpol':[0.58,0.41]}
       }

labend={8:'15\n00',
       9: '24\n00',
       10:'17\n00',
       11:'11\n00',
       12:'04\n00',
       13:'19\n00',
       14:'27\n00'
       }

for c, ax in zip(case, axes):

    wspd, wdir, time, hgt = wp.make_arrays2(resolution=res,
                                            surface=True,
                                            case=str(c),
                                            homedir=homedir)

    if c == 14:
        cbar = ax
    else:
        cbar = False

    wspdMerid=-wspd*cosd(wdir);

    ax, hcbar = wp.plot_time_height(ax=ax, 
                                      wspd=wspdMerid,
                                      time=time, height=hgt,
                                      spd_range=[0, 30], spd_delta=4,
                                      cmap='nipy_spectral',
                                      cbar=cbar
# 										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)