up [pdf]
from rsf.proj import *

# Smoothly variable velocity
Flow('vel7',None,
     '''
     spike n1=512 d1=5 k1=98 n2=512 d2=5 k2=98 |
     math output="550+0.00015*(x1-800)*(x1-800)+0.0001*(x2-500)*(x2-500)"
     ''')
Result('vel7',
       '''
       grey transp=n screenratio=0.9 
       label1="X" label2="Z" scalebar=y color=j bias=550 allpos=y
       unit1=m unit2=m  title=Velocity barlabel=Velocity barunit=m/s
       ''')

Flow('fft','vel7','fft1 | fft3 axis=2 pad=1')

nt=2500
dt=0.001

Flow('source7',None,
     '''
     spike n1=%d d1=%g k1=100 | 
     ricker1 frequency=20 
     '''%(nt,dt))
Result('source7','graph  title="Source Wavelet" ')

Flow('right left','vel7 fft',
     'isolr2 seed=2010 dt=%g fft=${SOURCES[1]} left=${TARGETS[1]}' % dt)

# CPU = 1.36 s (rank 2)

Flow('refl',None,'spike n1=512 d1=5 n2=512 d2=5 k1=256 k2=256')

Flow('wave','source7 refl left right',
     '''
     fftwave2 ref=${SOURCES[1]} left=${SOURCES[2]} right=${SOURCES[3]} verb=n snap=20 snaps=$TARGET
     ''',stdout=0)

# CPU = 45.89 s 

Plot('wave','grey gainpanel=all screenratio=1 wanttitle=n',view=1)

Result('wave',
       '''
       window n3=1 f3=80 |
       grey label2=Z label1=X title="Lowrank Approximation" screenratio=1
       yreverse=y transp=n unit1=m unit2=m 
       ''')

Result('slice','wave',
       '''
       window n3=1 f3=80 n1=1 f1=256 |
       graph label1=X unit1=m title="Lowrank Approximation"
       label2=Amplitude unit2=
       ''')

Flow('wavefd','source7 vel7',
     '''
     fd2bs vel=${SOURCES[1]} dt=%g nt=%d isx=256 isz=256 nb=0 c=0.01 
     '''%(dt,nt))

# CPU = 17.41 s 

# ratio = 2.6

Result('wavefd',
       '''
       window n3=1 f3=1600 |
       grey label2=Z label1=X title="Finite Differences" screenratio=1
       yreverse=y transp=n unit1=m unit2=m
       ''')

Result('slicefd','wavefd',
       '''
       window n3=1 f3=1600 n1=1 f1=256 |
       graph label1=X unit1=m title="Finite Differences"
       label2=Amplitude unit2=
       ''')

End()

sfspike
sfmath
sfgrey
sffft1
sffft3
sfricker1
sfgraph
sfisolr2
sffftwave2
sfwindow
sffd2bs