up [pdf]
from rsf.proj import *
def Grey(data,other):
        Result(data,'grey label2=Midpoint  unit2="km" clip=1.84785e+06 label1=Time unit1="s" title="" wherexlabel=t wanttitle=y wheretitle=b  screenratio=1.4 max1=2.5 %s '%other)

# Download data
Fetch('beinew.HH','midpts')

# Set dimensions
Flow('gulf','beinew.HH',
     '''
     dd form=native |
     put
     label1=Time unit1=s
     label2=Half-Offset unit2=km
     label3=Midpoint unit3=km | window f2=4
     ''')

# Display
Result('gulf',
       '''
       window min1=0.5 max1=2.5 max2=1.5 |byte |
       transp plane=23 |
       grey3 flat=n frame1=500 frame2=160 frame3=3  
       title="Gulf of Mexico Data" point1=0.8 point2=0.8
       ''')

# Velocity scan
Flow('vscan-gulf','gulf',
     'vscan v0=1.5 dv=0.02 nv=51 semblance=y',
     split=[3,250], reduce='cat')

Result('vscan-gulf',
       '''
       byte allpos=y gainpanel=all pclip=100 |
       transp plane=23 |
       grey3 flat=n frame1=750 frame2=100 frame3=25 
       label1=Time unit1=s color=j
       label3=Velocity unit3=km/s 
       label2=Midpoint unit2=km
       title="Velocity Scan (traditional)" point1=0.8 point2=0.8
       ''')

# Velocity picking
Flow('vnmo-gulf','vscan-gulf','pick rect1=5 rect2=5')

Result('vnmo-gulf',
     '''
     grey color=j allpos=y bias=1.5 clip=0.7
     scalebar=y barreverse=y barunit=km/s
     label2=Midpoint unit2=km label1=Time unit1=s
     title="NMO Velocity" 
     ''' )


# Stacking
##########

Flow('nmo-gulf','gulf vnmo-gulf','nmo velocity=${SOURCES[1]}')
Flow('stack-gulf','nmo-gulf','stack')

# DMO
########################
Flow('nmo0-gulf','gulf vnmo-gulf','nmo velocity=${SOURCES[1]}')
Flow('dstack-gulf','nmo0-gulf',
     '''
     window f1=250 | 
     logstretch | fft1 | 
     transp plane=13 memsize=1000 |
     finstack | 
     transp memsize=1000 |
     fft1 inv=y | logstretch inv=y | 
     pad beg1=250 | put unit1=s
     ''')

Plot('stack-gulf','grey title="Traditional Semblance"')
Plot('dstack-gulf','grey title="DMO Stack"')
Result('stackcomp','stack-gulf dstack-gulf','SideBySideAniso')


## Dix inversion
Flow('semblance-gulf','vscan-gulf vnmo-gulf','slice pick=${SOURCES[1]}')
Flow('vesti-gulf','vnmo-gulf semblance-gulf','dix weight=${SOURCES[1]} rect1=100 rect2=10')
Flow('vestiz-gulf','vesti-gulf','time2depth velocity=${SOURCES[0]} intime=y')
Result('vesti-gulf',
     '''
     grey color=j allpos=y bias=1.5 clip=0.7
     scalebar=y barreverse=y barunit=km/s
     label2=Midpoint unit2=km label1=Time unit1=s
     title="Interval Velocity" 
     ''' )
###############################################################
#### Similarity-weighted semblance
###############################################################
Flow('stack-ref','stack-gulf','spray axis=2 n=48 d=0.0335 o3=0.132')

Flow('simivscan-gulf','gulf stack-ref',
     'simivscan thr=0.2 ref=${SOURCES[1]} v0=1.4 dv=0.01 nv=111 semblance=y type="similarity-weighted"',
     split=[3,250], reduce='cat')
Result('simivscan-gulf',
       '''
       byte allpos=y gainpanel=all pclip=100 |
       transp plane=23 |
       grey3 flat=n frame1=750 frame2=50 frame3=25 movie=2
       label1=Time unit1=s color=j
       label3=Velocity unit3=km/s 
       label2=Midpoint unit2=km
       title="Velocity Scan (new)" point1=0.8 point2=0.8
       ''')

# Velocity picking
Flow('simivnmo-gulf','simivscan-gulf','pick rect1=5 rect2=5')

