up [pdf]
from rsf.proj import *

Flow('vrms',None,
     'math d1=0.004 n1=1001 o1=0 output="x1*125+2000+50*sin(9*x1)" ')

Flow('synt',None,
     '''
     spike d1=0.004 n1=1001 |
     noise rep=y seed=2006 |
     cut n1=100 | 
     bandpass flo=4 fhi=20 |
     spray axis=2 n=141 d=25 o=0 label=Offset unit=m 
     ''')

Flow('cmpa','synt vrms',
     'inmo velocity=${SOURCES[1]} half=n | noise seed=2007 var=1e-10 | put d2=0.025 label2="Offset" unit2="km" ')

Flow('top','synt','window n1=400')
Flow('mid','synt',
     'window f1=400 n1=300 | math output="input*(1-x2*%g)" ' % (2.0/3500))
Flow('bot','synt','window f1=700')

Flow('cmpb','top mid bot vrms',
     '''
     cat axis=1 ${SOURCES[1:3]} |
     inmo velocity=${SOURCES[3]} half=n |
     noise seed=2007 var=1e-10 | put d2=0.025 label2="Offset" unit2="km"
     ''')


#Flow('ref','cmpa','window n2=1')
#Flow('ref','abnmo','stack')
Flow('ref','synt','window n2=1')

dat='cmpa'
for typ in ('semblance','ab','weighted','similarity-weighted'):
        scn=typ+'scn'
        if typ == 'similarity-weighted':
                Flow(scn,[dat,'ref'],'simivscan thr=0.4 half=n v0=2 dv=0.01 nv=101 type=semblance weight=y nb=5 ref=${SOURCES[1]} | clip2 lower=0')
        else:
                Flow(scn,dat,'vscan half=n v0=2 dv=0.01 nv=101 weight=y type=%s nb=5 | clip2 lower=0'%typ)
        Plot(scn+'0',scn,
                '''
                grey color=j allpos=y title="%s" pclip=100 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
                '''%typ)
        pik=typ+'pik'
        Flow(pik,scn,'scale axis=2 | pick rect1=50')
        Plot(pik,
             '''
             graph yreverse=y transp=y min2=2 max2=3 pad=n
             plotcol=7 plotfat=15 wanttitle=n wantaxis=n
             ''')
        Result(scn,[scn+'0',pik],'Overlay')
        nmo = typ + 'nmo'
        Flow(nmo,[dat,pik],'nmo half=n velocity=${SOURCES[1]} str=0.1 ')
        Result(nmo,
                        '''
                        grey title="%s"
                        grid2=y gridcol=6 gridfat=7 g2num=0.5 clip=0.74 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
                        ''' % typ)

        inmo = typ + 'inmo'
        Flow(inmo,[nmo,pik],'inmo half=n velocity=${SOURCES[1]} str=0.4')
        Result(inmo,
                        '''
                        grey title="%s" clip=0.74 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
                        ''' % typ)

#Flow('ref','cmpa','window n2=1')
Flow('ref2','avo-abnmo','stack')
#Flow('ref','synt','window n2=1')

dat='cmpb'
for typ1 in ('semblance','ab','weighted','similarity-weighted'):
        typ='avo-'+typ1
        scn=typ+'scn'

        if typ == 'avo-similarity-weighted':
                Flow(scn,[dat,'ref2'],'simivscan thr=0.2 half=n v0=2 dv=0.01 nv=101 weight=y type=avo nb=5 ref=${SOURCES[1]} | clip2 lower=0')
        elif typ=='avo-semblance':
                Flow(scn,dat,'vscan half=n v0=2 dv=0.01 nv=101 weight=y type=semb nb=5 | clip2 lower=0')
        elif typ == 'avo-weighted':
                Flow(scn,dat,'vscan half=n v0=2 dv=0.01 nv=101 weight=y type=weighted nb=5 | clip2 lower=0')
        else:
                Flow(scn,dat,'vscan half=n v0=2 dv=0.01 nv=101 weight=y type=avo nb=5 | clip2 lower=0')

        Plot(scn+'0',scn,
                '''
                grey color=j allpos=y title="%s" pclip=100 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
                '''%typ)
        pik=typ+'pik'
        Flow(pik,scn,'scale axis=2 | pick rect1=50')
        Plot(pik,
             '''
             graph yreverse=y transp=y min2=2 max2=3 pad=n
             plotcol=7 plotfat=15 wanttitle=n wantaxis=n
             ''')
        Result(scn,[scn+'0',pik],'Overlay')
        nmo = typ + 'nmo'
        Flow(nmo,[dat,pik],'nmo half=n velocity=${SOURCES[1]} str=0.1 ')
        Result(nmo,
                        '''
                        grey title="%s"
                        grid2=y gridcol=6 gridfat=7 g2num=0.5 clip=0.74 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
                        ''' % typ)

        inmo = typ + 'inmo'
        Flow(inmo,[nmo,pik],'inmo half=n velocity=${SOURCES[1]} str=0.4')
        Result(inmo,
                        '''
                        grey title="%s" clip=0.74 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
                        ''' % typ)


