Example #1
0
#assuming linear profiles
slope=(Ttop - Tbot)/(Ptop - Pbot)
press=np.arange(Pbot, Ptop-10, -10)
Temp=(Tbot + slope*(press - Pbot));
slope=(Tdewtop - Tdewbot)/(Ptop - Pbot)
Tdew = (Tdewbot + slope*(press - Pbot))

#how big is the pressure vector?
numPoints= np.size(press);


#figure 1: cloud base at 900 hPa
plt.figure(1)
skew, ax = convecSkew(1)
#zoom the axis to focus on layer
skewLimits=convertTempToSkew([5,30],1.e3,skew)
plt.axis([skewLimits[0],skewLimits[1],1000,600])
xplot1=convertTempToSkew(Temp,press,skew)
#plot() returns a list of handles for each line plotted
Thandle, = plt.plot(xplot1,press,'k-', linewidth=2.5)
xplot2=convertTempToSkew(Tdew,press,skew)
TdHandle, = plt.plot(xplot2,press,'b--', linewidth=2.5)
plt.title('convectively unstable sounding: base at 900 hPa')

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)
Example #2
0
def convecSkew(figNum):
      """       
      Usage:  convecSkew(figNum)
      Input:  figNum = integer
       Takes any integer, creates figure(figNum), and plots a
       skewT logp thermodiagram.
      Output: skew=30 and the handle for the plot
      """
      fig=plt.figure(figNum)
      fig.clf()
      ax1=fig.add_subplot(111)
      yplot = range(1000,190,-10)
      xplot = range(-300,-139)
      pvals = np.size(yplot)
      tvals = np.size(xplot)
      temp = np.zeros([pvals, tvals])
      theTheta = np.zeros([pvals, tvals])
      ws = np.zeros([pvals, tvals])
      theThetae = np.zeros([pvals, tvals])      
      skew = 30 #skewness factor (deg C)

      # 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 i in yplot:
            for j in xplot:
                  # Note that we don't have to transform the y
                  # coordinate, as it is still pressure.
                  iInd = yplot.index(i)
                  jInd = xplot.index(j)
                  temp[iInd, jInd] = convertSkewToTemp(j, i, skew)
                  Tk = c.Tc + temp[iInd, jInd]
                  pressPa = i * 100.
                  theTheta[iInd, jInd] = theta(Tk, pressPa)
                  ws[iInd, jInd] = wsat(Tk, pressPa)
                  theThetae[iInd, jInd] = thetaes(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)
      tempLevs = ax1.contour(xplot, yplot, temp, tempLabels, \
                            colors='k')
      
      #
      # Customize the plot
      #
      ax1.set_yscale('log')
      locs = np.array(range(100, 1100, 100))
      labels = locs
      ax1.set_yticks(locs)
      ax1.set_yticklabels(labels) # Conventionally labels semilog graph.
      ax1.set_ybound((200, 1000))
      plt.setp(ax1.get_xticklabels(), weight='bold')
      plt.setp(ax1.get_yticklabels(), weight='bold')
      ax1.yaxis.grid(True)

      
      thetaLabels = range(200, 390, 10)
      thetaLevs = ax1.contour(xplot, yplot, theTheta, thetaLabels, \
                        colors='b')


      wsLabels =[0.1,0.25,0.5,1,2,3] + range(4, 20, 2) + [20,24,28]

      wsLevs = ax1.contour(xplot, yplot, (ws * 1.e3), wsLabels, \
                        colors='g')

      thetaeLabels = np.arange(250, 410, 10)
      thetaeLevs = ax1.contour(xplot, yplot, theThetae, thetaeLabels, \
                        colors='r') 
      
      # Transform the temperature,dewpoint from data coords to
      # plotting coords.
      ax1.set_title('skew T - lnp chart')
      ax1.set_ylabel('pressure (hPa)')
      ax1.set_xlabel('temperature (deg C)')

      #
      # Crop image to a more usable size
      #    
      

      TempTickLabels = range(-15, 40, 5)

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

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

      ax1.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.
                
      thetaeLevs.clabel(thetaeLabels, inline=ovrlp, fmt='%5d', fontsize=fntsz,use_clabeltext=True)
      tempLevs.clabel(inline=ovrlp, fmt='%2d', fontsize=fntsz,use_clabeltext=True)
      thetaLevs.clabel(inline=ovrlp, fmt='%5d', fontsize=fntsz,use_clabeltext=True)
      wsLevs.clabel(inline=ovrlp, fmt='%2d', fontsize=fntsz,use_clabeltext=True)
      #print thetaeLabels
      #
      # Flip the y axis
      #
      
      ax1.invert_yaxis()
      ax1.figure.canvas.draw()
      
      return skew, ax1
