def dels_tropfn(p_out):
     T_BLtop = findTmoist(thetae0, p_BL) #temperature of boundary layer top 
     T_out = findTmoist(thetae0, p_out)
     thickness = lambda p: (c.Rd/(p*g))*findTmoist(thetae0, p)
     delz_trop = integrate.quad(thickness, p_out, p_BL)[0]
     delz_trop = np.zeros(len(p_out))
     for i,p_oute in enumerate(p_out):
         delz_trop[i] = integrate.quad(thickness, p_oute, p_BL)[0]
     dels_trop = c.cpd*np.subtract(T_BLtop, T_out) + g*(-delz_trop) #difference in dry static energy between boundary layer top and tropopause (J)
     return dels_trop
Esempio n. 2
0
def calcAdiabat(press0, thetae0, topPress):
    """
    
    Calculates the temperature-pressure coordinates of a moist adiabat.
    
    Parameters
    - - - - - -
    press0: the initial pressure (Pa)
    thetae0: the equivalent potential temperature (K) of the adiabat
    topPress: the final pressure (Pa)
    
    Returns
    - - - - - -
    (pressVals, tempVals): pressVals (Pa) and tempVals (K) are type ndarray
                           and are the coordinates of the thetae0 adiabat
                
    
    Tests
    - - - - -
    >>> p,T = calcAdiabat(800*100, 300, 1000*100)
    >>> len(p)
    50
    >>> len(T)
    50
    

    """
    
    pressVals = np.linspace(press0, topPress, 50)
    
    tempVals = findTmoist(thetae0, pressVals)
    
    return pressVals, np.asarray(tempVals)
Esempio n. 3
0
def calcTvDiff(press, thetae0, interpTenv, interpTdEnv):
    """
    
    Calculates the virtual temperature difference between the thetae0
    moist adiabat and a given sounding at some pressure.
    
    Parameters
    - - - - - -
    
    press: pressure (Pa)
    thetae0: equivalent potential temperature of the adiabat (K)
    interpTenv: interpolator for environmental temperature (deg C)
    interpTdEnv: interpolator for environmental dew point temperature (deg C)
    
    Returns
    - - - - - -
    TvDiff: the virtual temperature difference at pressure press 
    between the thetae0 moist adiabat and the given sounding (K).
    
   
    """
    
    Tcloud=findTmoist(thetae0,press)
    wvcloud=wsat(Tcloud,press)
    Tvcloud=Tcloud*(1. + c.eps*wvcloud)
    Tenv=interpTenv(press*1.e-2) + c.Tc
    Tdenv=interpTdEnv(press*1.e-2) + c.Tc
    wvenv=wsat(Tdenv,press)
    Tvenv=Tenv*(1. + c.eps*wvenv)
    return Tvcloud - Tvenv
    
    
def dels_BLfn(p_BL): 
    T_BLtop = findTmoist(thetae0, p_BL) #temperature of boundary layer top 
    delz_BL = np.subtract(p_s, p_BL)/(g*rho_BL)
    s_BLtop = c.cpd*np.array(T_BLtop) + g*np.array(delz_BL) #dry static energy at top of boundary layer
    s_BL = np.add(s_BLtop,s_surf)/2. #dry static energy of BL (well-mixed)
    dels_BL = np.subtract(s_BL, s_BLtop) #difference in dry static energy between BL and right above BL
    return dels_BL
 def equations(p):
     l_m, f = p
     p_LCL, T_LCL = findLCL0(f*q_sat, p_s, T_BL)
     T_LCL = findTmoist(thetae0, p_LCL)
     delz_LCL = integrate.quad(thickness, p_t, p_LCL)[0]
     dels_LCL = c.cpd*(T_LCL-T_t) + g*(-delz_LCL)
     return (l_m - ((omega_BL*l_d**2)/(omega_BL - (g*Q_mtrop)/(dels_LCL + L_v*(f*q_sat -  q_FA))))**(0.5), \
            (f-1)*q_sat - (2*zhat*(q_FAd - q_sat))/(l_d**2 - l_m**2)*(l_m + zhat - (zhat + l_d)*np.exp((l_m - l_d)/zhat)))
