Esempio n. 1
0
def therm_calc(the_row):
    rT = cloud_vars['wt']
    S = the_row[-1]
    temp, press,height = the_row[-4:-1]
    esat = find_esat(temp)
    e = S*esat
    rv = c.eps*e/(press - e)  #Thompkins eqn 2.20
    Td = find_Td(rv,press)
    thetae = find_thetaet(Td,rT,temp,press)
    hm = c.cpd*temp + find_lv(temp)*rv + c.g0*height
    return (thetae, hm)
Esempio n. 2
0
def makeSkewWet(ax, corners=[-30, 25], skew=30):
    """       
      draw a skew-T lnP diagram on an axis

      Parameters
      ----------
      
      ax : matplotlib.axes
           matplotlib figure axis

      corners : [float]
                x axis temperature limits (degC)

      skew : float

             adjustable coefficient to make isotherms slope
             compared to adiabats

      Returns
      -------
      
      ax : matplotlib.axes
           the modified figure axis

      """
    yplot = range(1000, 190, -6)  #
    xcorners = find_corners(corners, skew=skew)
    xplot = list(np.linspace(xcorners[0], xcorners[1], 45))
    pvals = np.size(yplot)
    tvals = np.size(xplot)
    temp = np.zeros([pvals, tvals])
    theTheta = np.zeros_like(temp)
    the_rsat = np.zeros_like(temp)
    theThetae = np.zeros([pvals, tvals])

    # 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. The transformation is given by W&H 3.56, p. 78.  Note
    # that there is a sign difference, because rather than
    # taking y= -log(P) like W&H, I take y= +log(P) and
    # then reverse the y axis

    for presshPa in yplot:  #loop over pressures
        for skewed in xplot:  #loop over skewed xcoords
            # Note that we don't have to transform the y
            # coordinate, as it is still pressure.
            iInd = yplot.index(presshPa)
            jInd = xplot.index(skewed)
            temp[iInd, jInd] = convertSkewToTemp(skewed, presshPa, skew)
            Tk = c.Tc + temp[iInd, jInd]
            pressPa = presshPa * 100.
            theTheta[iInd, jInd] = find_theta(Tk, pressPa)
            rs = find_rsat(Tk, pressPa)
            the_rsat[iInd, jInd] = rs
            theThetae[iInd, jInd] = find_thetaet(Tk,rs,Tk, pressPa)
    #
    # Contour the temperature matrix.
    #

    # First, make sure that all plotted lines are solid.
    mpl.rcParams['contour.negative_linestyle'] = 'solid'
    tempLabels = range(-40, 50, 5)
    ax.contour(xplot, yplot, temp, tempLabels, \
                          colors='k')
    #
    # contour theta
    #
    thetaLabels = list(range(200, 390, 10))
    thetaLevs = ax.contour(xplot, yplot, theTheta, thetaLabels, \
                      colors='b')
    #
    # contour rsat
    #
    rsLabels = [0.1, 0.25, 0.5, 1, 2, 3] + list(range(4, 28, 2)) #+ [26,  28]
    rsLevs = ax.contour(xplot,
                        yplot,
                        the_rsat * 1.e3,
                        levels=rsLabels,
                        colors='g',
                        linewidths=.5)

    thetaeLabels = np.arange(250, 410, 10)
    thetaeLevs = ax.contour(xplot, yplot, theThetae, thetaeLabels, \
                      colors='r')
    #
    # Customize the plot
    #
    ax.set_yscale('log')
    locs = np.array(range(100, 1100, 100))
    labels = locs
    ax.set_yticks(locs)
    ax.set_yticklabels(labels)  # Conventionally labels semilog graph.
    ax.set_ybound((200, 1000))
    plt.setp(ax.get_xticklabels(), weight='bold')
    plt.setp(ax.get_yticklabels(), weight='bold')
    ax.yaxis.grid(True)

    ax.set_title('skew T - lnp chart')
    ax.set_ylabel('pressure (hPa)')
    ax.set_xlabel('temperature (deg C)')

    #
    # Crop image to a more usable size
    #

    TempTickLabels = range(-30, 40, 5)

    TempTickCoords = TempTickLabels
    skewTickCoords = convertTempToSkew(TempTickCoords, 1.e3, skew)
    ax.set_xticks(skewTickCoords)
    ax.set_xticklabels(TempTickLabels)

    skewLimits = convertTempToSkew([-15, 35], 1.e3, skew)

    ax.axis([skewLimits[0], skewLimits[1], 300, 1.e3])
    #
    # Create line labels
    #
    fntsz = 9  # Handle for 'fontsize' of the line label.
    ovrlp = True  # Handle for 'inline'. Any integer other than 0
    # creates a white space around the label.

    #tempLevs.clabel(inline=ovrlp, inline_spacing=0,fmt='%2d', fontsize=fntsz,use_clabeltext=True)
    thetaLevs.clabel(inline=ovrlp,
                     inline_spacing=0,
                     fmt='%3d',
                     fontsize=fntsz,
                     use_clabeltext=True)
    rsLevs.clabel(inline=ovrlp,
                  inline_spacing=0,
                  fmt='%3.2g',
                  fontsize=fntsz,
                  use_clabeltext=True)
    thetaeLevs.clabel(thetaeLabels,
                      inline_spacing=0,
                      inline=ovrlp,
                      fmt='%5g',
                      fontsize=fntsz,
                      use_clabeltext=True)

    ax.invert_yaxis()
    #ax.figure.canvas.draw()
    xcorners = find_corners(corners, skew=skew)
    ax.set(ylim=(1000, 300), xlim=xcorners)
    return ax, skew
