up [pdf]
from rsf.proj import*
from rsf.prog import RSFROOT
from math import *

def Grey(data,other):
      Result(data,
      '''
      put d1=0.002 d2=1 o1=0 o2=0 | 
      grey clip=0.2 transp=y yreverse=y  
      label2=Trace  unit2="" label1=Time unit1="s" title=""
      wherexlabel=t scalebar=n wheretitle=b screenratio=1.2  %s
      '''
      %other)

def Greyfk(data,data0,other):
        Result(data,data0,
                '''put d1=0.002 d2=1 d3=1| fft1 | fft3 axis=2 pad=1| fft3 axis=3 pad=1| window max1=100| cabs |byte clip=300 allpos=y | grey3 labelfat=4 font=2 titlefat=4 flat=n label2="Inline wavenumber" unit2= label3="Xline wavenumber" unit1=Hz label1=Frequency unit2= frame1=50 frame2=10 frame3=10 point1=0.8 point2=0.8 title= screenratio=1.2 unit2= unit3= %s color=j'''%other)

def Grey3(data,other):
      Result(data,
       '''
       put d1=0.002 o3=0 d2=100 d3=50  | byte  clip=0.2 |
       grey3 wanttitle=y flat=n labelfat=4 font=2 titlefat=4
       label1="Time" unit1=s label2=Inline label3=Xline unit3=
       frame1=120 frame2=15 frame3=10 point1=0.85 point2=0.75 screenratio=1.2
       clip= title= wheretitle=t 
       scalebar=n label1=Time unit1=s title= unit3=m unit2=m %s
       '''%other)

def Grey3n(data,other):
      Result(data,
       '''
       put d1=0.002 o3=0 | byte  clip=0.2 |
       grey3 wanttitle=y flat=n labelfat=4 font=2 titlefat=4
       label1="Time" unit1=s label2=Inline label3=Xline unit3=
       frame1=120 frame2=15 frame3=10 point1=0.85 point2=0.75 screenratio=1.2
       clip= title= wheretitle=t 
       scalebar=n %s
       '''%other)

def Grey3nn(data,other):
      Result(data,
       '''
       put d1=0.002 o3=0 | byte  clip=0.2 |
       grey3 wanttitle=y flat=n labelfat=4 font=2 titlefat=4
       label1="Time" unit1=s label2=Inline label3=Xline unit3=
       frame1=120 frame2=15 frame3=10 point1=0.85 point2=0.75 screenratio=1.2
       clip= title= wheretitle=t 
       scalebar=n %s
       '''%other)

def Greys(data,other):
        Result(data,
                '''put d1=0.002 o3=0 d2=100 d3=50  | byte clip=0.6 bar=bar.rsf|grey3 labelfat=4 font=2 titlefat=4 label1=Time unit1=s label2=Inline unit2=m label3=Xline unit2=m flat=n frame1=120 frame2=15 frame3=10 point1=0.85 point2=0.75 screenratio=1.3 title= unit3=m unit2=m %s'''%(other))

def Greys2d(data,other):
        Result(data,
                '''grey clip=0.6 label2=Inline unit2=km label3=Xline unit2=km flat=n screenratio=1.2 title=                             wanttitle=y flat=n labelfat=4 font=2 titlefat=4                         
                                label2=Trace unit2="" label1="Time"  unit1=s
                                title="" wherexlabel=b wheretitle=t poly=y 
                                wheretitle=t wherexlabel=b labelsz=10 %s'''%(other))


def Graph(data,other):
        Result(data,'graph label1="Iter #no" label2="SNR" unit2=dB unit1="" title="" wherexlabel=b wheretitle=t %s' %other)

def Greyz(data,other):
        Result(data,
       '''
       grey label2=Trace label1="Time" unit1= clip=0.2 title= screenratio=0.6
       color=g %s'''%other)

