This file is meant to demonstrate the use of gstlearn for Boolean Model
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
return false;
}
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
import random as rnd
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(5584)
rnd.seed(13155)
gp.setDefaultGeographic(dims=[7,7])
nxcell = 100
grid = gl.DbGrid.create([nxcell,nxcell])
grid.display();
Data Base Grid Characteristics ============================== Data Base Summary ----------------- File is organized as a regular grid Space dimension = 2 Number of Columns = 3 Total number of samples = 10000 Grid characteristics: --------------------- Origin : 0.000 0.000 Mesh : 1.000 1.000 Number : 100 100 Variables --------- Column = 0 - Name = rank - Locator = NA Column = 1 - Name = x1 - Locator = x1 Column = 2 - Name = x2 - Locator = x2
We now establish the stationary Boolean Model
tokens = gl.ModelBoolean(0.01, True)
We must first define the dictionary of shapes used in the Model, composed of
token_ellipsoid = gl.ShapeEllipsoid(0.4, 10., 20., 2.)
token_ellipsoid.setFactorX2Y(1.5)
tokens.addToken(token_ellipsoid)
token_parallelepiped = gl.ShapeParallelepiped(0.6, 5, 7., 1.)
tokens.addToken(token_parallelepiped)
tokens.display()
Object Model ============ - Poisson Intensity = 0.01 Token 1 ------- Full Ellipsoid - Proportion=0.4 - X-Extension: Constant=10 - Y-Extension: Constant=20 - Z-Extension: Constant=2 - Orientation Angle: Constant=0 Y-Extension = X_Extension * 1.5 Token 2 ------- Parallelepiped - Proportion=0.6 - X-Extension: Constant=5 - Y-Extension: Constant=7 - Z-Extension: Constant=1 - Orientation Angle: Constant=0
err = gl.simbool(None, grid, tokens, namconv=gl.NamingConvention("NC"))
grid
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 : 1.000 1.000 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 = NC.Facies - Locator = NA Column = 4 - Name = NC.Rank - Locator = NA
We have created two new variables in the output Grid file:
ax = grid.plot(nameRaster="NC.Facies")
ax.decoration(title="Facies")
ax = grid.plot(nameRaster="NC.Rank", flagLegendRaster=True)
ax.decoration(title="Rank")
We sample the grid in order to create a new Point data base: the number of selected points is small.
ndat = 20
randomlist = rnd.sample(range(0, grid.getSampleNumber()), ndat)
data = gl.Db.createReduce(grid, ranks = randomlist)
ax = grid.plot(nameRaster="NC.Facies")
ax = data.plot(nameColor="NC.Facies")
ax.decoration(title="Conditioning Information")
We must slightly transform the facies information that will serve as conditioning
data["Facies1"] = np.nan_to_num(data["NC.Facies"], nan=0.)
data.setLocator("Facies1",gl.ELoc.Z, cleanSameLocator=True)
We can now launch a conditional simulation
err = gl.simbool(data, grid, tokens, verbose=True, namconv=gl.NamingConvention("CD1"))
grid
Boolean simulation ================== - Conditioning option = YES Simulating the initial tokens ----------------------------- - Number of grains to be covered = 9 - Number of conditioning pores = 11 - Number of Initial Objects = 8 - Number of iterations = 8 Simulating the secondary tokens ------------------------------- - Ending number of primary objects = 0 - Total number of objects = 93
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 : 1.000 1.000 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 = NC.Facies - Locator = NA Column = 4 - Name = NC.Rank - Locator = NA Column = 5 - Name = CD1.Facies1.Facies - Locator = NA Column = 6 - Name = CD1.Facies1.Rank - Locator = NA
ax = grid.plot(nameRaster="CD1.Facies1.Facies")
ax = data.plot(nameColor="Facies1")
ax.decoration(title="Conditional Simulation (Small)")
We now sample the grid in order to create a lot of conditioning samples
ndat = 20
randomlist = rnd.sample(range(0, grid.getSampleNumber()), ndat)
data = gl.Db.createReduce(grid, ranks = randomlist)
data["Facies2"] = np.nan_to_num(data["NC.Facies"], nan=0.)
data.setLocator("Facies2",gl.ELoc.Z, cleanSameLocator=True)
ax = grid.plot(nameRaster="NC.Facies")
ax = data.plot(nameColor="NC.Facies")
ax.decoration(title="Conditioning Information (Large)")
err = gl.simbool(data, grid, tokens, verbose=True, namconv=gl.NamingConvention("CD2"))
grid
Boolean simulation ================== - Conditioning option = YES Simulating the initial tokens ----------------------------- - Number of grains to be covered = 13 - Number of conditioning pores = 7 - Number of Initial Objects = 12 - Number of iterations = 14 Simulating the secondary tokens ------------------------------- - Ending number of primary objects = 0 - Total number of objects = 96
Data Base Grid Characteristics ============================== Data Base Summary ----------------- File is organized as a regular grid Space dimension = 2 Number of Columns = 9 Total number of samples = 10000 Grid characteristics: --------------------- Origin : 0.000 0.000 Mesh : 1.000 1.000 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 = NC.Facies - Locator = NA Column = 4 - Name = NC.Rank - Locator = NA Column = 5 - Name = CD1.Facies1.Facies - Locator = NA Column = 6 - Name = CD1.Facies1.Rank - Locator = NA Column = 7 - Name = CD2.Facies2.Facies - Locator = NA Column = 8 - Name = CD2.Facies2.Rank - Locator = NA
ax = grid.plot(nameRaster="CD2.Facies2.Facies")
ax = data.plot(nameColor="Facies2")
ax.decoration(title="Conditional Simulation (Large)")