Month: August 2008

SLIMpy: SLIM-UBC’s Python interface to Madagascar

August 6, 2008 Systems No comments

In the light of the recent discussion on extending the Python interface to Madagascar, I would like to inform those of you who did not know already about the public release of SLIMpy: SLIM-UBC’s Python interface to out-of-core seismic data processing.
SLIMpy is a Python interface that exposes the functionality of seismic data processing packages, such as MADAGASCAR, through operator overloading. SLIMpy provides a concrete coordinate-free implementation of classes for out-of-core linear (implicit matrix-vector), and element-wise operations, including calculation of norms and other basic vector operations. The library is intended to provide the user with an abstract scripting language to program iterative algorithms from numerical linear algebra. These algorithms require repeated evaluation of operators that were initially designed to be run as part of batch-oriented processing flows. The current implementation supports a plugin for Madagascar’s out-of-core UNIX pipe-based applications and is extenable to pipe-based collections of programs such as Seismic Un*x, SEPLib, and FreeUSP. To optimize performance, SLIMpy uses an Abstract Syntax Tree that parses the algorithm and optimizes the pipes.
The main features of SLIMpy include:
– Powerful interpreted programming language (Python)
– Syntax (through overloading) close to pseudo-code for numerical linear algebra
– Abstract Syntax Tree analyzer/optimizer (including command rearrangement form improved performance)
– Concrete linear operator and vector classes, including dottests, domain-range and type checks
– Elementwise reduction-transformation operations (norms, elementary math)
– Compounded linear operators
– Augmented linear operators and vector classes
– Plugin mechanism for Unix pipe-based collections of (seismic) data processing programs
– Parallel execution of reduction/transformation operations
– Parallel execution of embarrassingly parallel linear operators (block diagonal)
– Integration with SCons
– Automatic cleanup of temporary datafiles (garbage collection)
– In-code documentation through Doxygen
SLIMpy is an academic research code that we share with the community through this alpha release. By making SLIMpy available as open source, we hope to create an active community to further develop this software.
SLIMpy is released under GNU Lesser General Public License, and it is available for download from SVN repositories:
– the core packages from
– the contributions from
Additional documentation and tutorials can be found at
– SLIMpy’s documentation
– SLIMpy’s tutorial
Through this release, we hope that SLIMpy can grow into a widely-used Library, supplementing the functionality of currently available processing-flow oriented (seismic) software packages. Please, use SLIMpy-user ( mailing list to report concerns and exchange the ideas. Those of you, who wish to contribute to development, please, subscribe to SLIMpy-devel (
Most of the credit for developing SLIMpy goes to Sean Ross-Ross of the SLIM group.

Extending Python interface

August 3, 2008 Systems No comments

Work is under way on extending the Python interface to Madagascar. With new tools, you should be able to use an interactive Python session rather than a Unix shell to run Madagascar modules. Here are some examples:

import m8r as sf
import numpy, pylab

f = sf.spike(n1=1000,k1=300)[0]

# sf.spike is an operator
# f is an RSF file object


# Inspect the file with sfattr

b = sf.bandpass(fhi=2,phase=1)[f]

# Now f is filtered through sfbandpass

c = sf.spike(n1=1000,k1=300).bandpass(fhi=2,phase=1)[0]

# c is equivalent to b but created with a pipe

g = c.wiggle(clip=0.02,title='Welcome to Madagascar')

# g is a Vplot file object

# Display it on the screen

d = b - c

# Elementary arithmetic operations on files are defined

g = g + d.wiggle(wanttitle=False)

# So are operations on plots

# This shows a movie
c = numpy.clip(b,0,0.01)

# RSF file objects can be passed to pylab or numpy

s = c[300:310]

print s

# Taking a slice outputs a numpy array

c = sf.clip(clip=0.01)[b]

# Alternatively, apply sfclip

For doing reproducible research, one can also use the new syntax inside SConstruct files, as follows:

from rsf.proj import *
import m8r as sf

Result('filter',sf.wiggle(clip=0.02,title='Welcome to Madagascar'))


See also a 4-line dot-product test and 20-line conjugate-gradient algorithm.

The picture shows a screenshot of an interactive session in a SAGE web-based notebook