コード例 #1
0
years = np.array(years)
slp_full = np.array(slp_full)
###########################
# Get the necessary indices
###########################
[ind1a] = np.where(years == analysis_years[0])
[ind1b] = np.where(years == analysis_years[1])
[ind1c] = np.where(years == plot_year[0])

ind1a = int(ind1a)
ind1b = int(ind1b)
ind1c = int(ind1c)

nyears, nmonths = np.shape(slp_full)

slp_full = um.filter_numeric_nans(slp_full, 0, float('NaN'), 'low')
slp_yearin = slp_full[ind1c, :]

###########################
# Calculate the monthly mean
###########################
slp_monthly_mean = np.nanmean(slp_full[ind1a:ind1b + 1, :], 0)

print(slp_monthly_mean)
print(nyears, nmonths)

######################
# mass transport calculations
######################
dslp_full = np.empty([nyears, nmonths])
dslp_yearin = np.empty(nmonths)
コード例 #2
0
        cmap_opt = plt.cm.RdBu_r

        figname = "wrf_cross_section_ttendf"

        if dlat_dlon[0] == 0:
            figname = "wrf_cross_section_ew_tdynamics"
        if dlat_dlon[1] == 0:
            figname = "wrf_cross_section_ns_tdynamics"
elif plot_option == 14:
    u = nc.variables['U'][timeindex, :, :, :].squeeze()
    v = nc.variables['V'][timeindex, :, :, :].squeeze()
    ghgt = nc.variables['HEIGHT'][timeindex, :, :, :].squeeze()
    ghgt = um.nan2zero(ghgt)

    ug, vg = wm.geostrophic_cartesian(u, v, ghgt, lats, dy, dx)
    ug = um.filter_numeric_nans(ug, 200, float('NaN'), 'high')
    ug = um.filter_numeric_nans(ug, -200, float('NaN'), 'low')
    vg = um.filter_numeric_nans(vg, 200, float('NaN'), 'high')
    vg = um.filter_numeric_nans(vg, -200, float('NaN'), 'low')

    thickness = np.zeros_like(ghgt).astype('f')
    thickness[1:-1, :, :] = (ghgt[2:, :, :] - ghgt[:-2, :, :]) / 2
    thickness[0, :, :] = (ghgt[1, :, :] - ghgt[0, :, :])
    thickness[-1, :, :] = (ghgt[-1, :, :] - ghgt[-2, :, :])

    zeta_a = np.zeros_like(ghgt).astype('f')
    [iz, iy, ix] = np.shape(zeta_a)
    for ii in range(iz):
        zeta_a[ii, :, :] = wm.vertical_vorticity_cartesian(
            ug[ii, :, :].squeeze(), vg[ii, :, :].squeeze(), lats, dx, dy, 1)
コード例 #3
0
       #cbar_max_trth = 335
       cbar_max_trth = 380
       #cbar_max_trth = 400
       
       
       cint_trth = 1
       cflevs_trth =  np.arange(cbar_min_trth, cbar_max_trth, cint_trth)
       #cflevs_trth_cntrs = cflevs_trth[0:12]
       cflevs_trth_cntrs = cflevs_trth
       cflevs_trth_ticks = np.arange(cbar_min_trth,cbar_max_trth,4*cint_trth)
       cmap_opt = plt.cm.jet
       #cmap_opt = plt.cm.Blues_r

       trth = ndimage.gaussian_filter(trth,0.75)
       
       trth = um.filter_numeric_nans(trth,trth_thresh+cint_trth,trth_thresh+cint_trth,'high')
         
       
       plotvar = trth
       mstats(plotvar)
          	    
       #plotvar, lons = um.addcyclic(trth[tt,:,:].squeeze(), lonin)	    	    	    	    
       #plotvar = ndimage.gaussian_filter(plotvar,0.75)   
       
       titletext1 = 'Tropopause potential temperature gradient %s at %s UTC' % (dt.strftime('%d %b %Y'), dt.strftime('%H00'))        
   if plot_field == 'trpr' :
 
       cbarlabel = 'Pressure (hPa)'    
       
       cint_trth = 20
       cbar_max_trth = 800.
