Comparing Kriging and CoKriging¶
This test s meant to demonstrate the use of CoKriging in Heterotopic case. A second part also demonstrates the various cases of CoKriging simplifications, I;E; when Cokriging of several variables simplifies into one or several Kriging of each variable individually.
In [1]:
import gstlearn as gl
import gstlearn.plot as gp
import gstlearn.document as gdoc
import numpy as np
import matplotlib.pyplot as plt
import gstlearn.plot as gp
import scipy.sparse as sc
gdoc.setNoScroll()
CoKriging vs. Kriging in 2-D¶
We create a grid and two models
In [2]:
grid = gl.DbGrid.create(nx=[300,200])
modelC = gl.Model.createFromParam(gl.ECov.CUBIC,range=40)
modelE = gl.Model.createFromParam(gl.ECov.EXPONENTIAL,range=20)
In [3]:
ax = gp.model(modelC)
ax.decoration(title="Cubic Model")
In [4]:
ax = gp.model(modelE)
ax.decoration(title="Exponential Model")
Working on exhaustive grids¶
We simulate two underlying GRFs exhaustively on the grid
In [5]:
err = gl.simtub(None,grid,modelC)
grid.setName("Simu", "S1")
err = gl.simtub(None,grid,modelE)
grid.setName("Simu", "S2")
In [6]:
fig = plt.figure(figsize=(12,4))
ax1 = fig.add_subplot(1,2,1)
ax1 = gp.raster(grid,name="S1")
ax2 = fig.add_subplot(1,2,2)
ax2 = gp.raster(grid,name="S2")
fig.decoration(title="Factors")
Calculating the variograms on the two Factors benefiting from the Grid organization. We can check that they are point-wise and spatially independent.
In [7]:
grid.setLocators(["S*"],gl.ELoc.Z)
nlag=40
varioParamG = gl.VarioParam.createMultipleFromGrid(grid,nlag)
vario = gl.Vario.computeFromDb(varioParamG, grid)
axs = gp.varmod(vario)
gp.decoration(axs, title="Model for Factors")
In [8]:
ax = gp.correlation(grid, "S1", "S2", bins=100, cmin=1)
ax.decoration(title="Scatter Plot between Factors")
We define an internal function that generates two variables obtained as mixtures of the two underlying factors
In [9]:
def variable_generate(grid, c1, c2):
grid["Z1"] = c1[0] * grid["S1"] + c1[1] * grid["S2"]
grid["Z2"] = c2[0] * grid["S1"] + c2[1] * grid["S2"]
grid.setLocators(["Z*"],gl.ELoc.Z)
Create the two variables of interest
In [10]:
c1 = [3,1]
c2 = [1,2]
variable_generate(grid,c1,c2)
In [11]:
fig = plt.figure(figsize=(12,4))
ax1 = fig.add_subplot(1,2,1)
ax1 = gp.raster(grid,name="Z1")
ax2 = fig.add_subplot(1,2,2)
ax2 = gp.raster(grid,name="Z2")
fig.decoration(title="Variables")