Example #3
0
fig1 = plt.figure(1)
skew, ax1 = convecSkew(1)


pvec=np.arange(ptop, pbot, 1000)
#initialize vectors
Tvec_eq = np.zeros(pvec.size)
Tvec_sf = np.zeros(pvec.size)
wv = np.zeros(pvec.size)
wl = np.zeros(pvec.size)
xcoord_eq = np.zeros(pvec.size)
xcoord_sf = np.zeros(pvec.size)

for i in range(0, len(pvec)):
    Tvec_eq[i], wv[i], wl[i] = tinvert_thetae(thetae_eq, eqwv_bot, pvec[i])
    xcoord_eq[i] = convertTempToSkew(Tvec_eq[i] - c.Tc, pvec[i]*0.01, skew)
    Tvec_sf[i], wv[i], wl[i] = tinvert_thetae(thetae_sf, sfwv_bot, pvec[i])
    xcoord_sf[i] = convertTempToSkew(Tvec_sf[i] - c.Tc, pvec[i]*0.01, skew)
    
    
tempA=Tvec_sf[len(Tvec_sf)-1]
pressA=pbot
tempB=Tvec_eq[len(Tvec_eq)-1]
pressB=pbot
tempC=Tvec_eq[0]
pressC=ptop
tempD=Tvec_sf[0]
pressD=ptop;
wvD=wsat(tempD,ptop)
wvC=wsat(tempC,ptop)
    
