if read_temperature_fromfile == 'True': ab = np.loadtxt(datadir + infile1, skiprows=1) lats = ab[:, 0] T1a = ab[:, 1] # You need to read in the July temperature profile here [refind] = np.where(lats == reference_latitude) else: T1 = np.arange(-40, 41, 0.25) + 273.15 # Virtual temperatures T1a = T1 [refind] = np.where(T1a == 273.15) # weather_modules.py has a function to compute saturation vapor pressure. # If weather_modules.py does not work for you, then use that function as a # guide for placing the calculation below. es1 = wm.claus_clap(T1a) # saturation vapor pressure. ws1a = (epsi * es1) / (pres1 - es1) # saturation mixing ratio es1 = wm.claus_clap(T1b) # saturation vapor pressure ws1b = (epsi * es1) / (pres1 - es1) # saturation mixing ratio # Compute moist adiabatic lapse rate, first in z-coords # You need to compute fa and fb sat_lapse_a = gammad * fa sat_lapse_b = gammad * fb Rho_a = pres1 / (Rv * T1a) # Density, moist air Rho_b = pres1 / (Rv * T1b) deltap = pres2 - pres1 deltaz_a = (-1.0 * deltap) / (Rho_a * g) deltaz_b = (-1.0 * deltap) / (Rho_b * g)
titlestring = "Total diabatic heating rate " + date_string cmap_opt = plt.cm.RdBu_r figname = "wrf_cross_section_ttendf" if dlat_dlon[0] == 0: figname = "wrf_cross_section_ew_latent" if dlat_dlon[1] == 0: figname = "wrf_cross_section_ns_latent" elif plot_option == 16: temp = nc.variables['TEMP'][timeindex, :, :, :].squeeze() pres = nc.variables['PRES'][timeindex, :, :, :].squeeze() * 100 relh = nc.variables['RELH'][timeindex, :, :, :].squeeze() hght = nc.variables['HEIGHT'][timeindex, :, :, :].squeeze() es = wm.claus_clap(temp) qvs = wm.satur_mix_ratio(es, pres) qv = (relh / 100) * qvs dewpt = wm.mixrat_to_td(qv, pres) temp_cross = temp[:, xx, yy] pres_cross = pres[:, xx, yy] relh_cross = relh[:, xx, yy] hght_cross = hght[:, xx, yy] dewpt_cross = dewpt[:, xx, yy] [iz, ix] = np.shape(temp_cross) startp = 100000. capearr = np.zeros_like(temp_cross).astype('f') cinarr = np.zeros_like(temp_cross).astype('f')
pres=data["pres"] temp=data["temp"] dwpt=data["dwpt"] hght=data["hght"] theta=data["thta"] thetae=data["thte"] mixr=data["mixr"] thetav=data["thtv"] winddir=data["drct"] windspeed_kt=data["sknt"] Spd = windspeed_kt*0.514444 # To compute relative humidity, will need saturation mixing ratio. # Saturation mixing ratio depends on saturation vapor pressure and total pressure. es = wm.claus_clap(temp+273.15) esi = wm.claus_clap_ice(temp+273.15) ws = wm.satur_mix_ratio(es, pres*100) wsi = wm.satur_mix_ratio(esi,pres*100) # Calculate vertical derivatives. If you didn't know how to do this, there are numerous resources, including examples within weather_modules.py. # A quick search in Google will also give you some ways to do it. Be resourceful! # Below, I am using forward differencing in z dtemp_dz = ((temp[1::]-temp[0:-1]) / (hght[1::]-hght[0:-1])*10**3)*-1 # K km-1 dtheta_dz = (theta[1::]-theta[0:-1]) / (hght[1::]-hght[0:-1])*10**3 # K km-1 dthetae_dz = (thetae[1::]-thetae[0:-1]) / (hght[1::]-hght[0:-1])*10**3 # K km-1 dws_dz = (ws[1::]-ws[0:-1]) / (hght[1::]-hght[0:-1]) des_dz = (es[1::]-es[0:-1]) / (hght[1::]-hght[0:-1]) temp_k = temp + 273.15 # Convert to Kelvin theta_k = theta + 273.15
indat = np.loadtxt(datadir+infile2, skiprows=1) lats2 = indat[:,0] T2a = indat[:,months2compare[0]] T2b = indat[:,months2compare[1]] [refind2] = np.where(lats==reference_latitude) for ii in range(1,5): if ii == 1: Tnow = T1a if ii == 2: Tnow = T1b if ii == 3: Tnow = T2a if ii == 4: Tnow = T2b esnow = wm.claus_clap(Tnow) # saturation vapor pressure wsnow = (epsi*esnow)/(pres1-esnow) # saturation mixing ratio rhonow = pres1/(Rv*Tnow) # Density # Compute moist adiabatic lapse rate fnow = (( (1 + (Lv*wsnow)/(Rd*Tnow))) / (1.0 + (wsnow*(Lv**2)/(cp*Rv*Tnow**2.0)) ) ) sat_lapse_now = gammad*fnow # Vertical velocity, hydrostatic wnow = -omega/(rhonow*g) print('w in profile %d is %8.5f m s-1' %(ii,wnow[refind])) deltaz_now = (-1.0*deltap)/(rhonow*g) print('Cloud depth is %7.2f m in profile %d' % (deltaz_now[refind],ii))
# The below says to import all functions inside weather_modules.py as wm. So you must use "wm" to access them. import weather_modules as wm # <codecell> T = 10 # degrees Celsius p = 1000 # hPa Rd = 287.0 # The dot makes it a floating point value Rv = 461.0 # <codecell> T = T + 273.15 # Convert to Kelvin p = p * 100 # Convert to Pa # Saturation mixing ratio is a function of saturation vapor pressure and total pressure. Given temperature, we know we can compute saturation vapor pressure: es = wm.claus_clap(T) # Pa print "Saturation vapor pressure is ", es / 100, " hPa" # Now we can compute saturation mixing ratio: epsi = Rd / Rv ws = epsi * (es / (p - es)) * 1000 # Convert to g/kg print "The saturation mixing ratio at ", T - 273.15, " degrees Celsius and ", p / 100, " hPa is ", ws, " g/kg" # <codecell> # Just for fun, let's check to see what the error in saturation mixing ratio is by the approximation we made to the formula. # ws = 0.622*(es/p). ws_approx = epsi * (es / p) * 1000 ws_err = ws - ws_approx print "The error in making the approximation at ", T - 273.15, " degrees Celsius and ", p / 100, " hPa is ", ws_err, " g/kg" # <codecell>
T = 10. # degrees Celsius p = 1000 # hPa Rd = 287. # The dot makes it a floating point value Rv = 461. epsi = Rd / Rv A = (2.53 * 10**(8.0)) * 10**(3.0) # convert to Pa B = 5.42 * 10**(3.0) # Kelvin # In[4]: T = T + 273.15 # Convert to Kelvin p = p * 100. # Convert to Pa # Saturation mixing ratio es = wm.claus_clap(T) # Pa # Let's try the way we computed in class: es_alt = A * np.exp(-B / T) # Calculation in SI units print( 'Saturation vapor pressure is %7.2f hPa from function and %7.2f hPa from above' % (es / 100., es_alt / 100.)) #Now we can compute saturation mixing ratio: ws = epsi * (es / (p - es)) * 1000. # Convert to g/kg print('The saturation mixing ratio at ', T - 273.15, ' degrees Celsius and ', p / 100, ' hPa is ', ws, ' g/kg') # In[5]: # Just for fun, let's check to see what the error in saturation mixing ratio is by the approximation we made to the formula.
cmap_opt = plt.cm.RdBu figname = "erainterim_cross_section_analysis_omega_" + orient elif plot_option == 11: f = netCDF4.Dataset(fpath, 'r') temp_cross = t_plot[:, latinds, loninds].squeeze() pres_cross = p_in[:, latinds, loninds].squeeze() * 100 relh_cross = np.zeros_like(temp_cross).astype('f') relh_cross[2:, :] = f.variables['R_H_3_ISBL_10'][record_num, 1:, latinds, loninds].squeeze() hght_cross = f.variables['HGT_3_ISBL_10'][record_num, :, latinds, loninds].squeeze() f.close es = wm.claus_clap(temp_cross) qvs = wm.satur_mix_ratio(es, pres_cross) qv = (relh_cross / 100) * qvs dewpt_cross = wm.mixrat_to_td(qv, pres_cross) #dewpt_cross = np.zeros_like(temp_cross).astype('f') plot_cross = np.zeros_like(temp_cross).astype('f') [iz, ix] = np.shape(temp_cross) startp = 100000. capearr = np.zeros_like(temp_cross).astype('f') cinarr = np.zeros_like(temp_cross).astype('f') pres_cross2 = pres_cross[::-1, :] temp_cross2 = temp_cross[::-1, :]
########################### # Read file, compute stuff ########################### if read_temperature_fromfile == 'True': ab = np.loadtxt(datadir+infile1, skiprows=0) lats = ab[:,0] T1 = ab[:,1] [refind] = np.where(lats==reference_latitude) print refind else: T1 = np.arange(-40,41,0.25)+273.15 # Virtual temperatures [refind] = np.where(T1 == 273.15) # Check to make sure it read in correctly mstats(T1) es1 = wm.claus_clap(T1) # saturation vapor pressure ws1 = (epsi*es1)/(pres1-es1) # saturation mixing ratio # Compute moist adiabatic lapse rate, first in z-coords sat_lapse = (9.81/cp)*(( (1 + (Lv*ws1)/(Rd*T1))) / (1 + (ws1*(Lv**2)/(cp*Rv*T1**2.0)) ) ) Rho=pres1/(Rv*T1) # Density, moist air sat_lapse_isobaric = -sat_lapse/(Rho*9.81) # Convert to p-coords # Temperature at top of ascent layer (T2) is equal to what it was initially (T1) plus slope (-gamma_m) * deltap T2 = T1 - (sat_lapse_isobaric)*(pres2-pres1) # Convert to Celsius (needed for plot if not reading from file) T1C = T1 - 273.15 T2C = T2 - 273.15 # Convert to K/km and K/hundred hPa
cbar_labels = 'Pa s-1' titlestring = "Vertical velocity " + date_string cmap_opt = plt.cm.RdBu figname = "erainterim_cross_section_analysis_omega_" + orient elif plot_option == 11: f = netCDF4.Dataset(fpath,'r') temp_cross = t_plot[:,latinds,loninds].squeeze() pres_cross = p_in[:,latinds,loninds].squeeze()*100 relh_cross = np.zeros_like(temp_cross).astype('f') relh_cross[2:,:] = f.variables['R_H_3_ISBL_10'][record_num,1:,latinds,loninds].squeeze() hght_cross = f.variables['HGT_3_ISBL_10'][record_num,:,latinds,loninds].squeeze() f.close es = wm.claus_clap(temp_cross) qvs = wm.satur_mix_ratio(es, pres_cross) qv = (relh_cross/100)*qvs dewpt_cross = wm.mixrat_to_td(qv, pres_cross) #dewpt_cross = np.zeros_like(temp_cross).astype('f') plot_cross = np.zeros_like(temp_cross).astype('f') [iz,ix] = np.shape(temp_cross) startp = 100000. capearr = np.zeros_like(temp_cross).astype('f') cinarr = np.zeros_like(temp_cross).astype('f') pres_cross2 = pres_cross[::-1,:]