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)
loni.setBounds(xib) lati.setBounds(yib) xi = loni.getValue() yi = lati.getValue() dx = N.diff(xi[0]).mean() dy = N.diff(yi[:, 0]).mean() xo = N.arange(xi.min()+10*dx, -30*dx+xi.max(), dx) yo = N.arange(yi.min()-20*dy, yi.max()-20*dy, dy) lono = cdms2.createAxis(xo) lono.designateLongitude() ; lono.units= 'degrees_east' lato = cdms2.createAxis(yo) lato.designateLatitude() ; lato.units = 'degrees_north' xob = bounds1d(lono) ; lono.setBounds(xob) yob = bounds1d(lato) ; lato.setBounds(yob) grido = cdms2.createRectGrid(lato, lono) xmin, xmax = minmax(loni.asma(),lono) ymin, ymax = minmax(lati.asma(), lato) nyo,nxo = grido.shape #print 'rank',rank basefile = code_file_name(ext=False) repfile = basefile+'.nt%(nt)s-nz%(nz)s-nyi%(nyi)s-nxi%(nxi)s.log'%locals() if rank==0: if os.path.exists(repfile): os.remove(repfile) f = open(repfile, 'w') if size: # print 'MPI', size print >>f, 'MPI: NPROC=%i'%size print >>f, 'NT=%(nt)i, NZ=%(nz)i'%locals() print >>f, 'NYI=%(nyi)i, NXI=%(nxi)i'%locals() print >>f, 'NYO=%(nyo)i, NXO=%(nxo)i'%locals()
dep = create_dep([-5000, -3000, -2000, -1000, -500, -300, -200, -100.]) var = {} var['t'] = MV2.reshape( N.arange(grid.size() * len(dep)) * 1., (len(dep), ) + grid.shape) set_grid(var['t'], grid) var['t'].setAxis(0, dep) # Arakawa manager ag = CGrid() # Interpolations for p in 'u', 'v', 'f', 'w': var[p] = ag.interp(var['t'], 't', p, mode='extrap') # Surface plots vmin, vmax = minmax(*[var[p][-1] for p in ['u', 'v', 'f']]) kw = dict(show=False, res=None, vmin=vmin, vmax=vmax, colorbar=False, grid=False, cmap='jet') m = map2(var['t'][-1], fill='pcolor', title='Interpolations on an Arakawa C grid: T->U/V/F', **kw) add_grid(var['t'], linestyle='-') kw.update(fill='scatter', contour=False, fill_s=60) markers = dict(u='>', v='^', f='D', t='o') for p in 't', 'u', 'v', 'f':
dep = create_dep([-5000, -3000, -2000, -1000, -500, -300, -200, -100.]) var = {} var['t'] = MV2.reshape(N.arange(grid.size()*len(dep))*1., (len(dep), )+grid.shape) set_grid(var['t'], grid) var['t'].setAxis(0, dep) # Arakawa manager ag = CGrid() # Interpolations for p in 'u', 'v', 'f', 'w': var[p] = ag.interp(var['t'], 't', p, mode='extrap') # Surface plots vmin, vmax = minmax(*[var[p][-1] for p in ['u', 'v', 'f']]) kw = dict(show=False, res=None, vmin=vmin, vmax=vmax, colorbar=False, grid=False, cmap='jet') m = map2(var['t'][-1], fill='pcolor', title='Interpolations on an Arakawa C grid: T->U/V/F', **kw) add_grid(var['t'], linestyle='-') kw.update(fill='scatter', contour=False, fill_s=60) markers = dict(u='>', v='^', f='D', t='o') for p in 't', 'u', 'v', 'f': m = map2(var[p][-1], fill_marker=markers[p], shadow=True, zorder=100, **kw) m.savefig(code_file_name(ext='_1.png')) m.close() # Vertical plot curve2(var['t'][:, 0, 0], 'o-b', ymax=0, show=False, title='Interpolations on an Arakawa C grid: T->W') curve2(var['w'][:, 0, 0], '^r', show=False, savefig=code_file_name(ext='_2.png'))