# net atm radiative and turbulent flux net = swdn_toa - swup_toa - olr + swup_sfc + lwup_sfc - swdn_sfc - lwdn_sfc + shflx + LE * evap net_atm[yri * 12 + moni, :, :] = np.mean(net, 0) nt = vcomp.shape[0] # calculate pressure phalf = grid.calcSigmaPres(ps, pk, bk) pfull = 0.5 * (phalf[:, 1:, :, :] + phalf[:, :-1, :, :]) dp = (phalf[:, 1:, :, :] - phalf[:, :-1, :, :])[:, ptop:, :, :] #%% # calculate MSE (subtract mean) MSE = CP_AIR * temp + GRAV * hght + LE * sphum - LF * ice_wat ene = CV_AIR * temp + GRAV * hght + LE * sphum - LF * ice_wat MSEm = np.sum(MSE * dp, 1) / np.sum(dp, 1) MSEm = np.mean(MSEm, 0) area = grid.calcGridArea(lat, lon) MSEm = np.sum(MSEm * area) / np.sum(area) # MSEm = np.mean(MSE[:,:,:,:]) MSE = MSE - MSEm # calculate dp dpMon = np.mean(dp, 0) dpMC[yri * 12 + moni, :, :, :] = dpMon pfullMC[yri * 12 + moni, :, :, :] = np.mean(pfull, 0) MSECol = np.sum(MSE * dpMon, 1) / GRAV dMSE[yri * 12 + moni, :, :] = (MSECol[-1, ...] - MSECol[0, ...]) / (np.size(mind) * 86400) eneCol = np.sum(MSE * dpMon, 1) / GRAV dene[yri * 12 + moni, :, :] = (eneCol[-1, ...] - eneCol[0, ...]) / (np.size(mind) * 86400)
filename = outdir+'dim.'+pert[0]+'.npz' npz = np.load(filename) lat = npz['lat'] nlat = np.size(lat) ntime = 100 tmp = np.zeros([npert,ntime,nlat]) t_ref = np.zeros([npert,ntime,nlat]) precip = np.zeros([npert,ntime,nlat]) netrad_toa = np.zeros([npert,ntime,nlat]) ind = range(npert) for i in ind: filename = outdir+outdir_sub+diag+'.'+time+'.'+pert[i]+'.npz' npz = np.load(filename) t_ref[i,:,:] = npz[var][:,:] area = grid.calcGridArea(lat,1) area.shape = [1,1,nlat] t_ref_gm = np.sum(t_ref*area,2)/np.sum(area) precip_gm = np.sum(precip*area,2) netrad_toa_gm = np.sum(netrad_toa*area,2)/np.sum(area) #tmp_gm = np.sum(tmp*weight1,2) sc = 1 z = np.zeros([npert,2]) plt.figure() for i in ind: x = t_ref_gm[i,:]-t_ref_gm[0,:] plt.plot(x) print np.mean(x[80:])
lon = fs[-1].variables['lon'][:].astype(np.float64) nlat = np.size(lat) nlon = np.size(lon) #phalf = fs[-1].variables['phalf'][:].astype(np.float64) #zsurf = fs[-1].variables['zsurf'][:].astype(np.float64) if ('land_mask' in fs[-1].variables): land_mask = fs[-1].variables['land_mask'][:].astype(np.float64) fs[-1].close() #%% filedir = atmdir+indir_sub files = [] for fi in range(nfile): filename = filedir+diag+'.'+yrstr[fi]+'.nc' files.append(filename) ts = pp.ts_multi_files(files,var,0) ts = np.array(ts) #%% if (flag != ''): ts = pp.month_to_year(ts,yr_ts,flag) if zm: ts_zon = np.mean(ts,-1) if gm: area = grid.calcGridArea(lat,lon) area.shape = [1,nlat,nlon] ts_glb = np.sum(ts*area,-1) ts_glb = np.sum(ts_glb,-1) ts_glb = ts_glb/np.sum(area) print ts_glb plt.plot(ts_zon[0,:]-ts_zon[0,0]) plt.legend(pert,fontsize=10)
npz = np.load(filename) lat = npz['lat'] nlat = np.size(lat) ntime = 100 tmp = np.zeros([npert,ntime,nlat]) t_ref = np.zeros([npert,ntime,nlat]) precip = np.zeros([npert,ntime,nlat]) netrad_toa = np.zeros([npert,ntime,nlat]) ind = range(npert) for i in ind: filename = outdir+outdir_sub+diag+'.'+time+'.'+pert[i]+'.npz' npz = np.load(filename) t_ref[i,:,:] = npz[var1] netrad_toa[i,:,:] = npz[var2] area = grid.calcGridArea(lat,1) area.shape = [1,1,nlat] t_ref_gm = np.sum(t_ref*area,2)/np.sum(area) precip_gm = np.sum(precip*area,2)/np.sum(area) netrad_toa_gm = np.sum(netrad_toa*area,2)/np.sum(area) #tmp_gm = np.sum(tmp*weight1,2) sc = 1 z = np.zeros([npert,2]) plt.figure() for i in range(1,npert): x = (t_ref_gm[i,:]-t_ref_gm[0,:])[:20] y = (netrad_toa_gm[i,:]-netrad_toa_gm[0,:])[:20] plt.scatter(x,y)