up [pdf]
from rsf.proj import *

trace = [0,1,3,0,-2,-5,-2,2,5,0,-1,1,0,2,4,1,-3,-5,-1,0]
nt = len(trace)

Flow('trace.asc',None,'echo %s n1=%d o1=0 d1=1 data_format=ascii_int in=$TARGET' % (' '.join(map(str,trace)),nt))
Flow('trace','trace.asc','dd type=float form=native')

graph = '''
graph wanttitle=n min2=-6 max2=6 min1=-0.5 max1=%g screenht=8 screenwd=32 
label2=Amplitude label1="Time Samples"
''' % (nt-0.5)

Flow('ctrace','trace','math output=x1 | cmplx $SOURCE')

Plot('ctrace',graph + ' symbol=o symbolsz=8 plotcol=7')
Plot('lines','ctrace','math output=x1 | cat axis=2 $SOURCE | transp | %s plotcol=7' % graph)
Plot('zero','trace','math output=0 | %s plotcol=7' % graph)
Plot('trace','zero lines ctrace','Overlay')

d1 = (nt-1.0)/20000

Flow('linear','trace','remap1 order=2 n1=20000 d1=%g o1=0' % d1)
Flow('spline','trace linear','spline pattern=${SOURCES[1]}')

Plot('spline','linear spline','cat axis=2 ${SOURCES[1]} | %s plotcol=1,2' % graph)

Plot('trace2','trace spline','Overlay')

Result('trace2','Overlay')

Flow('envelope','spline','window j1=100 | envelope')

Plot('envelope','scale dscale=-1 | cat $SOURCE axis=2 | %s plotcol=4 dash=1,0' % graph)

# different kinds of averages

def attr(par):
    'extract parameter from sfattr and put it in mag=par form'
    return '''
    attr want=%s | sed s/%s/mag/ | sed "s/[ \\t]*//g" 
    ''' % (par,par)

Flow('rms.par','spline',attr('rms'))
Flow('absmean.par','spline','math output="abs(input)" | ' + attr('mean'))
Flow('envmean.par','envelope',attr('mean'))

for par in ('rms','absmean','envmean'):
    Plot(par,['spline',par+'.par'],
         'spike par=${SOURCES[1]} label1= unit1= | %s plotcol=5' % graph)

Result('envelope','trace2 envelope rms absmean envmean','Overlay')

End()

sfdd
sfmath
sfcmplx
sfgraph
sfcat
sftransp
sfremap1
sfspline
sfwindow
sfenvelope
sfscale
sfattr
sfspike