############################################################
####### Blend 
############################################################
## Apply dithering
Flow('dither','cmpa',
     '''
     window n1=1 |
     noise rep=y seed=122011 var=10 | math output="1000*input"
     ''')

Flow('shottime1','cmpa','window n1=1 | math output=3*100000*x1')
Flow('shottime2','shottime1 dither','add scale=1,1 ${SOURCES[1]}')


## Blend 
Flow('cmpc','cmpa cmpa shottime1 shottime2','blend shot_time_in=${SOURCES[3]} shot_time_out=${SOURCES[2]} |add scale=1,1 ${SOURCES[1]}' )

dat='cmpc'
for typ1 in ('semblance','ab','weighted','similarity-weighted'):
        typ='blend-'+typ1
        scn=typ+'scn'
        if typ == 'blend-similarity-weighted':
                Flow(scn,[dat,'ref'],'simivscan thr=0.4 half=n v0=2 dv=0.01 nv=101 type=semblance weight=y nb=5 ref=${SOURCES[1]} | clip2 lower=0')
        else:
                Flow(scn,dat,'vscan half=n v0=2 dv=0.01 nv=101 weight=y type=%s nb=5 | clip2 lower=0'%typ1)
        Plot(scn+'0',scn,
                '''
                grey color=j allpos=y title="%s" pclip=100 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
                '''%typ)
        pik=typ+'pik'
        Flow(pik,scn,'scale axis=2 | pick rect1=50')
        Plot(pik,
             '''
             graph yreverse=y transp=y min2=2 max2=3 pad=n
             plotcol=7 plotfat=15 wanttitle=n wantaxis=n
             ''')
        Result(scn,[scn+'0',pik],'Overlay')
        nmo = typ + 'nmo'
        Flow(nmo,[dat,pik],'nmo half=n velocity=${SOURCES[1]} str=0.1 ')
        Result(nmo,
                        '''
                        grey title="%s"
                        grid2=y gridcol=6 gridfat=7 g2num=0.5 clip=0.74 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
                        ''' % typ)

        inmo = typ + 'inmo'
        Flow(inmo,[nmo,pik],'inmo half=n velocity=${SOURCES[1]} str=0.4')
        Result(inmo,
                        '''
                        grey title="%s" clip=0.74 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
                        ''' % typ)



Result('cmpa','grey title="CMP" clip=0.74 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2')
Result('cmpb','grey title="CMP with AVO" clip=0.74 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2')
Result('cmpc','grey title="Blended CMP" clip=0.74 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2')
Result('synth-comp1','./Fig/cmpa.vpl ./Fig/semblancescn.vpl ./Fig/abscn.vpl ./Fig/similarity-weightedscn.vpl','SideBySideAniso')
Result('synth-comp2','./Fig/cmpb.vpl ./Fig/avo-semblancescn.vpl ./Fig/avo-abscn.vpl ./Fig/avo-similarity-weightedscn.vpl','SideBySideAniso')

Result('synth-comp3','./Fig/cmpc.vpl ./Fig/blend-semblancescn.vpl ./Fig/blend-abscn.vpl ./Fig/blend-similarity-weightedscn.vpl','SideBySideAniso')

#Result('comp2','./Fig/cmpa.vpl ./Fig/semblancenmo.vpl ./Fig/abnmo.vpl ./Fig/weightednmo.vpl','SideBySideAniso')
#Result('comp3','./Fig/cmpa.vpl ./Fig/semblanceinmo.vpl ./Fig/abinmo.vpl ./Fig/weightedinmo.vpl','SideBySideAniso')

#Result('comp4','./Fig/cmpb.vpl ./Fig/avo-semblancescn.vpl ./Fig/avo-abscn.vpl ./Fig/avo-weightedscn.vpl','SideBySideAniso')
#Result('comp5','./Fig/cmpb.vpl ./Fig/avo-semblancenmo.vpl ./Fig/avo-abnmo.vpl ./Fig/avo-weightednmo.vpl','SideBySideAniso')
#Result('comp6','./Fig/cmpb.vpl ./Fig/avo-semblanceinmo.vpl ./Fig/avo-abinmo.vpl ./Fig/avo-weightedinmo.vpl','SideBySideAniso')


#Flow('test1','cmpa','vscan half=n avosemblance=n semblance=y v0=2 dv=0.01 nv=101 type=s | clip2 lower=0')
#Flow('test2','cmpa','vscan half=n avosemblance=y semblance=y v0=2 dv=0.01 nv=101 type=a | clip2 lower=0')

#Plot('test1',
#               '''
#               grey color=j allpos=y title="%s" pclip=100 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
#               ''')
#Plot('test2',
#               '''
#               grey color=j allpos=y title="%s" pclip=100 labelsz=14 labelfat=2 font=2 titlesz=14 titlefat=2
#               ''')
#Result('test','test1 test2','SideBySideAniso')

End()

sfmath
sfspike
sfnoise
sfcut
sfbandpass
sfspray
sfinmo
sfput
sfwindow
sfcat
sfvscan
sfclip2
sfgrey
sfscale
sfpick
sfgraph
sfnmo
sfsimivscan
sfstack
sfadd
sfblend