filename = '/home/z1s/research/climate/atmos_level.static.nc' fs = nc.netcdf_file(filename, 'r', mmap=True) lat = fs.variables['lat'][:] nlat = np.size(lat) lon = fs.variables['lon'][:] nlon = np.size(lon) land_mask1 = fs.variables['land_mask'][:] fs.close() land_mask = land_mask1.copy() if not land: land_mask[:, :] = 1 region_mask = -np.ones((nlat, nlon)) region_mask_obs = -np.ones((nlat, nlon)) latt, lont, land_mask_obs = pp.grid_for_map(lat, lon, land_mask) for regi in range(nregion): (latlim, lonlim) = grid.get_region_lim(region[regi], lonmax=360) nlim = np.shape(latlim)[0] for i in range(nlim): mask = grid.regionMask(lat, lon, latlim[i], lonlim[i]) region_mask[np.where(mask == 1)] = regi + 1 (latlim, lonlim) = grid.get_region_lim(region[regi], lonmax=180) nlim = np.shape(latlim)[0] for i in range(nlim): mask = grid.regionMask(latt, lont, latlim[i], lonlim[i]) region_mask_obs[np.where(mask == 1)] = regi + 1 region_mask[np.where(land_mask < 0.3)] = -1 region_mask_obs[np.where(land_mask_obs < 0.3)] = -1
MCdiv_rm = MCdiv*area*region_mask MCdiv_rm = np.sum(np.sum(MCdiv_rm,-1),-1)/np.sum(area*region_mask) Trdiv_rm = Trdiv*area*region_mask Trdiv_rm = np.sum(np.sum(Trdiv_rm,-1),-1)/np.sum(area*region_mask) uvdh_rm = uvdh*area*region_mask uvdh_rm = np.sum(np.sum(uvdh_rm,-1),-1)/np.sum(area*region_mask) wdh_rm = wdh*area*region_mask wdh_rm = np.sum(np.sum(wdh_rm,-1),-1)/np.sum(area*region_mask) de_rm = de*area*region_mask de_rm = np.sum(np.sum(de_rm,-1),-1)/np.sum(area*region_mask) #%% clev = np.arange(-190,191,20) m = Basemap(projection='mill',\ fix_aspect=True,\ llcrnrlat=-35,urcrnrlat=5,llcrnrlon=-120,urcrnrlon=-20) latt,lont,nett = pp.grid_for_map(lat,lon,net) latt,lont,Totdivt = pp.grid_for_map(lat,lon,Totdiv) latt,lont,det = pp.grid_for_map(lat,lon,de) latt,lont,MCdivt = pp.grid_for_map(lat,lon,MCdiv) latt,lont,Trdivt = pp.grid_for_map(lat,lon,Trdiv) latt,lont,uvdht = pp.grid_for_map(lat,lon,uvdh) latt,lont,wdht = pp.grid_for_map(lat,lon,wdh) latt,lont,whbott = pp.grid_for_map(lat,lon,whbot) latt,lont,whtopt = pp.grid_for_map(lat,lon,whtop) lons,lats = np.meshgrid(lont,latt) x,y = m(lons,lats) cmap = plt.cm.RdYlBu #%% plt.figure() m.drawcoastlines() m.drawcountries()
MCdiv_rm = MCdiv * area * region_mask MCdiv_rm = np.sum(np.sum(MCdiv_rm, -1), -1) / np.sum(area * region_mask) Trdiv_rm = Trdiv * area * region_mask Trdiv_rm = np.sum(np.sum(Trdiv_rm, -1), -1) / np.sum(area * region_mask) uvdh_rm = uvdh * area * region_mask uvdh_rm = np.sum(np.sum(uvdh_rm, -1), -1) / np.sum(area * region_mask) wdh_rm = wdh * area * region_mask wdh_rm = np.sum(np.sum(wdh_rm, -1), -1) / np.sum(area * region_mask) de_rm = de * area * region_mask de_rm = np.sum(np.sum(de_rm, -1), -1) / np.sum(area * region_mask) #%% clev = np.arange(-190, 191, 20) m = Basemap(projection='mill',\ fix_aspect=True,\ llcrnrlat=-35,urcrnrlat=5,llcrnrlon=-120,urcrnrlon=-20) latt, lont, nett = pp.grid_for_map(lat, lon, net) latt, lont, Totdivt = pp.grid_for_map(lat, lon, Totdiv) latt, lont, det = pp.grid_for_map(lat, lon, de) latt, lont, MCdivt = pp.grid_for_map(lat, lon, MCdiv) latt, lont, Trdivt = pp.grid_for_map(lat, lon, Trdiv) latt, lont, uvdht = pp.grid_for_map(lat, lon, uvdh) latt, lont, wdht = pp.grid_for_map(lat, lon, wdh) latt, lont, whbott = pp.grid_for_map(lat, lon, whbot) latt, lont, whtopt = pp.grid_for_map(lat, lon, whtop) lons, lats = np.meshgrid(lont, latt) x, y = m(lons, lats) cmap = plt.cm.RdYlBu #%% plt.figure() m.drawcoastlines() m.drawcountries()
plt.xticks(lattick) plt.ylim([-30,5]) plt.tight_layout() #%% tmpzon = np.mean(tmp,2) weight = np.cos(lat*np.pi/180.) weight1 = weight/np.sum(weight) weight1.shape = [1,nlat] tmpglb = np.sum(tmpzon*weight1,1) """ #%% tmp = tmp-tmp[0,:,:,:] tmp = np.min(tmp,1) tmp[:,np.where(land_mask>0)[0],np.where(land_mask>0)[1]] = np.nan latt,lont,tmpt = pp.grid_for_map(lat,lon,tmp) data = tmpt*sc clabel = "Temperature difference (K)" m = Basemap(projection='mill',\ fix_aspect=True,\ llcrnrlat=-90,urcrnrlat=90,llcrnrlon=-180,urcrnrlon=180) cmap = plt.cm.RdYlBu_r clev = np.arange(-1,1.1,0.2) lons,lats = np.meshgrid(lont,latt) x,y = m(lons,lats) plt.figure() m.drawcoastlines() m.contourf(x,y,data[1,:,:],clev,cmap=cmap,extend='both') cb = m.colorbar(location='bottom',size='5%',pad='8%')
plt.legend(['c25','c30'],fontsize=fsize,loc='best') plt.ylabel('swdn_toa (W m$^{-2}$)') plt.xticks(lattick) plt.ylim([-30,5]) plt.tight_layout() #%% tmpzon = np.mean(tmp,2) weight = np.cos(lat*np.pi/180.) weight1 = weight/np.sum(weight) weight1.shape = [1,nlat] tmpglb = np.sum(tmpzon*weight1,1) """ #%% latt, lont, tmpt = pp.grid_for_map(lat, lon, tmp) latt, lont, speedt = pp.grid_for_map(lat, lon, speed) tmpt = tmpt * sc clabel = "t_surf (K)" m = Basemap(projection='mill',\ fix_aspect=True,\ llcrnrlat=20,urcrnrlat=55,llcrnrlon=60,urcrnrlon=140) cmap = plt.cm.RdYlBu_r clev = np.arange(-0.1, 0.11, 0.01) lons, lats = np.meshgrid(lont, latt) x, y = m(lons, lats) yy = np.arange(0, len(latt), 1) xx = np.arange(0, len(lont), 1) points = np.meshgrid(yy, xx)
plt.xticks(lattick) plt.ylim([-30,5]) plt.tight_layout() #%% tmpzon = np.mean(tmp,2) weight = np.cos(lat*np.pi/180.) weight1 = weight/np.sum(weight) weight1.shape = [1,nlat] tmpglb = np.sum(tmpzon*weight1,1) """ #%% tmp = tmp - tmp[0, :, :, :] tmp = np.min(tmp, 1) tmp[:, np.where(land_mask > 0)[0], np.where(land_mask > 0)[1]] = np.nan latt, lont, tmpt = pp.grid_for_map(lat, lon, tmp) data = tmpt * sc clabel = "Temperature difference (K)" m = Basemap(projection='mill',\ fix_aspect=True,\ llcrnrlat=-90,urcrnrlat=90,llcrnrlon=-180,urcrnrlon=180) cmap = plt.cm.RdYlBu_r clev = np.arange(-1, 1.1, 0.2) lons, lats = np.meshgrid(lont, latt) x, y = m(lons, lats) plt.figure() m.drawcoastlines() m.contourf(x, y, data[1, :, :], clev, cmap=cmap, extend='both') cb = m.colorbar(location='bottom', size='5%', pad='8%')
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) var = 't_ref' diag = 'var2d' time = '1850-2015' 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'] land_mask_in = npz['land_mask'] (latt,lont,land_maskt) = pp.grid_for_map(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.'+sim[si]+'.npz' fio.save(outfile,lat=lat_out,lon=lon_out,land_mask=land_mask_out) filename = indir+indir_sub+diag+'.'+time+'.'+sim[si]+'.npz' npz = np.load(filename) tmp_in = npz[var] latt,lont,tmpt = pp.grid_for_map(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)
sim = [] for i in range(npert): for j in range(nens): sim.append(pert[i]+ens[j]) nsim = np.size(sim) var = 't_ref' diag = 'var2d' time = '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+'.'+time+'.'+sim[si]+'.npz' npz = np.load(filename) tmp_in = npz[var] latt,lont,tmpt = pp.grid_for_map(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') outfile = outdir+outdir_sub+diag+'.'+time+'.'+sim[si]+'.npz' fio.save(outfile,**{var:tmp_out}) print sim[si]
plt.legend(['c25','c30'],fontsize=fsize,loc='best') plt.ylabel('swdn_toa (W m$^{-2}$)') plt.xticks(lattick) plt.ylim([-30,5]) plt.tight_layout() #%% tmpzon = np.mean(tmp,2) weight = np.cos(lat*np.pi/180.) weight1 = weight/np.sum(weight) weight1.shape = [1,nlat] tmpglb = np.sum(tmpzon*weight1,1) """ #%% latt,lont,tmpt = pp.grid_for_map(lat,lon,tmp) latt,lont,speedt = pp.grid_for_map(lat,lon,speed) tmpt = tmpt*sc clabel = "t_surf (K)" m = Basemap(projection='mill',\ fix_aspect=True,\ llcrnrlat=20,urcrnrlat=55,llcrnrlon=60,urcrnrlon=140) cmap = plt.cm.RdYlBu_r clev = np.arange(-0.1,0.11,0.01) lons,lats = np.meshgrid(lont,latt) x,y = m(lons,lats) yy = np.arange(0,len(latt),1) xx = np.arange(0,len(lont),1) points = np.meshgrid(yy,xx)
filename = '/home/z1s/research/climate/atmos_level.static.nc' fs = nc.netcdf_file(filename,'r',mmap=True) lat = fs.variables['lat'][:] nlat = np.size(lat) lon = fs.variables['lon'][:] nlon = np.size(lon) land_mask1 = fs.variables['land_mask'][:] fs.close() land_mask = land_mask1.copy() if not land: land_mask[:,:] = 1 region_mask = -np.ones((nlat,nlon)) region_mask_obs = -np.ones((nlat,nlon)) latt,lont,land_mask_obs = pp.grid_for_map(lat,lon,land_mask) for regi in range(nregion): (latlim,lonlim) = grid.get_region_lim(region[regi],lonmax=360) nlim = np.shape(latlim)[0] for i in range(nlim): mask = grid.regionMask(lat,lon,latlim[i],lonlim[i]) region_mask[np.where(mask==1)] = regi+1 (latlim,lonlim) = grid.get_region_lim(region[regi],lonmax=180) nlim = np.shape(latlim)[0] for i in range(nlim): mask = grid.regionMask(latt,lont,latlim[i],lonlim[i]) region_mask_obs[np.where(mask==1)] = regi+1 region_mask[np.where(land_mask<0.3)] = -1 region_mask_obs[np.where(land_mask_obs<0.3)] = -1