up [pdf]
from rsf.proj import *

Fetch('trend.HH','viking')

Flow('trend','trend.HH','dd form=native | put label1=Offset unit1=km label2=Shot unit2=km')

n1=120
n2=994

Flow('rms','trend',
     '''
     mul $SOURCE | stack axis=2 norm=n | stack axis=1 norm=n |
     math output="sqrt(%d/input)" | spray axis=1 n=%d | spray axis=2 n=%d
     ''' % (n1*n2,n1,n2))

Flow('rtrend','trend rms','div ${SOURCES[1]}')

Result('amplitude','rtrend','grey bias=0.132783 clip=0.0258115 wanttitle=n')

Flow('model','rtrend','stripes mo=30 ms=100 my=120 mr=60')

Result('model','grey allpos=y wanttitle=n')

# Convert a source vs. offset input plane into the source vs. receiver space

Flow('source','rtrend','math output="x2/0.025" ')
Flow('receiver','rtrend','math output="(x1+x2)/0.0125" ')

Flow('head','receiver source',
     'cat axis=3 ${SOURCES[1]} | dd type=int | transp plane=23 | transp')

for case in ('rtrend','sobalcd','balanced'):
    Flow('sr-'+case,[case,'head'],
         '''
         spray axis=1 n=1 | intbin head=${SOURCES[1]} xkey=0 ykey=1 | window j2=2 |
         put label1=Receiver d1=0.0125 o1=-3.2375 d2=0.025 o2=0 | 
         window n1=300 f1=405 n2=200 f2=385
         ''')

Result('sramplitude','sr-rtrend','grey bias=0.132783 clip=0.0258115 wanttitle=n')

Flow('off src mid rcv so-stp rv-stp','rtrend',
     '''
     srseidel niter=10 
     src=${TARGETS[1]} mid=${TARGETS[2]} rcv=${TARGETS[3]} so=${TARGETS[4]} rv=${TARGETS[5]}
     ''')

comps = dict(src='source',off='offset',mid='midpoint',rcv='receiver')

for comp in comps.keys():
    Result(comps[comp],comp,'graph wanttitle=n unit2= min2=0.11 max2=0.16')

Result('sostripes','so-stp','grey mean=y wanttitle=n')
Result('rvstripes','rv-stp','grey mean=y wanttitle=n')

Flow('off2','off','spray axis=2 n=994 d=0.025 o=0')
Flow('src2','src','spray axis=1 n=120 d=0.025 o=-3.2375')
Flow('offsrc','off2 src2','mul ${SOURCES[1]}')

Flow('sobalcd','rtrend offsrc','div ${SOURCES[1]}')

Result('sobalcd','grey mean=y wanttitle=n bias=7.21426 clip=0.750707')

Result('srsobalcd','sr-sobalcd','grey mean=y wanttitle=n bias=7.21426 clip=0.750707')

Flow('rmap','off2','math output=x1+x2 | put n2=1 n1=%d' % (994*120))
Flow('rcv2','rcv rmap','iwarp warp=${SOURCES[1]} inv=n | put n1=120 n2=994')

Flow('offsrcrcv','offsrc rcv2','mul ${SOURCES[1]}')

Flow('balanced','rtrend offsrcrcv','div ${SOURCES[1]}')

Result('balanced','grey mean=y wanttitle=n bias=53.191 clip=5.57576')

Result('srbalanced','sr-balanced','grey mean=y wanttitle=n bias=53.191 clip=5.57576')

End()

sfdd
sfput
sfmul
sfstack
sfmath
sfspray
sfdiv
sfgrey
sfstripes
sfcat
sftransp
sfintbin
sfwindow
sfsrseidel
sfgraph
sfiwarp

data/viking/trend.HH