コード例 #4
0
# Backward Euler
z = 1.0/((1-X)**(2.0) + (Y)**(2.0) )


# In[5]:

# Set global figure properties
golden = (pylab.sqrt(5)+1.)/2.
figprops = dict(figsize=(8., 16./golden),dpi=128)
adjustprops = dict(left=0.15, bottom=0.1, right=0.90, top = 0.93, wspace=0.2, hspace=0.2)

cint = 0.1
clevs = np.arange(0.0,2.0+(cint/2),cint)
cmap_opt = plt.cm.RdBu_r

z = um.filter_numeric_nans(z,np.max(clevs),np.max(clevs),'high')


# In[6]:

fig = plt.figure(**figprops)   # New figure   
ax1 = fig.add_axes([0.1,0.1,0.8,0.8])

CS1 = plt.contourf(X,Y,z,cmap=cmap_opt,levels=clevs)
cbar = plt.colorbar(CS1, shrink=0.95, orientation='horizontal',extend='both',pad=0.10)


CS2 = ax1.contour(X,Y,z,levels=clevs, colors='k',extend='both',zorder=1,linewidths=2)
plt.clabel(CS2, inline=1, fontsize=10)

CS3 = plt.contour(X,Y,z,(1.0,),colors='r',extend='both',zorder=1,linewidths=4)
コード例 #5
0
def find_amplitude(datain,dataininds,thresh,min_or_max):
    """

   Finds the amplitude of datain

   Input:    

       datain - 2D data array 
       dataininds - masked array of indices denoting section of datain array to search for minimum or maximum
       thresh - threshold min/max of datain
       min_or_max - 'min' to find the amplitude from a minimum and 'max' to find the amplitude from a maximum

    Steven Cavallo
    February 2013
    University of Oklahoma
    
    """

   

    import utilities_modules as um
    import numpy as np
    datain = um.filter_numeric_nans(datain,thresh,thresh,'high')
            
    datasave = datain
    
    if min_or_max == 'min':
        mininds=np.where(datain==np.min(datain[dataininds]))   
    else:
        mininds=np.where(datain==np.max(datain[dataininds]))        
    mininds2 = np.ma.getdata(mininds)    
    
    minval = datasave[mininds2[0],mininds2[1]]       
       
    #datain = ndimage.gaussian_filter(datain,0.75)
    datain = ndimage.gaussian_filter(datain,5.0)
    
    [iy,ix] = np.shape(datain)
    minsearch = np.min(mininds2)       
    amps = np.zeros(8)
    for ii in range(0,8):
        for jj in range(minsearch-1,0,-1):
        # Search up
            if ii==0:
                try:
                    if datain[jj-1,mininds2[1]] < datain[jj,mininds2[1]]:           
                        amps[ii] = datasave[jj,mininds2[1]] - minval
                        break
                except:
                    continue
                    
        # Search NE
            if ii==1:
                try:         
                    if datain[jj-1,jj+1] < datain[jj,jj]:           
                        amps[ii] = datasave[jj,jj] - minval
                        break   
                except:
                    continue

        # Search right
            if ii==2:
                try:         
                    if datain[mininds2[0],jj+1] < datain[mininds2[0],jj]:           
                        amps[ii] = datasave[mininds2[0],jj] - minval
                        break                 
                except:
                    continue

       # Search SE
            if ii==3:
                try:         
                    if datain[jj+1,jj+1] < datain[jj,jj]:           
                        amps[ii] = datasave[jj,jj] - minval
                        break                
                except:
                    continue
         
       # Search down
            if ii==4:
                try:         
                    if datain[jj+1,mininds2[1]] < datain[jj,mininds2[1]]:           
                        amps[ii] = datasave[jj,mininds2[1]] - minval
                        break         
                except:
                    continue

       # Search SW
            if ii==5:
                try:         
                    if datain[jj+1,jj-1] < datain[jj,jj]:           
                        amps[ii] = datasave[jj,jj] - minval
                        break             
                except:
                    continue
         
       # Search left
            if ii==6:
                try:         
                    if datain[mininds2[0],jj-1] < datain[mininds2[0],jj]:           
                        amps[ii] = datasave[mininds2[0],jj] - minval
                        break         
                except:
                    continue

       # Search NW
            if ii==7:
                try:                 
                    if datain[jj-1,jj-1] < datain[jj,jj]:           
                        amps[ii] = datasave[jj,jj] - minval
                        break             
                except:
                    continue


    try:
       ampinds = np.where((amps>=1) & (amps<=50))
       #ampout = np.min(amps[ampinds])
       
       ampsort = np.sort(amps[ampinds])
       ampout = np.median(ampsort[0:2])
    except:
       ampout = float('NaN')

    
    #ampout = np.median(amps)
    
    return ampout
