Interpolations¶
This Tutorial is meant to give some hints about using Interpolation methods in gstlearn
import numpy as np
import pandas as pd
import sys
import os
import gstlearn as gl
import gstlearn.plot as gp
import matplotlib.pyplot as plt
Setting some global variables
# Set the Global Options
verbose = True
flagGraphic = True
# Define the Space Dimension
ndim = 2
gl.defineDefaultSpace(gl.ESpaceType.RN, ndim)
# Set the Seed for the Random Number generator
gl.law_set_random_seed(32131)
Generating an initial square grid covering a 1 by 1 surface (100 meshes along each direction).
grid = gl.DbGrid.create([100,100], [0.01,0.01])
Creating a Data Set. The set is generated using a non-conditional geostatistical simulation (performed using the Turning Bands method). This simulation is first performed on the grid which is then sampled to constitute the Point Data Set.
model = gl.Model.createFromParam(gl.ECov.EXPONENTIAL, 0.1, 1.)
gl.simtub(None, grid, model)
if verbose:
grid.display()
np = 100
data = gl.Db.createSamplingDb(grid, 0., np, ["x1","x2","Simu"])
if verbose:
data.display()
Data Base Grid Characteristics ============================== Data Base Summary ----------------- File is organized as a regular grid Space dimension = 2 Number of Columns = 4 Total number of samples = 10000 Grid characteristics: --------------------- Origin : 0.000 0.000 Mesh : 0.010 0.010 Number : 100 100 Variables --------- Column = 0 - Name = rank - Locator = NA Column = 1 - Name = x1 - Locator = x1 Column = 2 - Name = x2 - Locator = x2 Column = 3 - Name = Simu - Locator = z1 Data Base Characteristics ========================= Data Base Summary ----------------- File is organized as a set of isolated points Space dimension = 2 Number of Columns = 4 Total number of samples = 100 Variables --------- Column = 0 - Name = rank - Locator = NA Column = 1 - Name = x1 - Locator = x1 Column = 2 - Name = x2 - Locator = x2 Column = 3 - Name = Simu - Locator = z1
if flagGraphic:
ax = data.plot()
ax.decoration(title="Data Set")
ax.geometry(xlim=[0,1],ylim=[0,1])
Interpolation using Moving Average technique¶
In this paragraph, we experiment an interpolation based on Moving average technique. We need to define a Moving Neighborhood first
nmini = 5
nmaxi = 5
radius = 0.2
neigh = gl.NeighMoving.create(False, nmaxi, radius, nmini)
neigh.display()
Moving Neighborhood =================== Minimum number of samples = 5 Maximum number of samples = 5 Maximum horizontal distance = 0.2
gl.movingAverage(data, grid, neigh)
if verbose:
grid.display()
Data Base Grid Characteristics ============================== Data Base Summary ----------------- File is organized as a regular grid Space dimension = 2 Number of Columns = 5 Total number of samples = 10000 Grid characteristics: --------------------- Origin : 0.000 0.000 Mesh : 0.010 0.010 Number : 100 100 Variables --------- Column = 0 - Name = rank - Locator = NA Column = 1 - Name = x1 - Locator = x1 Column = 2 - Name = x2 - Locator = x2 Column = 3 - Name = Simu - Locator = NA Column = 4 - Name = MovAve.Simu.estim - Locator = z1
if flagGraphic:
ax = grid.plot()
ax.decoration(title="Moving Average")
Interpolation using Inverse Distance technique¶
In this paragraph, we experiment an interpolation based on Inverse Distance technique. We use the squared distance weighting function (default option).
gl.inverseDistance(data, grid)
if verbose:
grid.display()
Data Base Grid Characteristics ============================== Data Base Summary ----------------- File is organized as a regular grid Space dimension = 2 Number of Columns = 6 Total number of samples = 10000 Grid characteristics: --------------------- Origin : 0.000 0.000 Mesh : 0.010 0.010 Number : 100 100 Variables --------- Column = 0 - Name = rank - Locator = NA Column = 1 - Name = x1 - Locator = x1 Column = 2 - Name = x2 - Locator = x2 Column = 3 - Name = Simu - Locator = NA Column = 4 - Name = MovAve.Simu.estim - Locator = NA Column = 5 - Name = InvDist.Simu.estim - Locator = z1
if flagGraphic:
ax = grid.plot()
ax.decoration(title="Inverse Squared Distance")
Least Square Polynomial Fit¶
In this paragraph, we experiment an interpolation based on Least Square Polynomial Fit technique. We use a polynomial of degree 1, fitted locally (on the samples neighboring the target grid node). Note that a bigger neighborhood had to be defined (more than 5 samples per neighborhood)
nmini = 5
nmaxi = 10
radius = 0.5
neigh = gl.NeighMoving.create(False, nmaxi, radius, nmini)
neigh.display()
Moving Neighborhood =================== Minimum number of samples = 5 Maximum number of samples = 10 Maximum horizontal distance = 0.5
gl.leastSquares(data, grid, neigh, 1)
if verbose:
grid.display()
Data Base Grid Characteristics ============================== Data Base Summary ----------------- File is organized as a regular grid Space dimension = 2 Number of Columns = 7 Total number of samples = 10000 Grid characteristics: --------------------- Origin : 0.000 0.000 Mesh : 0.010 0.010 Number : 100 100 Variables --------- Column = 0 - Name = rank - Locator = NA Column = 1 - Name = x1 - Locator = x1 Column = 2 - Name = x2 - Locator = x2 Column = 3 - Name = Simu - Locator = NA Column = 4 - Name = MovAve.Simu.estim - Locator = NA Column = 5 - Name = InvDist.Simu.estim - Locator = NA Column = 6 - Name = LstSqr.Simu.estim - Locator = z1
if flagGraphic:
ax = grid.plot()
ax.decoration(title="Least Squares Polynomial Fit")