up [pdf]
from rsf.proj import *


#### sythetic data
Flow('spike1',None,'spike n1=100 nsp=1 mag=1 d1=0.004 o1=0 k1=43 | ricker1 freq=0.1')

Flow('spike2',None,'spike n1=100 nsp=1 mag=1 d1=0.004 o1=0 k1=50 | ricker1 freq=0.1')

Flow('spike3',None,'spike n1=100 nsp=1 mag=1 d1=0.004 o1=0 k1=50 | ricker1 freq=0.1')

Flow('spike4',None,'spike n1=100 nsp=1 mag=1 d1=0.004 o1=0 k1=50 | ricker1 freq=0.1')

Flow('spike5',None,'spike n1=100 nsp=1 mag=1 d1=0.004 o1=0 k1=50 | ricker1 freq=0.1')

Flow('syn','spike1 spike2 spike3 spike4 spike5',
     '''
     cat axis=2 ${SOURCES[1]} ${SOURCES[2]} ${SOURCES[3]} ${SOURCES[4]} | 
     put o2=1 | noise seed=1 type=y mean=0 var=0.00011
     ''')
Flow('synsvd','syn','svddenoise pclip=10')

Plot('syn','wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Trace labelsz=12 title="(a)" screenratio=0.8')
Plot('synsvd','wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Trace labelsz=12 title="(b)" screenratio=0.8')
Result('syncomp','syn synsvd','SideBySideAniso')
### initial stack

#################################################
## Stack using orignal data
#################################################
Flow('stack','syn','stack')
Plot('stack','stack','put o2=0 | wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="(b)" screenratio=0.8')

## SNR stack
Flow('snrstack','syn','snrstack  w=45 eps=5000')
Plot('snrstack','snrstack','wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="(d)" screenratio=0.8')

## 
Flow('stacks','stack','spray axis=2 n=5')
## similarity
Flow('weights', 'syn stacks',
     '''similarity other=${SOURCES[1]} niter=30 rect1=11 rect2=1
     ''')
Flow('tweights','weights','threshold pclip=100')
Plot('weights','tweights','wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Trace labelsz=12 title="b)" screenratio=0.8')
Flow('smstack','syn','smstack s=7 ifwt=y ee=5000 esp=0.1')
Plot('smstack','smstack','wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="(c)" screenratio=0.8')

Flow('simistack','tweights syn',
     '''
     sfmath y=${SOURCES[1]} output=input*y | stack  
     ''')
Plot('simistack-t','simistack','put o2=0| wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="(b)" screenratio=0.8')
Plot('simistack','simistack','put o2=0| wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="(e)" screenratio=0.8')
Plot('simistack-0','simistack','put o2=0| wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="(e)" screenratio=0.8')
Plot('simistack-00','simistack','put o2=0| wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="(b)" screenratio=0.8')

Flow('norweights','tweights','stack')
Flow('norsimistack','simistack norweights','sfmath y=${SOURCES[1]} output=input/y')
Plot('norsimistack','norsimistack','wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Trace labelsz=12 title="(e)" screenratio=0.8')
Result('compare','syn stack smstack snrstack simistack ', 'SideBySideAniso',vppen='txscale=2.4')

#################################################
## Stack after TSVD
#################################################

Flow('stack-svd','synsvd','stack')
Plot('stack-svd','stack-svd','put o2=0 | wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="c)" screenratio=0.8')

## SNR stack
Flow('snrstack-svd','synsvd','snrstack  w=45 eps=5000')
Plot('snrstack-svd','snrstack-svd','wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="(d)" screenratio=0.8')

## 
Flow('stacks-svd','stack-svd','spray axis=2 n=5')
## similarity
Flow('weights-svd', 'synsvd stacks-svd',
     '''similarity other=${SOURCES[1]} niter=30 rect1=11 rect2=1
     ''')
Flow('tweights-svd','weights-svd','threshold pclip=100')
Plot('weights-svd','tweights-svd','wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Trace labelsz=12 title="b)" screenratio=0.8')
Flow('smstack-svd','synsvd','smstack s=7 ifwt=y ee=5000 esp=0.1')
Plot('smstack-svd','smstack-svd','wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="d)" screenratio=0.8')

Flow('simistack-svd','tweights-svd synsvd',
     '''
     sfmath y=${SOURCES[1]} output=input*y | stack  
     ''')
Plot('simistack-svd','simistack-svd','put o2=0| wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="f)" screenratio=0.8')

Flow('norweights-svd','tweights-svd','stack')
Flow('norsimistack-svd','simistack-svd norweights-svd','sfmath y=${SOURCES[1]} output=input/y')
Plot('norsimistack-svd','norsimistack-svd','wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Trace labelsz=12 title="e)" screenratio=0.8')
Result('compare-svd','synsvd stack-svd smstack-svd snrstack-svd simistack-svd ', 'SideBySideAniso',vppen='txscale=2.4')

#################################################
## Combined SVD and Smart & SNR & Similarity
#################################################

Flow('simistack-combine','tweights synsvd',
     '''
     sfmath y=${SOURCES[1]} output=input*y | stack  
     ''')
Plot('simistack-combine-0','simistack-combine','put o2=0| wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="(c)" screenratio=0.8')


Plot('arrow',None,
        '''
        box x0=4.6 y0=6.00 label="" xt=-0.5 yt=0.5 length=0.5 
        ''')
Plot('simistack-combine','simistack-combine-0 arrow','Overlay')
Plot('simistack-1','simistack-00 arrow','Overlay')

# Ture trace
Plot('true','spike5','put o2=0| wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="f)" screenratio=0.8')
Plot('true-2','spike5','put o2=0| wiggle  transp=y yreverse=y poly=y wanttitle=n label2=Amplitude labelsz=12 title="(a)" screenratio=0.8')
Result('simi-combine','true-2 simistack-1 simistack-combine', 'SideBySideAniso')

#SNR comparison: spike5,simistack,simistack-combine
Flow('dif1','spike5 simistack','add scale=1,-1 ${SOURCES[1]} | put n2=1')
Flow('dif2','spike5 simistack-combine','add scale=1,-1 ${SOURCES[1]} |put n2=1')
Flow('snr1','spike5 dif1','put n2=1 |snr2 noise=${SOURCES[1]}')
Flow('snr2','spike5 dif2','put n2=1 |snr2 noise=${SOURCES[1]}')



End()

sfspike
sfricker1
sfcat
sfput
sfnoise
sfsvddenoise
sfwiggle
sfstack
sfsnrstack
sfspray
sfsimilarity
sfthreshold
sfsmstack
sfmath
sfbox
sfadd
sfsnr2