up [pdf]
from rsf.proj import *
from rsf.prog import RSFROOT
def Grey(data,other):
        Result(data,'grey screenratio=1.3 title= clip=0.29 %s '%other)

Fetch('cmp807_raw.HH','rad')

Flow('cmp0','cmp807_raw.HH','dd form=native | pow pow1=2 | mutter v0=1.3 tp=0.2 half=n | scale axis=2 | window max2=2.5')
Grey('cmp0','')

Flow('vscan','cmp0','vscan semblance=y v0=1.2 dv=0.01 nv=180 half=n')


Flow('pick','vscan','mutter inner=y half=n x0=1.2 v0=0.35 | scale axis=2 | pick rect1=10')

Flow('nmo','cmp0 pick','nmo velocity=${SOURCES[1]} half=n')
Grey('nmo','')

Flow('mo','nmo','window')
Plot('mo','grey title="Input CMP" clip=0.3')

Flow('cmp','mo','cp')

# randomization
Flow('off','mo','window n1=1 | noise rep=y seed=201516')
Flow('rand','mo off','headersort head=${SOURCES[1]}')

Flow('mo3','mo','spray axis=3 n=50 o=0 d=1 label=Sample')
Flow('off3','mo3','window n1=1 | noise rep=y seed=2015')
Flow('rand3','mo3 off3','headersort head=${SOURCES[1]}')

Flow('tx3','rand3','smooth rect2=4 rect3=4')


# Add random noise
Flow('ncmp','cmp','noise seed=2015 var=0')
Flow('nrand','ncmp off','headersort head=${SOURCES[1]}')
Grey('nrand','')


#Flow('pef lag','nrand','lopef a=3,7 w=10,50 lag=${TARGETS[1]}') 
#Flow('tx','nrand pef','decon filt=${SOURCES[1]} predictive=y')

Flow('tx','nrand','transp | mf nfw=5 | transp')

Flow('inv','off','math output=x1 | spray axis=1 n=1 | headersort head=$SOURCE')
Flow('back','tx inv','headersort head=${SOURCES[1]}')

Flow('dif','ncmp back','add scale=1,-1 ${SOURCES[1]}')

Plot('back','grey title="CMP (3-D)" clip=0.62')

Plot('dif','grey title="Difference (3-D)" clip=0.62')




Fetch('mo_supp.HH','haskell')

Flow('hm','mo_supp.HH','dd form=native ')

for case in ('mo','back','hm'):
    Plot(case+'-trace',case,
         '''
         bandpass fhi=50 | 
         window min1=2 max1=3 n2=3 | 
         wiggle poly=y clip=0.4 labelsz=12 labelfat=1 titlesz=12 titlefat=1 title="%s" label2= unit2=
         ''' % {'mo':'Input','back':'PEF (3-D)','hm': 'Velocity Stack'}[case])

Result('mo-near-offset-tx','mo-trace back-trace hm-trace','SideBySideAniso')



########################################################################
# INITIALIZATION
########################################################################
matlab         = WhereIs('matlab')
matROOT = '../matfun/'
matfun = 'FXEMDM'
matlabpath = os.environ.get('MATLABPATH',os.path.join(RSFROOT,'lib'))

if not matlab:
    sys.stderr.write('\nCannot find Matlab.\n')
    sys.exit(1)

n1=1000
n2=46
dt=0.004
lf=5
hf=120
N=3
verb=0
############################################################
## with parameter
############################################################
Flow('nrand-emd-t',[os.path.join(matROOT,matfun+'.m'),'nrand'],
     '''MATLABPATH=%(matlabpath)s %(matlab)s 
     -nosplash -nojvm -r "addpath %(matROOT)s;%(matfun)s('${SOURCES[1]}','${TARGETS[0]}',%(n1)d,%(n2)d,%(dt)g,%(lf)g,%(hf)g,%(N)d,%(verb)d);quit"
     '''%vars(),stdin=0,stdout=-1)
Flow('nrand-emd','nrand-emd-t','put  d2=0.05 d1=0.004 o2=0.262 o1=0 label2=Offset unit2=km label1=Time unit1=s')
Flow('nrand-emd-back','nrand-emd inv','headersort head=${SOURCES[1]}')

Flow('emd-dif','ncmp nrand-emd-back','add scale=1,-1 ${SOURCES[1]}')

Flow('demul-mf','back pick','inmo velocity=${SOURCES[1]} half=n')
Flow('demul-emd','nrand-emd-back pick','inmo velocity=${SOURCES[1]} half=n')
Flow('vscan-emd','demul-emd1','vscan semblance=y v0=1.2 dv=0.01 nv=180 half=n')
Flow('vscan-mf','demul-mf','vscan semblance=y v0=1.2 dv=0.01 nv=180 half=n')

Grey('vscan','color=j allpos=y unit2="km/s"')
Grey('vscan-emd','color=j allpos=y clip=0.6 unit2="km/s"')
Grey('vscan-mf','color=j allpos=y clip=0.6 unit2="km/s"')

Grey('ncmp','')
Grey('back','')
Grey('dif','')
Grey('nrand-emd-back','')
Grey('emd-dif','')
Grey('demul-emd','')
Grey('demul-mf','')

ns0=5
## Structural-oriented smoothing filter
Flow('dip','demul-emd','bandpass fhi=30 | dip rect1=%d rect2=%d'%(5,5))
Grey('dip','color=j clip=4.7')

Flow('spray',['demul-emd','dip'],
        '''
     pwspray dip=${SOURCES[1]} ns=%d 
     ''' % (ns0))
Flow('demul-emd1','spray','transp plane=12 | mf nfw=%d | transp plane=12 | window n2=1 f2=%d '%(ns0,ns0))
Grey('demul-emd1','')

Flow('emd-dif1','demul-emd demul-emd1','add scale=1,-1 ${SOURCES[1]}')
Grey('emd-dif1','')

Flow('dif-mf','cmp0 demul-mf','add scale=1,-1 ${SOURCES[1]}')
Grey('dif-mf','')

Flow('dif-emd','cmp0 demul-emd1','add scale=1,-1 ${SOURCES[1]}')
Grey('dif-emd','')

End()

sfdd
sfpow
sfmutter
sfscale
sfwindow
sfgrey
sfvscan
sfpick
sfnmo
sfcp
sfnoise
sfheadersort
sfspray
sfsmooth
sftransp
sfmf
sfmath
sfadd
sfbandpass
sfwiggle
sfput
sfinmo
sfdip
sfpwspray

data/rad/cmp807_raw.HH
data/haskell/mo_supp.HH