Tutorial for R2I Package

How to use RGeostats package step-by-step.
Direct access to Tutorial index and Frequently Asked Questions

Tutorial for R2I Package

Postby Fabien Ors » Wed Jul 29, 2015 2:51 pm

R2I is a package which enables the direct communication between RGeostats and Isatis (from Geovariances).
It is based on the capabilities offered by the GTXserver layer and allows to copy information between the Db (of RGeostats) in the file structure (of Isatis) and vice versa.

Download R2I by clicking here !

It has been developed in two modes:
- an interactive mode (easy to use for beginners)
- a scripted mode which enables coding it within procedures.
This Topic gives an example which can serve as a tutorial for both modes.

We assume that Isatis has been launched in the Study called My_Study
The package R2I is launched in an R session which is empty at the beginning.
We assume that the package RGeostats is loaded.

Establishing the connection

We must first connect the Isatis process to the RGeostats session.
This operation needs the user to designate:
  • the full path to the GTXserver executable file (avoiding any symbol specific to the operating system): say GTXserver_location,
  • the path of the Directory which contains the list of the studies for Isatis (file study.def): say Isatis_location.
The two paths must be specified using quotes.
Code: Select all
ConnectIsatis(GTX.SERVER="GTXserver_location",GTX.INIT="Isatis_location")

The previous command can be performed adding the argument flag.verbose=TRUE. All subsequent steps of the connection are echoed, as demonstrated next:

Code: Select all
GTX.INIT = "Isatis_location"
GTX.SERVER = "GTXserver_location"
Hostname = localhost
Launching GTXserver...
GTXserver 16.00-150412 (2016-150412) - (c)2010 Geovariances
Connecting to Isatis file system...

When ConnectIsatis is called more than one time, a message warns the user. If necessary, the connection can be interrupted by simply typing:

Code: Select all
DisconnectIsatis()


Creating the Information in RGeostats

We now create two Db files:
  • A 2-D Point Db file containing 100 samples randomly located within the square [0;1.5] x [0;1.2], with a variable called VPoint (uniform between 0 and 1): say Db.Point
  • A 2-D Grid Db file with 15 x 12 nodes, with a square mesh 0.1 x 0.1 and the origin located at point (0.,0.), with a variable called VGrid (randomly generated according to a Normal distribution): say Db.Grid
Both variables are then defined as located as Z-variables.
Code: Select all
Db.Point = db.create(x1=1.5*runif(100),x2=1.2*runif(100),VPoint=runif(100))
Db.Grid = db.create(nx=c(15,12),dx=c(0.1,0.1),VGrid=rnorm(180))
Db.Point = db.locate(Db.Point,"VPoint","z")
Db.Grid = db.locate(Db.Grid,"VGrid","z")


Interactive Transfer from RGeostats to Isatis

We use the Interactive mode in order to transfer this information into the Isatis Study. Note that the connection between Isatis and RGeostats must have been established beforehand (using ConnectIsatis() command).
Code: Select all
Db2I(Db.Point)

The program establishes the numbered list of all the existing studies and ask for the rank of the target study:
Code: Select all
Rank | Isatis Study
-----|-------------
   1 | ...
   2 | ...
  10 | My_Study
  11 | ...
     |
 new | Create a new item
 del | Delete an item
help | Display the current list
stop | Stop browsing
Enter your choice : 10

At that stage, the Study is empty. A new Directory must then be created, say Isatis_Directory.
Code: Select all
Currently in : My_Study/
Rank | Isatis Directory
-----|-----------------
  .. | Return to upper level
     |
 new | Create a new item
help | Display the current list
stop | Stop browsing
Enter your choice : new
New Directory Name ('stop' to cancel) : Isatis_Directory

Then the user must create a new File, say Isatis_PointFile.
Code: Select all
Currently in : My_Study/Isatis_Directory/
Rank | Isatis File
-----|------------
  .. | Return to upper level
     |
 new | Create a new item
help | Display the current list
stop | Stop browsing
Enter your choice : new
New File Name ('stop' to cancel) : Isatis_PointFile

At this stage, the program enters a loop where one selected variable at a time will be transferred from Db.Point into Isatis. Here only the variable called Vpoint and numbered 4 will be transferred.
Code: Select all
Loop for selecting Variable(s) to be copied from Db into Isatis
===============================================================

Currently in : My_Study/Isatis_Directory/Isatis_PointFile/
Rank | Db Variable
-----|------------
   1 | rank
   2 | x1
   3 | x2
   4 | VPoint
     |
help | Display the current list
stop | Stop browsing
Enter your choice : 4

To interrupt the loop, it suffices to answer stop.

