def plot(xx, yy, target, label, figfiles, figfile, lon=None, lat=None, show=False): xs, ys, mask = coord2slice(target, lon=lon, lat=lat) P.figure(figsize=(6, 3.5)) P.title('Target=%(label)s / select: lon=%(lon)s, lat=%(lat)s' % locals()) add_grid((xx, yy)) xx = xx.asma() yy = yy.asma() if isinstance(lon, tuple): P.axvline(lon[0], color='m', ls='--', lw=2) P.axvline(lon[1], color='m', ls='--', lw=2) elif isinstance(lon, slice): i, j, k = lon.indices(xx.shape[1]) P.plot(xx[:, i], yy[:, i], 'c--', lw=2) P.plot(xx[:, j - 1], yy[:, j - 1], 'c--', lw=2) if isinstance(lat, tuple): P.axhline(lat[0], color='m', ls='--', lw=2) P.axhline(lat[1], color='m', ls='--', lw=2) elif isinstance(lat, slice): i, j, k = lat.indices(yy.shape[0]) P.plot(xx[i], yy[i], 'c--', lw=2) P.plot(xx[j - 1], yy[j - 1], 'c--', lw=2) P.xticks(N.arange(xx.min() - 1, xx.max() + 1)) P.yticks(N.arange(yy.min() - 1, yy.max() + 1)) xxi, yyi = xx, yy xx = xx[ys, xs] yy = yy[ys, xs] # mask = mask[ys, xs] xxb, yyb = meshbounds(xx, yy) P.pcolormesh(xxb, yyb, mask, shading='faceted') P.scatter(xx.ravel(), yy.ravel(), c=(0, 1, 0)) P.grid(True) P.axis('image') P.tight_layout() i = len(figfiles) savefig = figfile % i if os.path.exists(savefig): os.remove(savefig) P.savefig(savefig) figfiles.append(savefig) if show: P.show() else: P.close()
def myplot(vari, depi, varol, varoc, depo, figfile): def getdv(var, dep): v = var[1, :, 1, :] if dep[:].ndim == var.ndim: dep = dep[1, :, 1, :] elif dep[:].ndim == 3: dep = dep[:, 1, :] xb, yb = meshcells(v.getAxis(-1), dep) return xb, yb, v.asma() xbi, ybi, vi = getdv(vari, depi) xbo, ybo, vol = getdv(varol, depo) _, _, voc = getdv(varoc, depo) vmin, vmax = minmax(vi, vol, voc) kw = dict(vmin=vmin, vmax=vmax) P.figure(figsize=(10, 4)) ax = P.subplot(131) P.pcolormesh(xbi, ybi, vi, **kw) P.title('Original') P.subplot(132, sharex=ax, sharey=ax) P.pcolormesh(xbo, ybo, vol, **kw) P.title('Linear') P.subplot(133, sharex=ax, sharey=ax) P.pcolormesh(xbo, ybo, voc, **kw) P.ylim(ymin=min(ybi.min(), ybo.min()), ymax=max(ybi.max(), ybo.max())) P.title('Cellave') P.tight_layout() P.savefig(figfile)
def myplot(vari, depi, varol, varoc, depo, figfile): def getdv(var, dep): v = var[1, :, 1, :] if dep[:].ndim==var.ndim: dep = dep[1, :, 1, :] elif dep[:].ndim==3: dep = dep[:, 1, :] xb, yb = meshcells(v.getAxis(-1), dep) return xb, yb, v.asma() xbi, ybi, vi = getdv(vari, depi) xbo, ybo, vol = getdv(varol, depo) _, _, voc = getdv(varoc, depo) vmin, vmax = minmax(vi, vol, voc) kw = dict(vmin=vmin, vmax=vmax) P.figure(figsize=(10, 4)) ax = P.subplot(131) P.pcolormesh(xbi, ybi, vi, **kw) P.title('Original') P.subplot(132, sharex=ax, sharey=ax) P.pcolormesh(xbo, ybo, vol, **kw) P.title('Linear') P.subplot(133, sharex=ax, sharey=ax) P.pcolormesh(xbo, ybo, voc, **kw) P.ylim(ymin=min(ybi.min(), ybo.min()), ymax=max(ybi.max(), ybo.max())) P.title('Cellave') P.tight_layout() P.savefig(figfile)
yi = N.array(yi) zi = N.array(zi) xxg, yyg = N.meshgrid(xg, yg) xo = xxg.ravel() yo = yyg.ravel() vgm = variogram_model('linear', n=0, s=sill, r=range) # Setup the kriger sck = SimpleCloudKriger(xi, yi, zi, vgf=vgm, farvalue=farvalue) # Interpolate zo = sck(xo, yo) # Check a far value zzg = zo.reshape(ny, nx) N.testing.assert_allclose(zzg[-1, -1],farvalue) # Plot vmin = min(zi.min(), zo.min()) vmax = max(zi.max(), zo.max(), farvalue) cmap = 'cmocean_ice' kw = dict(vmin=vmin, vmax=vmax) P.pcolormesh(xxg, yyg, zzg, cmap=cmap, **kw) P.colorbar() P.scatter(xi, yi, c=zi, s=100, cmap=cmap, **kw) P.axis('image') P.title('Simple kriging with fixed far value') P.savefig(code_file_name(ext='.png')) P.show() P.close()
zov2 = xy2xy(xi, yi, zi, xo, yo) # Krigeage from vacumm.misc.grid.kriging import krig zzok = krig(xi, yi, zi, xxr.ravel(), yyr.ravel(), nproc=1).reshape(zzr.shape) # -> Tester nproc et npmax # Plots from vcmq import meshbounds, P xxrb, yyrb = meshbounds(xr, yr) P.figure(figsize=(10, 8)) axis = [xxrb.min(), xxrb.max(), yyrb.min(), yyrb.max()] # P.subplot(332) P.pcolormesh(xxrb, yyrb, zzr, **vminmax) P.scatter(xi, yi, c='k') P.title('Original') P.axis(axis) # P.subplot(334) P.pcolormesh(xxrb, yyrb, zzoc, **vminmax) P.title('CDAT/Natgrid') P.axis(axis) # P.subplot(335) P.pcolormesh(xxrb, yyrb, zzork, **vminmax) P.title('MPL/R.K. grid') P.axis(axis) # P.subplot(336)
coordSys='cart') # Norm frac = diag['dstAreaFractions'] mask = frac == 0. frac[mask] = 1. varo[:] /= frac varo[:] = MV2.masked_where(mask, varo, copy=0) # Plot rc('font', size=9) kw = dict(vmin=vari.min(), vmax=vari.max()) axis = [xxbi.min(), xxbi.max(), yybo.min(), yybo.max()] P.figure(figsize=(7, 3)) P.subplot(121, aspect=1) P.pcolormesh(xxbi, yybi, vari, **kw) P.colorbar(shrink=0.7) add_grid(gridi, color='0.5') add_grid(grido) P.axis(axis) P.title('Original: max=%g min=%g' % (vari.max(), vari.min())) P.subplot(122, aspect=1) P.pcolormesh(xxbo, yybo, varo, **kw) P.colorbar(shrink=0.7) add_grid(gridi) add_grid(grido, color='0.5') P.axis(axis) P.title('Regridded: max=%g min=%g' % (varo.max(), varo.min())) P.tight_layout() savefigs(code_file_name(), verbose=False) P.close()
frac = diag['dstAreaFractions'] if frac is not None: mask = frac<=1.e-3 frac[mask] = 1. frac = N.resize(frac, varo.shape) mask = N.resize(mask, varo.shape) varo[:] /= frac varo[:] = MV2.masked_where(mask, varo, copy=0) # del r gc.collect() if rank==0: print >>f, ' plot' P.figure(figsize=(12, 6)) P.subplots_adjust(right=0.9) P.subplot(121) P.pcolormesh(xi, yi, vari[0,0].asma(),vmin=vmin,vmax=vmax) P.axis([xmin, xmax, ymin, ymax]) P.colorbar() P.title('Original') P.subplot(122) P.pcolormesh(xo, yo, varo[0,0].asma(),vmin=vmin,vmax=vmax) P.axis([xmin, xmax, ymin, ymax]) P.title(tool.upper()+' / '+method.upper()) P.colorbar(extend='min')#cax=P.axes([0.92, 0.3, 0.02, 0.6])) figfile = basefile+'_%(tool)s_%(method)s.png'%vars() if os.path.exists(figfile): os.remove(figfile) P.savefig(figfile) P.close() del varo if rank==0:print >>f, 'Done' f.close()
zzge = zoe.reshape(ny, nx) # Plot vmin = min(zi.min(), zo.min(), zoe.min()) vmax = max(zi.max(), zo.max(), zoe.max()) vmax = max(abs(vmin), abs(vmax)) vmin = -vmax cmap = 'cmocean_tempo' cmap = 'cmocean_delta' kw = dict(vmin=vmin, vmax=vmax) P.figure(figsize=(6, 5.5)) ax = P.subplot(221) P.pcolormesh(xxg, yyg, zzg, cmap=cmap, **kw) P.colorbar() P.scatter(xi, yi, c=zi, s=100, cmap=cmap, **kw) P.title('Without obs error') P.subplot(222, sharex=ax, sharey=ax) P.pcolormesh(xxg, yyg, zzge, cmap=cmap, **kw) P.colorbar() P.scatter(xi, yi, c=zi, s=100, cmap=cmap, **kw) #P.axis('image') P.title('With obs error') P.subplot(223, sharex=ax, sharey=ax) vmax = abs(zzge-zzg).max() vmin = -vmax P.pcolormesh(xxg, yyg, zzge-zzg, cmap=cmap, vmin=vmin, vmax=vmax)
yi = N.array(yi) zi = N.array(zi) xxg, yyg = N.meshgrid(xg, yg) xo = xxg.ravel() yo = yyg.ravel() vgm = variogram_model('linear', n=0, s=sill, r=range) # Setup the kriger sck = SimpleCloudKriger(xi, yi, zi, vgf=vgm, farvalue=farvalue) # Interpolate zo = sck(xo, yo) # Check a far value zzg = zo.reshape(ny, nx) N.testing.assert_allclose(zzg[-1, -1], farvalue) # Plot vmin = min(zi.min(), zo.min()) vmax = max(zi.max(), zo.max(), farvalue) cmap = 'cmocean_ice' kw = dict(vmin=vmin, vmax=vmax) P.pcolormesh(xxg, yyg, zzg, cmap=cmap, **kw) P.colorbar() P.scatter(xi, yi, c=zi, s=100, cmap=cmap, **kw) P.axis('image') P.title('Simple kriging with fixed far value') P.savefig(code_file_name(ext='.png')) P.show() P.close()
diag=diag, coordSys='cart') # Norm frac = diag['dstAreaFractions'] mask = frac==0. frac[mask]=1. varo[:] /= frac varo[:] = MV2.masked_where(mask, varo, copy=0) # Plot rc('font', size=9) kw = dict(vmin=vari.min(), vmax=vari.max()) axis = [xxbi.min(), xxbi.max(), yybo.min(), yybo.max()] P.figure(figsize=(7, 3)) P.subplot(121, aspect=1) P.pcolormesh(xxbi, yybi, vari, **kw) P.colorbar(shrink=0.7) add_grid(gridi, color='0.5') add_grid(grido) P.axis(axis) P.title('Original: max=%g min=%g'%(vari.max(), vari.min())) P.subplot(122, aspect=1) P.pcolormesh(xxbo, yybo, varo, **kw) P.colorbar(shrink=0.7) add_grid(gridi) add_grid(grido, color='0.5') P.axis(axis) P.title('Regridded: max=%g min=%g'%(varo.max(), varo.min())) P.tight_layout() savefigs(code_file_name(), verbose=False) P.close()
# Ajustment for conservative methode frac = diag['dstAreaFractions'] if method=='conservative': # divide by dstAreaFractions for conservative log(f, ' frac: %s'%frac) mask = frac==0. frac[mask] = 1. varo[:] /= frac varo[:] = MV2.masked_where(mask, varo, copy=0) log(f, ' dstareas: %s'%diag['dstAreas']) log(f, ' varo: %s'%varo) # Plot P.figure(figsize=(6,3)) P.subplot(121).set_aspect(1) P.pcolormesh(xxib,yyib,vari.asma(),**kw) #P.colorbar() P.title('Original') kwg = dict(alpha=1, linewidth=1., centers=True) add_grid(gridi, color=(0,0,.2), marker='o', **kwg) add_grid(grido, color=(.2,0,0), marker='+', markersize=10,**kwg) P.axis('image') axis = P.axis() P.subplot(122).set_aspect(1) P.pcolormesh(xxob,yyob,varo.asma(),**kw) #P.colorbar() P.title('%(tool)s / %(method)s'%locals()) add_grid(gridi, color=(0,0,.2), marker='o', **kwg) add_grid(grido, color=(.2,0,0), marker='+',markerlinewidth=1,markersize=8,**kwg) P.axis(axis) ifig = len(figfiles)