up [pdf]
from rsf.proj import *

Flow('spike',None,'spike n1=41 k1=21 d1=1 label1=" " ')

exps = []
tris = []
repeat = 5

for iter in range(1,repeat+1):
    exp = 'exp%d' % iter
    tri = 'tri%d' % iter
    exps.append(exp)
    tris.append(tri)
    Flow(tri,'spike','smooth    rect1=5 repeat=%d' % iter)
    Flow(exp,'spike','smoothreg eps=5   repeat=%d' % iter)

def dots(n=repeat):
    return '''
    cat axis=2 ${SOURCES[1:%d]} |
    dots dots=0 yreverse=y label1=Time unit1=sample gaineach=n
    labels=%s
    ''' % (n,string.join(map(str,range(1,n+1)),':'))

def sdots(n=repeat):
    return '''
    cat axis=2 ${SOURCES[1:%d]} | spectra > one.rsf &&
    window f1=1 < one.rsf | reverse which=1 opt=n | cat axis=1 one.rsf |
    dots dots=0 yreverse=y label1=Frequency unit1=cycle gaineach=n
    labels=%s
    ''' % (n,string.join(map(str,range(1,n+1)),':'))

def graph(title):
    return '''
    cat axis=2 ${SOURCES[1:%d]} | spectra |
    graph title="%s" label1="Frequency (cycles)"
    labelsz=10 titlesz=12
    ''' % (repeat,title)

Plot('exp',exps,dots())
Plot('tri',tris,dots())

Result('exp2',exps[:repeat-1],dots(repeat-1))
Result('tri2',tris[:repeat-1],dots(repeat-1))

#Plot('exp1',exps,graph('Spectrum of regularized smoothing'))
#Plot('tri1',tris,graph('Spectrum of triangle smoothing'))

Plot('exp1',exps,sdots())
Plot('tri1',tris,sdots())

for case in ['exp','tri']:
    Result(case,[case,case+'1'],'SideBySideAniso')

def contour(title):
    return '''
    contour transp=n yreverse=n title="%s" scalebar=y
    barlabel=' ' label1=' ' label2=' ' c0=0.0005 dc=0.0005 nc=100 
    screenratio=1
    ''' % title

Flow('spike2',None,'spike n1=41 n2=41 k1=21 k2=21 d1=1 d2=1')

for rep in (1,3):
    exp = 'exp2-%d' % rep
    tri = 'tri2-%d' % rep
    all = 'all2-%d' % rep
    Flow(exp,'spike2','smoothreg2 eps=17 repeat=%d' % rep)
    Plot(exp,contour('Regularized Smoothing'))
    Flow(tri,'spike2','smooth rect1=17 rect2=17 repeat=%d' % rep)
    Plot(tri,contour('Triangle Smoothing'))
    Result(all,[exp,tri],'SideBySideIso')

trismooth = 'trismooth2 rect1=5 rect2=10 dip=${SOURCES[1]}'
trismooth = 'pwdsmooth2 rect1=5 rect2=10 dip=${SOURCES[1]}'

preds=[]
for adj in range(4):
    pred = 'pred%d' % adj
    preds.append(pred)
    if adj < 2:
        Flow(pred,'spike2 one','predict dip=${SOURCES[1]} adj=%d' % adj)
    else:
        Flow(pred,'pred%d one' % (adj-2),
             'predict dip=${SOURCES[1]} adj=%d' % (3-adj))
    Plot(pred,'grey allpos=y wanttitle=n label1=" " label2=" " ')
Result('pred',preds,'SideBySideAniso')

Flow('one','spike2','math output=1')
Flow('two','spike2','math output=-2')
Flow('spike-2','spike2 two',trismooth)
Flow('spike1','spike2 one',trismooth)
Flow('spike12','spike1 two',trismooth)
Flow('spike21','spike-2 one',trismooth)
Flow('test12','spike1 spike-2 spike12 spike21',
     'add ${SOURCES[1:4]} scale=1,1,-0.5,-0.5')

Result('test12',
       '''
       grey allpos=y wanttitle=n transp=n
       unit1= unit2= label1="X Sample" label2="Y Sample" screenratio=1
       ''')

Flow('spike3',None,'spike n1=41 n2=41 n3=41 k1=21 k2=21 k3=21 d1=1 d2=1 d3=1 unit1= unit2= unit3=')

Flow('one3','spike3','math output=1')
Flow('two3','spike3','math output=-2')

Flow('plane','spike3 one3 two3',
     '''
     trismooth2 rect1=5 rect2=20 dip=${SOURCES[1]} |
     transp plane=23 |
     trismooth2 rect1=5 rect2=10 dip=${SOURCES[2]} |
     transp plane=23
     ''')

Result('plane',
       '''byte allpos=y gainpanel=all |
       grey3 flat=n screenratio=1 frame1=20 frame2=20 frame3=20
       point1=0.6 point2=0.6
       label1="Y Sample" label2="X Sample" label3="Z Sample" wanttitle=n
       ''')

Flow('plane2','spike3 one3 two3',
     '''
     pwdsmooth2 rect1=3 rect2=20 dip=${SOURCES[1]} |
     transp plane=23 |
     pwdsmooth2 rect1=3 rect2=10 dip=${SOURCES[2]} |
     transp plane=23
     ''')

Result('plane2',
       '''byte allpos=y gainpanel=all |
       grey3 flat=n screenratio=1 frame1=20 frame2=20 frame3=20
       point1=0.6 point2=0.6
       label1=' ' label2=' ' label3=' ' wanttitle=n
       ''')

###########################################################################
End()

sfspike
sfsmooth
sfsmoothreg
sfcat
sfdots
sfspectra
sfwindow
sfreverse
sfsmoothreg2
sfcontour
sfpredict
sfgrey
sfmath
sfpwdsmooth2
sfadd
sftrismooth2
sftransp
sfbyte
sfgrey3