"""
def Wig(data,other): 
        Result(data,'''
                                put d1=0.002 |
                                wiggle transp=y yreverse=y screenratio=1.2
                                wanttitle=y flat=n labelfat=4 font=2 titlefat=4                         
                                label2=Trace unit2="" label1="Time"  unit1=s
                                title="" wherexlabel=b wheretitle=t poly=y 
                                wheretitle=t wherexlabel=b clip=0.2 labelsz=10 %s'''%other)
"""

def Wig(data,other):
        Result(data,'''
                                put d1=0.002 |
                                grey transp=y yreverse=y screenratio=1.2
                                wanttitle=y flat=n labelfat=4 font=2 titlefat=4                         
                                label2=Trace unit2="" label1="Time"  unit1=s color=g color=b
                                title="" wherexlabel=b wheretitle=t poly=y 
                                wheretitle=t wherexlabel=b clip=0.2 labelsz=10 %s'''%other)

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

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

############################################################
## generate and process synthetic data
############################################################
Flow('syn-c syn-n syn-fk syn-lr syn-dlr syn-olr',[os.path.join(matROOT,matfun+'.m')],
    '''MATLABPATH=%(matlabpath)s %(matlab)s 
    -nosplash -nojvm -r "addpath %(matROOT)s;%(matfun)s('${TARGETS[0]}','${TARGETS[1]}','${TARGETS[2]}','${TARGETS[3]}','${TARGETS[4]}','${TARGETS[5]}');quit"
    '''%vars(),stdin=0,stdout=-1)

Flow('syn3d-6-c','syn-c','put n1=300 n2=20 n3=20')
Flow('syn3d-6-n','syn-n','put n1=300 n2=20 n3=20')
Flow('syn3d-6-fk','syn-fk','put n1=300 n2=20 n3=20')
Flow('syn3d-6-lr','syn-lr','put n1=300 n2=20 n3=20')
Flow('syn3d-6-dlr','syn-dlr','put n1=300 n2=20 n3=20')
Flow('syn3d-6-olr','syn-olr','put n1=300 n2=20 n3=20')

Flow('syn3d-6-n-fk','syn3d-6-n syn3d-6-fk',' add scale=1,-1 ${SOURCES[1]}')
Flow('syn3d-6-n-lr','syn3d-6-n syn3d-6-lr',' add scale=1,-1 ${SOURCES[1]}')
Flow('syn3d-6-n-dlr','syn3d-6-n syn3d-6-dlr',' add scale=1,-1 ${SOURCES[1]}')
Flow('syn3d-6-n-olr','syn3d-6-n syn3d-6-olr',' add scale=1,-1 ${SOURCES[1]}')


Flow('syn3d-6-simi1','syn3d-6-n-fk syn3d-6-fk','similarity other=${SOURCES[1]} niter=20 rect1=3 rect2=3 rect3=3')
Flow('syn3d-6-simi2','syn3d-6-n-lr syn3d-6-lr','similarity other=${SOURCES[1]} niter=20 rect1=3 rect2=3 rect3=3')
Flow('syn3d-6-simi3','syn3d-6-n-dlr syn3d-6-dlr','similarity other=${SOURCES[1]} niter=20 rect1=3 rect2=3 rect3=3 ')
Flow('syn3d-6-simi4','syn3d-6-n-olr syn3d-6-olr','similarity other=${SOURCES[1]} niter=20 rect1=3 rect2=3 rect3=3 ')
Greys('syn3d-6-simi1','color=j scalebar=y clip=0.8 minval=0 maxval=0.6 title="FK" barlabel="Similarity"')
Greys('syn3d-6-simi2','color=j scalebar=y clip=0.8 minval=0 maxval=0.6 title="RR" barlabel="Similarity"')
Greys('syn3d-6-simi3','color=j scalebar=y clip=0.8 minval=0 maxval=0.6 title="DRR" barlabel="Similarity"')
Greys('syn3d-6-simi4','color=j scalebar=y clip=0.8 minval=0 maxval=0.6 title="ODRR" barlabel="Similarity"')



