<jupyter_start><jupyter_text>This notebook is the reproduction of an exercise found at http://people.ku.edu/~gbohling/cpe940/Kriging.pdf<jupyter_code>import sys
sys.path.append('..')
sys.path.append('../geostatsmodels')
from geostatsmodels import utilities, variograms, model, kriging, geoplot
import matplotlib.pyplot as plt
import numpy as np
import pandas<jupyter_output><empty_output><jupyter_text>We'll read the data from `ZoneA.dat`.<jupyter_code>z = utilities.readGeoEAS('../data/ZoneA.dat')<jupyter_output><empty_output><jupyter_text>We want the first, second and fourth columns of the data set, representing the x and y spatial coordinates, and the porosity.<jupyter_code>P = z[:,[0,1,3]]<jupyter_output><empty_output><jupyter_text>We'll be interested in determining the porosity at a point (2000,4700).<jupyter_code>pt = [2000, 4700]<jupyter_output><empty_output><jupyter_text>We can plot our region of interest as follows:<jupyter_code>plt.scatter(P[:,0], P[:,1], c=P[:,2], cmap=geoplot.YPcmap)
plt.title('Zone A Subset % Porosity')
plt.colorbar()
xmin, xmax = 0, 4250
ymin, ymax = 3200, 6250
plt.xlim(xmin,xmax)
plt.ylim(ymin,ymax)
for i in range(len(P[:,2])):
    x, y, por = P[i]
    if (x < xmax) & (y > ymin) & (y < ymax):
        plt.text( x+100, y, '{:4.2f}'.format( por ) ) 
plt.scatter(pt[0], pt[1], marker='x', c='k')
plt.text(pt[0] + 100 , pt[1], '?')
plt.xlabel('Easting (m)')
plt.ylabel('Northing (m)');<jupyter_output><empty_output><jupyter_text>We can determine the parameters for our model by looking at the semivariogram and trying to determine the appropriate range and sill.<jupyter_code>tolerance = 250
lags = np.arange(tolerance, 10000, tolerance*2)
sill = np.var(P[:,2])<jupyter_output><empty_output><jupyter_text>The semivariogram plotting function, `svplot()`, plots sill as a dashed line, and the empirical semivariogram as determined from the data. It optionally plots a semivariance model.<jupyter_code>geoplot.semivariogram(P, lags, tolerance)<jupyter_output><empty_output><jupyter_text>We can pass a model to this function using the optional `model` argument and see it plotted in red.<jupyter_code>svm = model.semivariance(model.spherical, (4000, sill))
geoplot.semivariogram(P, lags, tolerance, model=svm)<jupyter_output><empty_output><jupyter_text>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.<jupyter_code>covfct = model.covariance(model.spherical, (4000, sill))<jupyter_output><empty_output><jupyter_text>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.<jupyter_code>kriging.simple(P, covfct, pt, N=6)
kriging.ordinary(P, covfct, pt, N=6)
est, kstd = kriging.krige(P, covfct, [[2000,4700],[2100,4700],[2000,4800],[2100,4800]], 'simple', N=6)
est
kstd<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12760581174984206, 'fraction_numerical': 0.036007580543272265, 'mean_word_length': 6.64975845410628, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '30945', 'license': 'MIT', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1117, 'n_words': 313, 'path': 'notebooks/KrigingExample.ipynb', 'repo_name': 'alessandro-gentilini/geostatsmodels', 'size': '3166'}