コード例 #6
0
        latarr = np.zeros_like(trth).astype('f')
        lonarr = np.zeros_like(trth).astype('f')
        for ii in range(0, len(lons)):
            for jj in range(0, len(lats)):
                latarr[jj, ii] = lats[jj]
                lonarr[jj, ii] = lons[ii]

        cint_bg = 1
        cbar_min_bg = 270
        cbar_max_bg = 380
        cmap_opt_bg = plt.cm.jet
        cflevs_bg = np.arange(cbar_min_bg, cbar_max_bg + (cint_bg / 2),
                              cint_bg)

    plotvar_bg = um.filter_numeric_nans(plotvar_bg,
                                        cbar_max_bg - (cint_bg / 2),
                                        cbar_max_bg, 'high')
    plotvar_bg = um.filter_numeric_nans(plotvar_bg, cbar_min_bg, cbar_min_bg,
                                        'low')

    golden = (np.sqrt(5) + 1.) / 2.
    #m = Basemap(projection='npstere',boundinglat=30,lon_0=270.,resolution='l')

    # Get the cross section points.  This is a function in utilities_modules.

    if cross_method == 1:
        m = Basemap(projection='npstere',
                    boundinglat=30,
                    lon_0=270.,
                    resolution='l')
コード例 #7
0
def eliassen_palm_flux_sphere(geop,theta,lats,lons,levs):
    """

   Computes the 3-D Eliassen-Palm flux vectors and divergence on a 
   latitude/longitude grid with any vertical coordinate 
   
   Computation is Equation 5.7 from:
   R. A. Plumb, On the Three-dimensional Propagation of Stationary Waves, J. Atmos. Sci., No. 3, 42 (1985).

   Input:    
       geop:      3D geopotential (m^2 s-2)
       theta:     3D potential temperature (K)
       lats,lons: 1D latitude and longitude vectors
       levs:      1D pressure vector (Pa)

   Output:      
      Fx, Fy, Fz: Eliassen-Palm flux x, y, z vector components
      divF: Eliassen-Palm flux divergence
   

   Steven Cavallo
   March 2014
   University of Oklahoma
    
    """
    import utilities_modules as um
    
    iz, iy, ix = geop.shape
    
    # First need to filter out numeric nans    
    geop = um.filter_numeric_nans(geop,0,0,'low')    
    theta = um.filter_numeric_nans(theta,200,0,'low')
    theta = um.filter_numeric_nans(theta,10000,0,'high')

    theta_anom, theta_anom_std = spatial_anomaly(theta,1) 
    geop_anom , geop_anom_std = spatial_anomaly(geop,1)          
        
    latarr = np.zeros_like(geop).astype('f')    
    farr = np.zeros_like(geop).astype('f')    
    for kk in range(0,iz):
        for jj in range(0,iy):            
            latarr[kk,jj,:] = lats[jj]
            farr[kk,jj,:] = 2*omeg_e*np.sin(lats[jj]*(np.pi/180))
          
    psi = geop / farr     
    psi_anom, psi_anom_std = spatial_anomaly(psi,1) 
        
    pres = np.zeros_like(theta_anom).astype('f')   
    for kk in range(0,iz):      
        pres[kk,:,:] = levs[kk]
    
    coef = pres*np.cos(latarr*(np.pi/180))    
    arg1 = coef/( 2*np.pi*(R_earth**2)*np.cos(latarr*(np.pi/180))*np.cos(latarr*(np.pi/180)) )
    arg2 = coef/( 2*np.pi*(R_earth**2)*np.cos(latarr*(np.pi/180)) )
    arg3 = coef*(2*(omeg_e**2)*np.sin(latarr*(np.pi/180))*np.sin(latarr*(np.pi/180)))
   
    dthdz, yy, xx = gradient_cendiff_latlon(theta, geop/g, lats, lons) 
    xx, dthdy, dthdx = gradient_cendiff_latlon(theta_anom, geop/g, lats, lons)        
    dpsidz, dpsidy, dpsidx = gradient_cendiff_latlon(psi_anom, geop/g, lats, lons)          
    d2psidxdz, d2psidxdy, d2psidx2 = gradient_cendiff_latlon(dpsidx, geop/g, lats, lons)     
    aaa, d2psidxdz, ccc = gradient_cendiff_latlon(dpsidz, geop/g, lats, lons) 

    N2 = (g/theta)*(dthdz)
    arg4 = arg3/(N2*R_earth*np.cos(latarr*(np.pi/180)))        
    
    Fx = arg1*( dpsidx**2      - (psi_anom*d2psidx2))
    Fy = arg2*((dpsidy*dpsidx) - (psi_anom*d2psidxdy))
    Fz = arg4*((dpsidx*dpsidz) - (psi_anom*d2psidxdz))          
    
    Fx_z, Fx_y, Fx_x = gradient_sphere(Fx, geop/g, lats, lons)    
    Fy_z, Fy_y, Fy_x = gradient_sphere(Fy, geop/g, lats, lons)    
    Fz_z, Fz_y, Fz_x = gradient_sphere(Fz, geop/g, lats, lons)    
       
    divF = Fx_x + Fy_y + Fz_z
    
    return Fx, Fy, Fz, divF