Esempio n. 3
0
    """
    return the_string.format_map(the_tup._asdict())
    
   
get_ipython().magic('matplotlib inline')
pa2hPa = 1.e-2

A_press = 1.e5  #Pa
B_press = 4.e4  #Pa
A_temp = 300  #K
RH = 0.8
e = find_esat(A_temp)*RH
A_rv = c.eps*e/(A_press - e)
A_Td = find_Td(A_rv,A_press)
print('tropical surface dewpoint: {} K'.format(A_Td))
A_thetae=find_thetaet(A_Td,A_rv,A_temp,A_press)
print('tropical surface thetae: {} K'.format(A_thetae))
A_temp,A_rv,A_rl = tinvert_thetae(A_thetae,A_rv,A_press)
fields=['id','temp','rv','rl','press']
A_dict = dict(zip(fields,('A',A_temp,A_rv,A_rl,A_press)))
A_tup = calc_enthalpy(A_dict)
print(format_tup(A_tup))


# ### B. Lift to 400 hPa and remove 80% of the liquied water

# In[201]:

plt.close('all')
fig,ax = plt.subplots(1,1,figsize=[10,8])
ax,skew = makeSkewWet(ax,corners=[-15,35])
Esempio n. 4
0
def makeSkewWet(ax, corners=[-30, 25], skew=30):
    """       
      draw a skew-T lnP diagram on an axis

      Parameters
      ----------
      
      ax : matplotlib.axes
           matplotlib figure axis

      corners : [float]
                x axis temperature limits (degC)

      skew : float

             adjustable coefficient to make isotherms slope
             compared to adiabats

      Returns
      -------
      
      ax : matplotlib.axes
           the modified figure axis

      """
    yplot = range(1000, 190, -6)  #
    xcorners = find_corners(corners, skew=skew)
    xplot = list(np.linspace(xcorners[0], xcorners[1], 45))
    pvals = np.size(yplot)
    tvals = np.size(xplot)
    temp = np.zeros([pvals, tvals])
    theTheta = np.zeros_like(temp)
    the_rsat = np.zeros_like(temp)
    theThetae = np.zeros([pvals, tvals])

    # 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. The transformation is given by W&H 3.56, p. 78.  Note
    # that there is a sign difference, because rather than
    # taking y= -log(P) like W&H, I take y= +log(P) and
    # then reverse the y axis

    for presshPa in yplot:  #loop over pressures
        for skewed in xplot:  #loop over skewed xcoords
            # Note that we don't have to transform the y
            # coordinate, as it is still pressure.
            iInd = yplot.index(presshPa)
            jInd = xplot.index(skewed)
            temp[iInd, jInd] = convertSkewToTemp(skewed, presshPa, skew)
            Tk = c.Tc + temp[iInd, jInd]
            pressPa = presshPa * 100.
            theTheta[iInd, jInd] = find_theta(Tk, pressPa)
            rs = find_rsat(Tk, pressPa)
            the_rsat[iInd, jInd] = rs
            theThetae[iInd, jInd] = find_thetaet(Tk, rs, Tk, pressPa)
    #
    # Contour the temperature matrix.
    #

    # First, make sure that all plotted lines are solid.
    mpl.rcParams['contour.negative_linestyle'] = 'solid'
    tempLabels = range(-40, 50, 10)
    ax.contour(xplot, yplot, temp, tempLabels, \
                          colors='k')
    #
    # contour theta
    #
    thetaLabels = list(range(200, 390, 10))
    thetaLevs = ax.contour(xplot, yplot, theTheta, thetaLabels, \
                      colors='b')
    #
    # contour rsat
    #
    rsLabels = [0.1, 0.25, 0.5, 1, 2, 3] + list(range(4, 28, 2))  #+ [26,  28]
    rsLevs = ax.contour(xplot,
                        yplot,
                        the_rsat * 1.e3,
                        levels=rsLabels,
                        colors='g',
                        linewidths=.5)

    thetaeLabels = np.arange(250, 410, 10)
    thetaeLevs = ax.contour(xplot, yplot, theThetae, thetaeLabels, \
                      colors='r')
    #
    # Customize the plot
    #
    ax.set_yscale('log')
    locs = np.array(range(100, 1100, 100))
    labels = locs
    ax.set_yticks(locs)
    ax.set_yticklabels(labels)  # Conventionally labels semilog graph.
    ax.set_ybound((200, 1000))
    plt.setp(ax.get_xticklabels(), weight='bold')
    plt.setp(ax.get_yticklabels(), weight='bold')
    ax.yaxis.grid(True)

    ax.set_title('skew T - lnp chart')
    ax.set_ylabel('pressure (hPa)')
    ax.set_xlabel('temperature (deg C)')

    #
    # Crop image to a more usable size
    #

    TempTickLabels = range(-30, 40, 5)

    TempTickCoords = TempTickLabels
    skewTickCoords = convertTempToSkew(TempTickCoords, 1.e3, skew)
    ax.set_xticks(skewTickCoords)
    ax.set_xticklabels(TempTickLabels)

    skewLimits = convertTempToSkew([-15, 35], 1.e3, skew)

    ax.axis([skewLimits[0], skewLimits[1], 300, 1.e3])
    #
    # Create line labels
    #
    fntsz = 9  # Handle for 'fontsize' of the line label.
    ovrlp = True  # Handle for 'inline'. Any integer other than 0
    # creates a white space around the label.

    #tempLevs.clabel(inline=ovrlp, inline_spacing=0,fmt='%2d', fontsize=fntsz,use_clabeltext=True)
    thetaLevs.clabel(inline=ovrlp,
                     inline_spacing=0,
                     fmt='%3d',
                     fontsize=fntsz,
                     use_clabeltext=True)
    rsLevs.clabel(inline=ovrlp,
                  inline_spacing=0,
                  fmt='%3.2g',
                  fontsize=fntsz,
                  use_clabeltext=True)
    thetaeLevs.clabel(thetaeLabels,
                      inline_spacing=0,
                      inline=ovrlp,
                      fmt='%5g',
                      fontsize=fntsz,
                      use_clabeltext=True)

    ax.invert_yaxis()
    #ax.figure.canvas.draw()
    xcorners = find_corners(corners, skew=skew)
    ax.set(ylim=(1000, 300), xlim=xcorners)
    return ax, skew
Esempio n. 5
0
end_z = np.searchsorted(z, 1200.0)
bot_z = np.searchsorted(z, 1000.0)


qv_sound = qv.mean(axis=(1, 2))[bot_z:end_z] * 1.0e-3  # kg/kg
temp_sound = temp.mean(axis=(1, 2))[bot_z:end_z]
press_sound = np.squeeze(press)[bot_z:end_z]
z_sound = z[bot_z:end_z]
# print(qv_sound.shape,temp_sound.shape,z_sound.shape,press_sound.shape)
thetal_sound = [
    find_thetal(the_press, the_temp, the_qv) for the_press, the_temp, the_qv in zip(press_sound, temp_sound, qv_sound)
]
Td_sound = find_Td(qv_sound, press_sound)
thetae_sound = [
    find_thetaet(the_Td, the_qv, the_temp, the_press)
    for the_Td, the_press, the_temp, the_qv in zip(Td_sound, press_sound, temp_sound, qv_sound)
]
fig, (ax1, ax2, ax3, ax4) = plt.subplots(1, 4, figsize=(16, 8))
ax1.plot(qv_sound * 1.0e3, z_sound)
ax2.plot(temp_sound, press_sound * 1.0e-2)
ax3.plot(thetal_sound, press_sound * 1.0e-2)
ax4.plot(thetae_sound, press_sound * 1.0e-2)
axes = [ax2, ax3, ax4]
[ax.invert_yaxis() for ax in axes]
p0 = press_sound[0] * 1.0e-2
[ax.set(ylim=(p0, 750)) for ax in axes]
axes = [ax1, ax2, ax3, ax4]
ax1.set(ylabel="heigth (m)")
ax2.set(ylabel="pressure (hPa)")
titles = ["$q_v\ (g/kg)$", "$temperature\ (K)$", r"$\theta_l\ (K)$", r"$\theta_e\ (K)$"]