Kriging vs. Simulation, A 2D Map Example - GeostatsPy Well-Documented Demonstration Geostatistical Workflows
Kriging vs. Simulation, A 2D Map Example - GeostatsPy Well-Documented Demonstration Geostatistical Workflows
Simulation, a 2D
Map Example
Contents
Estimation vs. Simulation
Spatial Estimation
Kriging
Sequential Gaussian Simulation
Load the Required Libraries
Declare Functions
Print to PDF
Set the Working Directory
Loading Tabular Data
Set Limits for Plotting, Colorbars and Grid Specification
Data Analytics and Visualization
Simple Kriging
Sequential Gaussian Simulation
Visualize Simulated Realizations and a Kriged Estimation Model
Comments
About the Author
Want to Work Together?
Pyrcz, M.J., 2024, GeostatsPyDemos: GeostatsPy Python Package for Spatial Data
Analytics and Geostatistics Demonstration Workflows Repository (0.0.1) [Software].
Zenodo. doi:10.5281/zenodo.12667036. GitHub Repository:
GeostatsGuy/GeostatsPyDemos DOI 10.5281/zenodo.12667036
By Michael J. Pyrcz
© Copyright 2024.
This chapter is a tutorial for / demonstration of Spatial Estimation with Kriging vs.
Simulation with Sequential Gaussian Simulation (SGSIM) with a 2D map example.
Trend Modeling
Kriging
Stochastic Simulation
Estimation:
Simulation:
Spatial Estimation
Consider the case of making an estimate at some unsampled location, , where
z(u 0 ) z is
the property of interest (e.g. porosity etc.) and u0 is a location vector describing the
unsampled location.
How would you do this given data, z(u 1 ), z(u 2 ), and z(u 3 )?
It would be natural to use a set of linear weights to formulate the estimator given the
available data.
∗
z (u) = ∑ λ α z(u α )
α=1
We could add an unbiasedness constraint to impose the sum of the weights equal to one.
What we will do is assign the remainder of the weight (one minus the sum of weights) to the
global average; therefore, if we have no informative data we will estimate with the global
average of the property of interest.
n n
∗ –
z (u) = ∑ λ α z(u α ) + (1 − ∑ λ α )z
α=1 α=1
We will make a stationarity assumption, so let’s assume that we are working with residuals,
y.
∗ ∗ –
y (u) = z (u) − z(u)
If we substitute this form into our estimator the estimator simplifies, since the mean of the
residual is zero. Skip to main content
n
∗
y (u) = ∑ λ α y(u α )
α=1
Kriging
Now the next question is what weights should we use?
n
, and the estimator would be the average of the local
data applied for the spatial estimate. This would not be very informative.
We could assign weights considering the spatial context of the data and the estimate:
redundancy the degree of spatial continuity between all of the available data with
themselves
closeness the degree of spatial continuity between the available data and the
estimation location
The kriging approach accomplishes this, calculating the best linear unbiased weights for the
local data to estimate at the unknown location. The derivation of the kriging system and the
resulting linear set of equations is available in the lecture notes. Furthermore kriging
provides a measure of the accuracy of the estimate! This is the kriging estimation variance
(sometimes just called the kriging variance).
2
σ (u) = C(0) − ∑ λ α C(u 0 − u α )
E
α=1
What is ‘best’ about this estimate? Kriging estimates are best in that they minimize the
above estimation variance.
Properties of Kriging
Here are some important properties of kriging:
Exact interpolator - kriging estimates with the data values at the data locations
In this chapter, we run kriging estimates and multiple simulation realizations, and compare
the statistics.
We will also need some standard packages. These should have been installed with
Anaconda 3.
If you get a package import error, you may have to first install some of these packages. This
can usually be accomplished by opening up a command window on Windows and then
typing ‘python -m pip install [package-name]’. More assistance is available with the
respective package docs.
Declare Functions
Here’s a convenience function for plotting variograms.
def vargplot(feature,lags,gamma_maj,gamma_min,npps_maj,npps_min,vmodel,azi,a
index_maj,lags_maj,gmod_maj,cov_maj,ro_maj = geostats.vmodel(nlag=100,xl
index_min,lags_min,gmod_min,cov_min,ro_min = geostats.vmodel(nlag=100,xl
def locpix_st(array,xmin,xmax,ymin,ymax,step,vmin,vmax,df,xcol,ycol,vcol,tit
xx, yy = np.meshgrid(np.arange(xmin, xmax, step), np.arange(ymax, ymin,
cs = plt.imshow(array,interpolation = None,extent = [xmin,xmax,ymin,ymax
plt.scatter(df[xcol],df[ycol],s=20,c=df[vcol],marker='o',cmap=cmap,vmin=
plt.scatter(df[xcol],df[ycol],s=40,c='white',marker='o',alpha=0.8,linewi
plt.title(title); plt.xlabel(xlabel)
plt.ylabel(ylabel); plt.xlim(xmin, xmax); plt.ylim(ymin, ymax)
cbar = plt.colorbar(cs,orientation="vertical",cmap=cmap)
cbar.set_label(vlabel, rotation=270, labelpad=20)
return cs
note the “fraction_data” variable is an option to random take part of the data (i.e., 1.0 is
all data).
this is not standard part of spatial estimation, but fewer data is easier to visualize
given our grid size (we want multiple cells between the data to see the behavior
away from data)
note, I often remove unnecessary data table columns. This clarifies workflows and
reduces the chance of blunders, e.g., using the wrong column!
X Y Porosity
location map
histogram
variogram
plt.subplot(222) # histogram
plt.hist(df['Porosity'].values,bins=np.linspace(pormin,pormax,30),color='dar
label = 'Porosity')
plt.hist(df['Porosity'].values,bins=np.linspace(pormin,pormax,30),color='dar
label = 'Porosity')
plt.xlabel('Porosity (%)'); plt.ylabel('Frequency'); plt.title('Porosity His
plt.subplot(223) # variogram
vmodel = GSLIB.make_variogram(nug,nst,it1,cc1,azi1,hmaj1,hmin1,it2,cc2,azi2,
vmodel_sim = GSLIB.make_variogram(nug,nst,it1,cc1/(cc1+cc2),azi1,hmaj1,hmin1
vargplot('Porosity',lags,gamma_maj,gamma_min,npps_maj,npps_min,vmodel,azi=0.
legend_pos='lower right') # plot the var
%%capture --no-display
por_vario = GSLIB.make_variogram(nug=vrel_nugget*sill,nst=1,it1=1,cc1=(1.0-v
azi1=vazi,hmaj1=vrange_maj,hmin1=vrange_min) # porosity var
%%capture --no-display
plt.subplot(223) # histograms
plt.hist(df['Porosity'].values,density=True,bins=np.linspace(pormin,pormax,5
edgecolor='black',label='Data',zorder=10)
plt.hist(por_kmap.flatten(),density=True,bins=np.linspace(pormin,pormax,50),
edgecolor='black',label='Kriging',zorder=1)
plt.xlabel('Porosity (%)'); plt.ylabel('Frequency'); plt.title('Porosity His
plt.subplot(224) # experimenta
vargplot('Porosity',lags,sk_gamma_maj,sk_gamma_min,npps_maj,npps_min,vmodel,
mcolor = 'red', rcolor = 'blue',size= 0.05,legend_pos = 'upper righ
%%capture --no-display
if run:
por_sim_one = geostats.sgsim(df,'X','Y','Porosity',wcol=-1,scol=-1,tmin=
twtcol=0,zmin=pormin,zmax=pormax,ltail=1,ltpar=0.0,utail=1,utpar
nx=nx,xmn=xmn,xsiz=xsiz,ny=ny,ymn=ymn,ysiz=ysiz,seed=73073,
ndmin=0,ndmax=20,nodmax=20,mults=0,nmult=2,noct=-1,
ktype=0,colocorr=0.0,sec_map=0,vario=vmodel_sim)[0]
plt.subplot(221) # pixelplot an
locpix_st(por_sim_one,xmin,xmax,ymin,ymax,xsiz,pormin,pormax,df,'X','Y','Por
plt.subplot(222) # histograms
plt.hist(df['Porosity'].values,density=True,bins=np.linspace(pormin,pormax,3
plt.hist(por_sim_one.flatten(),density=True,bins=np.linspace(pormin,pormax,3
plt.xlabel('Porosity (%)'); plt.ylabel('Frequency'); plt.title('Porosity His
Skip to main content
lags, sim_gamma_maj, npps_maj = geostats.gam(por_sim_one,tmin,tmax,xsiz,ysiz
lags, sim_gamma_min, npps_min = geostats.gam(por_sim_one,tmin,tmax,xsiz,ysiz
plt.subplot(223) # variograms
vargplot('Porosity',lags,sim_gamma_maj,sim_gamma_min,npps_maj,npps_min,vmode
mcolor = 'red', rcolor = 'green',size= 0.05,legend_pos = 'lower righ
plt.subplot(222) # pixelplot an
locpix_st(por_sim[1],xmin,xmax,ymin,ymax,xsiz,pormin,pormax,df,'X','Y','Poro
plt.subplot(223) # pixelplot an
locpix_st(por_sim[2],xmin,xmax,ymin,ymax,xsiz,pormin,pormax,df,'X','Y','Poro
plt.subplot(224) # pixelplot an
locpix_st(por_kmap,xmin,xmax,ymin,ymax,xsiz,pormin,pormax,df,'X','Y','Porosi
Comments
This was a basic demonstration and comparison of spatial estimation vs. spatial simulation
with kriging and sequential Gaussian simulation from GeostatsPy. Much more can be done, I
have other demonstrations for modeling workflows with GeostatsPy in the GitHub repository
GeostatsPy_Demos.
Professor Michael Pyrcz in his office on the 40 acres, campus of The University of Texas
at Austin.
Michael Pyrcz is a professor in the Cockrell School of Engineering, and the Jackson School
of Geosciences, at The University of Texas at Austin, where he researches and teaches
subsurface, spatial data analytics, geostatistics, and machine learning. Michael is also,
the principal investigator of the Energy Analytics freshmen research initiative and a core
faculty in the Machine Learn Laboratory in the College of Natural Sciences, The
University of Texas at Austin
an associate editor for Computers and Geosciences, and a board member for
Mathematical Geosciences, the International Association for Mathematical
Geosciences.
Michael has written over 70 peer-reviewed publications, a Python package for spatial data
analytics, co-authored a textbook on spatial data analytics, Geostatistical Reservoir
Modeling and author of two recently released e-books, Applied Geostatistics in Python: a
Hands-on Guide with GeostatsPy and Applied Machine Learning in Python: a Hands-on
Guide with Code.
All of Michael’s university lectures are available on his YouTube Channel with links to 100s
of Python interactive dashboards Skip
and well-documented
to main content workflows in over 40 repositories on
his GitHub account, to support any interested students and working professionals with
evergreen content. To find out more about Michael’s work and shared educational resources
visit his Website.
Want to invite me to visit your company for training, mentoring, project review, workflow
design and / or consulting? I’d be happy to drop by and work with you!
Interested in partnering, supporting my graduate student research or my Subsurface
Data Analytics and Machine Learning consortium (co-PI is Professor John Foster)? My
research combines data analytics, stochastic modeling and machine learning theory
with practice to develop novel methods and workflows to add value. We are solving
challenging subsurface problems!
I can be reached at [email protected].
Michael
Michael Pyrcz, Ph.D., P.Eng. Professor, Cockrell School of Engineering and The Jackson
School of Geosciences, The University of Texas at Austin
More Resources Available at: Twitter | GitHub | Website | GoogleScholar | Geostatistics Book
| YouTube | Applied Geostats in Python e-book | Applied Machine Learning in Python e-book |
LinkedIn
Previous Next
Kriging vs. Simulation, a 1D Indicator Simulation
Example