Editing
Reproducible computational experiments using SCons
(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!
===Example 2=== The plan for this experiment is to add random noise to the test "Lena" image and then attempt removing it by low-pass filtering and hard thresholding of coefficients in the Fourier domain. The resultant images are shown in the figures. [[Image:panel1.png|frame|center|Top left: original image. Top right: random noise added. Bottom left: original image spectrum in the Fourier (<math>F</math>-<math>X</math>) domain. Bottom right: noisy image spectrum in the Fourier (<math>F</math>-<math>X</math>) domain.]] [[Image:panel2.png|frame|center|Left: denoising by low-pass filtering. Right: denoising by hard thresholding in the Fourier domain.]] Since the <tt>SConstruct|</tt> file is a Python script, we can also use all the flexibility and power of the Python language in our Madagascar reproducible scripts. A demo script is available in the <tt>rsf/scons/rsfpy</tt> subdirectory of the Madagascar <tt>book</tt> directory. Rather than commenting on it line-by-line, we select some parts of interest. In the <tt>SConstruct</tt> script, we can declare Python variables <syntaxhighlight lang="python"> bias = 128 </syntaxhighlight> and use them later, for example, to define our customized plot command as a Python function <syntaxhighlight lang="python"> def grey(title,transp='n',bias=bias): return ''' sfgrey title="%s" transp=%s bias=%g clip=100 screenht=10 screenwd=10 crowd2=0.85 crowd1=0.8 label1= label2= ''' % (title,transp,bias) </syntaxhighlight> This Python function, named <tt>grey()</tt>, can then be called in Plot or Result commands, e.g. <syntaxhighlight lang="python"> Plot('lplena',grey('Noisy Lena LP filtered')) </syntaxhighlight> We can define a Python dictionary, e.g. <syntaxhighlight lang="python"> titles = {'lena':'Lena', 'nlena':'Noisy Lena'} </syntaxhighlight> and loop over its entries, e.g. <syntaxhighlight lang="python"> for name in titles.keys(): Plot(name,grey(titles[name]) ) cftitle = titles[name]+' in FX domain' Flow('fx'+name,name,'sfspectra') Plot('fx'+name,grey(cftitle,'y',100)) </syntaxhighlight> Note that the title of the plots is obtained by concatenating Python strings. Python strings can also be used to define sequences of commands used in several Flows, e.g. <syntaxhighlight lang="python"> # 2-D FFT fft2 = 'sffft1 sym=y | sffft3 sym=y' Flow('fnlena','nlena',fft2) </syntaxhighlight> Finally, in our Madagascar reproducible script, we may want the option to pass command line arguments when running SCons or use default values otherwise, e.g. <syntaxhighlight lang="python"> # denoising using thresholding in the Fourier domain fthr = float(ARGUMENTS.get('fthr', 70)) Flow('fthrlena','fnlena','sfthr thr=%f mode="hard"' % fthr) </syntaxhighlight> Running <tt>scons</tt> only, the default value set for fthr (i.e. 70) is used whereas running <tt>scons fthr=68</tt> set fthr to a command line specified value. This is by no means an exhaustive list of options, but hopefully, it will give you a flavor of the powerful tool you have in your hands. Enjoy! <!-- ===Useful SCons commands for reproducible scripts=== On top of SCons standard options (<tt>scons --help</tt> for more details), Madagascar has its own SCons options. We already saw <tt>scons plot.view</tt> that displays <tt>plot.vpl</tt> (in the <tt>Fig</tt> folder) obtained in a Result command. <tt>scons view</tt> displays the result plots one after the other. It is also possible to check the parameters for Madagascar programs in SCons Flow commands using the CHECKPAR option (\texttt{scons CHECKPAR=y target}). Note that CHECKPAR is an experimental option and will be enhanced in the future to include parameter ranges and other safety checks. To time the execution of processing flows in a SConstruct, use the TIMER option (<tt>scons TIMER=y target</tt>). <tt>scons lock</tt> is used to secure result plots and copy them from the <tt>Fig</tt> folder of your working directory to your <tt>$RSFFIGS</tt> folder where <tt>RSFFIGS</tt> is the environmental variable to the directory where you want Madagascar to put your key Madagascar result plots. Note that this is a necessary step before creating reproducible documentation. <tt>scons plot.flip</tt> runs <tt>xtpen Fig/plot.vpl /locked/figures/plot.vpl</tt> to flip between the new and locked figure. This is useful when detecting changes. -->
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