Grey3('syn3d-6-c','color=g color=b title=Clean')
Grey3('syn3d-6-n','color=g color=b title=Noisy')
Grey3('syn3d-6-lr','color=g color=b title=RR')
Grey3('syn3d-6-dlr','color=g color=b title=DRR')
Grey3('syn3d-6-olr','color=g color=b title=ODRR')
Grey3('syn3d-6-fk','color=g color=b title=FK')

Greyfk('syn3d-6-c-fkk','syn3d-6-c','title=Clean')
Greyfk('syn3d-6-n-fkk','syn3d-6-n','title=Noisy')
Greyfk('syn3d-6-lr-fkk','syn3d-6-lr','title=RR')
Greyfk('syn3d-6-dlr-fkk','syn3d-6-dlr','title=DRR')
Greyfk('syn3d-6-olr-fkk','syn3d-6-olr','title=ODRR')
Greyfk('syn3d-6-fk-fkk','syn3d-6-fk','title=FK')

Grey3('syn3d-6-n-lr','color=g color=b title=RR')
Grey3('syn3d-6-n-dlr','color=g color=b title=DRR')
Grey3('syn3d-6-n-olr','color=g color=b title=ODRR')
Grey3('syn3d-6-n-fk','color=g color=b title=FK')

Flow('syn3d-6-c-s','syn3d-6-c','window n3=1 f3=5')
Flow('syn3d-6-n-s','syn3d-6-n','window n3=1 f3=5')
Flow('syn3d-6-lr-s','syn3d-6-lr','window n3=1 f3=5')
Flow('syn3d-6-dlr-s','syn3d-6-dlr','window n3=1 f3=5')
Flow('syn3d-6-olr-s','syn3d-6-olr','window n3=1 f3=5')
Flow('syn3d-6-fk-s','syn3d-6-fk','window n3=1 f3=5')

Flow('syn3d-6-n-lr-s','syn3d-6-n-lr','window n3=1 f3=5')
Flow('syn3d-6-n-dlr-s','syn3d-6-n-dlr','window n3=1 f3=5')
Flow('syn3d-6-n-olr-s','syn3d-6-n-olr','window n3=1 f3=5')
Flow('syn3d-6-n-fk-s','syn3d-6-n-fk','window n3=1 f3=5')

Flow('syn3d-6-simi1-s','syn3d-6-simi1','window n3=1 f3=5')
Flow('syn3d-6-simi2-s','syn3d-6-simi2','window n3=1 f3=5')
Flow('syn3d-6-simi3-s','syn3d-6-simi3','window n3=1 f3=5')
Flow('syn3d-6-simi4-s','syn3d-6-simi4','window n3=1 f3=5')


Greys2d('syn3d-6-simi1-s','color=j scalebar=y minval=0 maxval=0.6 title="FK" barlabel="Similarity"')
Greys2d('syn3d-6-simi2-s','color=j scalebar=y minval=0 maxval=0.6 title="RR" barlabel="Similarity"')
Greys2d('syn3d-6-simi3-s','color=j scalebar=y minval=0 maxval=0.6 title="DRR" barlabel="Similarity"')
Greys2d('syn3d-6-simi4-s','color=j scalebar=y minval=0 maxval=0.6 title="ODRR" barlabel="Similarity"')

Wig('syn3d-6-c-s','title=Clean')
Wig('syn3d-6-n-s','title=Noisy')
Wig('syn3d-6-lr-s','title=RR')
Wig('syn3d-6-dlr-s','title=DRR')
Wig('syn3d-6-olr-s','title=ODRR')
Wig('syn3d-6-fk-s','title=FK')
Wig('syn3d-6-n-lr-s','title=RR')
Wig('syn3d-6-n-dlr-s','title=DRR')
Wig('syn3d-6-n-olr-s','title=ODRR')
Wig('syn3d-6-n-fk-s','title=FK')

End()

sfput
sfadd
sfsimilarity
sfbyte
sfgrey3
sffft1
sffft3
sfwindow
sfcabs
sfgrey