"""Test functions :func:`~vacumm.misc.grid.kriging.variogram`""" 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()
"""Test function :func:`~vacumm.misc.grid.kriging.krig`""" npi = 500 npo = 200 from vcmq import P, savefigs, code_file_name from vacumm.misc.grid.kriging import gridded_gauss3, random_gauss3, random_points, krig # Generate random field xg, yg, zzg = gridded_gauss3() xi, yi, zi = random_gauss3(np=npi) # Interpolate to random points xo, yo = random_points(np=npo) zo = krig(xi, yi, zi, xo, yo) # Plot # - source data axis = [xg.min(), xg.max(), yg.min(), yg.max()] kw = dict(vmin=zzg.min(), vmax=zzg.max()) kwim = dict(extent=axis, interpolation='bilinear', origin='lower', alpha=.2, **kw) kwsc = dict(lw=0.2, **kw) P.figure(figsize=(6, 3.5)) P.subplot(121) P.title('Source field') P.imshow(zzg, **kwim) P.scatter(xi, yi, c=zi, **kwsc)
"""Test functions :func:`~vacumm.misc.grid.kriging.variogram`""" 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()
"""Test class :func:`~vacumm.misc.grid.kriging.OrdinaryCloudKriger`""" npi = 50 from vcmq import P, savefigs, code_file_name from vacumm.misc.grid.kriging import (gridded_gauss3, random_gauss3, random_points, OrdinaryCloudKriger) # Generate random field xg, yg, zzg = gridded_gauss3() xi, yi, zi = random_gauss3(np=npi) # Setup kriger ock = OrdinaryCloudKriger(xi, yi, zi, n=0) # nugget = 0 # Interpolate to grid and get error xo, yo = P.meshgrid(xg[::4], yg[::4]) xo.shape = yo.shape = xo.size zo, zoe = ock(xo, yo, geterr=True) # Relative error zoemax = ock.variogram_func(P.inf) zoe /= zoemax zoe *= 100 # Variogram evolution rr = P.linspace(0, P.sqrt(xg.ptp()**2+yg.ptp()**2), 100) vv = ock.variogram_func(rr) # Plot P.figure(figsize=(8, 8))