Demonstration of gstlearn for a 2-D case study¶
This file demonstrates the use of Selectivity curves
In [1]:
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
return false;
}
Import packages¶
In [2]:
import numpy as np
import pandas as pd
import sys
import os
import matplotlib.pyplot as plt
import gstlearn as gl
import gstlearn.plot as gp
Reading the Grid file
In [3]:
!wget -q https://soft.minesparis.psl.eu/gstlearn/data/Selectivity/Grid_100.ascii
In [4]:
filename = "Grid_100.ascii"
db100 = gl.DbGrid.createFromNF(filename)
db100.display()
Data Base Grid Characteristics ============================== Data Base Summary ----------------- File is organized as a regular grid Space dimension = 2 Number of Columns = 4 Maximum Number of UIDs = 4 Total number of samples = 100 Grid characteristics: --------------------- Origin : 0.000 0.000 Mesh : 1.000 1.000 Number : 10 10 Variables --------- Column = 0 - Name = rank - Locator = NA Column = 1 - Name = x1 - Locator = x1 Column = 2 - Name = x2 - Locator = x2 Column = 3 - Name = z1 - Locator = z1
Plotting the grid of samples
In [5]:
gp.setDefaultGeographic(xlim=[-1,10],ylim=[-1,10])
gp.printDefault()
Non geographical defaults: - Figure dimensions = [5, 5] - Limits along X (not defined) - Limits along Y (not defined) - Aspect = auto Geographical defaults: - Figure dimensions = [8, 8] - Limits along X = [-1, 10] - Limits along Y = [-1, 10] - Aspect = 1
In [6]:
fig, ax = gp.initGeographic()
ax.raster(db100, name="z1")
ax.decoration(title="Data")
plt.show()
In [7]:
fig, ax = gp.initGeographic()
ax.literal(db100, name="z1")
ax.decoration(title="Data")
plt.show()
In [8]:
fig, ax = gp.init()
ax.histogram(db100, name="z1", bins=20)
ax.decoration(title="Data")
plt.show()
In [9]:
dum = db100.statistics(["z1"],[gl.EStatOption.MEAN, gl.EStatOption.VAR])
1.531 1.615
Creating the grid of blocks by averaging samples 2 by 2
In [10]:
db25 = gl.DbGrid.create(nx=[5,5], dx=[2,2], x0=[0.5,0.5])
dum = gl.dbStatisticsOnGrid(db100, db25, gl.EStatOption.MEAN, namconv = gl.NamingConvention(""))
In [11]:
fig, ax = gp.initGeographic()
ax.raster(db25, name="z1")
ax.decoration(title="Blocks")
plt.show()
In [12]:
fig, ax = gp.initGeographic()
ax.literal(db25,name="z1")
ax.decoration(title="Blocks")
plt.show()
In [13]:
fig, ax = gp.init()
ax.histogram(db25, name="z1", bins=10)
ax.decoration(title="Blocks")
plt.show()
In [14]:
dum = db25.statistics(["z1"],[gl.EStatOption.MEAN, gl.EStatOption.VAR])
1.531 0.974
Creating a samping grid keeping only the upper right corner sample for each block
In [15]:
db25s = gl.DbGrid.create(nx=[5,5],dx=[2,2],x0=[0.5,0.5])
dum = gl.migrate(db100,db25s,name="z1",namconv=gl.NamingConvention("",False))
In [16]:
fig, ax = gp.initGeographic()
ax.raster(db25s, name="z1")
ax.decoration(title="Sampling")
plt.show()
In [17]:
fig, ax = gp.initGeographic()
ax.literal(db25s,name="z1")
ax.decoration(title="Sampling")
plt.show()
In [18]:
dum = db25s.statistics(["z1"],[gl.EStatOption.MEAN, gl.EStatOption.VAR])
1.364 1.165
Using the Selectivity Curves¶
We compare the selectivity curves between Data and Blocks:
In [19]:
selectivity = gl.Selectivity(100)
table100 = selectivity.eval(db100, True)
table25 = selectivity.eval(db25, True)
table25s = selectivity.eval(db25s, True)
In [20]:
table100.getColumnNames()
Out[20]:
('Z-Cut', 'T-estim', 'Q-estim', 'B-estim', 'M-estim', 'T-stdev', 'Q-stdev')
- Ore tonnage as a function of the cutoff
In [21]:
fig, ax = gp.init()
ax.table(table100,[1,0],color='blue')
ax.table(table25,[1,0],color='red')
ax.decoration(title="T(z)")
plt.show()
- Metal as a function of the cutoff
In [22]:
fig, ax = gp.init()
ax.table(table100,[2,0],color='blue')
ax.table(table25,[2,0],color='red')
ax.decoration(title="Q(z)")
plt.show()
- Recovered grade as a function of the cutoff
In [23]:
fig, ax = gp.init()
ax.table(table100,[4,0],color='blue')
ax.table(table25,[4,0],color='red')
ax.decoration(title="M(z)")
plt.show()
- Conventional Benefit as a function of the cutoff
In [24]:
fig, ax = gp.init()
ax.table(table100,[3,0],color='blue')
ax.table(table25,[3,0],color='red')
ax.decoration(title="B(z)")
plt.show()
- Metal as a function of Ore Tonnage
In [25]:
fig, ax = gp.init()
ax.table(table100,[2,1],color='blue')
ax.table(table25,[2,1],color='red')
ax.plot([0.,1.], [0.,db100.getMean("z1")], linestyle='dashed')
ax.decoration(title="Q(T)")
plt.show()
Regressions¶
Display regressions
In [26]:
fig, ax = gp.init()
ax.correlation(db25,namex="z1",namey="z1",db2=db25s, asPoint=True, diagLine=True, regrLine=True)
ax.decoration(ylabel="Blocks",xlabel="Samples",title="Block vs. Sample")
plt.show()
In [27]:
fig, ax = gp.init()
ax.correlation(db25s,namex="z1",namey="z1",db2=db25, asPoint=True, diagLine=True, regrLine=True)
ax.decoration(xlabel="Blocks",ylabel="Samples",title="Sample vs. Block")
plt.show()
Comparing selectivity curves¶
In [28]:
fig, ax = gp.init()
ax.table(table100,[2,1],color='blue')
ax.table(table25,[2,1],color='red')
ax.table(table25s,[2,1],color='green')
ax.plot([0.,1.], [0.,db100.getMean("z1")], linestyle='dashed')
ax.plot([0.,1.], [0.,db25s.getMean("z1")], linestyle='dashed')
ax.decoration(title="Q(T)")
plt.show()