Esempio n. 6
0
def calcBuoy(height, thetae0, interpTenv, interpTdEnv, interpPress):

    #input: height (m), thetae0 (K), plus function handles for
    #T,Td, press soundings
    #output: Bout = buoyant acceleration in m/s^2
    #neglect liquid water loading in the virtual temperature
    
    press=interpPress(height)*100.#%Pa
    Tcloud=findTmoist(thetae0,press) #K
    wvcloud=wsat(Tcloud,press); #kg/kg
    Tvcloud=Tcloud*(1. + c.eps*wvcloud)
    Tenv=interpTenv(height) + c.Tc
    Tdenv=interpTdEnv(height) + c.Tc
    wvenv=wsat(Tdenv,press); #kg/kg
    Tvenv=Tenv*(1. + c.eps*wvenv)
    TvDiff=Tvcloud - Tvenv
    #print '%10.3f %10.3f %10.3f\n' %(press*0.01,height,TvDiff)
    return c.g0*(TvDiff/Tvenv)
 def T_afn(p_out):
     T_a = np.mean(findTmoist(thetae0, np.linspace(p_BL, p_out)))
     return T_a
eps_BLs = np.linspace(0.1, 0.8, 10)
eps_as = np.linspace(0.1, 0.8, 10)


eps_BLss, eps_ass = np.meshgrid(eps_BLs, eps_as)

p_outs = np.zeros(eps_BLss.shape)
#p_BLs = np.zeros(eps_BLss.shape)
#T_as = np.zeros(eps_BLss.shape)

q_sat = wsat(T_s, p_s) #mixing ratio above sea surface (100% saturated)    
thetae0 = thermo.theta_e(T_s, p_s, q_sat, 0) #theta_e in moist region 
                                            #use surface temperature to get moist adiabat

plevs = np.linspace(50e2, p_s, 1000)    
Tadb = findTmoist(thetae0, plevs)
                                                                                                                                                 

for i, eps_BL in enumerate(eps_BLs):
    
    print 'eps_BL', eps_BL
    
    for j, eps_a in enumerate(eps_as):
        
        print 'eps_a', eps_a

        #T_a = np.mean(Tadb)
        #T_out = findTmoist(thetae0, p_out)
        #T_strat = T_out
        #rho_BL = p_s/(c.Rd*T_BL)
        s_surf = c.cpd*T_s #dry static energy at surface
Esempio n. 9
0
plt.show()
#print -dpdf initial_sound.pdf

#put on the top and bottom LCLs and the thetae sounding
Tlcl=np.zeros(numPoints)
pLCL=np.zeros(numPoints)
theTheta=np.zeros(numPoints)
theThetae=np.zeros(numPoints)
Tpseudo=np.zeros(numPoints)
wtotal=np.zeros(numPoints)
for i in range(0, numPoints):
  wtotal[i]=wsat(Tdew[i] + c.Tc,press[i]*100.);
  Tlcl[i],pLCL[i]=LCLfind(Tdew[i] + c.Tc,Temp[i]+c.Tc,press[i]*100.)
  theThetae[i]=thetaep(Tdew[i] + c.Tc,Temp[i] + c.Tc,press[i]*100.)
  #find the temperature along the pseudo adiabat at press[i]
  Tpseudo[i]=findTmoist(theThetae[i],press[i]*100.)
  #no liquid water in sounding
xplot=convertTempToSkew(Tlcl[0] - c.Tc,pLCL[0]*0.01,skew);
bot,=plt.plot(xplot,pLCL[0]*0.01,'ro',markersize=12, markerfacecolor ='r')
xplot=convertTempToSkew(Tlcl[-1] - c.Tc,pLCL[-1]*0.01,skew)
top,=plt.plot(xplot,pLCL[-1]*0.01,'bd',markersize=12,markerfacecolor='b')
#print -dpdf initial_lcls.pdf
xplot=convertTempToSkew(Tpseudo - c.Tc,press,skew)
thetaEhandle,=plt.plot(xplot,press,'c-', linewidth=2.5)
ax.legend([Thandle, TdHandle, bot, top, thetaEhandle], ['Temp (deg C)','Dewpoint (deg C)',
       'LCL bot (835 hPa)','LCL top (768 hPa)','$\\theta_e$'])
