def thetaEchange(Tguess, thetaE0, press):
    """
    thetaEchange(Tguess, thetaE0, press)

    Evaluates the equation and passes it back to brenth.

    Parameters
    - - - - - -
    Tguess : float
        Trial temperature value (K).
    ws0 : float
        Initial saturated mixing ratio (kg/kg).
    press : float
        Pressure (Pa).

    Returns
    - - - -
    theDiff : float
        The difference between the values of 'thetaEguess' and
        'thetaE0'. This difference is then compared to the tolerance
        allowed by brenth.
        
    """
    q = wsat(Tguess, press)
    #assume no liquid water
    thetaEguess = thermo.theta_e(Tguess, press, q, 0);
    
    #when this result is small enough we're done
    theDiff = thetaEguess - thetaE0;
    return theDiff
Beispiel #2
0
def plot_rt_vs_theta_alpha(p, T, r, rl, alpha):
    theta_l = thermo.theta_l(p, T, r, rl)
    theta_e = thermo.theta_e(p, T, r, rl)
    theta_alpha = (1. - alpha)*theta_l + alpha*theta_e
    rt = r + rl
    
    ax = subplot(1,1,1)
    ax.plot(theta_alpha, rt*1000)
    
    yl = ax.get_ylim()
    if yl[0] < yl[1]: ax.set_ylim([yl[1], yl[0]])
Beispiel #3
0
def make_skewT(tmin, tmax, pmax, pmin, skew=30.):
    #make a blank skewT diagram
    clf()
    #get a dense range of p, t0 to contour
    yplot = linspace(1050, 100, 100)
    xplot = linspace(-50, 50, 100)
    xplot, yplot = meshgrid(xplot, yplot)
    
    #lay down a reference grid that labels xplot,yplot points 
    #in the new (skewT-lnP) coordinate system .
    # Each value of the temp matrix holds the actual (data) temperature
    # label (in deg C)  of the xplot, yplot coordinate pairs
    #note that we don't have to transform the y coordinate
    #it's still the pressure

    #use the real (data) value to get the potential temperature
    T = xplot + skew*log(0.001*yplot)
    Tk = T + 273.15 #convert from C to K for use in thermo functios
    p = yplot*100. #convert from hPa to Pa

    th = thermo.theta(p, Tk) #theta labels

    #add the mixing ratio
    rstar = thermo.r_star(p, Tk)  #wsat labels

    #saturated adiabat, so Tdew=Tk
    thetaeVals = thermo.theta_e(p, Tk, rstar, 0.)    
    
    tempLabels = arange(-140., 50., 10.)
    con1 = contour(xplot, yplot, T, levels = tempLabels, colors = 'k', linewidths=.5)
    ax = gca()
    ax.set_yscale('log')
    lines = arange(100., 1100., 100.)
    yticks(lines, ['100','200','300','400','500','600','700','800','900','1000'])
    for line in lines:
        axhline(line, ls=':', color='k', linewidth=.5)
    thetaLabels = arange(200., 380., 10.)
    con2 = contour(xplot, yplot, th, levels = thetaLabels, colors='b', linewidths=.5)
    #rsLabels = [.1,.2,.4,.6, 1, 2, 3, 4, 5, 6, 8, 10, 15, 20, 25, 30, 40]
    #con3 = contour(xplot, yplot, rstar*1.e3, levels=rsLabels, colors='g', linewidths=.5)
    #thetaeLabels = linspace(200,400,21)
    #con4 = contour(xplot, yplot, thetaeVals, levels = thetaeLabels, colors='r', linewidths=.5)
    axis([tmin, tmax, pmax, pmin])
    clabel(con1, inline = False, fmt = '%1.0f')
    clabel(con2, inline = False, fmt = '%1.0f')
    #clabel(con3, inline = False, fmt = '%1.1f')
    #clabel(con4, inline = False, fmt = '%1.0f')
    title('skew T - lnp chart')
    ylabel('pressure (hPa)')
    xlabel('temperature (black, degrees C)')
    delhs = np.zeros(len(domsizes))
    delhseff = np.zeros(len(domsizes))
    p_LCLs = 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
        
        
Beispiel #5
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':
import site
import sys
site.addsitedir('/Users/cpatrizio/Dropbox/research/code/thermlib/')
import findTmoist
import findTmoist_new
from wsat import wsat
from constants import constants
import numpy as np
import thermo
import matplotlib.pyplot as plt

T_s = 302
p_s = 1000e2
p_t = 200e2
q_sat = wsat(T_s, p_s)
thetae0 = thermo.theta_e(T_s, p_s, q_sat, 0)

plevs = np.linspace(p_t, p_s, 1000)[::-1]

delp = np.diff(plevs)[0]


c = constants()

gamma_m = 6.5/1000. #lapse rate in K m^-1
gamma_d = 9.8/1000. #lapse rate in K m^-1

Tgm = np.zeros(plevs.shape)
Tgd = np.zeros(plevs.shape)

Tgm[0] = T_s
import site
import sys
site.addsitedir('/Users/cpatrizio/Dropbox/research/code/thermlib/')
import findTmoist
import findTmoist_new
from wsat import wsat
from constants import constants
import numpy as np
import thermo
import matplotlib.pyplot as plt

T_s = 302
p_s = 1000e2
p_t = 200e2
q_sat = wsat(T_s, p_s)
thetae0 = thermo.theta_e(T_s, p_s, q_sat, 0)

plevs = np.linspace(p_t, p_s, 1000)[::-1]

delp = np.diff(plevs)[0]

c = constants()

gamma_m = 6.5 / 1000.  #lapse rate in K m^-1
gamma_d = 9.8 / 1000.  #lapse rate in K m^-1

Tgm = np.zeros(plevs.shape)
Tgd = np.zeros(plevs.shape)

Tgm[0] = T_s
Tgd[0] = T_s