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 min1=60 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=20 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=m unit2=m
       frame1=120 frame2=15 frame3=10 point1=0.85 point2=0.75 screenratio=1.2
       clip= title= wheretitle=t 
       scalebar=n %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 label2=Inline unit2=m label3=Xline unit2=m flat=n frame1=120 frame2=15 frame3=10 point1=0.85 point2=0.75 screenratio=1.2 label1=Time unit1=s title= unit3=m unit2=m %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)



########################################################################
# INITIALIZATION
########################################################################
matlab         = WhereIs('matlab')
matROOT = '../matfun'
matfun = 'Syn_hf'
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('syn3dhf-c','syn-c','put n1=300 n2=20 n3=20')
Flow('syn3dhf-n','syn-n','put n1=300 n2=20 n3=20')
Flow('syn3dhf-fk','syn-fk','put n1=300 n2=20 n3=20')
Flow('syn3dhf-lr','syn-lr','put n1=300 n2=20 n3=20')
Flow('syn3dhf-dlr','syn-dlr','put n1=300 n2=20 n3=20')
Flow('syn3dhf-olr','syn-olr','put n1=300 n2=20 n3=20')

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

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

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


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

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


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

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

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



End()

sfput
sfsimilarity
sfbyte
sfgrey3
sfadd
sffft1
sffft3
sfwindow
sfcabs
sfwiggle