plt.title('convectively unstable sounding: base at 900 hPa')
plt.show()
#print -dpdf base900_thetae.pdf

Esempio n. 10
0
zeta_levs = -h * np.log(plevs / p_s)
zeta_T = 16

for i, zeta in enumerate(zeta_levs):
    if (zeta < zeta_T):
        Tphumb[i] = T_s - gamma_ph * zeta
    else:
        Tphumb[i] = T_s - gamma_ph * zeta_T

Told = np.zeros(plevs.shape)
Tnew = np.zeros(plevs.shape)

for i, p in enumerate(plevs[:-1]):
    Tgm[i + 1] = Tgm[i] * (1 + gamma_m * c.Rd * delp / p)
    Tgd[i + 1] = Tgd[i] * (1 + gamma_d * c.Rd * delp / p)
    Told[i] = findTmoist.findTmoist(thetae0, p)
    Tnew[i] = findTmoist_new.findTmoist(thetae0, p, q_sat, 0)

plt.figure(1)
plt.plot(Told[:-1],
         plevs[:-1] / 100.,
         color='r',
         label='Told - root finder moist adiabat')
plt.plot(Tnew[:-1],
         plevs[:-1] / 100.,
         color='b',
         label='Tnew - root finder moist adiabat')
plt.plot(Tgm[:-1], plevs[:-1] / 100., 'g--', label='constant gamma_m')
plt.plot(Tgd[:-1], plevs[:-1] / 100., 'k--', label='constant gamma_d')
plt.plot(Tphumb, plevs / 100., color='y', label='pierre humbert profile')
plt.legend()
 def T_BLfn(p_BL):
     T_BLtop = findTmoist(thetae0, p_BL) #temperature of boundary layer top 
     T_BL = np.add(T_s,T_BLtop)/2. #temperature of boundary layer, consistent with well-mixed assumption (linear mixing)
     return T_BL
RH_ms = np.zeros(eps_BLss.shape)
delhs = np.zeros(eps_BLss.shape)
massbalance = np.zeros(eps_BLss.shape)
p_LCLs = np.zeros(eps_BLss.shape)

q_sat = wsat(T_s, p_s) #mixing ratio above sea surface (100% saturated)    
thetae0 = thermo.theta_e(T_s, p_s, q_sat, 0) #theta_e in moist region 
                                            #use surface temperature to get moist adiabat

plevs = np.linspace(50e2, p_s, 1000)    
#Tadb = findTmoist(thetae0, plevs)
omega_BLs = np.zeros(eps_BLss.shape)
w_BLs = np.zeros(eps_BLss.shape)

#T_out = findT(T_s, p_out)
T_out = findTmoist(thetae0, p_out)
T_strat = T_out
#T_strat = np.mean(findTmoist(thetae0, np.linspace(95,p_out,50)))
#rho_BL = p_s/(c.Rd*T_BL)
s_surf = c.cpd*T_s #dry static energy at surface

q_FA = wsat(T_out, p_out)

l_d = 3000e3
                                                                                                                                                 

for i, eps_BL in enumerate(eps_BLs):
    
    print 'eps_BL', eps_BL
    
    for j, eps_a in enumerate(eps_as):
