pert = ['LU'] npert = np.size(pert) ens = ['_A1','_A2','_A3','_A4','_A5'] nens = np.size(ens) diag = 'var2d' var = ['t_ref'] #var = ['salt_col','dust_col'] """ var = ['swdn_sfc','swup_sfc','swdn_toa','swup_toa',\ 'swdn_sfc_clr','swup_sfc_clr','swdn_toa_clr','swup_toa_clr',\ 'lwdn_sfc','lwdn_sfc_clr','lwup_sfc','lwup_sfc_clr','olr','olr_clr',\ 'evap','shflx','netrad_toa','netrad_toa_clr'] """ nvar = np.size(var) time = '1870-2015' for vi in range(nvar): for i in range(npert): filename = indir+indir_sub+diag+'.'+time+'.'+pert[i]+ens[0]+'.npz' npz = np.load(filename) tmp = npz[var[vi]] av = np.zeros(tmp.shape+(nens,)) for j in range(nens): filename = indir+indir_sub+diag+'.'+time+'.'+pert[i]+ens[j]+'.npz' npz = np.load(filename) av[...,j] = npz[var[vi]] av = np.mean(av,-1) outfile = outdir+outdir_sub+diag+'.'+time+'.'+pert[i]+'_mean'+'.npz' fio.save(outfile,**{var[vi]:av}) print var[vi]
for i in range(ts_ann.shape[0]): nan_ind = np.where(np.isnan(ts_ann[i,:,:])) land_mask[0,nan_ind[0],nan_ind[1]] = 0 ts_ann[np.where(np.isnan(ts_ann))]=0 ts_gm = np.sum(np.nansum(ts_ann*area*land_mask,-1),-1)/np.nansum(area*land_mask) land_mask.shape = (nlat,nlon) area.shape = (nlat,nlon) weight = area/np.sum(area) """ if zm: ts = np.mean(ts,-1) #%% if init: outfile = outdir+'dim.'+obs+'.npz' fio.save(outfile,lat=lat,lon=lon,land_mask=land_mask) if init3d: tmp = nc.netcdf_file(files[-1],'r',mmap=True) pfull = tmp.variables['pfull'][:].astype(np.float64) outfile = outdir+'dim.'+obs+'.npz' fio.save(outfile,pfull=pfull) ts_flag = ts.copy() for flagi in range(nflag): if (flag[flagi] != ''): ts_flag = pp.month_to_year(ts,yr_ts,flag[flagi]) outdir_sub='ts/'+sub_dict[flag[flagi]]+'/' outfile = outdir+outdir_sub+diago+'.'+timeo+'.'+obs+'.npz' fio.save(outfile,**{varo:ts_flag})
var = fs[-1].variables[var_name][500:,:,:,:].astype(np.float64) #t,p,lat,lon ps = fs[-1].variables['ps'][500:,:,:].astype(np.float64) fs[-1].close() var_tr = var-np.mean(var,-1)[...,np.newaxis] power = np.abs(fft.fft(var_tr,axis=-1))**2 phalf = grid.calcSigmaPres(ps,pk,bk) dp = (phalf[:,1:,:,:]-phalf[:,:-1,:,:]) dp_m = np.mean(dp,-1)[...,np.newaxis] power_col = np.sum(power*dp,1)/np.sum(dp,1) power_m = np.mean(power_col,0)[:,:nlon/2] k = np.arange(0,nlon/2) k_m = np.sum(power_m*k,-1)/np.sum(power_m,-1) L[si,:] = 2*np.pi*RADIUS*np.cos(lat*np.pi/180.)/k_m if init: outfile = outdir+'dim.'+perto[si]+'.npz' fio.save(outfile,lat=lat,lon=lon,phalf=phalf) if init3d: pfull = fs[-1].variables['pfull'][:].astype(np.float64) outfile = outdir+'dim.'+perto[si]+'.npz' fio.save(outfile,pfull=pfull) #outfile = outdir+'av/'+diago+'.'+perto[si]+'.npz' #fio.save(outfile,**{varo_name:tr_zm}) #%% """ Tot1 = (MMC+St+Tr) xsc = 2*np.pi*Rad*np.cos(lat/90*np.pi/2) xsc.shape = [1,nlat] clev = np.arange(-7,8,1)*1e15 plt.figure(figsize=[4*6/3,4])
ind = np.where(np.isinf(ratio1)) ratio1[ind] = 0 ratio.shape = (nt,1,nlat,1) ratio1.shape = (nt,1,nlat,1) vAdj = vPos*np.sqrt(ratio1)+vNeg*np.sqrt(ratio) """ vMSE_ed1 = np.sum(vcomp_ed * MSE_m * dp_ed, 1) / GRAV vMSEcol_Ed1 = np.mean(np.mean(vMSE_ed1, -1), 0) vMSE_ed2 = np.sum(vcomp_m * MSE_ed * dp_ed, 1) / GRAV vMSEcol_Ed2 = np.mean(np.mean(vMSE_ed2, -1), 0) vMSE_ed3 = np.sum(vcomp_ed * MSE_ed * dp_ed, 1) / GRAV vMSEcol_Ed3 = np.mean(np.mean(vMSE_ed3, -1), 0) if init: outfile = outdir + 'dim.' + perto[si] + '.npz' fio.save(outfile, lat=lat, lon=lon) if init3d: pfull = fs[-1].variables['pfull'][:].astype(np.float64) outfile = outdir + 'dim.' + perto[si] + '.npz' fio.save(outfile, pfull=pfull) outfile = outdir + 'av/' + diago + '.' + perto[si] + '.npz' fio.save(outfile,\ vMSETot_col_zm=vMSEcol_Tot,vMSEMMC_col_zm=vMSEcol_MMC,vMSEEd_col_zm=vMSEcol_Ed) #%% """ plt.figure() plt.contourf(lat,pfull,np.mean(np.mean(vcomp_m,-1),0),cmap=plt.cm.RdYlBu_r) plt.gca().invert_yaxis() plt.colorbar() """ #%%
nlat = np.size(lat) nlon = np.size(lon) nlev = np.size(phalf) #%% filename = atmdir+'00000.atmos_daily.nc' fs.append(nc.netcdf_file(filename,'r',mmap=True)) var1 = fs[-1].variables[var1_name][500:,:,:,:].astype(np.float64) #t,p,lat,lon var2 = fs[-1].variables[var2_name][500:,:,:,:].astype(np.float64) #t,p,lat,lon var1_tr = var1-np.mean(var1,-1)[...,np.newaxis] var2_tr = var2-np.mean(var2,-1)[...,np.newaxis] tr = var1_tr*var2_tr tr_zm = np.mean(tr,-1) tr_zm = np.mean(tr_zm,0) if init: outfile = outdir+'dim.'+perto[si]+'.npz' fio.save(outfile,lat=lat,lon=lon,phalf=phalf) if init3d: pfull = fs[-1].variables['pfull'][:].astype(np.float64) outfile = outdir+'dim.'+perto[si]+'.npz' fio.save(outfile,pfull=pfull) outfile = outdir+'av/'+diago+'.'+perto[si]+'.npz' fio.save(outfile,**{varo_name:tr_zm}) #%% """ Tot1 = (MMC+St+Tr) xsc = 2*np.pi*Rad*np.cos(lat/90*np.pi/2) xsc.shape = [1,nlat] clev = np.arange(-7,8,1)*1e15 plt.figure(figsize=[4*6/3,4])
lat = fs[-1].variables['lat'][:].astype(np.float64) lon = fs[-1].variables['lon'][:].astype(np.float64) phalf = fs[-1].variables['phalf'][:].astype(np.float64) zsurf = fs[-1].variables['zsurf'][:].astype(np.float64) fs[-1].close() nlat = np.size(lat) nlon = np.size(lon) nphalf = np.size(phalf) #%% filedir = atmdir + 'ts/daily/1yr/' yr = np.arange(1, 10, 1) nyr = np.size(yr) data = np.zeros([nyr, nphalf - 1, nlat]) #tmpZon = np.zeros([nmon,nlev-1,nlat]) #phalfZon = np.zeros([nmon,nlev,nlat]) for yri in range(nyr): yrC = '000' + str(yr[yri]) + '0101-' + '000' + str(yr[yri]) + '1231.' filename = filedir + diag + '.' + yrC + var + '.nc' fs.append(nc.netcdf_file(filename, 'r', mmap=True)) #pfull = fs[-1].variables['pfull'][:].astype(np.float64) tmp = fs[-1].variables[var][:].astype(np.float64) #t,p,lat,lon #tmp[np.where(tmp<-999)] = np.nan tmp = np.mean(tmp, 3) data[yri, :, :] = np.mean(tmp, 0) fs[-1].close() #%% #outfile = outdir+'dim.'+perto[i]+'_sigma.npz' #fio.save(outfile,lat=lat,lon=lon,phalf=phalf,pfull=pfull) outfile = outdir + diago + '.' + perto[i] + '_sigma.npz' fio.save(outfile, **{varo: data})
nlat = np.size(lat) nlon = np.size(lon) nphalf = np.size(phalf) #%% filedir = atmdir+indir_sub files = [] for fi in range(nfile): filename = filedir+diag+'.'+yrstr[fi]+'ann.nc' files.append(filename) ts = pp.ts_multi_files(files,var[vi],0) if zm: ts = np.nanmean(ts,-1) #%% if init and vi==0: outfile = outdir+'dim.'+simo[i]+'.npz' fio.save(outfile,lat=lat,lon=lon,phalf=phalf,land_mask=land_mask,year=yr) if init3d: tmp = nc.netcdf_file(files[-1],'r',mmap=True) pfull = tmp.variables['pfull'][:].astype(np.float64) outfile = outdir+'dim.'+simo[i]+'.npz' fio.save(outfile,pfull=pfull) if init3dp: tmp = nc.netcdf_file(files[-1],'r',mmap=True) level = tmp.variables['level'][:].astype(np.float64) outfile = outdir+'dim.'+simo[i]+'.npz' fio.save(outfile,level=level) for flagi in range(nflag): ts_flag = ts outdir_sub='ts/'+sub_dict[flag[flagi]]+'/' if (flag[flagi] != ''): ts_flag = pp.month_to_year(ts,flag[flagi])
time1 = '1870-2015' time2 = '1870-2014' for si in range(nsim): grid_inf = indir+'dim.'+sim[0]+'.npz' npz = np.load(grid_inf) lat_in = npz['lat'] lon_in = npz['lon'] filename = indir+indir_sub+diag+'.'+time1+'.'+sim[si]+'.npz' npz = np.load(filename) tmp_in = npz[var] ntime = np.shape(tmp_in)[0] grid_outf = outdir+'dim.'+sim[0]+'.npz' npz = np.load(grid_outf) lat_out = npz['lat'] nlat = np.size(lat_out) lon_out = npz['lon'] nlon = np.size(lon_out) (lonm_out,latm_out) = np.meshgrid(lon_out,lat_out) tmp_out = np.zeros((ntime-1,nlat,nlon)) for ti in range(ntime-1): (lonm_in,latm_in) = np.meshgrid(lon_in,lat_in) """ tmp_rbf = interp.Rbf(latm_in,lonm_in,tmpt[ti,:,:],function='linear',smooth=0) tmp_out[ti,:,:] = tmp_rbf(latm_out,lonm_out) """ tmp_out[ti,:,:] = \ interp.griddata(np.array([latm_in.ravel(),lonm_in.ravel()]).T,\ tmp_in[ti,:,:].ravel(),(latm_out,lonm_out),method='nearest') outfile = outdir+outdir_sub+diag+'.'+time2+'.'+sim[si]+'.npz' fio.save(outfile,**{var:tmp_out}) print sim[si]
pfull = fs[-1].variables['pfull'][:].astype(np.float64) #zsurf = fs[-1].variables['zsurf'][:].astype(np.float64) fs[-1].close() #%% filename = atmdir+'00000.atmos_daily.nc' fs.append(nc.netcdf_file(filename,'r',mmap=True)) temp = fs[-1].variables['temp'][500:,:,:,:].astype(np.float64) #t,p,lat,lon q = fs[-1].variables['mix_rat'][500:,:,:,:].astype(np.float64) pfull.shape = (1,20,1,1) theta = temp*(p0/pfull)**(Rair/Cp) thetae = theta*np.exp(sc[i]*Le*q/(Cp*temp)) temp_zm = np.mean(np.mean(temp,3),0) theta_zm = np.mean(np.mean(theta,3),0) thetae_zm = np.mean(np.mean(thetae,3),0) pfull.shape = (20) tmp = fs[-1].variables[var][500:,:,:,:].astype(np.float64) tmp_zm = np.mean(np.mean(tmp,3),0) if init: outfile = outdir+'dim.'+perto[i]+'.npz' fio.save(outfile,lat=lat,lon=lon) if init3d: pfull = fs[-1].variables['pfull'][:].astype(np.float64) outfile = outdir+'dim.'+perto[i]+'.npz' fio.save(outfile,pfull=pfull,phalf=phalf) outfile = outdir+'av/'+diago+'.'+perto[i]+'.npz' fio.save(outfile,**{varo:tmp_zm}) fio.save(outfile,temp_zm=temp_zm,theta_zm=theta_zm,thetae_zm=thetae_zm)
nlev = np.size(phalf) #%% filename = atmdir + '00000.atmos_daily.nc' fs.append(nc.netcdf_file(filename, 'r', mmap=True)) var1 = fs[-1].variables[var1_name][500:, :, :, :].astype( np.float64) #t,p,lat,lon var2 = fs[-1].variables[var2_name][500:, :, :, :].astype( np.float64) #t,p,lat,lon var1_tr = var1 - np.mean(var1, -1)[..., np.newaxis] var2_tr = var2 - np.mean(var2, -1)[..., np.newaxis] tr = var1_tr * var2_tr tr_zm = np.mean(tr, -1) tr_zm = np.mean(tr_zm, 0) if init: outfile = outdir + 'dim.' + perto[si] + '.npz' fio.save(outfile, lat=lat, lon=lon, phalf=phalf) if init3d: pfull = fs[-1].variables['pfull'][:].astype(np.float64) outfile = outdir + 'dim.' + perto[si] + '.npz' fio.save(outfile, pfull=pfull) outfile = outdir + 'av/' + diago + '.' + perto[si] + '.npz' fio.save(outfile, **{varo_name: tr_zm}) #%% """ Tot1 = (MMC+St+Tr) xsc = 2*np.pi*Rad*np.cos(lat/90*np.pi/2) xsc.shape = [1,nlat] clev = np.arange(-7,8,1)*1e15 plt.figure(figsize=[4*6/3,4])
bk = fs[-1].variables['bk'][:].astype(np.float64) pk = fs[-1].variables['pk'][:].astype(np.float64) lat = fs[-1].variables['lat'][:].astype(np.float64) lon = fs[-1].variables['lon'][:].astype(np.float64) phalf = fs[-1].variables['phalf'][:].astype(np.float64) zsurf = fs[-1].variables['zsurf'][:].astype(np.float64) fs[-1].close() nlat = np.size(lat) nlon = np.size(lon) nphalf = np.size(phalf) #%% filedir = atmdir+indir_sub files = [] for fi in range(nfile): filename = filedir+diag+'.'+yrstr[fi]+'.nc' files.append(filename) av = pp.av_multi_files(files,var,0) av = np.mean(av,-1) #%% if init: outfile = outdir+'dim.'+perto[i]+'.npz' fio.save(outfile,lat=lat,lon=lon,phalf=phalf) if init3d: tmp = nc.netcdf_file(files[-1],'r',mmap=True) pfull = tmp.variables['pfull'][:].astype(np.float64) outfile = outdir+'dim.'+perto[i]+'.npz' fio.save(outfile,pfull=pfull) outfile = outdir+outdir_sub+diago+'.'+perto[i]+'.npz' fio.save(outfile,**{varo:av})
time1 = '1870-2015' time2 = '1870-2014' for si in range(nsim): grid_inf = indir + 'dim.' + sim[0] + '.npz' npz = np.load(grid_inf) lat_in = npz['lat'] lon_in = npz['lon'] filename = indir + indir_sub + diag + '.' + time1 + '.' + sim[si] + '.npz' npz = np.load(filename) tmp_in = npz[var] ntime = np.shape(tmp_in)[0] grid_outf = outdir + 'dim.' + sim[0] + '.npz' npz = np.load(grid_outf) lat_out = npz['lat'] nlat = np.size(lat_out) lon_out = npz['lon'] nlon = np.size(lon_out) (lonm_out, latm_out) = np.meshgrid(lon_out, lat_out) tmp_out = np.zeros((ntime - 1, nlat, nlon)) for ti in range(ntime - 1): (lonm_in, latm_in) = np.meshgrid(lon_in, lat_in) """ tmp_rbf = interp.Rbf(latm_in,lonm_in,tmpt[ti,:,:],function='linear',smooth=0) tmp_out[ti,:,:] = tmp_rbf(latm_out,lonm_out) """ tmp_out[ti,:,:] = \ interp.griddata(np.array([latm_in.ravel(),lonm_in.ravel()]).T,\ tmp_in[ti,:,:].ravel(),(latm_out,lonm_out),method='nearest') outfile = outdir + outdir_sub + diag + '.' + time2 + '.' + sim[si] + '.npz' fio.save(outfile, **{var: tmp_out}) print sim[si]
nens = np.size(ens) diag = 'var2d' var = ['precip', 'low_cld_amt'] #var = ['salt_col','dust_col'] """ var = ['swdn_sfc','swup_sfc','swdn_toa','swup_toa',\ 'swdn_sfc_clr','swup_sfc_clr','swdn_toa_clr','swup_toa_clr',\ 'lwdn_sfc','lwdn_sfc_clr','lwup_sfc','lwup_sfc_clr','olr','olr_clr',\ 'evap','shflx','netrad_toa','netrad_toa_clr'] """ nvar = np.size(var) time = '1870-2015' for vi in range(nvar): for i in range(npert): filename = indir + indir_sub + diag + '.' + time + '.' + pert[i] + ens[ 0] + '.npz' npz = np.load(filename) tmp = npz[var[vi]] av = np.zeros(tmp.shape + (nens, )) for j in range(nens): filename = indir + indir_sub + diag + '.' + time + '.' + pert[ i] + ens[j] + '.npz' npz = np.load(filename) av[..., j] = npz[var[vi]] av = np.mean(av, -1) outfile = outdir + outdir_sub + diag + '.' + time + '.' + pert[ i] + '_mean' + '.npz' fio.save(outfile, **{var[vi]: av}) print var[vi]
nphalf = np.size(phalf) #%% filedir = atmdir + indir_sub files = [] for fi in range(nfile): filename = filedir + diag + '.' + yrstr[fi] + 'ann.nc' files.append(filename) ts = pp.ts_multi_files(files, var[vi], 0) if zm: ts = np.nanmean(ts, -1) #%% if init and vi == 0: outfile = outdir + 'dim.' + simo[i] + '.npz' fio.save(outfile, lat=lat, lon=lon, phalf=phalf, land_mask=land_mask, year=yr) if init3d: tmp = nc.netcdf_file(files[-1], 'r', mmap=True) pfull = tmp.variables['pfull'][:].astype(np.float64) outfile = outdir + 'dim.' + simo[i] + '.npz' fio.save(outfile, pfull=pfull) if init3dp: tmp = nc.netcdf_file(files[-1], 'r', mmap=True) level = tmp.variables['level'][:].astype(np.float64) outfile = outdir + 'dim.' + simo[i] + '.npz' fio.save(outfile, level=level) for flagi in range(nflag): ts_flag = ts outdir_sub = 'ts/' + sub_dict[flag[flagi]] + '/'
ens = ['A1','A2','A3','A4','A5'] npert = np.size(pert) nens = np.size(ens) sim = [] for i in range(npert): for j in range(nens): sim.append(pert[i]+ens[j]) nsim = np.size(sim) #npert = 4 diag = 'rad2d.' time = '1870-2015.' #tmp = np.zeros([12,24,90]) var = ['swup_toa','swdn_toa','olr'] #varo = ['z500','pv500'] nvar = np.size(var) for si in range(nsim): filename = basedir+diag+time+sim[si]+'.npz' npz = np.load(filename) netrad_toa= npz['swdn_toa']-npz['swup_toa']-npz['olr'] fio.save(filename,netrad_toa=netrad_toa) for vi in range(nvar): filename = basedir+diag+time+sim[si]+'.npz' npz = np.load(filename) #tmp = npz[var[vi]] #fio.save(outfile,**{var[vi]:tmp}) if var[vi] in npz.keys(): fio.delete(filename,var[vi]) #fio.delete(filename,'pv500') print sim[si]
lon = fs[-1].variables['lon'][:].astype(np.float64) phalf = fs[-1].variables['phalf'][:].astype(np.float64) zsurf = fs[-1].variables['zsurf'][:].astype(np.float64) fs[-1].close() nlat = np.size(lat) nlon = np.size(lon) nphalf = np.size(phalf) #%% filedir = atmdir+'ts/daily/1yr/' yr = np.arange(1,10,1) nyr = np.size(yr) data = np.zeros([nyr,nphalf-1,nlat]) #tmpZon = np.zeros([nmon,nlev-1,nlat]) #phalfZon = np.zeros([nmon,nlev,nlat]) for yri in range(nyr): yrC = '000'+str(yr[yri])+'0101-'+'000'+str(yr[yri])+'1231.' filename = filedir+diag+'.'+yrC+var+'.nc' fs.append(nc.netcdf_file(filename,'r',mmap=True)) #pfull = fs[-1].variables['pfull'][:].astype(np.float64) tmp = fs[-1].variables[var][:].astype(np.float64) #t,p,lat,lon #tmp[np.where(tmp<-999)] = np.nan tmp = np.mean(tmp,3) data[yri,:,:] = np.mean(tmp,0) fs[-1].close() #%% #outfile = outdir+'dim.'+perto[i]+'_sigma.npz' #fio.save(outfile,lat=lat,lon=lon,phalf=phalf,pfull=pfull) outfile = outdir+diago+'.'+perto[i]+'_sigma.npz' fio.save(outfile,**{varo:data})
land_mask = np.array(land_mask) fs[-1].close() #%% files = [] nfile = 1 for fi in range(nfile): files.append(filename) ts = pp.ts_multi_files(files,var,0) #%% ts = ts[1200:-5,:,:] #ts = ts[:-6,:,:] #ts[np.where(abs(ts)>999)] = np.nan if zm: ts = np.mean(ts,-1) #%% if init: outfile = outdir+'dim.'+obs+'.npz' fio.save(outfile,lat=lat,lon=lon,land_mask=land_mask) if init3d: tmp = nc.netcdf_file(files[-1],'r',mmap=True) pfull = tmp.variables['pfull'][:].astype(np.float64) outfile = outdir+'dim.'+obs+'.npz' fio.save(outfile,pfull=pfull) for flagi in range(nflag): if (flag[flagi] != ''): ts_flag = pp.month_to_year(ts,yr_ts,flag[flagi]) outdir_sub='ts/'+sub_dict[flag[flagi]]+'/' outfile = outdir+outdir_sub+diago+'.'+timeo+'.'+obs+'.npz' fio.save(outfile,**{varo:ts_flag})
np.float64) #t,p,lat,lon ps = fs[-1].variables['ps'][500:, :, :].astype(np.float64) fs[-1].close() var_tr = var - np.mean(var, -1)[..., np.newaxis] power = np.abs(fft.fft(var_tr, axis=-1))**2 phalf = grid.calcSigmaPres(ps, pk, bk) dp = (phalf[:, 1:, :, :] - phalf[:, :-1, :, :]) dp_m = np.mean(dp, -1)[..., np.newaxis] power_col = np.sum(power * dp, 1) / np.sum(dp, 1) power_m = np.mean(power_col, 0)[:, :nlon / 2] k = np.arange(0, nlon / 2) k_m = np.sum(power_m * k, -1) / np.sum(power_m, -1) L[si, :] = 2 * np.pi * RADIUS * np.cos(lat * np.pi / 180.) / k_m if init: outfile = outdir + 'dim.' + perto[si] + '.npz' fio.save(outfile, lat=lat, lon=lon, phalf=phalf) if init3d: pfull = fs[-1].variables['pfull'][:].astype(np.float64) outfile = outdir + 'dim.' + perto[si] + '.npz' fio.save(outfile, pfull=pfull) #outfile = outdir+'av/'+diago+'.'+perto[si]+'.npz' #fio.save(outfile,**{varo_name:tr_zm}) #%% color = ['k', 'b', 'r', 'b', 'r'] ls = ['-', '-', '-', '--', '--'] plt.figure() for si in range(npert): plt.plot(lat, L[si, :] / 1.e6, color=color[si], ls=ls[si]) plt.xlim(-90, 90) plt.xticks(np.arange(-60, 61, 30))
fs.append(nc.netcdf_file(stafile,'r',mmap=True)) """ bk = fs[-1].variables['bk'][:].astype(np.float64) pk = fs[-1].variables['pk'][:].astype(np.float64) lat = fs[-1].variables['lat'][:].astype(np.float64) lon = fs[-1].variables['lon'][:].astype(np.float64) phalf = fs[-1].variables['phalf'][:].astype(np.float64) zsurf = fs[-1].variables['zsurf'][:].astype(np.float64) fs[-1].close() nlat = np.size(lat) nlon = np.size(lon) nphalf = np.size(phalf) """ #%% filedir = atmdir+subdir filename = filedir+diag+'.'+yrC+'.'+var+'.nc' fs.append(nc.netcdf_file(filename,'r',mmap=True)) #pfull = fs[-1].variables['pfull'][:].astype(np.float64) tmp = fs[-1].variables[var][:].astype(np.float64) #t,p,lat,lon #tmp[np.where(tmp<-999)] = np.nan tmp = np.mean(tmp,2) tmp = np.mean(tmp,0) fs[-1].close() #%% #outfile = outdir+'dim.'+perto[i]+'_sigma.npz' #fio.save(outfile,lat=lat,lon=lon,phalf=phalf,pfull=pfull) outfile = outdir+diago+'.'+perto[i]+'_sigma.npz' fio.save(outfile,**{varo:tmp})
var = 't_ref' diag = 'var2d' time = '1880-2015' grid_inf = indir + 'dim.' + obs_in + '.npz' npz = np.load(grid_inf) lat_in = npz['lat'] lon_in = npz['lon'] land_mask_in = npz['land_mask'] (latt, lont, land_maskt) = (lat_in, lon_in, land_mask_in) (lonm_in, latm_in) = np.meshgrid(lont, latt) land_mask_out = interp.griddata(np.array([latm_in.ravel(),lonm_in.ravel()]).T,\ land_maskt.ravel(),(latm_out,lonm_out),method='linear') outfile = outdir + 'dim.' + obs_out + '.npz' fio.save(outfile, lat=lat_out, lon=lon_out, land_mask=land_mask_out) filename = indir + indir_sub + diag + '.' + time + '.' + obs_in + '.npz' npz = np.load(filename) tmp_in = npz[var] latt, lont, tmpt = lat_in, lon_in, tmp_in ntime = np.shape(tmpt)[0] tmp_out = np.zeros((ntime, nlat, nlon)) for ti in range(ntime): (lonm_in, latm_in) = np.meshgrid(lont, latt) """ tmp_rbf = interp.Rbf(latm_in,lonm_in,tmpt[ti,:,:],function='linear',smooth=0) tmp_out[ti,:,:] = tmp_rbf(latm_out,lonm_out) """ tmp_out[ti,:,:] = \ interp.griddata(np.array([latm_in.ravel(),lonm_in.ravel()]).T,\ tmpt[ti,:,:].ravel(),(latm_out,lonm_out),method='linear')
for i in ind: atmdir = basedir + exper + pert[i] + plat + 'pp/' + diag + '/' stafile = atmdir + diag + '.static.nc' fs = [] fs.append(nc.netcdf_file(stafile, 'r', mmap=True)) bk = fs[-1].variables['bk'][:].astype(np.float64) pk = fs[-1].variables['pk'][:].astype(np.float64) lat = fs[-1].variables['lat'][:].astype(np.float64) lon = fs[-1].variables['lon'][:].astype(np.float64) phalf = fs[-1].variables['phalf'][:].astype(np.float64) zsurf = fs[-1].variables['zsurf'][:].astype(np.float64) fs[-1].close() nlat = np.size(lat) nlon = np.size(lon) nphalf = np.size(phalf) #%% filedir = atmdir + subdir filename = filedir + diag + '.' + yrC + '.' + var + '.nc' fs.append(nc.netcdf_file(filename, 'r', mmap=True)) #pfull = fs[-1].variables['pfull'][:].astype(np.float64) tmp = fs[-1].variables[var][:].astype(np.float64) #t,p,lat,lon #tmp[np.where(tmp<-999)] = np.nan tmp = np.mean(tmp, 2) #tmp = np.mean(tmp,0) fs[-1].close() #%% #outfile = outdir+'dim.'+perto[i]+'_sigma.npz' #fio.save(outfile,lat=lat,lon=lon,phalf=phalf,pfull=pfull) outfile = outdir + diago + '.' + perto[i] + '_sigma.npz' fio.save(outfile, **{varo: tmp})
pfull = fs[-1].variables['pfull'][:].astype(np.float64) #zsurf = fs[-1].variables['zsurf'][:].astype(np.float64) fs[-1].close() #%% filename = atmdir + '00000.atmos_daily.nc' fs.append(nc.netcdf_file(filename, 'r', mmap=True)) temp = fs[-1].variables['temp'][500:, :, :, :].astype( np.float64) #t,p,lat,lon q = fs[-1].variables['mix_rat'][500:, :, :, :].astype(np.float64) pfull.shape = (1, 20, 1, 1) theta = temp * (p0 / pfull)**(Rair / Cp) thetae = theta * np.exp(sc[i] * Le * q / (Cp * temp)) temp_zm = np.mean(np.mean(temp, 3), 0) theta_zm = np.mean(np.mean(theta, 3), 0) thetae_zm = np.mean(np.mean(thetae, 3), 0) pfull.shape = (20) tmp = fs[-1].variables[var][500:, :, :, :].astype(np.float64) tmp_zm = np.mean(np.mean(tmp, 3), 0) if init: outfile = outdir + 'dim.' + perto[i] + '.npz' fio.save(outfile, lat=lat, lon=lon) if init3d: pfull = fs[-1].variables['pfull'][:].astype(np.float64) outfile = outdir + 'dim.' + perto[i] + '.npz' fio.save(outfile, pfull=pfull, phalf=phalf) outfile = outdir + 'av/' + diago + '.' + perto[i] + '.npz' fio.save(outfile, **{varo: tmp_zm}) fio.save(outfile, temp_zm=temp_zm, theta_zm=theta_zm, thetae_zm=thetae_zm)