nbins = [rbins, zbins] print 'calculating z-r plots' for varname in varnames: print 'loading', varname vari = varis3D[varname] field = varis3D[varname][t3 - aveperiod3D:t3, :, :, :] field_tave = np.mean(field, axis=0) #calculate relative humidity if varname == 'TABS': varname = 'RH' QV = varis3D['QV'][t3 - aveperiod3D:t3, :, :, :] QV_tave = np.mean(QV, axis=0) RH_tave = np.zeros(QV_tave.shape) for i, plev in enumerate(p): wsat_tave = 1000 * wsat(field_tave[i, :, :], plev) #convert to g/kg RH_tave[i, :, :] = 100 * (QV_tave[i, :, :] / wsat_tave ) #convert to percent field_tave = RH_tave #calculate wind speed if varname == 'U': V = varis3D['V'][t3 - aveperiod3D:t3, :, :, :] #V = V[ntrunc:,:,:,:] #U = varis3D['U'][t3-aveperiod3D:t3,:,:,:] #U = U[ntrunc:,:,:,:] field = np.sqrt(np.power(V, 2) + np.power(field, 2)) #field_tmp = field.reshape(nt3D/ntave3D, ntave3D, nz, nx, ny) #field_tave = np.mean(field_tmp, axis=1) print 'calculating temporal averages' #average over nave days #field_t = np.mean(field[t-nave3D:t,:,:,:], axis=0)
nbins=[rbins, zbins] print 'calculating z-r plots' for varname in varnames: print 'loading', varname vari = varis3D[varname] field = varis3D[varname][t3-aveperiod3D:t3,:,:,:] field_tave = np.mean(field, axis=0) #calculate relative humidity if varname == 'TABS': varname = 'RH' QV = varis3D['QV'][t3-aveperiod3D:t3,:,:,:] QV_tave = np.mean(QV, axis=0) RH_tave = np.zeros(QV_tave.shape) for i, plev in enumerate(p): wsat_tave = 1000*wsat(field_tave[i,:,:], plev) #convert to g/kg RH_tave[i,:,:] = 100*(QV_tave[i,:,:]/wsat_tave) #convert to percent field_tave = RH_tave #calculate wind speed if varname == 'U': V = varis3D['V'][t3-aveperiod3D:t3,:,:,:] #V = V[ntrunc:,:,:,:] #U = varis3D['U'][t3-aveperiod3D:t3,:,:,:] #U = U[ntrunc:,:,:,:] field = np.sqrt(np.power(V, 2) + np.power(field, 2)) #field_tmp = field.reshape(nt3D/ntave3D, ntave3D, nz, nx, ny) #field_tave = np.mean(field_tmp, axis=1) print 'calculating temporal averages' #average over nave days #field_t = np.mean(field[t-nave3D:t,:,:,:], axis=0) #calculate adiabatic warming + QRAD balance
nbins=[rbins, zBL] print 'calculating z-r plots' for varname in varnames: print 'loading', varname vari = varis3D[varname] field = varis3D[varname][t3-aveperiod3D:t3,:,:,:] field_tave = np.mean(field, axis=0) #calculate relative humidity if varname == 'TABS': varname = 'RH' QV = varis3D['QV'][t3-aveperiod3D:t3,:,:,:] QV_tave = np.mean(QV, axis=0) RH_tave = np.zeros(QV_tave.shape) for i, plev in enumerate(p): wsat_tave = 1000*wsat(field_tave[i,:,:], plev) #convert to g/kg RH_tave[i,:,:] = 100*(QV_tave[i,:,:]/wsat_tave) #convert to percent field_tave = RH_tave #calculate wind speed if varname == 'U': V = varis3D['V'][t3-aveperiod3D:t3,:,:,:] #V = V[ntrunc:,:,:,:] #U = varis3D['U'][t3-aveperiod3D:t3,:,:,:] #U = U[ntrunc:,:,:,:] field = np.sqrt(np.power(V, 2) + np.power(field, 2)) #field_tmp = field.reshape(nt3D/ntave3D, ntave3D, nz, nx, ny) #field_tave = np.mean(field_tmp, axis=1) print 'calculating temporal averages' #average over nave days #field_t = np.mean(field[t-nave3D:t,:,:,:], axis=0) #calculate adiabatic warming + QRAD balance
dsdz = (s[1:,:,:] - s[:-1,:,:])/(diffz3D) W_adb = (c.cp*QRAD_tave[:-1,:,:])/(dsdz*3600*24) W_diab = W_tave[:-1,:,:] - blockave3D(W_adb, db) field_tave = W_diab #calculate RH elif varname == 'TABS': varname = 'RH' QV = varis3D['QV'][t3-aveperiod3D:t3,:,:,:] QV_tave = np.mean(QV, axis=0) TABS = varis3D['TABS'][t3-aveperiod3D:t3,:,:,:] TABS_tave = np.mean(TABS, axis=0) RH_tave = np.zeros(QV_tave.shape) for pi, plev in enumerate(p): wsat_tave = 1000*wsat(TABS_tave[pi,:,:], plev) #convert to g/kg RH_tave[pi,:,:] = 100*(QV_tave[pi,:,:]/wsat_tave) #convert to percent field_tave = RH_tave field_tave = blockave3D(field_tave, db) elif varname == 'VERTMASSFLUX': w = varis3D['W'][t3-aveperiod3D:t3,:,:,:] T = varis3D['TABS'][t3-aveperiod3D:t3,:,:,:] nt = T.shape[0] p3D = np.zeros((ny, nx, nz)) p3D[:,:,:] = p p3D = p3D[:,:,:,np.newaxis] p4D = np.tile(p3D,nt) p4D = p4D.T gc.collect() rho = p4D/(T*c.Rd)
y = varis2D['y'][:] p = varis3D['p'][:] p = p * 1e2 #z = varis3D['z'][:] #p = varis3D['p'][:] #p = p*1e2 W = varis3D['W'][t - aveperiod3D:t, :, :, :] W_tave = np.mean(W, axis=0) QV = varis3D['QV'][t - aveperiod3D:t, :, :, :] QV_tave = np.mean(QV, axis=0) TABS = varis3D['TABS'][t - aveperiod3D:t, :, :, :] TABS_tave = np.mean(TABS, axis=0) RH_tave = np.zeros(QV_tave.shape) for pi, plev in enumerate(p): wsat_tave = 1000 * wsat(TABS_tave[pi, :, :], plev) #convert to g/kg RH_tave[pi, :, :] = 100 * (QV_tave[pi, :, :] / wsat_tave ) #convert to percent RH_tave = blockave3D(RH_tave, db) W_tave = blockave3D(W_tave, db) #Wvertbar = np.mean(np.mean(W, axis=0),axis=0) #Wblock = blockave2D(Wvertbar, db) #W500 = varis2D['W500'][t-aveperiod:t,:,:] #W500_tave = np.mean(W500, axis=0) #W500_block = blockave2D(W500_tave, db) #nt3D = t3D.size #nz = z.size
p = varis3D['p'][:] z = varis3D['z'][:] x = varis['x'][:] y = varis['y'][:] xx, yy = np.meshgrid(x, y) nz = z.size nx = x.size ny = y.size t = -1 p_s = p[0] T_s = varisSTAT['TABS'][t, 0] q_sat = wsat(T_s, p_s * 1e2) Tenv = varis3D['TABS'][t, :, :, :] QV = varis3D['QV'][t, :, :, :] QV = QV * 1e-3 Tenv_ave = np.mean(np.mean(Tenv, axis=2), axis=1) thetae0 = thermo.theta_e(T_s, p_s * 1e2, q_sat, 0) #theta_e in moist region Tadiabat = findTmoist(thetae0, p * 1e2) qvadiabat = [] for i, plev in enumerate(p * 1e2):
nbins=[rbins, zBL] print 'calculating z-r plots' for varname in varnames: print 'loading', varname vari = varis3D[varname] field = varis3D[varname][t3-aveperiod3D:t3,:,:,:] field_tave = np.mean(field, axis=0) #calculate relative humidity if varname == 'TABS': varname = 'RH' QV = varis3D['QV'][t3-aveperiod3D:t3,:,:,:] QV_tave = np.mean(QV, axis=0) RH_tave = np.zeros(QV_tave.shape) for j, plev in enumerate(p): wsat_tave = 1000*wsat(field_tave[j,:,:], plev) #convert to g/kg RH_tave[j,:,:] = 100*(QV_tave[j,:,:]/wsat_tave) #convert to percent field_tave = RH_tave #calculate wind speed if varname == 'U': V = varis3D['V'][t3-aveperiod3D:t3,:,:,:] #V = V[ntrunc:,:,:,:] #U = varis3D['U'][t3-aveperiod3D:t3,:,:,:] #U = U[ntrunc:,:,:,:] field = np.sqrt(np.power(V, 2) + np.power(field, 2)) #field_tmp = field.reshape(nt3D/ntave3D, ntave3D, nz, nx, ny) #field_tave = np.mean(field_tmp, axis=1) print 'calculating temporal averages' #average over nave days #field_t = np.mean(field[t-nave3D:t,:,:,:], axis=0) #calculate adiabatic warming + QRAD balance
p_s = 1000e2 def findT(T_s, p): zeta = -h * (np.log(p / p_s)) if (zeta < zeta_T): T = T_s - gamma_PH * zeta else: T = T_s - gamma_PH * zeta_T return T qv_s = np.zeros(p.size) for i, plev in enumerate(p): qv = wsat(findT(T_s, plev), p_s) qv_s[i] = qv * 1e3 interior = np.bitwise_and(z > z_BL, z < z_t) zint = z[interior] moist_prof = moist_prof[interior] dry_prof = dry_prof[interior] moist_profave = np.mean(moist_prof) dry_profave = np.mean(dry_prof) qv_s = qv_s[interior] plt.figure() f, axarr = plt.subplots(2, 1) plt.suptitle(
p_s = 1000e2 def findT(T_s, p): zeta = -h*(np.log(p/p_s)) if (zeta < zeta_T): T = T_s - gamma_PH*zeta else: T = T_s - gamma_PH*zeta_T return T qv_s = np.zeros(p.size) for i, plev in enumerate(p): qv = wsat(findT(T_s, plev), p_s) qv_s[i] = qv*1e3 interior = np.bitwise_and(z > z_BL, z < z_t) zint = z[interior] moist_prof = moist_prof[interior] dry_prof = dry_prof[interior] moist_profave = np.mean(moist_prof) dry_profave = np.mean(dry_prof) qv_s = qv_s[interior] plt.figure() f, axarr = plt.subplots(2,1) plt.suptitle(r'{:s} ({:s}), day {:3.0f} to {:3.0f} average, domain size = {:d} km$^2$, convective region {:s} threshold = {:2.1f} {:s} '.format(varname, units, t3D[0], t3D[-1], domsize, mvarname, mfieldcrit, mvar.units.strip()))
tdouble = 90 nc_data1 = Dataset(nc_in1) nc_data2 = Dataset(nc_in2) nc_data3 = Dataset(nc_in3) #nc_data4 = Dataset(nc_in4) nc_vars1 = nc_data1.variables nc_vars2 = nc_data2.variables nc_vars3 = nc_data3.variables #nc_vars4 = nc_data4.variables T_s = 302 p_s = 1000e2 q_sat = wsat(T_s, p_s) #mixing ratio above sea surface (100% saturated) thetae0 = thermo.theta_e(T_s, p_s, q_sat, 0) #theta_e in moist region #use surface temperature to get moist adiaba z1 = nc_vars1['z'][:] z2 = nc_vars2['z'][:] z3 = nc_vars3['z'][:] #z4 = nc_vars4['z'][:] p1 = nc_vars1['p'][:] p2 = nc_vars2['p'][:] p3 = nc_vars3['p'][:] #p4 = nc_vars4['p'][:] t1 = nc_vars1['time'][:] t2 = nc_vars2['time'][:]