コード例 #8
0
        cbar_min = -300
        cbar_max = 300+(cint/2)            
        
	cbar_labels = 'm K s-1'
	titlestring = "Heat flux " + date_string
	
	cmap_opt = plt.cm.RdBu 

epvin = nc.variables['PV'][timeindex,:,:,:].squeeze()
epv_cross = epvin[:,xx,yy]       

thetain = nc.variables['THETA'][timeindex,:,:,:].squeeze()
theta_cross = thetain[:,xx,yy]
nc.close    

plot_cross = um.filter_numeric_nans(plot_cross,cbar_max-(cint/2),cbar_max,'high')
plot_cross = um.filter_numeric_nans(plot_cross,cbar_min,cbar_min,'low')

x, y = m(lons, lats)
clevs1 = np.arange(240, 360, 2)
#clevs2 = np.arange(250, 340, 2)
clevs2 = np.arange(cbar_min,cbar_max+(cint/2),cint)

clevs2_ticks = clevs2[::5]
slplevs = np.arange(948,1000,4)
slp_ticks = slplevs[::2]

golden = (np.sqrt(5)+1.)/2.

# Plot plan view map with solid white line indicating the location of the cross section
fig = plt.figure(figsize=(8., 16./golden), dpi=128)   # New figure
コード例 #9
0
        if ((plot_tpvs_at_specific_time == 'True')
                and (plot_tpvs_within_timerange == 'False')):
            plotTrack1 = False
            #plotTrack = True
            if (int(datestrinit <= date_firstrecord)
                    and (int(datestrfin >= date_firstrecord))):
                plotTrack1 = True
                print datestrinit, datestrfin
        else:
            #plotTrack1 = True
            aa = 1

        latnow = lat[sind:eind]
        lonnow = lon[sind:eind]
        lonnow = um.filter_numeric_nans(lonnow, 361., float('NaN'), 'high')
        lonnow = um.filter_numeric_nans(lonnow, -1., float('NaN'), 'low')
        latnow = um.filter_numeric_nans(latnow, 91., float('NaN'), 'high')
        latnow = um.filter_numeric_nans(latnow, -91., float('NaN'), 'low')
        x, y = m(lonnow, latnow)

        if plot_cyclones_inbox == 'True':
            plotTrack2 = False
            for ii in xrange(0, len(latnow)):
                if lonnow[ii] < 0:
                    lonnow[ii] = lonnow[ii] + 360.

                distance = abs(tpvmod.rEarth * tpvmod.distance_on_unit_sphere(
                    box_center_latlon[0], box_center_latlon[1], latnow[ii],
                    lonnow[ii]))
                distance = distance / 1000.
