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
f.attr()
# 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
g.show()
# 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
g.show()
# This shows a movie
pylab.show(pylab.plot(b))
c = numpy.clip(b,0,0.01)
# RSF file objects can be passed to pylab or numpy
c.attr()
s = c[300:310]
print s
# Taking a slice outputs a numpy array
c = sf.clip(clip=0.01)[b]
c.attr()
# 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
Flow('filter',None,sf.spike(n1=1000,k1=300).bandpass(fhi=2,phase=1))
Result('filter',sf.wiggle(clip=0.02,title='Welcome to Madagascar'))
End()
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
code
more code
~~~~