In the Isatis package, the user can use the File Manage Utility to visualize the result of the transfer. Note that it may be necessary to press the Refresh button in order to update the contents of the Study. The variable VPoint has been copied successfully. Note that it may be necessary to update the Format of the transferred variable as this notion does not exist in RGeostats.

If the transfer procedure is launched again, the Study, Directory and File are already defined: the user can directly transfer some additional variables from RGeostats to Isatis. In order to select a different Study, Directory or File, the command Db2I must be started using the flag.reset=TRUE.

Interactive Transfer from Isatis to RGeostats

This step consists in copying the contents of one or several variables of Isatis into RGeostats. In the following syntax, the new Db file Db.NewPoint is created:
Code: Select all
Db.NewPoint = I2Db()

The program allows the user to navigate through the Isatis architecture until the target File is reached (for a complete description, see the previous paragraph). Note that if the command Db2I or I2Db has already been used, the Target Study, Directory and File may already be defined. If the user wishes to use a different Study, Directory or File, the command I2Db can be launched using flag.reset=TRUE.

The program enters in a loop for transferring the variables one at a time from Isatis to RGeostats: here we copy the variables SN+ Sample Number (READONLY) and Vpoint. The loop is interrupted by answer stop.
Code: Select all
Loop for selecting Variable(s) to be copied from Isatis into Db
===============================================================

Currently in : My_Study/Isatis_Directory/Isatis_PointFile/
Rank | Isatis Variable
-----|----------------
   1 | SN+ Sample Number (READONLY)
   2 | X+ Gravity Center
   3 | Y+ Gravity Center
   4 | VPoint
     |
help | Display the current list
stop | Stop browsing
Enter your choice : 4

Loop for selecting Variable(s) to be copied from Isatis into Db
===============================================================

Currently in : My_Study/Isatis_Directory/Isatis_PointFile/
Rank | Isatis Variable
-----|----------------
   1 | SN+ Sample Number (READONLY)
   2 | X+ Gravity Center
   3 | Y+ Gravity Center
   4 | VPoint
     |
help | Display the current list
stop | Stop browsing
Enter your choice : stop

The user can check the contents of the newly created Db File Db.NewPoint: the two selected variables have been transferred successfully (in addition to the sample rank and coordinates). Note that the lastly recovered variable (i.e. Vpoint) is located as a Z-variable.

If the user wishes to concatenate the recovered variables to an already existing file (say Db.OldPoint), it suffices to launch the command I2Db with the following syntax:
Code: Select all
Db.OldPoint = I2Db(Db.OldPoint)

Obviously this operation will only be performed is the Isatis File and Db.OldPoint share the same file characteristics.

Scripted Transfer from RGeostats to Isatis

In this paragraph, we will perform the same operations as in the previous paragraphs, but using the Db Grid File (i.e. Db.Grid) and the scripted version of R2I.

We first establish the connection between Isatis and RGeostats:
Code: Select all
ConnectIsatis(GTX.SERVER="GTXserver_location",GTX.INIT="Isatis_location")

A series of functions are available to help navigating through the Isatis architecture:
  • IGetSudyList which provides the list of the available Studies, among which My_Study
  • GetDirList("My_Study") which provides the list of Directories in the target Study: i.e. Isatis_Directory
  • GetFileList("My_Study","Isatis_Directory") which provides the list of Files in the target Study and Directory: i.e. Isatis_PointFile

Next the user wants to create a new File called Isatis_GridFile within Isatis with the same characteristics as the Db Grid Db.Grid:
Code: Select all
ICreateFile(Db.Grid,"Isatis_GridFile")

Note that it may not be necessary to specify the names of the Study, Directory or File: the program keeps track of the locations specified in the previous commands.

The user finally wishes to copy the variable VGrid from the Db.Grid File into the newly created Isatis_GridFile (currently defined target file):
Code: Select all
CopyVariableDb2I(Db.Grid,"VGrid")


Scripted Transfer from Isatis to RGeostats

The last operation consists in retrieving the contents of the variable Vgrid in the File Isatis_GridFile, in the Directory Isatis_Directory, in the Study My_Study in RGeostats.

The following command will create a new Db Grid file with the newly retrieved variable VGrid:
Code: Select all
CopyVariableI2Db("VGrid")


Note that the retrieved variable could be appended to the contents of a previously existing Db Grid File (say Db.OldGrid):
Code: Select all
Db.OldGrid = CopyVariableI2Db("VGrid", db=Db.OldGrid)
Fabien Ors
Administrateur du site
 
Posts: 124
Joined: Thu Sep 20, 2012 1:07 pm

Return to Tutorials and FAQ

Who is online

Users browsing this forum: No registered users and 2 guests

cron