up [pdf]
from rsf.proj import *

nt=500
dt=0.002
t0 = nt*dt/7

Flow('trend',None,
     '''
     math n1=%d o1=%g d1=0.002 label1=Time unit1=s label=Velocity unit=km/s
     output="0.2+x1-%g" | cut max1=%g | add add=1.5 
     ''' % (nt,dt,t0,t0))
Flow('trend2','trend','math output="0.6+x1-%g" | cut max1=%g | add add=1.5' % (t0,t0))

Flow('switch','trend',
     'noise rep=y type=n mean=0.5 seed=2014 | mask min=0.8')
Flow('spikes','switch',
     '''
     dd type=float | transp | headerwindow mask=$SOURCE | window |
     dd type=complex | math output="conj(input)" | dd type=float
     ''')
Flow('switch2','spikes switch',
     '''
     transp | headerwindow mask=${SOURCES[1]} inv=y | window | causint
     ''')

Flow('int','trend trend2 switch2',
     'math t2=${SOURCES[1]} m=${SOURCES[2]} output="m*input+(1-m)*t2" ')
Plot('int','graph title="Interval Velocity" label2=Velocity unit2=km/s transp=1 yreverse=1')

Flow('rms','int','mul $SOURCE | causint | math output="sqrt(0.002*input/(x1+0.002))" | clip2 lower=1.5')
Plot('rms','graph title="RMS Velocity" label2=Velocity unit2=km/s transp=1 yreverse=1')

offset = 3.0
n2 = 15

Flow('tau','rms',
     '''
     mul $SOURCE | spray axis=2 n=%d d=%g o=%g | 
     math output="sqrt(x1*x1 + x2*x2/input)" 
     ''' % (n2,offset/n2,offset/n2))
Plot('tau','graph title="t(\F10 t\F3 )" label2=Time unit2=s label1=Tau yreverse=1')

Result('superres','int rms tau','SideBySideAniso',vppen='txscale=2')

End()

sfmath
sfcut
sfadd
sfnoise
sfmask
sfdd
sftransp
sfheaderwindow
sfwindow
sfcausint
sfgraph
sfmul
sfclip2
sfspray