Tutorial on Boolean Model¶
This file is meant to demonstrate the use of gstlearn for Boolean Model
In [1]:
import numpy as np
import pandas as pd
import sys
import os
import gstlearn as gl
import gstlearn.plot as gp
import gstlearn.document as gdoc
import matplotlib.pyplot as plt
import random as rnd
gdoc.setNoScroll()
Setting some global variables
In [2]:
# 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])
In [3]:
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
In [4]:
tokens = gl.ModelBoolean(0.01, True)
We must first define the dictionary of shapes used in the Model, composed of
- Ellipsoids
- parallelelipieds
In [5]:
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
Non conditional simulation¶
In [6]:
err = gl.simbool(None, grid, tokens, namconv=gl.NamingConvention("NC"))
grid
Out[6]:
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:
- the Facies
- the Rank of the object
In [7]:
ax = grid.plot(nameRaster="NC.Facies")
ax.decoration(title="Facies")
In [8]:
ax = grid.plot(nameRaster="NC.Rank", flagLegendRaster=True)
ax.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.
In [9]:
ndat = 20
randomlist = rnd.sample(range(0, grid.getSampleNumber()), ndat)
data = gl.Db.createReduce(grid, ranks = randomlist)
In [10]:
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
In [11]:
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
In [12]:
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
Out[12]:
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
In [13]:
ax = grid.plot(nameRaster="CD1.Facies1.Facies")
ax = data.plot(nameColor="Facies1")
ax.decoration(title="Conditional Simulation (Small)")
Lots of conditioning points¶
We now sample the grid in order to create a lot of conditioning samples
In [14]:
ndat = 20
randomlist = rnd.sample(range(0, grid.getSampleNumber()), ndat)
data = gl.Db.createReduce(grid, ranks = randomlist)
In [15]:
data["Facies2"] = np.nan_to_num(data["NC.Facies"], nan=0.)
data.setLocator("Facies2",gl.ELoc.Z, cleanSameLocator=True)
In [16]:
ax = grid.plot(nameRaster="NC.Facies")
ax = data.plot(nameColor="NC.Facies")
ax.decoration(title="Conditioning Information (Large)")
In [17]:
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
Out[17]:
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
In [18]:
ax = grid.plot(nameRaster="CD2.Facies2.Facies")
ax = data.plot(nameColor="Facies2")
ax.decoration(title="Conditional Simulation (Large)")