Loading the required libraries
import gstlearn as gl
import pandas as pd
import numpy as np
We first create the Data Base 'db' with few samples and 4 variables.
ndat = 10
db = gl.Db.create()
np.random.seed(123)
db["long"] = np.random.uniform(size = ndat)
db["lat"] = np.random.uniform(size = ndat)
db["z"] = np.random.normal(size = ndat)
db["sel"] = np.random.binomial(1, 0.5, size = ndat)
Each of these variables is assigned a Locator.
db.setLocators(["l*"], gl.ELoc.X)
db.setLocators(["z"], gl.ELoc.Z)
db.setLocators(["sel"], gl.ELoc.SEL)
The next printout shows the contents of the Db using gstlearn format
db
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 = 10 Number of active samples = 3 Variables --------- Column = 0 - Name = long - Locator = x1 Column = 1 - Name = lat - Locator = x2 Column = 2 - Name = z - Locator = z1 Column = 3 - Name = sel - Locator = sel
We now convert it into a Panda file
dat = db.toTL()
We check its contents using Panda own format
dat
long | lat | z | sel | |
---|---|---|---|---|
0 | 0.696469 | 0.343178 | 1.004054 | 0.0 |
1 | 0.286139 | 0.729050 | 0.386186 | 0.0 |
2 | 0.226851 | 0.438572 | 0.737369 | 0.0 |
3 | 0.551315 | 0.059678 | 1.490732 | 0.0 |
4 | 0.719469 | 0.398044 | -0.935834 | 0.0 |
5 | 0.423106 | 0.737995 | 1.175829 | 0.0 |
6 | 0.980764 | 0.182492 | -1.253881 | 0.0 |
7 | 0.684830 | 0.175452 | -0.637752 | 1.0 |
8 | 0.480932 | 0.531551 | 0.907105 | 1.0 |
9 | 0.392118 | 0.531828 | -1.428681 | 1.0 |
The conversion is performed once more, but keeping track of the locator information assigned to each variable.
dat = db.toTL(True)
The printout is not modified.
dat
long | lat | z | sel | |
---|---|---|---|---|
0 | 0.696469 | 0.343178 | 1.004054 | 0.0 |
1 | 0.286139 | 0.729050 | 0.386186 | 0.0 |
2 | 0.226851 | 0.438572 | 0.737369 | 0.0 |
3 | 0.551315 | 0.059678 | 1.490732 | 0.0 |
4 | 0.719469 | 0.398044 | -0.935834 | 0.0 |
5 | 0.423106 | 0.737995 | 1.175829 | 0.0 |
6 | 0.980764 | 0.182492 | -1.253881 | 0.0 |
7 | 0.684830 | 0.175452 | -0.637752 | 1.0 |
8 | 0.480932 | 0.531551 | 0.907105 | 1.0 |
9 | 0.392118 | 0.531828 | -1.428681 | 1.0 |
But each variable can show the locator which is attached to it. The syntax is as follows:
dat.sel.locator
'sel'