Migrate Facility¶

In [1]:
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
    return false;
}

This case study is meant to demonstrate how to use gstlearn for migrating information from Db to DbGrid and vice-versa. Note that, in order to test the whole possibilities, we add a selection to both files.

In [2]:
import gstlearn as gl
import gstlearn.plot as gp
import matplotlib.pyplot as plt
import numpy as np

Global parameters.

In [3]:
ndim = 2
gl.defineDefaultSpace(gl.ESpaceType.RN,ndim)

Generate initial data set

In [4]:
data = gl.Db.createFillRandom(ndat=20, ndim=ndim, nvar=1)
data.addSelectionByRanks(np.arange(2,18))
data.display()
Data Base Characteristics
=========================

Data Base Summary
-----------------
File is organized as a set of isolated points
Space dimension              = 2
Number of Columns            = 4
Maximum Number of UIDs       = 4
Total number of samples      = 20
Number of active samples     = 16

Variables
---------
Column = 0 - Name = x-1 - Locator = x1
Column = 1 - Name = x-2 - Locator = x2
Column = 2 - Name = z - Locator = z1
Column = 3 - Name = NewSel - Locator = sel
 
In [5]:
gp.plot(data, name_size="z")
No description has been provided for this image

Create a grid, over the [0,1] x [0,1]

In [6]:
grid = gl.DbGrid.create([50,50],dx=[0.02,0.02])
grid.addSelectionFromDbByConvexHull(data,0.05)
grid.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      = 2500
Number of active samples     = 1738

Grid characteristics:
---------------------
Origin :      0.000     0.000
Mesh   :      0.020     0.020
Number :         50        50

Variables
---------
Column = 0 - Name = rank - Locator = NA
Column = 1 - Name = x1 - Locator = x1
Column = 2 - Name = x2 - Locator = x2
Column = 3 - Name = Hull - Locator = sel
 

Migrate the information from data to grid. The migration is limited to te cell to which each sample belongs.

In [7]:
err = gl.migrate(data, grid, "z", namconv=gl.NamingConvention("Migrate-NoFill",False))
ax = gp.grid(grid)
ax = gp.plot(data)
No description has been provided for this image

In this second attempt, we use the flag_fill option to fill the whole grid. However we compensate by specifying a maximum filling distance. Moreover we make this maximum distance anisotropic for ckecking.

In [8]:
err = gl.migrate(data, grid, "z", flag_fill=True, dmax=[0.1,0.2], 
                 namconv=gl.NamingConvention("Migrate-Fill",False))
ax = gp.grid(grid)
ax = gp.plot(data)
No description has been provided for this image