Editing
Tutorial
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===SConstructs and commands=== SCons scripts are called SConstructs. In order to use SCons, you must create an SConstruct in the local directory where you want to work. Since SCons is written in Python, an SConstruct is simply a text file written using Python syntax. If you don't know Python, you can still use SCons, because the syntax is simple. First, a primer on Python syntax. In SConstructs we are going to deal with Python functions and strings. Python functions are simple, and should be familiar to anyone who has used a programming language. For example, calling a Python function, foo, looks like: <pre> One argument - foo(1). Many arguments - foo(1,2,3,4,5,123) </pre> Python functions can take many arguments, and arguments of different types, but the syntax is the same. Python strings are also very similar to other programming languages. In Python anything inside double quotes is automatically considered to be a string, and not a variable declaration. However, Python also supports a few notations to indicate strings (or long strings) as shown below: <syntaxhighlight lang="python"> "this is a string" 'this is a string' """this is a string""" "'this is a string"' </syntaxhighlight> Somtimes in Python you will need to nest a string within a string. To do use one of the string representations for the outer string, and use a different one for the inner string. For example: <syntaxhighlight lang="python"> """sfgraph title="my plot" """ OR ''' sfgraph title="my plot" ''' OR ' sfgraph title="my plot" ' </syntaxhighlight> Fundamentally, Madagascar's data-processing SConstructs are composed of only four commands: '''Fetch''' , '''Flow''' , '''Plot''' and '''Result''' . The main command is '''Flow''' . A '''Flow''' creates a relationship between the input file, the output file, and the processing command used to create the output file from the input file. The syntax for a '''Flow''' is: <pre> Flow(output file,input file,command) </pre> where, target and source are file names (strings), and command is a string that contains the Madagascar program to be used, along with the command line parameters needed for that program to run. For example: <syntaxhighlight lang="python"> Flow("spike1","spike","scale dscale=4.0") </syntaxhighlight> creates a dependency relationship between the output file 'spike1' and the input file 'spike'. The dependency indicates that 'spike1' cannot be created without 'spike' and that if 'spike' changes then 'spike1' also changes. The relationship in this case is that 'spike1' should be 'spike' scaled by four times. The equivalent command on the command line would be: <pre> < spike.rsf sfscale dscale=4.0 > spike1.rsf </pre> '''Note: the file names of the input and output files do not need to include '.rsf' on the end of the files as SCons automatically adds the suffix to all of our file names.''' Now that we can create relationships between files using '''Flow''' s, we can create an SConstruct to do all of our data processing using SCons. However, we often want to visualize the results of our processing in order to quality control the results. In order to create '''Plot''' s (or other visualizations) in Madagascar we have two additional SCons commands: '''Plot''' and '''Result''' . '''Plot''' and '''Result''' tell SCons how to use Madagascar's plotting programs to create visualizations of files on the fly after they have been computed. The syntax for both '''Plot''' and '''Result''' is as follows: <pre> Plot(input file, command) </pre> OR <pre> Result(input file, command) </pre> In both cases, the '''Plot''' or '''Result''' command tells SCons to build a VPLOT file with same file name as the input file (with the .vpl suffix instead) from the input file using the command provided. For example, if we want to make a graph of a file we could use: <syntaxhighlight lang="python"> Plot("spike1","sfgraph pclip=100") </syntaxhighlight> Behind the scenes, SCons establishes that we want to use "spike1.rsf" to create a '''Plot''' called "spike1.vpl" using sfgraph. The equivalent command line operation is: <pre> < spike1.rsf sfgraph pclip=100 > spike1.vpl </pre> '''Result''' can be used in the same way as '''Plot''' , illustrated above. At this point, you might be asking yourself, what's the difference between '''Plot''' and '''Result''' ? The answer is that '''Plot''' creates all VPLOT files in the local directory, whereas '''Result''' creates its VPLOT files in a subdirectory called <tt>Fig</tt>. <tt>Fig</tt> is a location used to store '''Plot''' s that we want to later use when creating papers using L<sup>A</sup>TEX. By default, you should use '''Plot''' when creating visualizations. Only use '''Result''' when you want to save something to be used in a paper. Note: since the VPLOTs from '''Plot''' and '''Result''' are placed in different locations you can use both '''Plot''' and '''Result''' for a single RSF file, but create two different plots for the same file.
Summary:
Please note that all contributions to Madagascar are considered to be released under the GNU Free Documentation License 1.3 or later (see
My wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
English
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Getting Madagascar
download
Installation
GitHub repository
SEGTeX
Introduction
Package overview
Tutorial
Hands-on tour
Reproducible documents
Hall of Fame
User Documentation
List of programs
Common programs
Popular programs
The RSF file format
Reproducibility with SCons
Developer documentation
Adding programs
Contributing programs
API demo: clipping data
API demo: explicit finite differences
Community
Conferences
User mailing list
Developer mailing list
GitHub organization
LinkedIn group
Development blog
Twitter
Slack
Tools
What links here
Related changes
Special pages
Page information