up [pdf]
from rsf.proj import *

# bad idea to uncomment the SConstruct.  It will download and return segy, even
# when the fetch directory is up to date.  fetch is separate directory to avoid
# the repeated reruns.
#SConscript('../fetch/SConstruct')

Flow(['gather_subset.rsf','gather_subset_hdr.rsf','onetrace.rsf','onetrace_hdr.rsf'],
     ['../fetch/npr3_gathers.rsf','../fetch/npr3_gathers_hdr.rsf'],
     '''
     sftahsort 
        input=$SOURCE 
        sort="iline:169,181  xline:104,116 offset:0,11000" 
        verbose=1  
     | sftahmakeskey pkey=iline,xline skey=cdpt verbose=1      
     | sftahnmo 
       verbose=1  
       tnmo=0,.617,.769,.913,1.027,1.196,1.767,3.010.00
       vnmo=9132.86,10764.47,10941.73,11235.75,11902.71,12580.03,14513.85,16982.86
     | sftahwrite 
        verbose=1                           
        label2="cdpt"  o2=1 n2=34  d2=1   
        label3="xline" o3=104 n3=13 d3=1   
        label4="iline" o4=169 n4=13  d4=1   
        output=$TARGET
     | sftahwrite 
        verbose=1                           
        label2="cdpt"  o2=1 n2=34  d2=1   
        label3="xline" o3=104 n3=1 d3=1   
        label4="iline" o4=169 n4=1  d4=1   
        output=${TARGETS[2]}
     ''',stdout=0,stdin=0)
Flow(['alltraces.rsf','alltraces_hdr.rsf'],
     ['../fetch/npr3_gathers.rsf','../fetch/npr3_gathers_hdr.rsf'],
     '''
     sftahsort 
        input=$SOURCE 
        sort="iline:169,181  xline:104,116 offset:0,11000" 
        verbose=1  
     | sftahnmo 
       verbose=1
       tnmo=0,.617,.769,.913,1.027,1.196,1.767,3.010.00
       vnmo=9132.86,10764.47,10941.73,11235.75,11902.71,12580.03,14513.85,16982.86
     | sftahmakeskey 
        pkey=dt
        skey=tracr
     | sftahwrite 
        verbose=1                           
        label2="tracr"  o2=1 n2=5047  d2=1   
        output=${TARGETS[0]}
     ''',stdout=0,stdin=0)

# I used these header prints to get the range of shots and traces to resort 
# the data back to shot record and look for better coherency
# header ranges are fldr:384,573  tracf:1,940
#sftahsort sort="fldr:1,99999 tracf" input=gather_subset.rsf | sftahgethw key=fldr,tracf >/dev/null 
#sftahsort sort="tracf fldr:1,99999" input=gather_subset.rsf | sftahgethw key=fldr,tracf,gx,gy >/dev/null 
Flow(['shot_subset.rsf'  ,'shot_subset_hdr.rsf',
      'group_subset.rsf' ,'group_subset_hdr.rsf'],
     ['gather_subset.rsf','gather_subset_hdr.rsf'],
     '''
     sftahsort input=${SOURCES[0]} sort="fldr:1,999999 tracf" verbose=1
     |  sftahwrite 
        verbose=1                           
        label3="fldr"  o3=384 n3=190  d3=1   
        label2="tracf" o2=1   n2=940  d2=1   
        output=${TARGETS[0]}
     |  sftahwrite 
        verbose=1                           
        label2="fldr"  o2=384 n2=190  d3=1   
        label3="tracf" o3=1   n3=940  d2=1   
        output=${TARGETS[2]}
     ''',stdout=0,stdin=0)

Plot('gather_subset','grey title="gather_subset"',view=1)
Plot('zoomgather_subset','gather_subset',
     'sfwindow max1=2. | grey title="gather_subset_zoom"',view=1)

Plot('shot_subset','grey title="shot_subset"',view=1)
Plot('zoomshot_subset','shot_subset',
     'sfwindow max1=2. | grey title="shot_subset_zoom"',view=1)

Plot('group_subset','grey title="group_subset"',view=1)
Plot('zoomgroup_subset','group_subset',
     'sfwindow max1=2. | grey title="shot_subset_zoom"',view=1)
Result('shot_subset',
        '''
        sfwindow max1=2. n2=300 min3=437 max3=437 
        | sfgrey title="shot_subset",
        ''')
Result('zoomshot_subset','shot_subset',
      '''
      sfwindow max1=2. n2=300 min3=437 max3=437 
      | sfgrey title="shot_subset_zoom"
      ''')
Result('zoomgroup_subset','group_subset',
      '''
      sfwindow max1=2. min3=558 max3=558 
      | sfgrey title="group_subset_zoom"
      ''')

Result('gather_subset',
       '''
       put n4=1 o3=1 n3=169 
       | bandpass fhi=30
       | window max1=2. 
       | byte 
       | grey3 frame1=400 frame2=0 frame3=83
       title=Gathers label2=Trace label3=CDP
       ''')

Flow('onetrace_offset','onetrace_hdr',
     'dd type=float | headermath output=offset')

Result('wiggle','onetrace.rsf onetrace_offset.rsf',
       '''
       window max1=1.5 
       | bandpass fhi=30 
       | wiggle xpos=${SOURCES[1]} poly=y transp=y yreverse=y
       ''')

# Doing it without tah
Flow('iline','../fetch/npr3_gathers_hdr.rsf',
     'window n1=1 f1=73 | mask min=169 max=181')
Flow('xline','../fetch/npr3_gathers_hdr.rsf',
     'window n1=1 f1=74 | mask min=104 max=116')
Flow('offset','../fetch/npr3_gathers_hdr.rsf',
     'window n1=1 f1=11 | mask min=0 max=11000')
Flow('mask','iline xline offset','mul ${SOURCES[1:3]}')

Flow('window','../fetch/npr3_gathers.rsf mask',
     'headerwindow mask=${SOURCES[1]}')
Flow('window_hdr','../fetch/npr3_gathers_hdr.rsf mask',
     'headerwindow mask=${SOURCES[1]}')

Flow('gather','window window_hdr','intbin3 head=${SOURCES[1]} xkey=-1')

# Add NMO as above!

Plot('gather','grey title="gather_subset"',view=1)
Plot('zoomgather','gather',
     'sfwindow max1=2. | grey title="gather_subset_zoom"',view=1)

Result('gather',
       '''
       put n4=1 o3=1 n3=169 
       | bandpass fhi=30
       | window max1=2. 
       | byte 
       | grey3 frame1=400 frame2=0 frame3=83
       title=Gathers label2=Trace label3=CDP
       ''')

End()

sfgrey
sfbyte
sfgrey3
sfsegyread
sfheaderattr
sftahsort
sftahmakeskey
sftahnmo
sftahwrite
sfwindow
sfput
sfbandpass
sfdd
sfheadermath
sfwiggle
sfmask
sfmul
sfheaderwindow
sfintbin3

teapot/final_stack.rsf
teapot/npr3_gathers.sgy
teapot/npr3_field.sgy
teapot/3dload_Teapot_Dome_3D.pdf
teapot/teapot_processing.pdf