P.plot(xi, zzi[iyi], 'ob-', markersize=8, label='Original' if label else None) P.plot(xo, zzo[iyi * r], 'or-', markersize=5, lw=.8, label='Interpolated' if label else None) P.legend(loc='best', framealpha=0.5) P.grid() P.title('Section') P.tight_layout() savefigs(code_file_name(ext='_0.png'), verbose=False, pdf=True) # Maps P.figure(figsize=(8, 4)) levels = auto_scale(vmin=zzi.min(), vmax=zzi.max(), nmax=30) P.subplot(121) P.contourf(xxi, yyi, zzi, levels=levels) P.contour(xxi, yyi, zzi, linewidths=0.1, levels=levels, colors='k') add_grid((xxi, yyi), alpha=.3, centers=True) for iyi in iyis: P.axhline(yi[iyi], linestyle='--', color='k') P.title('Original') P.subplot(122) P.contourf(xxo, yyo, zzo, levels=levels) P.contour(xxo, yyo, zzo, linewidths=0.1, levels=levels, colors='k') add_grid((xxo, yyo), alpha=.2, centers=True)
# -*- coding: utf8 -*- # Read sea level at Brest from vcmq import cdms2, P, curve2, savefigs, data_sample f = cdms2.open(data_sample("tide.sealevel.BREST.mars.nc")) sea_level = f('sea_level') f.close() # Filtering from vacumm.tide.filters import demerliac cotes, tide = demerliac(sea_level, get_tide=True) # Plots kwplot = dict(date_fmt='%d/%m', show=False, date_rotation=0) # - tidal signal curve2(sea_level, 'k', subplot=211, label='Original', title='Sea level at Brest', **kwplot) curve2(tide, 'b', label='Tidal signal', **kwplot) P.legend().legendPatch.set_alpha(.7) # - surcotes/decotes curve2(cotes, 'r', subplot=212, hspace=.3, label='Demerliac', **kwplot) P.legend().legendPatch.set_alpha(.7) savefigs(__file__, savefigs_pdf=True) P.close()
zirn = griddata(xi, yi, zi, (xr, yr), method='linear', ext=True, sub=6) # - ifremer cargen zirk = griddata(xi, yi, zi, (xr, yr), method='carg') # %% Plots P.figure(1, figsize=(6, 8)) P.subplots_adjust(hspace=.3, bottom=.05, top=.95, left=.06) # - original P.subplot(311) P.pcolor(xrb, yrb, zzr, **vminmax) P.xlim(xrb.min(), xrb.max()) P.ylim(yrb.min(), yrb.max()) P.title('Original') stdref = zzr.std() # - linear interp P.subplot(312) P.pcolor(xrb, yrb, zirn, **vminmax) P.plot(xi, yi, 'ko') P.xlim(xrb.min(), xrb.max()) P.ylim(yrb.min(), yrb.max()) P.title('Scipy/linear (err = %02i%%)' % ((zzr - zirn).std() * 100 / stdref)) # - ifremer cargen interp P.subplot(313) P.pcolor(xrb, yrb, zirk, **vminmax) P.plot(xi, yi, 'ko') P.xlim(xrb.min(), xrb.max()) P.ylim(yrb.min(), yrb.max()) P.title('Cargen (err = %02i%%)' % ((zzr - zirk).std() * 100 / stdref)) savefigs(__file__) P.close()
set_grid(vari, gridi) # set grid and axes # Extend and plot rc('font', size=9) P.figure(figsize=(6, 6)) kw = dict(xmin=xxi.min() - 3, xmax=xxi.max() + 3, ymin=yyi.min() - 3, ymax=yyi.max() + 3, show=False, xhide='auto', yhide='auto') # - original plot2d(vari, title='Original', subplot=(2, 2, 1), **kw) # - extend1d for i, (axis, ext, mode) in enumerate([(-1, (2, 2), 'same'), (-2, 2, 'linear')]): varo = extend1d(vari, ext=ext, axis=axis, mode=mode) plot2d(varo, subplot=(2, 2, i + 3), title='interp1d: axis=%s\next=%s, mode=%s' % (axis, ext, mode), **kw) varo = extend2d(vari, iext=2, jext=2, mode='linear') plot2d(varo, subplot=(2, 2, 2), title='interp2d: mode=linear\niext=2, jext=2', **kw) P.tight_layout() savefigs(code_file_name(), verbose=False) P.close()
nx = ny = 50 np = 500 mtype = 'gauss' dmax = 2.5 from vcmq import N, P, code_file_name, savefigs from vacumm.misc.grid.kriging import gridded_gauss3, random_gauss3, variogram, variogram_fit # Generate random field xxg, yyg, zzg = gridded_gauss3(nx=nx, ny=ny) x, y, z = random_gauss3(np=np) # Variogram from data d, v = variogram(x, y, z, dmax=dmax) # Variogram fit with null nugget vm = variogram_fit(x, y, z, mtype, n=0, dmax=dmax) D = N.linspace(0, d.max()) V = vm(D) # Compare P.figure(figsize=(6, 4)) P.title('Variogram') P.plot(d, v, 'ob', label='From data') P.plot(D, V, '-r', label='Fitted model (%s)'%mtype) P.legend(loc='best') P.ylim(ymin=0) savefigs(code_file_name(ext=False), pdf=True, verbose=False) P.close()
nx = ny = 50 np = 500 mtype = 'gauss' distmax = 2.5 from vcmq import N, P, code_file_name, savefigs from vacumm.misc.grid.kriging import gridded_gauss3, random_gauss3, variogram, variogram_fit # Generate random field xxg, yyg, zzg = gridded_gauss3(nx=nx, ny=ny) x, y, z = random_gauss3(np=np) # Variogram from data d, v = variogram(x, y, z, distmax=distmax) # Variogram fit with null nugget vm = variogram_fit(x, y, z, mtype, n=0, distmax=distmax) D = N.linspace(0, d.max()) V = vm(D) # Compare P.figure(figsize=(6, 4)) P.title('Variogram') P.plot(d, v, 'ob', label='From data') P.plot(D, V, '-r', label='Fitted model (%s)' % mtype) P.legend(loc='best') P.ylim(ymin=0) savefigs(code_file_name(ext=False), pdf=True, verbose=False) P.close()
# Interpolate zzo = krig(xxi.ravel(), yyi.ravel(), zzi.ravel(), xxo.ravel(), yyo.ravel()) zzo.shape = xxo.shape # Section P.figure(figsize=(8, 4)) iyis = [3, 4] for iyi in iyis: label = iyi==iyis[0] P.plot(xi, zzi[iyi], 'ob-', markersize=8, label='Original' if label else None) P.plot(xo, zzo[iyi*r], 'or-', markersize=5, lw=.8, label='Interpolated' if label else None) P.legend(loc='best', framealpha=0.5) P.grid() P.title('Section') P.tight_layout() savefigs(code_file_name(ext='_0.png'), verbose=False, pdf=True) # Maps P.figure(figsize=(8, 4)) levels = auto_scale(vmin=zzi.min(), vmax=zzi.max(), nmax=30) P.subplot(121) P.contourf(xxi, yyi, zzi, levels=levels) P.contour(xxi, yyi, zzi, linewidths=0.1, levels=levels, colors='k') add_grid((xxi, yyi), alpha=.3, centers=True) for iyi in iyis: P.axhline(yi[iyi], linestyle='--', color='k') P.title('Original') P.subplot(122) P.contourf(xxo, yyo, zzo, levels=levels) P.contour(xxo, yyo, zzo, linewidths=0.1, levels=levels, colors='k') add_grid((xxo, yyo), alpha=.2, centers=True)
rr = P.linspace(0, P.sqrt(xg.ptp()**2+yg.ptp()**2), 100) vv = ock.variogram_func(rr) # Plot P.figure(figsize=(8, 8)) axis = [xg.min(), xg.max(), yg.min(), yg.max()] kwmm = dict(vmin=zi.min(), vmax=zi.max()) kwsc = dict(lw=0.2, **kwmm) ax = P.subplot(221, aspect=1) P.imshow(zzg, extent=axis, interpolation='bilinear', origin='lower', alpha=.2, **kwmm) P.scatter(xi, yi, c=zi, s=20, lw=0.2, **kwmm) P.axis(axis) P.title('Input points') P.subplot(222, aspect=1) P.scatter(xo, yo, c=zo, s=40, lw=0.2, **kwmm) P.axis(axis) P.title('Interpolated points') P.subplot(223, aspect=1) P.scatter(xo, yo, c=zoe, s=40, lw=0.2, vmin=0, vmax=100) P.axis(axis) P.colorbar(shrink=.8) P.title('Relative interpolation error') P.subplot(224) P.plot(rr, vv) P.xlabel('Distance') P.ylabel('Error') P.title('Fitted variogram') P.tight_layout() savefigs(code_file_name(), verbose=False) P.close()
# -*- coding: utf8 -*- # Read sea level at Brest from vcmq import cdms2, P, curve2, savefigs, data_sample f = cdms2.open(data_sample("tide.sealevel.BREST.mars.nc")) sea_level = f('sea_level') f.close() # Filtering from vacumm.tide.filters import demerliac cotes, tide = demerliac(sea_level, get_tide=True) # Plots kwplot = dict(date_fmt='%d/%m', show=False, date_rotation=0) # - tidal signal curve2(sea_level, 'k', subplot=211, label='Original', title='Sea level at Brest',**kwplot) curve2(tide, 'b', label='Tidal signal', **kwplot) P.legend().legendPatch.set_alpha(.7) # - surcotes/decotes curve2(cotes, 'r', subplot=212, hspace=.3, label='Demerliac', **kwplot) P.legend().legendPatch.set_alpha(.7) savefigs(__file__, savefigs_pdf=True)