Model Definition¶
In [1]:
import gstlearn as gl
import gstlearn.plot as gp
import gstlearn.widgets as gw
import gstlearn.document as gdoc
import numpy as np
import os
import matplotlib.pyplot as plt
import pandas as pd
from scipy.spatial import distance_matrix
%matplotlib inline
%matplotlib notebook
gdoc.setNoScroll()
We create the Dictionary of the available basic structures in gstlearn: we concentrate on the only ones that can be simulated using the Turning Bands method
In [2]:
modelList = gl.CovHelper.getAllCovariances(flagSimtub = True)
models = dict()
for rank in range(len(modelList)):
loctype = gl.ECov.fromKey(modelList[rank])
locname = gl.ECov.getDescr(loctype)
models[locname] = loctype
In [3]:
modelList
Out[3]:
('NUGGET', 'EXPONENTIAL', 'SPHERICAL', 'GAUSSIAN', 'CUBIC', 'SINCARD', 'BESSELJ', 'MATERN', 'STABLE')
In [4]:
model = gl.Model.createFromParam(gl.ECov.SPHERICAL,range=2,sill=3)
Defining the visualization function
In [5]:
def plotModel(axs, model, n=50, ymax=1.4, nbtuba=200, nlag=25):
# Calculate the Grids
dbp = gl.DbGrid.create(nx=[1,1],x0=[n,n])
db = gl.DbGrid.create(nx=[2*n,2*n])
gl.simtub(None,db,model,nbtuba=nbtuba)
db["model"] = 1 - model.evalCovMatrix(db,dbp).toTL()
sill = model.getSill(0,0,0)
# Calculate the experimental variogram
varioparam = gl.VarioParam.createMultipleFromGrid(db, nlag)
vario = gl.Vario.computeFromDb(varioparam, db)
# Draw the Theoretical variogram Map
axs[0][0].clear()
axs[0][0].raster(db,"model")
axs[0][0].decoration(title="Model")
# Draw one simulation
axs[0][1].clear()
axs[0][1].raster(db,"*Simu")
axs[0][1].decoration(title="Simulation")
# Draw the Model
axs[1][0].clear()
axs[1][0].model(model,hmax=70,codir=[1,0],c="red")
axs[1][0].model(model,hmax=70,codir=[0,1],c="black")
axs[1][0].geometry(xlim=[0,None])
axs[1][0].geometry(ylim=[0,sill*ymax])
axs[1][0].decoration(title="Variogram Model")
# Draw the experimental variograms in the two main Grid directions
axs[1][1].clear()
axs[1][1].variogram(vario,idir=0,color="red")
axs[1][1].variogram(vario,idir=1,color="black")
axs[1][1].geometry(xlim=[0,None])
axs[1][1].geometry(ylim=[0,sill*ymax])
axs[1][1].decoration(title="Experimental Variogram")
# Delete the newly created variables on the grid
db.deleteColumn("model")
db.deleteColumn("*Simu")
plt.show()
Sensitivity of Model parameters¶
In [6]:
def myCallBack(model):
plotModel(axs, model)
In [7]:
objectModel = gw.WModel(models, myCallBack, defrank=2)
display(objectModel)
fig, axs = plt.subplots(2,2,figsize=(7,7))
plotModel(axs, model)
Creating a Model with drift¶
We consider building a Model of a 2-D Random Variable by pieces.
We first define the covariance part (nested structures with a Nugget Effect and an isotropic Spherical scheme); then we add some drift conditions (first order Random Function).
In [8]:
# Creating an empty Model
model = gl.Model()
# Adding the covariance elements
model.addCovFromParam(type=gl.ECov.NUGGET, sill=2)
model.addCovFromParam(type=gl.ECov.SPHERICAL, range=10, sill=3)
# Adding the drift items
model.addDrift(gl.DriftM())
model.addDrift(gl.DriftM([1]))
model.addDrift(gl.DriftM([0,1]))
model
Out[8]:
Model characteristics ===================== Space dimension = 2 Number of variable(s) = 1 Number of basic structure(s) = 2 Number of drift function(s) = 3 Number of drift equation(s) = 3 Covariance Part --------------- Nugget Effect - Sill = 2.000 Spherical - Sill = 3.000 - Range = 10.000 Total Sill = 5.000 Drift Part ---------- Universality_Condition Drift:x1 Drift:x2