up [pdf]
from rsf.proj import *

##################
# Field data test
##################
ns=7
Fetch('bei-agc.rsf','midpts')
Flow('bei','bei-agc.rsf',
     'dd form=native |put label1=Time unit1=s label2=Trace o2=1 d2=1')
Plot('bei','grey title="Input"')
Result('bei',
       '''
       grey wanttitle=n clip=3.25434 labelfat=4 font=2 titlefat=4
       o1num=0 d1num=60 n1tic=5
       ''')

Flow('rdip','bei','dip rect1=20 rect2=10')
Result('rdip',
       '''
       grey color=j scalebar=y wanttitle=n barlabel=Slope barunit=samples
       labelfat=4 font=2 titlefat=4 o1num=0 d1num=60 n1tic=5 bartype=h
       ''')

Flow('rspray','bei rdip','pwspray dip=${SOURCES[1]} ns=%d' % ns)

Result('rcube','rspray',
       '''
       transp plane=23 | put d3=1 o3=%d | byte gainpanel=all |
       grey3 wanttitle=n flat=n label3="Prediction" unit3=Trace labelfat=4
       font=2 titlefat=4 frame1=437 frame2=124 frame3=%d
       point1=0.9 point2=0.8 o3num=-6 d3num=3 n3tic=%d
       o1num=0 d1num=60 n1tic=5
       ''' % (-1*ns,ns+1,ns-2))

Flow('rstacks','bei','spray axis=2 n=%d ' % (2*ns+1))
Flow('rweight','rstacks rspray',
     '''
     similarity other=${SOURCES[1]} rect1=10 rect3=1 | threshold pclip=99
     ''')

# Improved similarity stacking (Gaussian taper)
Flow('rgausweight','rspray',
     '''
     put o2=-7 | window n3=1 | sfmath output="exp(-x2*x2/((2)*(2)))" |
     spray axis=3 n=250 | put d2=1 o2=1
     ''')
Flow('rweight1','rgausweight rweight',
     '''
     add mode=p ${SOURCES[1]}
     ''')

Result('rweight','rweight1',
       '''
       transp plane=23 | put d3=1 o3=%d |
       byte gainpanel=all allpos=y  bar=bar1.rsf |
       grey3 wanttitle=n flat=n color=j label3="Prediction" unit3=Trace
       frame1=437 frame2=124 frame3=%d point1=0.9 point2=0.8
       o3num=-6 d3num=3 n3tic=%d o1num=0 d1num=60 n1tic=5
       scalebar=y bar=bar1.rsf bartype=h labelfat=4 font=2 titlefat=4
       barlabel=Weight barunit=samples
       ''' % (-1*ns,ns+1,5))
Flow('norm','rweight1','stack')
Flow('rgsimilarstack','rspray rweight1 norm',
     'add mode=p ${SOURCES[1]} | stack | add mode=d ${SOURCES[2]}')
Result('rgsimilarstack',
       '''
       grey wanttitle=n clip=3.25434 labelfat=4 font=2 titlefat=4
       o1num=0 d1num=60 n1tic=5
       ''')

Flow('rgdif','bei rgsimilarstack','sfadd scale=1,-1 ${SOURCES[1]}')
Result('rgdif',
       '''
       grey wanttitle=n clip=3.25434 label2=Trace labelfat=4 font=2
       titlefat=4 o1num=0 d1num=60 n1tic=5
       ''')

# LUM filtering
Flow('rmedian','rspray',
     '''
     transp plane=12 | lum nfw=%d shnclip=%d smnclip=%d boundary=y |
     sfwindow n1=1 f1=%d
     ''' % ((2*ns+1),ns,ns,ns))
Result('rmedian',
       '''
       grey wanttitle=n clip=3.25434 unit2= labelfat=4 font=2 titlefat=4
       o1num=0 d1num=60 n1tic=5
       ''')
Flow('rldif','bei rmedian','sfadd scale=1,-1 ${SOURCES[1]}')
Result('rldif',
       '''
       grey wanttitle=n clip=3.25434 label2=Trace labelfat=4 font=2
       titlefat=4 o1num=0 d1num=60 n1tic=5
       ''')

End()

sfdd
sfput
sfgrey
sfdip
sfpwspray
sftransp
sfbyte
sfgrey3
sfspray
sfsimilarity
sfthreshold
sfwindow
sfmath
sfadd
sfstack
sflum

data/midpts/bei-agc.rsf