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 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.pcolor(xxb, yyb, mask, shading='faceted') P.scatter(xx.ravel(), yy.ravel(), c=(0, 1, 0)) P.grid('on') 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()
"""Test :meth:`~vacumm.data.misc.OceanDataset.plot_hsection` with MFS""" # Inits ncfile = "mfs.nc" depth = -1000.0 # Imports from vcmq import DS, data_sample, os, code_file_name # Setup dataset ds = DS(data_sample(ncfile), "nemo", logger_level="critical") # Plot hsection figfile = code_file_name(ext="png") if os.path.exists(figfile): os.remove(figfile) ds.plot_hsection("temp", depth, savefig=figfile, fill="contourf", show=False, close=True)
yyob, xxob = meshcells(yyo, x) varon = N.ma.masked_values(interp1dxx(vari.filled(), yyi, yyo, mv, 0, extrap=0), mv) varol = N.ma.masked_values(interp1dxx(vari.filled(), yyi, yyo, mv, 1, extrap=0), mv) varoh = N.ma.masked_values(interp1dxx(vari.filled(), yyi, yyo, mv, 3, extrap=0), mv) kw = dict(vmin=vari.min(), vmax=vari.max()) axlims = [x[0], x[-1], yo[0], yo[-1]] P.figure(figsize=(8, 8)) P.subplot(221) P.pcolor(xxib, yyib, vari) P.axis(axlims) P.title('Original') P.subplot(222) P.pcolor(xxob, yyob, varon, **kw) P.axis(axlims) P.title('Nearest1dxx') P.subplot(223) P.pcolor(xxob, yyob, varol, **kw) P.axis(axlims) P.title('Linear1dxx') P.subplot(224) P.pcolor(xxob, yyob, varoh, **kw) P.axis(axlims) P.title('Hermit1dxx') P.tight_layout() figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) P.savefig(figfile) P.close()
"""Test :func:`~vacumm.misc.plot.add_logo`""" # Imports from vcmq import N, P, add_logo, os, code_file_name, data_sample import matplotlib.image as mpimg # Inits logofile = data_sample('logo_ifremer.png') P.plot([2, 6]) # Default add_logo(logofile, scale=1) # Upper right / no rescale add_logo(logofile, loc='upper right') # Rescale add_logo(logofile, loc='upper left', scale=2) # Alpha add_logo(logofile, loc='lower right', alpha=0.2) # Save figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) P.savefig(figfile)
from time import time # Input nx = ny = 300 vari = MV2.array(N.arange(nx*ny*1.).reshape(ny, nx)) gridi = create_grid2d(vari.getAxis(1)[:]*50/nx, vari.getAxis(0)[:]*50/nx) set_grid(vari, gridi) # Output grid gridor = create_grid2d(vari.getAxis(1)[:]*0.09*50/nx, vari.getAxis(0)[:]*0.09*50/nx) gridoc = rotate_grid(gridi, 30) # Log logfile = code_file_name(ext='log') if os.path.exists(logfile): os.remove(logfile) f = open(logfile, 'w') print >>f, 'NY=%(ny)i, NX=%(nx)i'%locals() # Loop on methods for tool, methods in config.items(): for method in methods: # print tool.upper(), method print >>f, tool.upper(), method # rect... t0 = time() r = CDATRegridder(vari, gridor, tool=tool, method=method) t1 = time() dt = t1-t0 varo = r(vari)