Esempio n. 13
0
     
     d = 100000e3 #
     
     p_s = 1000e2 #surface pressure (Pa)
     p_t = 200e2 #tropopause (Pa)
     p_BL = 900e2 #boundary layer top (Pa)
     T_s = 302
     delz_BL = z[BLi]
     c_E = 0.001
     l_d = domsize*1e3*(1./np.sqrt(2))
     #r = np.linspace(0, l_d, 1e6)
     q_sat = wsat(T_s, p_s) #mixing ratio above sea surface (100% saturated)    
 
     q_sat = wsat(T_s, p_s) #mixing ratio above sea surface (100% saturated)    
     thetae0 = thermo.theta_e(T_s, p_s, q_sat, 0) #theta_e in moist region 
     T_BLtop = findTmoist(thetae0, p_BL) #temperature of boundary layer top 
     T_t = findTmoist(thetae0, p_t) #temperature of tropopause (outflow region)
     T_BL = (T_s + T_BLtop)/2. #temperature of boundary layer, consistent with well-mixed assumption (linear mixing)
     q_FA = wsat(T_t, p_t) #free troposphere water vapor mixing ratio
     
     zhat = delz_BL/c_E
 
 
     q_BL = q_sat + 2*zhat*(q_FA - q_sat)/(l_d**2 - rbin_centers**2)*(rbin_centers + zhat - (zhat + l_d)*np.exp((rbin_centers - l_d)/zhat))
     
     RH_c = q_BL/q_sat
     
     if varname == 'QV':
        titlename = r'$q_v$'
     if varname == 'RH':
        titlename = 'RH'
w_ms = np.zeros(len(domsizes))
l_ms = np.zeros(len(domsizes))
l_ds = np.zeros(len(domsizes))
massbalance = np.zeros(len(domsizes))
waterbalance = np.zeros(len(domsizes))
Ebalance = np.zeros(len(domsizes))
RHs = np.zeros(len(domsizes))
Ps = np.zeros(len(domsizes))
delhs = np.zeros(len(domsizes))
p_LCLs = np.zeros(len(domsizes))

q_sat = wsat(T_s, p_s) #mixing ratio above sea surface (100% saturated)    
thetae0 = thermo.theta_e(T_s, p_s, q_sat, 0) #theta_e in moist region 
                                            #use surface temperature to get moist adiabat
T_a = np.mean(findTmoist(thetae0, np.linspace(p_s, p_t)))
T_out = findTmoist(thetae0, p_out)
T_BL = T_s
M_BL = (p_s - p_BL)/g #mass of boundary layer in kg m^-2
rho_BL = p_s/(c.Rd*T_BL)
s_surf = c.cpd*T_s #dry static energy at surface

                                            
                                            
#def T_BLfn(p_BL):
#    T_BLtop = findTmoist(thetae0, p_BL) #temperature of boundary layer top 
#    T_BL = np.add(T_s,T_BLtop)/2. #temperature of boundary layer, consistent with well-mixed assumption (linear mixing)
#    return T_BL
    
#def T_afn(p_BL):
#    T_a = np.mean(findTmoist(thetae0, np.linspace(p_BL, p_out)))
Esempio n. 15
0
for i, zeta in enumerate(zeta_levs):
    if (zeta < zeta_T):
      Tphumb[i] = T_s - gamma_ph*zeta
    else:
      Tphumb[i] = T_s - gamma_ph*zeta_T



Told = np.zeros(plevs.shape)
Tnew = np.zeros(plevs.shape)

for i, p in enumerate(plevs[:-1]):
    Tgm[i+1] = Tgm[i]*(1 + gamma_m*c.Rd*delp/p)
    Tgd[i+1] = Tgd[i]*(1+ gamma_d*c.Rd*delp/p)
    Told[i] = findTmoist.findTmoist(thetae0, p)
    Tnew[i] = findTmoist_new.findTmoist(thetae0, p, q_sat, 0)

   

    
    

