def sgs(data, model, hs, bw, xs, ys=None, pad=0.0): ''' Input: (data) <N,3> NumPy array of data (hs) NumPy array of distances (bw) bandwidth of the semivariogram (xs) number of cells in the x dimension (ys) number of cells in the y dimension Output: (M) <xsteps,ysteps> NumPy array of data representing the simulated distribution of the variable of interest ''' # check for meshsize in second dimension if ys == None: ys = xs # create path xdim = (data[:, 0].min() - pad, data[:, 0].max() + pad, xs) ydim = (data[:, 1].min() - pad, data[:, 1].max() + pad, ys) path = gridpath(xdim, ydim) # create array for the output M = np.zeros((xs, ys)) # for each cell in the grid.. for step in path: # grab the index, the cell address, and the physical location idx, cell, loc = step # perform the kriging kv = k.krige(data, model, hs, bw, loc, 4) # add the kriging estimate to the output M[cell[0], cell[1]] = kv # add the kriging estimate to a spatial location newdata = [loc[0], loc[1], kv] # add this new point to the data used for kriging data = np.vstack((data, newdata)) return M
def sgs( data, model, hs, bw, xs, ys=None, pad=0.0 ): ''' Input: (data) <N,3> NumPy array of data (hs) NumPy array of distances (bw) bandwidth of the semivariogram (xs) number of cells in the x dimension (ys) number of cells in the y dimension Output: (M) <xsteps,ysteps> NumPy array of data representing the simulated distribution of the variable of interest ''' # check for meshsize in second dimension if ys == None: ys = xs # create path xdim = ( data[:,0].min()-pad, data[:,0].max()+pad, xs ) ydim = ( data[:,1].min()-pad, data[:,1].max()+pad, ys ) path = gridpath( xdim, ydim ) # create array for the output M = np.zeros((xs,ys)) # for each cell in the grid.. for step in path : # grab the index, the cell address, and the physical location idx, cell, loc = step # perform the kriging kv = k.krige( data, model, hs, bw, loc, 4 ) # add the kriging estimate to the output M[cell[0],cell[1]] = kv # add the kriging estimate to a spatial location newdata = [ loc[0], loc[1], kv ] # add this new point to the data used for kriging data = np.vstack(( data, newdata )) return M
def test_simple_kriging_gaussian_model(self): ''' Does krige() return a result within eps=0.0001 of a benchmarked value? ''' kv = k.krige(data, k.gaussian, hs, bw, u, N) ans = 2.14052910511 self.assertTrue(abs(ans - kv) < eps)
def test_simple_kriging_exponential_model(self): ''' Does krige() return a result within eps=0.0001 of a benchmarked value? ''' kv = k.krige(data, k.exponential, hs, bw, u, N) ans = 2.42879523605 self.assertTrue(abs(ans - kv) < eps)
def test_simple_kriging_spherical_model(self): ''' Does krige() return a result within eps=0.0001 of a benchmarked value? ''' kv = k.krige(data, k.spherical, hs, bw, u, N) ans = 2.29891949337 self.assertTrue(abs(ans - kv) < eps)
def test_simple_kriging_gaussian_model( self ): ''' Does krige() return a result within eps=0.0001 of a benchmarked value? ''' kv = k.krige( data, k.gaussian, hs, bw, u, N ) ans = 2.14052910511 self.assertTrue( abs( ans - kv ) < eps )
def test_simple_kriging_exponential_model( self ): ''' Does krige() return a result within eps=0.0001 of a benchmarked value? ''' kv = k.krige( data, k.exponential, hs, bw, u, N ) ans = 2.42879523605 self.assertTrue( abs( ans - kv ) < eps )
def test_simple_kriging_spherical_model( self ): ''' Does krige() return a result within eps=0.0001 of a benchmarked value? ''' kv = k.krige( data, k.spherical, hs, bw, u, N ) ans = 2.29891949337 self.assertTrue( abs( ans - kv ) < eps )
covfct = model.covariance(model.spherical, (4000, sill)) # <markdowncell> # We can then krige the data, using the covariance model, the point we are interested in, (2000,47000), and `N=6` signifying that we only want to use the six nearest points. The output of the simple and ordinary kriging functions below is the krigin estimate, and the standard deviation of the kriging estimate. # <codecell> kriging.simple(P, covfct, pt, N=6) # <codecell> kriging.ordinary(P, covfct, pt, N=6) # <codecell> est, kstd = kriging.krige( P, covfct, [[2000, 4700], [2100, 4700], [2000, 4800], [2100, 4800]], 'simple', N=6) # <codecell> est # <codecell> kstd
# The covariance modeling function function will return a spherical covariance model that takes a distance as input, and returns an covariance estimate. We've used the global variance of the porosity in `ZoneA.dat` as the sill. # <codecell> covfct = model.covariance( model.spherical, ( 4000, sill ) ) # <markdowncell> # We can then krige the data, using the covariance model, the point we are interested in, (2000,47000), and `N=6` signifying that we only want to use the six nearest points. The output of the simple and ordinary kriging functions below is the krigin estimate, and the standard deviation of the kriging estimate. # <codecell> kriging.simple( P, covfct, pt, N=6 ) # <codecell> kriging.ordinary( P, covfct, pt, N=6 ) # <codecell> est, kstd = kriging.krige( P, covfct, [[2000,4700],[2100,4700],[2000,4800],[2100,4800]], 'simple', N=6 ) # <codecell> est # <codecell> kstd