Result('simivnmo-gulf',
     '''
     grey color=j allpos=y bias=1.5 clip=0.7
     scalebar=y barreverse=y barunit=km/s
     label2=Midpoint unit2=km label1=Time unit1=s
     title="NMO Velocity" 
     ''' )
# Stacking
##########

Flow('siminmo-gulf','gulf simivnmo-gulf','nmo velocity=${SOURCES[1]}')
Flow('simistack-gulf','siminmo-gulf','stack')

# DMO
########################
Flow('siminmo0-gulf','gulf simivnmo-gulf','nmo velocity=${SOURCES[1]}')
Flow('simidstack-gulf','siminmo0-gulf',
     '''
     window f1=250 | 
     logstretch | fft1 | 
     transp plane=13 memsize=1000 |
     finstack | 
     transp memsize=1000 |
     fft1 inv=y | logstretch inv=y | 
     pad beg1=250 | put unit1=s
     ''')

Plot('simistack-gulf','grey title="Similarity Semblance"')
Plot('simidstack-gulf','grey title="DMO Stack"')
Result('simistackcomp','simistack-gulf simidstack-gulf','SideBySideAniso')


## Dix inversion
Flow('simisemblance-gulf','simivscan-gulf simivnmo-gulf','slice pick=${SOURCES[1]}')
Flow('simivesti-gulf','simivnmo-gulf simisemblance-gulf','dix weight=${SOURCES[1]} rect1=100 rect2=10')
Flow('simivestiz-gulf','simivesti-gulf','time2depth velocity=${SOURCES[0]} intime=y')
Result('simivesti-gulf',
     '''
     grey color=j allpos=y bias=1.5 clip=0.7
     scalebar=y barreverse=y barunit=km/s
     label2=Midpoint unit2=km label1=Time unit1=s
     title="Interval Velocity" 
     ''' )

Grey('stack-gulf','title="Traditional approach" min1=0.5')
Grey('simistack-gulf','title="Proposed approach" min1=0.5')

Flow('stack-A','stack-gulf','window min1=0.6 max1=0.8 min2=13.5 15.8')
Flow('simistack-A','simistack-gulf','window min1=0.6 max1=0.8 min2=13.5 15.8')
Grey('stack-A','screenratio=0.75 max1=0.8 ')
Grey('simistack-A','screenratio=0.75 max1=0.8')

Flow('stack-A','stack-gulf','window min1=0.6 max1=0.8 min2=13.5 max2=15.8')
Flow('simistack-A','simistack-gulf','window min1=0.6 max1=0.8 min2=13.5 max2=15.8')
Grey('stack-A','screenratio=0.75 max1=0.8 title="Traditional approach"')
Grey('simistack-A','screenratio=0.75 max1=0.8 title="Proposed approach"')

Flow('stack-B','stack-gulf','window min1=1.25 max1=1.5 min2=10 max2=12.5')
Flow('simistack-B','simistack-gulf','window min1=1.25 max1=1.5 min2=10 max2=12.5')
Grey('stack-B','screenratio=0.75 max1=1.5 title="Traditional Semblance" clip=3.84785e+06 color=g')
Grey('simistack-B','screenratio=0.75 max1=1.5 title="Similarity Semblance" clip=3.84785e+06 color=g')

## Creating framebox
x=13.5
y=0.6
w=2.3
w1=0.22

Flow('frame.asc',None,'echo %s n1=10 data_format=ascii_float in=$TARGET'% \
        string.join(map(str,(x,y,x+w,y,x+w,y+w1,x,y+w1,x,y))))
Plot('frame','frame.asc',
        '''
        dd type=complex form=native |
        graph min1=7.705 max1=16.0465 min2=0 max2=2.5 pad=n plotfat=15 plotcol=2 screenratio=1.4
        wantaxis=n wanttitle=n yreverse=y 
        ''')

Result('stack','Fig/stack-gulf.vpl frame','Overlay')
Result('simistack','Fig/simistack-gulf.vpl frame','Overlay')

End()

sfdd
sfput
sfwindow
sfbyte
sftransp
sfgrey3
sfvscan
sfpick
sfgrey
sfnmo
sfstack
sflogstretch
sffft1
sffinstack
sfpad
sfslice
sfdix
sftime2depth
sfspray
sfsimivscan
sfgraph

data/midpts/beinew.HH