Esempio n. 1
0
def answer_entrain():
    filename = 'littlerock.nc'
    print 'reading file: %s\n' %(filename)
    nc_file = Dataset(filename)
    var_names = nc_file.variables.keys()
    print nc_file.ncattrs()
    print nc_file.units
    print nc_file.col_names
    
    sound_var = nc_file.variables[var_names[3]]
    press = sound_var[:,0]
    height = sound_var[:,1]
    temp = sound_var[:,2]
    dewpoint = sound_var[:,3]
    
    #height must have unique values
    envHeight= nudge(height)
    #Tenv and TdEnv interpolators return temp. in deg C, given height in m
    #Press interpolator returns pressure in hPa given height in m
    interpTenv = lambda zVals: np.interp(zVals, envHeight, temp)
    interpTdEnv = lambda zVals: np.interp(zVals, envHeight, dewpoint)
    interpPress = lambda zVals: np.interp(zVals, envHeight, press)
    
    p900_level = np.where(abs(900 - press) < 2.)
    p800_level = np.where(abs(800 - press) < 7.)
    thetaeVal=thetaep(dewpoint[p900_level] + c.Tc,temp[p900_level] + c.Tc,press[p900_level]*100.)
    height_800=height[p800_level]
    wTcloud = wsat(dewpoint[p900_level] + c.Tc, press[p900_level]*100.)
    entrain_rate = 2.e-4
    winit = 0.5 #initial velocity (m/s)
    yinit = [winit, height_800, thetaeVal, wTcloud]  
    tinit = 0
    tfin = 2500
    dt = 10
    
    #want to integrate F using ode45 (from MATLAB) equivalent integrator
    r = ode(F).set_integrator('dopri5')
    r.set_f_params(entrain_rate, interpTenv, interpTdEnv, interpPress)
    r.set_initial_value(yinit, tinit)
    
    y = np.array(yinit)
    t = np.array(tinit)
    
    #stop tracking the parcel when the time runs out, or if the parcel stops moving/is desecnding
    while r.successful() and r.t < tfin and r.y[0] > 0:
        #find y at the next time step
        #(r.integrate(t) updates the fields r.y and r.t so that r.y = F(t) and r.t = t 
        #where F is the function being integrated)
        r.integrate(r.t+dt)
        if r.y[0] <= 0:
            break
        #keep track of y at each time step
        y = np.vstack((y, r.y))
        t = np.vstack((t, r.t))
        
    wvel = y[:,0]
    cloud_height = y[:,1]
    thetae_cloud = y[:,2]
    wT_cloud = y[:,3]
    
    plt.figure(1)
    plt.plot(wvel, cloud_height)
    plt.xlabel('vertical velocity (m/s)')
    plt.ylabel('height above surface (m)')
    plt.gca().set_title('vertical velocity of a cloud parcel vs height,\
 entrainment rate of %4.1e $s^{-1}$' %entrain_rate)
    
    Tcloud = np.zeros(cloud_height.size)
    wvCloud = np.zeros(cloud_height.size)
    wlCloud = np.zeros(cloud_height.size)
    
    for i in range(0, len(cloud_height)):
        the_press = interpPress(cloud_height[i])*100.
        Tcloud[i], wvCloud[i], wlCloud[i] = tinvert_thetae(thetae_cloud[i], 
                                                        wT_cloud[i], the_press)
        
    Tadia= np.zeros(cloud_height.size)
    wvAdia = np.zeros(cloud_height.size)
    wlAdia = np.zeros(cloud_height.size)
    
   
    for i in range(0, len(cloud_height)):
        the_press = interpPress(cloud_height[i])*100.
        Tadia[i], wvAdia[i], wlAdia[i] = tinvert_thetae(thetae_cloud[0], 
                                                      wT_cloud[0], the_press)
    
    plt.figure(2)
    TcloudHandle, = plt.plot(Tcloud - c.Tc, cloud_height, 'r-')
    TenvHandle, = plt.plot(temp, envHeight, 'g-')
    TadiaHandle, = plt.plot(Tadia - c.Tc, cloud_height, 'b-')
    plt.xlabel('temperature (deg C)')
    plt.ylabel('height above surface (m)')
    plt.gca().set_title('temp. of rising cloud parcel vs height,\
 entrainment rate of %4.1e $s^{-1}$' %entrain_rate)
    plt.gca().legend([TcloudHandle, TenvHandle, TadiaHandle],['cloud', 'environment', 'moist adiabat'])
    plt.show()