def convecSkew(figNum):
    """    
      Skew-T diagram for the level of free convection. 
      Take any integer, creates figure(figNum), and plots a
      skewT logp thermodiagram.
      """
    fig = plt.figure(figNum)
    fig.clf()
    ax1 = fig.add_subplot(111)
    yplot = range(1000, 190, -10)
    xplot = range(-300, -139)
    pvals = np.size(yplot)
    tvals = np.size(xplot)
    temp = np.zeros([pvals, tvals])
    theTheta = np.zeros([pvals, tvals])
    ws = np.zeros([pvals, tvals])
    theThetae = np.zeros([pvals, tvals])
    skew = 30  #skewness factor (deg C)
    """
      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 i in yplot:
        for j in xplot:
            # We don't have to transform the y
            # coordinate, as it is still pressure.
            iInd = yplot.index(i)
            jInd = xplot.index(j)
            temp[iInd, jInd] = convertSkewToTemp(j, i, skew)
            Tk = c.Tc + temp[iInd, jInd]
            pressPa = i * 100.
            theTheta[iInd, jInd] = theta(Tk, pressPa)
            ws[iInd, jInd] = wsat(Tk, pressPa)
            theThetae[iInd, jInd] = thetaes(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)
    tempLevs = ax1.contour(xplot, yplot, temp, tempLabels, \
                          colors="k")

    # Customize the plot
    ax1.set_yscale("log")
    locs = np.array(range(100, 1100, 100))
    labels = locs
    ax1.set_yticks(locs)
    ax1.set_yticklabels(labels)  # Conventionally labels semilog graph.
    ax1.set_ybound((200, 1000))
    plt.setp(ax1.get_xticklabels(), weight="bold")
    plt.setp(ax1.get_yticklabels(), weight="bold")
    ax1.yaxis.grid(True)

    thetaLabels = range(200, 390, 10)
    thetaLevs = ax1.contour(xplot, yplot, theTheta, thetaLabels, \
                      colors="b")

    wsLabels = [0.1, 0.25, 0.5, 1, 2, 3] + range(4, 20, 2) + [20, 24, 28]

    wsLevs = ax1.contour(xplot, yplot, (ws * 1.e3), wsLabels, \
                      colors="g")

    thetaeLabels = np.arange(250, 410, 10)
    thetaeLevs = ax1.contour(xplot, yplot, theThetae, thetaeLabels, \
                      colors="r")

    # Transform the temperature,dewpoint from data coords to
    # plotting coords.
    ax1.set_title("skew T - lnp chart")
    ax1.set_ylabel("pressure (hPa)")
    ax1.set_xlabel("temperature (deg C)")

    #
    # Crop image to a more usable size
    #

    TempTickLabels = range(-15, 40, 5)

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

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

    ax1.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.

    thetaeLevs.clabel(thetaeLabels,
                      inline=ovrlp,
                      fmt="%5d",
                      fontsize=fntsz,
                      use_clabeltext=True)
    tempLevs.clabel(inline=ovrlp,
                    fmt="%2d",
                    fontsize=fntsz,
                    use_clabeltext=True)
    thetaLevs.clabel(inline=ovrlp,
                     fmt="%5d",
                     fontsize=fntsz,
                     use_clabeltext=True)
    wsLevs.clabel(inline=ovrlp, fmt="%2d", fontsize=fntsz, use_clabeltext=True)
    #print thetaeLabels
    #
    # Flip the y axis
    #

    ax1.invert_yaxis()
    ax1.figure.canvas.draw()

    return skew, ax1
Example #5
0
print nc_file.col_names

#get the fourth sounding
sound_var = nc_file.variables[var_names[3]]
press = sound_var[:,0]
temp = sound_var[:,2]
dewpt = sound_var[:,3]

#create the skewT-lnp graph on figure 1
fig1 = plt.figure(1)
skew, ax1 = convecSkew(1)


#get the skewed coords of the temp. and dewpoint temp.
#and plot
xdew = convertTempToSkew(dewpt, press, skew)
xtemp = convertTempToSkew(temp, press, skew)
plt.semilogy(xtemp, press, 'g', linewidth=3)
plt.semilogy(xdew, press, 'b', linewidth =3)
#**have to reset the y tick labels after using using semilogy
#**haven't found a fix for this yet
labels = np.array(range(100, 1100, 100))
ax1.set_yticks(labels)
ax1.set_yticklabels(labels)
ax1.set_ybound((400, 1000))
xlims = convertTempToSkew([-10, 30], 1.e3, skew)
ax1.set_xbound((xlims[0], xlims[1]))
ax1.set_title('littlerock sounding, %s' %var_names[3])
fig1.canvas.draw()

#get user inputed coords to draw moist adiabat
Example #6
0
direct= sound_var[:,6]
speed= sound_var[:,7]

plt.figure(1)
plt.semilogy(temp, press)
plt.semilogy(dewpoint, press)
plt.gca().invert_yaxis()
plt.gca().set_ybound((200, 1000))
plt.gca().set_title('littlerock sounding, %s' %var_names[3])
plt.ylabel('pressure (hPa)')
plt.xlabel('temperature (deg C)')
plt.show()

plt.figure(2)
skew, ax2 = convecSkew(2)
xtemp=convertTempToSkew(temp,press,skew)
xdew=convertTempToSkew(dewpoint,press,skew)
plt.semilogy(xtemp,press,'g-',linewidth=4)
plt.semilogy(xdew,press,'b-',linewidth=4)

#use 900 hPa sounding level for adiabat
#array.argmin() finds the index of the min. value of array 
p900_level = np.abs(900 - press).argmin()

thetaeVal=thetaep(dewpoint[p900_level] + c.Tc,temp[p900_level] + c.Tc,press[p900_level]*100.)
pressVals,tempVals =calcAdiabat(press[p900_level]*100.,thetaeVal,200.e2)
xTemp=convertTempToSkew(tempVals - c.Tc,pressVals*1.e-2,skew)
p900_adiabat = plt.semilogy(xTemp,pressVals*1.e-2,'r-',linewidth=4)
xleft=convertTempToSkew(-20,1.e3,skew)
xright=convertTempToSkew(25.,1.e3,skew)
Example #7
0
thetaA = theta(tempA, pressA)
thetaC = theta(tempC, pressC)
thetaB = thetaC
tempB = tempA
term1 = (thetaB / tempB)**(c.cpd / c.Rd)
term1 = 1. / term1
pressB = term1 * 1.e5
tempD = tempC
thetaD = thetaA
term1 = (thetaD / tempD)**(c.cpd / c.Rd)
term1 = 1. / term1
pressD = term1 * 1.e5
plt.figure(1)
skew, ax1 = convecSkew(1)

xtempA = convertTempToSkew(tempA - c.Tc, pressA * 0.01, skew)
xtempB = convertTempToSkew(tempB - c.Tc, pressB * 0.01, skew)
xtempC = convertTempToSkew(tempC - c.Tc, pressC * 0.01, skew)
xtempD = convertTempToSkew(tempD - c.Tc, pressD * 0.01, skew)

plt.text(xtempA, pressA * 0.01, "A", fontweight="bold", fontsize=22, color="b")
plt.text(xtempB, pressB * 0.01, "B", fontweight="bold", fontsize=22, color="b")
plt.text(xtempC, pressC * 0.01, "C", fontweight="bold", fontsize=22, color="b")
plt.text(xtempD, pressD * 0.01, "D", fontweight="bold", fontsize=22, color="b")

xmin = convertTempToSkew(0, pressA * 0.01, skew)
xmax = convertTempToSkew(35, pressA * 0.01, skew)
plt.axis([xmin, xmax, 1000, 600])
plt.title("forward carnot cycle")
plt.show()
# plot
fig1 = plt.figure(1)
skew, ax1 = convecSkew(1)

# Initialize vector arrays.
pvec = np.arange(ptop, pbot, 1000)
Tvec_eq = np.zeros(pvec.size)
Tvec_sf = np.zeros(pvec.size)
wv = np.zeros(pvec.size)
wl = np.zeros(pvec.size)
xcoord_eq = np.zeros(pvec.size)
xcoord_sf = np.zeros(pvec.size)

for i in range(0, len(pvec)):
    Tvec_eq[i], wv[i], wl[i] = tinvert_thetae(thetae_eq, eqwv_bot, pvec[i])
    xcoord_eq[i] = convertTempToSkew(Tvec_eq[i] - c.Tc, pvec[i]*0.01, skew)
    Tvec_sf[i], wv[i], wl[i] = tinvert_thetae(thetae_sf, sfwv_bot, pvec[i])
    xcoord_sf[i] = convertTempToSkew(Tvec_sf[i] - c.Tc, pvec[i]*0.01, skew)
    
tempA = Tvec_sf[len(Tvec_sf)-1]
pressA = pbot
tempB = Tvec_eq[len(Tvec_eq)-1]
pressB = pbot
tempC = Tvec_eq[0]
pressC = ptop
tempD = Tvec_sf[0]
pressD = ptop
wvD = wsat(tempD, ptop)
wvC = wsat(tempC, ptop)

hot_adiabat = plt.plot(xcoord_eq,pvec*0.01, "r-", linewidth=3)
Example #9
0
thetaA=theta(tempA,pressA)
thetaC=theta(tempC,pressC)
thetaB=thetaC
tempB=tempA
term1=(thetaB/tempB)**(c.cpd/c.Rd)
term1=1./term1
pressB=term1*1.e5
tempD=tempC
thetaD=thetaA
term1=(thetaD/tempD)**(c.cpd/c.Rd)
term1=1./term1
pressD=term1*1.e5
plt.figure(1)
skew, ax1 =convecSkew(1)

xtempA=convertTempToSkew(tempA - c.Tc,pressA*0.01,skew)
xtempB=convertTempToSkew(tempB - c.Tc,pressB*0.01,skew)
xtempC=convertTempToSkew(tempC - c.Tc,pressC*0.01,skew)
xtempD=convertTempToSkew(tempD - c.Tc,pressD*0.01,skew)

plt.text(xtempA,pressA*0.01,'A', fontweight='bold',fontsize= 22, color='b')
plt.text(xtempB,pressB*0.01,'B', fontweight='bold',fontsize= 22,color='b')
plt.text(xtempC,pressC*0.01,'C', fontweight='bold',fontsize= 22,color='b')
plt.text(xtempD,pressD*0.01,'D', fontweight='bold',fontsize= 22, color='b')

xmin = convertTempToSkew(0,pressA*0.01,skew)
xmax = convertTempToSkew(35,pressA*0.01,skew)
plt.axis([xmin, xmax, 1000, 600])
plt.title('forward carnot cycle')
plt.show()