plt.figure(1)
plt.plot(Told[:-1], plevs[:-1]/100., color='r', label='Told - root finder moist adiabat')
plt.plot(Tnew[:-1], plevs[:-1]/100., color='b', label='Tnew - root finder moist adiabat')
plt.plot(Tgm[:-1], plevs[:-1]/100., 'g--', label='constant gamma_m')
plt.plot(Tgd[:-1], plevs[:-1]/100., 'k--', label='constant gamma_d')
plt.plot(Tphumb, plevs/100., color ='y', label='pierre humbert profile')
plt.legend()
#plt.gca().invert_yaxis()
 def T_stratfn(p_out):
     return findTmoist(thetae0, p_out)
    q_BLms = np.zeros(len(domsizes))
    omega_ms = np.zeros(len(domsizes))

    for j, domsize in enumerate(domsizes):

        l_d = domsize * 1000
        print l_d / 1e3

        r = np.linspace(0, l_d, 1e6)

        q_sat = wsat(T_s,
                     p_s)  #mixing ratio above sea surface (100% saturated)
        thetae0 = thermo.theta_e(T_s, p_s, q_sat, 0)  #theta_e in moist region
        #use surface temperature to get moist adiaba

        T_BLtop = findTmoist(thetae0, p_BL)  #temperature of boundary layer top
        T_t = findTmoist(thetae0,
                         p_t)  #temperature of tropopause (outflow region)
        #T_BL = (T_s + T_BLtop)/2. #temperature of boundary layer, consistent with well-mixed assumption (linear mixing)
        T_BL = T_s
        q_BLsat = wsat(T_BL, (p_s + p_BL) / 2.)
        q_BLtopsat = wsat(T_BLtop, p_BL)

        q_FA = wsat(T_t, p_t)  #free troposphere water vapor mixing ratio
        #q_FA = 0.01

        q_FAd = q_FA

        #q_FA = 0.001

        M_trop = (p_BL - p_t) / g  #mass of troposphere in kg m^-2

    for j, domsize in enumerate(domsizes):
        
    
        l_d = domsize*1000
        print l_d/1e3
        
        r = np.linspace(0, l_d, 1e6)
        
        
        q_sat = wsat(T_s, p_s) #mixing ratio above sea surface (100% saturated)    
        thetae0 = thermo.theta_e(T_s, p_s, q_sat, 0) #theta_e in moist region 
                                                    #use surface temperature to get moist adiaba
        
        T_BLtop = findTmoist(thetae0, p_BL) #temperature of boundary layer top 
        T_t = findTmoist(thetae0, p_t) #temperature of tropopause (outflow region)
        #T_BL = (T_s + T_BLtop)/2. #temperature of boundary layer, consistent with well-mixed assumption (linear mixing)
        T_BL = T_s
        q_BLsat = wsat(T_BL, (p_s + p_BL)/2.)
        q_BLtopsat = wsat(T_BLtop, p_BL)
        
        q_FA = wsat(T_t, p_t) #free troposphere water vapor mixing ratio
        #q_FA = 0.01
        
        q_FAd = q_FA
        
        
        #q_FA = 0.001
        
        M_trop = (p_BL - p_t)/g #mass of troposphere in kg m^-2
     
     d = 100000e3 #
     
     p_s = 1000e2 #surface pressure (Pa)
     p_t = 200e2 #tropopause (Pa)
     p_BL = 900e2 #boundary layer top (Pa)
     T_s = 302
     delz_BL = zBL
     c_E = 0.001
     l_d = domsize*(1./np.sqrt(2))
     #r = np.linspace(0, l_d, 1e6)
     q_sat = wsat(T_s, p_s) #mixing ratio above sea surface (100% saturated)    
 
     q_sat = wsat(T_s, p_s) #mixing ratio above sea surface (100% saturated)    
     thetae0 = thermo.theta_e(T_s, p_s, q_sat, 0) #theta_e in moist region 
     T_BLtop = findTmoist(thetae0, p_BL) #temperature of boundary layer top 
     T_t = findTmoist(thetae0, p_t) #temperature of tropopause (outflow region)
     T_BL = (T_s + T_BLtop)/2. #temperature of boundary layer, consistent with well-mixed assumption (linear mixing)
     q_FA = wsat(T_t, p_t) #free troposphere water vapor mixing ratio
     
     zhat = delz_BL/c_E
 
 
     q_BL = q_sat + 2*zhat*(q_FA - q_sat)/(l_d**2 - rbin_centers**2)*(rbin_centers + zhat - (zhat + l_d)*np.exp((rbin_centers - l_d)/zhat))
 
 
     #plot vertical means
     plt.figure(1)
     fieldmeanbar = np.mean(fieldmeans, axis=0)
     fieldaverage = np.mean(fieldmeanbar)