up [pdf]
from rsf.proj import *
from rsf.recipes.beg import server as private

Fetch('5_gather.segy','rsi',private)

Flow('gath tgath gath.h gath.b','5_gather.segy',
     '''
     segyread tape=$SOURCE
     tfile=${TARGETS[1]} hfile=${TARGETS[2]} bfile=${TARGETS[3]}
     ''',stdin=0)

Flow('gaths','gath',
     'intbin xk=cdpt yk=cdp | window min1=2.8 | put label1=Time unit1=s')

Flow('off','tgath',
     '''
     dd type=float |
     headermath output=offset/1000 |
     intbin xk=cdpt yk=cdp head=$SOURCE |
     window n3=1 
     ''')

grey = 'grey title="(a)" label2=Trace grid2=y gridcol=2'

wiggle = '''
wiggle xpos=${SOURCES[1]} title="(b)"
transp=y yreverse=y poly=y label2=Offset unit2=kft
wheretitle=b wherexlabel=t
'''

for g in range(5):
    gath = 'gath%d' % g

    Flow(gath,'gaths','window n3=1 f3=%d' % g)
    Plot(gath,grey)
    Plot('w'+gath,[gath,'off'],wiggle)
    Result(gath,[gath,'w'+gath],'SideBySideAniso')

    for case in ('','avo'):
        scan = '%sscan%d' % (case,g)
        pick = '%spick%d' % (case,g)
        nmod = '%snmod%d' % (case,g)
        slic = '%sslic%d' % (case,g)

        Flow(scan,[gath,'off'],
             '''
             vscan %ssemblance=y offset=${SOURCES[1]} half=n
             slowness=y v0=-0.01 nv=101 dv=0.0002 squared=y nb=1
             ''' % case)
        Plot(scan+'a',scan,
             '''
             grey title="%s Scan" color=j allpos=y
             label2="Residual Curvature" unit2="s\^2\_/kft\^2"
             ''' % ('(a) Semblance','(b) AVO-Friendly Semblance')[case=='avo'])

        Flow(pick,scan,'pick rect1=20 vel0=0 | window')
        Plot(pick,
             '''
             graph transp=y yreverse=y transp=y min2=-0.01 max2=0.01
             pad=n plotcol=7 plotfat=7 wanttitle=n wantaxis=n
             ''')

        Plot(scan,[scan+'a',pick],'Overlay')

        Flow(slic,[scan,'avopick%d' % g],'slice pick=${SOURCES[1]}')

        Flow(nmod,[gath,pick,'off'],
             '''
             nmo velocity=${SOURCES[1]} offset=${SOURCES[2]}
             half=n slowness=y squared=y
             ''')
        Plot(nmod,grey)
        Plot('w'+nmod,[nmod,'off'],wiggle)
        Result(nmod,[nmod,'w'+nmod],'SideBySideAniso')

    scan = 'scan%d' % g
    Result(scan,[scan,'avo'+scan],'SideBySideAniso')

    attr = 'attr%d' % g
    Flow(attr,['avoslic%d' % g,'slic%d' % g],
         '''
         add mode=d ${SOURCES[1]} | smooth rect1=25 |
         spray axis=2 n=40 d=1 o=1
         ''')

    Plot(attr,['avonmod%d' % g,attr],
         '''
         scale axis=2 |
         add ${SOURCES[1]} |
         %s color=j allpos=y gridcol=7
         ''' % grey)

    Result('nmo%d' % g,[attr,'wnmod%d' % g],'SideBySideAniso')

End()

sfsegyread
sfintbin
sfwindow
sfput
sfdd
sfheadermath
sfgrey
sfwiggle
sfvscan
sfpick
sfgraph
sfslice
sfnmo
sfadd
sfsmooth
sfspray
sfscale