示例#1
0
def ode_littlerock():
    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
    newHeight= 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, newHeight, temp)
    interpTdEnv = lambda zVals: np.interp(zVals, newHeight, dewpoint)
    interpPress = lambda zVals: np.interp(zVals, newHeight, 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]
    
    yinit = [0.5, height_800]  #(intial velocity = 0.5 m/s, initial height in m)
    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(thetaeVal, interpTenv, interpTdEnv, interpPress)
    r.set_initial_value(yinit, tinit)
    
    y = np.array(yinit)
    t = np.array(tinit)
    
    #stop integration when the parcel changes direction, or time runs out
    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)
        #keep track of y at each time step
        y = np.vstack((y, r.y))
        t = np.vstack((t, r.t))
        
    wvel = y[:,0]
    height = y[:,1]
    
    plt.figure(1)
    plt.plot(wvel, height)
    plt.xlabel('vertical velocity (m/s)')
    plt.ylabel('height about surface (m)')
    plt.show()
示例#2
0
def F(t, y, entrain_rate, interpTenv, interpTdEnv, interpPress):
    yp = np.zeros((4,1))
    velocity = y[0]
    height = y[1]
    thetae_cloud = y[2]
    wT_cloud = y[3]
    #yp[0] is the acceleration, in this case the buoyancy 
    yp[0] = calcBuoy(height, thetae_cloud, interpTenv, interpTdEnv, interpPress)
    press = interpPress(height)*100. #Pa
    Tdenv = interpTdEnv(height) + c.Tc #K
    Tenv = interpTenv(height) + c.Tc #K
    wTenv = wsat(Tdenv, press) #kg/kg
    thetaeEnv = thetaep(Tdenv, Tenv, press)
    #yp[1] is the rate of change of height
    yp[1] = velocity
    #yp[2] is the rate of change of thetae_cloud
    yp[2] = entrain_rate*(thetaeEnv - thetae_cloud)
    #yp[3] is the rate of change of wT_cloud
    yp[3] = entrain_rate*(wTenv - wT_cloud)
    return yp
示例#3
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()
示例#4
0
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)
theThetae=np.zeros(numPoints)
Tpseudo=np.zeros(numPoints)
wtotal=np.zeros(numPoints)
for i in range(0, numPoints):
  wtotal[i]=wsat(Tdew[i] + c.Tc,press[i]*100.);
  Tlcl[i],pLCL[i]=LCLfind(Tdew[i] + c.Tc,Temp[i]+c.Tc,press[i]*100.)
  theThetae[i]=thetaep(Tdew[i] + c.Tc,Temp[i] + c.Tc,press[i]*100.)
  #find the temperature along the pseudo adiabat at press[i]
  Tpseudo[i]=findTmoist(theThetae[i],press[i]*100.)
  #no liquid water in sounding
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)
top,=plt.plot(xplot,pLCL[-1]*0.01,'bd',markersize=12,markerfacecolor='b')
#print -dpdf initial_lcls.pdf
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
示例#5
0

c = constants();

eqT_bot=30 + c.Tc
eqwv_bot=14*1.e-3
sfT_bot=21 + c.Tc
sfwv_bot=3.e-3
eqwv_top=3.e-3
sfwv_top=3.e-3
ptop=410.e2
pbot=1000.e2

eqTd_bot=findTdwv(eqwv_bot,pbot)
sfTd_bot=findTdwv(sfwv_bot,pbot)
thetae_eq=thetaep(eqTd_bot,eqT_bot,pbot)
thetae_sf=thetaep(sfTd_bot,sfT_bot,pbot)

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)
示例#6
0
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)

#
#interpolator fails if two pressure values are the same
#
newPress = nudge(press)
#independent variable used to interpolate must be in increasing order 
#pVals must be in hPa
interpTenv = lambda pVals: np.interp(pVals, newPress[::-1], temp[::-1])
interpTdenv = lambda pVals: np.interp(pVals, newPress[::-1], dewpoint[::-1])
interpDirec = lambda pVals: np.interp(pVals, newPress[::-1], direct[::-1])
示例#7
0
c = constants()

eqT_bot = 30 + c.Tc
eqwv_bot = 14*1.e-3
sfT_bot = 21 + c.Tc
sfwv_bot = 3.e-3
eqwv_top = 3.e-3
sfwv_top = 3.e-3
ptop = 4e2
pbot = 1000.e2

# Perform the functions as the heat expands
eqTd_bot = findTdwv(eqwv_bot,pbot)
sfTd_bot = findTdwv(sfwv_bot,pbot)
thetae_eq = thetaep(eqTd_bot,eqT_bot,pbot)
thetae_sf = thetaep(sfTd_bot,sfT_bot,pbot)

# 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)
示例#8
0
from findLCL0 import findLCL0
from findTmoist import findTmoist


press0=1.e5
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\