Tutorial on Boolean Model¶
This file is meant to demonstrate the use of gstlearn for Boolean Model
import numpy as np
import gstlearn as gl
import gstlearn.plot as gp
import gstlearn.document as gdoc
import random as rnd
gdoc.setNoScroll()
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)
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
- Ellipsoids
- parallelelipieds
token_ellipsoid = gl.ShapeEllipsoid(0.4, 10.0, 20.0, 2.0)
token_ellipsoid.setFactorX2Y(1.5)
tokens.addToken(token_ellipsoid)
token_parallelepiped = gl.ShapeParallelepiped(0.6, 5, 7.0, 1.0)
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
Non conditional simulation¶
We perform a single non-conditional simulation on the Grid.
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 = z1
We have created two new variables in the output Grid file:
- the Facies
- the Rank of the object
gp.plot(grid, "NC.Facies")
gp.decoration(title="Facies")
gp.plot(grid, "NC.Rank", flagLegend=True)
gp.decoration(title="Rank")
Conditional simulation¶
Few conditioning points¶
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.getNSample()), ndat)
data = gl.Db.createReduce(grid, ranks=randomlist)
We must slightly transform the facies information that will serve as conditioning
data["Facies1"] = np.nan_to_num(data["NC.Facies"], nan=0.0)
data.setLocator("Facies1", gl.ELoc.Z, cleanSameLocator=True)
data.getStatsByCategoryAsTable("Facies1", "Facies1")
Number Minimum Maximum Mean St. Dev. Variance Category: 0.000000 14.000 0.000 0.000 0.000 0.000 0.000 Category: 1.000000 6.000 1.000 1.000 1.000 0.000 0.000
We produce the non-conditional simulation grid and the set of sampled points: their color is blue for pore and yellow for grain.
gp.plot(grid, "NC.Facies")
gp.plot(data, nameColor="Facies1", s=50)
gp.decoration(title="Conditioning Information")
We can now launch a series of 6 conditional simulations
err = gl.simbool(data, grid, tokens, nbsimu=6, namconv=gl.NamingConvention("CD1"))
Display of the Simulations: the Facies is displayed
fig, axs = gp.init(2, 3, figsize=(18, 10), flagEqual=True)
axs[0, 0].raster(grid, name="CD1.Facies1.Facies.S1")
axs[0, 0].symbol(data, nameColor="Facies1", s=50)
axs[0, 0].decoration(title="Simulation #1")
axs[0, 1].raster(grid, name="CD1.Facies1.Facies.S2")
axs[0, 1].symbol(data, nameColor="Facies1", s=50)
axs[0, 1].decoration(title="Simulation #2")
axs[0, 2].raster(grid, name="CD1.Facies1.Facies.S3")
axs[0, 2].symbol(data, nameColor="Facies1", s=50)
axs[0, 2].decoration(title="Simulation #3")
axs[1, 0].raster(grid, name="CD1.Facies1.Facies.S4")
axs[1, 0].symbol(data, nameColor="Facies1", s=50)
axs[1, 0].decoration(title="Simulation #4")
axs[1, 1].raster(grid, name="CD1.Facies1.Facies.S5")
axs[1, 1].symbol(data, nameColor="Facies1", s=50)
axs[1, 1].decoration(title="Simulation #5")
axs[1, 2].raster(grid, name="CD1.Facies1.Facies.S6")
axs[1, 2].symbol(data, nameColor="Facies1", s=50)
axs[1, 2].decoration(title="Simulation #6")
Display of the Simulations: the Object Rank is displayed
fig, axs = gp.init(2, 3, figsize=(18, 10), flagEqual=True)
axs[0, 0].raster(grid, name="CD1.Facies1.Rank.S1")
axs[0, 0].symbol(data, nameColor="Facies1", s=50)
axs[0, 0].decoration(title="Simulation #1")
axs[0, 1].raster(grid, name="CD1.Facies1.Rank.S2")
axs[0, 1].symbol(data, nameColor="Facies1", s=50)
axs[0, 1].decoration(title="Simulation #2")
axs[0, 2].raster(grid, name="CD1.Facies1.Rank.S3")
axs[0, 2].symbol(data, nameColor="Facies1", s=50)
axs[0, 2].decoration(title="Simulation #3")
axs[1, 0].raster(grid, name="CD1.Facies1.Rank.S4")
axs[1, 0].symbol(data, nameColor="Facies1", s=50)
axs[1, 0].decoration(title="Simulation #4")
axs[1, 1].raster(grid, name="CD1.Facies1.Rank.S5")
axs[1, 1].symbol(data, nameColor="Facies1", s=50)
axs[1, 1].decoration(title="Simulation #5")
axs[1, 2].raster(grid, name="CD1.Facies1.Rank.S6")
axs[1, 2].symbol(data, nameColor="Facies1", s=50)
axs[1, 2].decoration(title="Simulation #6")
Lots of conditioning points¶
We now sample the grid in order to create a lot of conditioning samples
ndat = 200
randomlist = rnd.sample(range(0, grid.getNSample()), ndat)
data = gl.Db.createReduce(grid, ranks=randomlist)
data["Facies2"] = np.nan_to_num(data["NC.Facies"], nan=0.0)
data.setLocator("Facies2", gl.ELoc.Z, cleanSameLocator=True)
gp.plot(grid, "NC.Facies")
gp.plot(data, nameColor="Facies2", s=50)
gp.decoration(title="Conditioning Information (Large)")
We launch a serie of 6 conditional simulations
err = gl.simbool(data, grid, tokens, nbsimu=6, namconv=gl.NamingConvention("CD2"))
fig, axs = gp.init(2, 3, figsize=(18, 10), flagEqual=True)
axs[0, 0].raster(grid, name="CD2.Facies2.Facies.S1")
axs[0, 0].symbol(data, nameColor="Facies2", s=50)
axs[0, 0].decoration(title="Simulation #1")
axs[0, 1].raster(grid, name="CD2.Facies2.Facies.S2")
axs[0, 1].symbol(data, nameColor="Facies2", s=50)
axs[0, 1].decoration(title="Simulation #2")
axs[0, 2].raster(grid, name="CD2.Facies2.Facies.S3")
axs[0, 2].symbol(data, nameColor="Facies2", s=50)
axs[0, 2].decoration(title="Simulation #3")
axs[1, 0].raster(grid, name="CD2.Facies2.Facies.S4")
axs[1, 0].symbol(data, nameColor="Facies2", s=50)
axs[1, 0].decoration(title="Simulation #4")
axs[1, 1].raster(grid, name="CD2.Facies2.Facies.S5")
axs[1, 1].symbol(data, nameColor="Facies2", s=50)
axs[1, 1].decoration(title="Simulation #5")
axs[1, 2].raster(grid, name="CD2.Facies2.Facies.S6")
axs[1, 2].symbol(data, nameColor="Facies2", s=50)
axs[1, 2].decoration(title="Simulation #6")
fig, axs = gp.init(2, 3, figsize=(18, 10), flagEqual=True)
axs[0, 0].raster(grid, name="CD2.Facies2.Rank.S1")
axs[0, 0].symbol(data, nameColor="Facies2", s=50)
axs[0, 0].decoration(title="Simulation #1")
axs[0, 1].raster(grid, name="CD2.Facies2.Rank.S2")
axs[0, 1].symbol(data, nameColor="Facies2", s=50)
axs[0, 1].decoration(title="Simulation #2")
axs[0, 2].raster(grid, name="CD2.Facies2.Rank.S3")
axs[0, 2].symbol(data, nameColor="Facies2", s=50)
axs[0, 2].decoration(title="Simulation #3")
axs[1, 0].raster(grid, name="CD2.Facies2.Rank.S4")
axs[1, 0].symbol(data, nameColor="Facies2", s=50)
axs[1, 0].decoration(title="Simulation #4")
axs[1, 1].raster(grid, name="CD2.Facies2.Rank.S5")
axs[1, 1].symbol(data, nameColor="Facies2", s=50)
axs[1, 1].decoration(title="Simulation #5")
axs[1, 2].raster(grid, name="CD2.Facies2.Rank.S6")
axs[1, 2].symbol(data, nameColor="Facies2", s=50)
axs[1, 2].decoration(title="Simulation #6")