コード例 #10
0

	latarr = np.zeros_like(trth).astype('f')
	lonarr = np.zeros_like(trth).astype('f')
	for ii in range(0,len(lons)):
	   for jj in range(0,len(lats)):
               latarr[jj,ii] = lats[jj]
               lonarr[jj,ii] = lons[ii]

	cint_bg = 1
	cbar_min_bg = 270
	cbar_max_bg = 380
	cmap_opt_bg = plt.cm.jet 
	cflevs_bg = np.arange(cbar_min_bg,cbar_max_bg+(cint_bg/2),cint_bg)       

    plotvar_bg = um.filter_numeric_nans(plotvar_bg,cbar_max_bg-(cint_bg/2),cbar_max_bg,'high')
    plotvar_bg = um.filter_numeric_nans(plotvar_bg,cbar_min_bg,cbar_min_bg,'low')


    golden = (np.sqrt(5)+1.)/2.
    #m = Basemap(projection='npstere',boundinglat=30,lon_0=270.,resolution='l')

    # Get the cross section points.  This is a function in utilities_modules.

    if cross_method == 1:
	m = Basemap(projection='npstere',boundinglat=30,lon_0=270.,resolution='l')

	
	xx, yy = um.xsection_inds(lon_range[0], lat_range[0], lon_range[1], lat_range[1], lonarr, latarr, m)
	#x, y = m(lonarr, latarr)
	# Plot plan view map with solid white line indicating the location of the cross section
コード例 #11
0
        #cbar_max_trth = 335
        cbar_max_trth = 380
        #cbar_max_trth = 400

        cint_trth = 1
        cflevs_trth = np.arange(cbar_min_trth, cbar_max_trth, cint_trth)
        #cflevs_trth_cntrs = cflevs_trth[0:12]
        cflevs_trth_cntrs = cflevs_trth
        cflevs_trth_ticks = np.arange(cbar_min_trth, cbar_max_trth,
                                      4 * cint_trth)
        cmap_opt = plt.cm.jet
        #cmap_opt = plt.cm.Blues_r

        trth = ndimage.gaussian_filter(trth, 0.75)

        trth = um.filter_numeric_nans(trth, trth_thresh + cint_trth,
                                      trth_thresh + cint_trth, 'high')

        plotvar = trth
        mstats(plotvar)

        #plotvar, lons = um.addcyclic(trth[tt,:,:].squeeze(), lonin)
        #plotvar = ndimage.gaussian_filter(plotvar,0.75)

        titletext1 = 'Tropopause potential temperature gradient %s at %s UTC' % (
            dt.strftime('%d %b %Y'), dt.strftime('%H00'))
    if plot_field == 'trpr':

        cbarlabel = 'Pressure (hPa)'

        cint_trth = 20
        cbar_max_trth = 800.