Example #1
0
def invert_theta_l(theta_l, rt, p):
    T = thermo.theta_to_T(theta_l, p)
    r_star = thermo.r_star(p, T)
    if r_star < rt:
        T0 = numpy.array([233.15, theta_l])
        T = rootfinder.fzero(Tfind, T0, p, theta_l, rt)
    return T
Example #2
0
def make_rt_vs_theta_l(tlmin, tlmax, rtmin, rtmax, p):
    #make a blank skewT diagram
    clf()
    
    #get a dense range of p, t0 to contour
    theta_l_vals = linspace(tlmin, tlmax, 100)
    r_vals = linspace(rtmin, rtmax, 100)
    theta_l_vals, r_vals = meshgrid(theta_l_vals, r_vals)
    
    Tvals = zeros(theta_l_vals.shape, float)

    for i in range(100):
        for j in range(100):
            Tvals[j,i] = invert_theta_l(theta_l_vals[j,i], r_vals[j,i], p)
    
    #use the real (data) value to get the potential temperature
    r_star = thermo.r_star(p, Tvals)
    rl = r_vals - r_star
    rl[rl < 0.] = 0.
    r = r_vals - rl

    theta_v = thermo.theta_v(p, Tvals, r)
    
    contour(theta_l_vals, r_vals*1000., -theta_v, 20, colors='k', linestyles=':')
    
    axis([tlmin, tlmax, rtmin*1000., rtmax*1000.])
    title('(theta_l, rt) Conserved Variable Diagram')
    ylabel('rt (g kg-1)')
    xlabel('theta_l (K)')
Example #3
0
def make_rt_vs_theta_l(tlmin, tlmax, rtmin, rtmax, p):
    #make a blank skewT diagram
    clf()

    #get a dense range of p, t0 to contour
    theta_l_vals = linspace(tlmin, tlmax, 100)
    r_vals = linspace(rtmin, rtmax, 100)
    theta_l_vals, r_vals = meshgrid(theta_l_vals, r_vals)

    Tvals = zeros(theta_l_vals.shape, float)

    for i in range(100):
        for j in range(100):
            Tvals[j, i] = invert_theta_l(theta_l_vals[j, i], r_vals[j, i], p)

    #use the real (data) value to get the potential temperature
    r_star = thermo.r_star(p, Tvals)
    rl = r_vals - r_star
    rl[rl < 0.] = 0.
    r = r_vals - rl

    theta_v = thermo.theta_v(p, Tvals, r)

    contour(theta_l_vals,
            r_vals * 1000.,
            -theta_v,
            20,
            colors='k',
            linestyles=':')

    axis([tlmin, tlmax, rtmin * 1000., rtmax * 1000.])
    title('(theta_l, rt) Conserved Variable Diagram')
    ylabel('rt (g kg-1)')
    xlabel('theta_l (K)')
Example #4
0
def invert_theta_l(theta_l, rt, p):
    T = thermo.theta_to_T(theta_l, p)
    r_star = thermo.r_star(p, T)
    if r_star < rt:
        T0 = numpy.array([233.15, theta_l])
        T = rootfinder.fzero(Tfind, T0, p, theta_l, rt)
    return T
def _main(tmin, tmax, rmin, rmax):
    result = _get_sounding('sounding.txt')
    T = result['T']
    p = result['p']
    RH = result['RH']
    rt = thermo.p_T_RH_to_r(p, T, RH)

    r_star = thermo.r_star(p, T)
    rl = rt - r_star
    rl[rl < 0] = 0.
    r = rt - rl

    plot_rt_vs_theta_alpha(p, T, r, rl, 1.)
    show()
Example #6
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)')
Example #7
0
def _main(tmin, tmax, rmin, rmax):
    result = _get_sounding('sounding.txt')
    T = result['T']
    p = result['p']
    RH = result['RH']
    rt = thermo.p_T_RH_to_r(p, T, RH)
    
    r_star = thermo.r_star(p, T)
    rl = rt - r_star
    rl[rl < 0] = 0.
    r = rt - rl
        
    plot_rt_vs_theta_alpha(p, T, r, rl, 1.)    
    show()
Example #8
0
def main(tmin, tmax, rmin, rmax):
    result = get_sounding('sounding.txt')
    T = result['T']
    p = result['p']
    RH = result['RH']
    rt = thermo.p_T_RH_to_r(p, T, RH)
        
    make_rt_vs_theta_l(270, 310, 0./1000., 6./1000., 84000.)
    
    r_star = thermo.r_star(p, T)
    rl = rt - r_star
    rl[rl < 0] = 0.
    r = rt - rl
        
    plot_rt_vs_theta_l(p, T, r, rl)
    axis([270,310,0,6])
    
    show()
Example #9
0
def main(tmin, tmax, rmin, rmax):
    result = get_sounding('sounding.txt')
    T = result['T']
    p = result['p']
    RH = result['RH']
    rt = thermo.p_T_RH_to_r(p, T, RH)

    make_rt_vs_theta_l(270, 310, 0. / 1000., 6. / 1000., 84000.)

    r_star = thermo.r_star(p, T)
    rl = rt - r_star
    rl[rl < 0] = 0.
    r = rt - rl

    plot_rt_vs_theta_l(p, T, r, rl)
    axis([270, 310, 0, 6])

    show()
Example #10
0
def Tfind(Tguess, p, theta_l, rt):
    # due to the check in invert_theta_l, we can assume that r = r_star.
    # However, we don't know the exact value of r_star because we don't know T.
    r = thermo.r_star(p, Tguess)
    rl = rt - r
    return theta_l - thermo.theta_l(p, Tguess, r, rl)
Example #11
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)')
Example #12
0
def Tfind(Tguess, p, theta_l, rt):
    # due to the check in invert_theta_l, we can assume that r = r_star.
    # However, we don't know the exact value of r_star because we don't know T.
    r = thermo.r_star(p, Tguess)
    rl = rt - r
    return theta_l - thermo.theta_l(p, Tguess, r, rl)