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

def velplot(title,label1='Depth',unit1='kft'):
    return '''
    grey color=j allpos=y title="%s" scalebar=y
    barlabel=Velocity barunit=kft/s
    label1="%s" unit1="%s" label2=Lateral unit2=kft
    barreverse=y pclip=100 
    ''' % (title,label1,unit1)

def graph(transp,o2,d2,n2,col,fat,extra=''):
    return '''
    graph transp=%d yreverse=y pad=n min2=%g max2=%g
    plotcol=%d plotfat=%d wantaxis=n wanttitle=n %s
    ''' % (transp,o2,o2+(n2-1)*d2,col,fat,extra)


v0=1500
dv=10
nv=301

#####################
# AGC
#####################
#Flow('cmp.rsf','cmp_raw.rsf','agc')

Fetch('AVO_cmp1.rsf','uh',server)

Flow('cmp.rsf','AVO_cmp1.rsf','window')
#####################
# Velocity scan
#####################
Flow('scan','cmp.rsf',
     '''
     vscan type=avo semblance=y half=n
     v0=%g dv=%g nv=%d
     ''' % (v0,dv,nv))

Plot('scan','scan',
    '''
    grey color=j allpos=y
    label2=Velocity unit2=m/s title="(b)"
    wheretitle=t wherexlabel=b
    ''')

#####################
# Velocity picking
#####################
Flow('pick','scan',
     '''
     pick rect1=50 rect2=100 vel0=1400 | window
     ''')

########################
# NMO and initial stack
########################
Flow('nmo','cmp.rsf pick',
     'nmo velocity=${SOURCES[1]}')

Plot('nmo', 'nmo',
       '''
       put o2=1 d2=1 label2=Trace unit2="" |
       sfwiggle poly=y yreverse=y transp=y wanttitle=n
       ''')

Flow('stack','nmo','stack')

Plot('cmp', 'cmp',
       '''
       put o2=1 d2=1 label2=Trace unit2="" | sfwiggle poly=y yreverse=y transp=y title='(a)' labelsz=13 titlesz=14 plotcol=7 gridcol=7
       ''')




########################
# Obtain reference trace 

Flow('zotrace','cmp.rsf','window f2=0 n2=1')

#Flow('zotrace','cmp.rsf','stack')

Flow('onenmostacks','zotrace',
     '''
     spray axis=2 n=59
     ''')


Flow('weight1','onenmostacks nmo',
     '''
     similarity other=${SOURCES[1]} niter=30 rect1=5 rect2=7
     ''')

Flow('tweight1','weight1','threshold pclip=20')

Flow('onesimistack', 'tweight1 nmo',
     '''
     math y=${SOURCES[1]} output=input*y | stack

     ''')

Plot('stack1','stack','put o2=0 label2=Amplitude unit2="" | wiggle poly=y yreverse=y transp=y title="(b)" titlesz=14 labelsz=13 plotcol=7 gridcol=7')

Plot('onesimistack1','onesimistack','put o2=0 label2=Amplitude unit2="" | wiggle poly=y yreverse=y transp=y title="(d)" titlesz=14 labelsz=13 plotcol=7 gridcol=7')

Flow('snrstack','nmo','snrstack w=15 ee=1e-1 esp=1000 ')
Plot('snrstack1','snrstack','put o2=0 label2=Amplitude unit2="" | wiggle poly=y yreverse=y transp=y title="(c)" titlesz=14 labelsz=13 plotcol=7 gridcol=7')

Result('cmpstack1',' cmp stack1 snrstack1 onesimistack1', 'SideBySideAniso',vppen='txscale=1.8')



End()

sfwindow
sfvscan
sfgrey
sfpick
sfnmo
sfput
sfwiggle
sfstack
sfspray
sfsimilarity
sfthreshold
sfmath
sfsnrstack