Automating tasks in S-GeMS
There are two ways of automating tasks in S-GeMS:
- S-GeMS commands
- Python script
Most of the tasks performed in S-GeMS using the graphical interface, e.g.
creating a new cartesian grid or executing a geostatistics algorithm,
can be executed using a command line. For example, the following
will create a new cartesian grid called "mygrid", of dimensions
Commands can be entered in the Command Panel. The Command Panel is not
displayed by default. To display it, go to the View menu and select Commands Panel.
To execute a command, type it in the field under "Run Command" (refered
to as the command line) and
The S-GeMS Commands History tab
shows a log of all commands performed either from the graphical
interface or the command line. The commands appear in black. Messages
are displayed in blue, and warnings or errors in red. Commands can be
copied from the log, pasted to the command line, edited and executed.
Clicking the Run Command
button will prompt for a file containing a list of commands to be
executed. Each command in the file must start on a new line and be
contained on a single line. Comments start with a # sign.
Use the Help command (just
type Help in the command
line) to get a list of all available commands.
S-GeMS actually keeps two logs of the commands executed during a session:
one is displayed in the S-GeMS
Commands History tab, the other one is recorded to a file called
"sgems_history.log". This file is located in the directory where S-GeMS
was started. It only contains the commands: messages, warnings and
errors are not recorded.
Commands are an easy way to automate tasks in S-GeMS. They however offer
limited flexibility: there are no control structures such as loops,
tests, etc. Hence performing 20 runs of a given algorithm, each time
changing a parameter, would require that the 20 commands corresponding
to each run are written in the commands file. If more powerful
scripting capabilities are needed, one should turn to the other
automation facility of S-GeMS: Python scripts.
S-GeMS provides a powerful way of performing repetitive tasks by
embedding the Python language. Useful information about Python
(including a beginner's guide, tutorials and reference manuals) can be
found at http://python.org/doc.
S-GeMS provides a Python extension modules that allows Python to call
S-GeMS commands. The module name is sgems.
It offers three functions:
In the following example, a 100x100x1 grid called mygrid is created. A property
called prop is then added to
object. It contains values ranging from 1 to 100*100*1
- execute( "command" ) : executes S-GeMS command command.
- get_property( "grid_name", "property_name" ) : returns a list
containing the values of property property_name
of object grid_name.
- set_property( "grid_name", "property_name", vec ) : sets the
values of property property_name
of object grid_name to the
values of list vec. If object
grid_name has no property
called property_name a new
property is created.
sgems.execute( "NewCartesianGrid mygrid::100::100::1" )
sgems.set_property( "mygrid", "prop", a)
This is an example of a script that creates a Gaussian field on a 100x130x10 cartesian grid. The field is anisotropic, such that as z increases, the anisotropy angle turns by 15 degrees: layer n has a n*15 degrees anisotropy.