Esempio n. 2
0
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


#figure 2: lift cloud base by 50 hPa to 850 hPa 
for i in range(0,numPoints):
  press[i]=press[i] - 50
  #find the temperature along the pseudoadiabats at press[i]
  Tpseudo[i]=findTmoist(theThetae[i],press[i]*100.)
  #find the actual temperature and dewpoint
  Temp[i],wv,wl=tinvert_thetae(theThetae[i],wtotal[i],press[i]*100.)
  Tdew[i]=Tdfind(wv,press[i]*100.)

plt.figure(2)
skew, ax = convecSkew(2)
skewLimits=convertTempToSkew([5,30],1.e3,skew)
plt.axis([skewLimits[0],skewLimits[1],1000,600])
xplot1=convertTempToSkew(Temp - c.Tc,press,skew)
Thandle,=plt.plot(xplot1,press,'k-', linewidth=2.5)
xplot2=convertTempToSkew(Tdew -c.Tc,press,skew)
TdHandle,=plt.plot(xplot2,press,'b--', linewidth=2.5)
xplot=convertTempToSkew(Tpseudo - c.Tc,press,skew)
thetaEhandle,=plt.plot(xplot,press,'c-', linewidth=2.5)
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)
Esempio n. 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)
Esempio n. 4
0
#updraft speed
   
plt.figure(5)
maxvel=np.sqrt(2*cumCAPE);
plt.plot(maxvel, presslevs[1:]*0.01,'k-');
plt.title('maximum updraft (m/s) vs. pressure (hPa)');
plt.gca().invert_yaxis()
plt.show()

#
# find storm indices
#
#  lifted index 
thetaeVal=thetaep(dewpoint[0] + c.Tc,temp[0] + c.Tc,press[0]*100.)
wT=wsat(dewpoint[0] + c.Tc,press[0]*100.)
Tadia_500,wv,wl=tinvert_thetae(thetaeVal,wT,500.e2)
Temp_500=interpTenv(500.) + c.Tc
lifted_index= Temp_500 - Tadia_500
# total totals = vertical totals plus cross totals
Temp_850=interpTenv(850.) + c.Tc
dew_850 = interpTdenv(850.) + c.Tc
TT_index=Temp_850 + dew_850 - 2*Temp_500
#  Sholwater
thetaeVal=thetaep(dew_850,Temp_850,850.*100.)
wT=wsat(dew_850,850*100.)
Tadia_500,wv,wl=tinvert_thetae(thetaeVal,wT,500.e2)
sholwater=Temp_500 - Tadia_500
#  SWEAT
speed_850=interpSpeed(850.)
speed_500=interpSpeed(500.)
dir_850=interpDirec(850.)
Esempio n. 5
0
# 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)
Esempio n. 6
0
Temp0=15 + c.Tc
Td0=2 + c.Tc
#
#step 1: find the lcl
#
wv0=wsat(Td0,press0)
plcl, Tlcl =findLCL0(wv0,press0,Temp0)

print 'found Plcl=%8.2f (hPa) and Tlcl=%8.2f (deg C)\n' %(plcl*1.e-2, Tlcl - c.Tc)

the_thetae=thetaep(Tlcl,Tlcl,plcl)

# step 2  raise air 200 hPa above plcl along pseudo adiabat,
# find wsat at that temperature, compare to wv0 to find the amount
# of liquid water condensed

pnew = plcl - 200.e2

newTemp, newWv, newWl = tinvert_thetae(the_thetae, wv0, pnew)

#check:
#ws = wsat(newTemp, pnew)
#wl = wv0 - ws

out_msg = '\nat new pressure level %8.2f hPa\n\
          the temperature is  %8.2f deg C\n\
          the vapor mixing ratio is %8.2f g/kg\n\
          and there are %8.4f g/kg of liquid water\n\n'

print out_msg %(pnew*1.e-2, newTemp - c.Tc, newWv*1.e3, newWl*1e3)