Skip to content

Commit b00dc18

Browse files
committed
Merge branch 'master' of https://github.com/ahay/src
2 parents c2abe51 + 44f8c16 commit b00dc18

File tree

7 files changed

+4855
-238
lines changed

7 files changed

+4855
-238
lines changed

book/tccs/deblend/deblend.ipynb

Lines changed: 4341 additions & 0 deletions
Large diffs are not rendered by default.

book/tccs/deblend/deblend2.py

Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
## This is a script for the test of deblending using sparsity promotion with shaping regularization (Using the SNR definition from Araz).
2+
3+
## Copyright (C) 2013
4+
## Yangkang Chen, The Univeristy of Texas at Austin
5+
6+
## The are several assumptions for implementing the following scripts:
7+
## 1. data1 and data2 have the same dimensions
8+
## 2. data1 and data2 are sparse in fourier or seislet domains
9+
## 3. the unblended data is known (in other words it's used for testing).
10+
## Otherwise, the unblended1(2) is substituted by blended1(2), in which case
11+
## The error diagram has no physical meanings.
12+
13+
14+
15+
from rsf.proj import*
16+
def Grey(data,other):
17+
Result(data,'grey label2=Trace unit2="" label1=Time unit1="s" title="" wherexlabel=b wheretitle=t color=b %s'%other)
18+
19+
def Greyplot(data,other):
20+
Plot(data,'grey label2=Trace unit2="" label1=Time unit1="s" title="" wherexlabel=b wheretitle=t color=b %s'%other)
21+
22+
def Graph(data,other):
23+
Result(data,'graph label1="" label2="" unit1="" unit2="" title="" wherexlabel=b wheretitle=t %s' %other)
24+
25+
def Graphplot(data,other):
26+
Plot(data,'graph label1="" label2="" unit1="" unit2="" title="" wherexlabel=b wheretitle=t %s' %other)
27+
28+
def shapeslet(sig1,sig2,dip1,dip2,mute1,mute2,padno,n2,mode,thr,i): #mute1(2) is a string, when there is no mute, mute1(2) is "cp"
29+
Flow(sig1+"p%g"%(i+1),[sig1,dip1],
30+
'''
31+
%s |pad n2=%g |
32+
seislet dip=${SOURCES[1]} eps=0.1
33+
adj=y inv=y unit=y type=b |
34+
threshold1 type=%s ifperc=1 thr=%f |
35+
seislet dip=${SOURCES[1]} eps=0.1
36+
inv=y unit=y type=b |
37+
window n2=%g |%s
38+
'''%(mute1,padno,mode,thr,n2,mute1))
39+
Flow(sig2+"p%g"%(i+1),[sig2,dip2],
40+
'''
41+
%s|pad n2=%g |
42+
seislet dip=${SOURCES[1]} eps=0.1
43+
adj=y inv=y unit=y type=b |
44+
threshold1 type=%s ifperc=1 thr=%f |
45+
seislet dip=${SOURCES[1]} eps=0.1
46+
inv=y unit=y type=b |
47+
window n2=%g | %s
48+
'''%(mute2,padno,mode,thr,n2,mute2))
49+
return (sig1+"p%g"%(i+1),sig2+"p%g"%(i+1))
50+
51+
def shapefft(sig1,sig2,mute1,mute2,mode,thr,i):#mute1(2) is a string, when there is no mute, mute1(2) is "cp"
52+
Flow(sig1+"p%g"%(i+1),sig1,
53+
'''
54+
%s|fft1 | fft3 axis=2 pad=1|
55+
threshold1 type=%s ifperc=1 thr=%f |
56+
fft3 inv=y axis=2 | fft1 inv=y |%s
57+
'''%(mute1,mode,thr,mute1))
58+
Flow(sig2+"p%g"%(i+1),sig2,
59+
'''
60+
%s|fft1 | fft3 axis=2 pad=1|
61+
threshold1 type=%s ifperc=1 thr=%f |
62+
fft3 inv=y axis=2 | fft1 inv=y | %s
63+
'''%(mute2,mode,thr,mute2))
64+
return (sig1+"p%g"%(i+1),sig2+"p%g"%(i+1))
65+
66+
def shapefxdecon(sig1,sig2,mute1,mute2,n2,i): #mute1(2) is a string, when there is no mute, mute1(2) is "cp"
67+
Flow(sig1+"p%g"%(i+1),[sig1],
68+
'''
69+
%s | fxdecon n2w=%g
70+
|%s
71+
'''%(mute1,n2,mute1))
72+
Flow(sig2+"p%g"%(i+1),[sig2],
73+
'''
74+
%s | fxdecon n2w=%g
75+
|%s
76+
'''%(mute2,n2,mute2))
77+
return (sig1+"p%g"%(i+1),sig2+"p%g"%(i+1))
78+
79+
def step(sig1,sig2,blended1,blended2,init1,init2,shottime1,shottime2,i,n2,fraction):
80+
# Flow(init1+'sigtemp'+'%g'%(i+1),[sig1,sig2],'cat axis=2 ${SOURCES[1]}')
81+
# Flow(init1+'shottimetemp'+'%g'%(i+1),[shottime1,shottime2],'cat axis=2 ${SOURCES[1]}')
82+
# Flow(init1+'blendedtemp'+'%g'%(i+1),[init1+'sigtemp'+'%g'%(i+1),init1+'shottimetemp'+'%g'%(i+1)],
83+
# '''
84+
# blend shot_time_in=${SOURCES[1]} shot_time_out=${SOURCES[1]}
85+
# ''')
86+
#
87+
# Flow(init1+"%g"%(i+1),[init1+'blendedtemp'+'%g'%(i+1),blended1,sig1],
88+
# '''
89+
# window n2=%g | add scale=-1,1 ${SOURCES[1]} | add scale=%g,%g ${SOURCES[2]}
90+
# '''%(n2,fraction,1))
91+
# Flow(init2+"%g"%(i+1),[init1+'blendedtemp'+'%g'%(i+1),blended2,sig2],
92+
# '''
93+
# window n2=%g f2=%g | add scale=-1,1 ${SOURCES[1]} | add scale=%g,%g ${SOURCES[2]}
94+
# '''%(n2,n2-1,fraction,1))
95+
96+
Flow(init1+"%g"%(i+1),[sig2,shottime1,shottime2,blended1,sig1],
97+
'''
98+
blend shot_time_in=${SOURCES[2]} shot_time_out=${SOURCES[1]}
99+
| add scale=%f,%f,%f ${SOURCES[3]} ${SOURCES[4]}
100+
'''%(-fraction,fraction,1-fraction))
101+
102+
Flow(init2+"%g"%(i+1),[sig1,shottime2,shottime1,blended2,sig2],
103+
'''
104+
blend shot_time_in=${SOURCES[2]} shot_time_out=${SOURCES[1]}
105+
| add scale=%f,%f,%f ${SOURCES[3]} ${SOURCES[4]}
106+
'''% (-fraction,fraction,1-fraction))
107+
return (init1+"%g"%(i+1),init2+"%g"%(i+1))
108+
109+
110+
def deblendfft(unblended1,
111+
unblended2,
112+
blended1,
113+
blended2,
114+
init1,
115+
init2,
116+
deblended1,
117+
deblended2,
118+
shottime1,
119+
shottime2,
120+
mute1,
121+
mute2,
122+
n1,
123+
n2,
124+
niter,
125+
mode,
126+
thr,
127+
clip,
128+
fraction):
129+
130+
sig1, sig2 = (init1,init2)
131+
sigs1=[]
132+
sigs2=[]
133+
snrsa=[]
134+
snrsb=[]
135+
Flow('zero',unblended1,'math output=0')
136+
Flow('energy1',[unblended1, 'zero'],'diff match=${SOURCES[1]}')
137+
Flow('energy2',[unblended2, 'zero'],'diff match=${SOURCES[1]}')
138+
for i in range(niter):
139+
old1,old2 = (sig1,sig2)
140+
snra=init1+'-snra%g'%i
141+
snrb=init2+'-snrb%g'%i
142+
143+
Flow(snra,[unblended1,sig1,'energy1'],'diff match=${SOURCES[1]} | math a=${SOURCES[2]} output="a/input"' )
144+
Flow(snrb,[unblended2,sig2,'energy2'],'diff match=${SOURCES[1]} | math a=${SOURCES[2]} output="a/input"' )
145+
146+
(nsig1,nsig2)=step(sig1,sig2,blended1,blended2,init1,init2,shottime1,shottime2,i,n2,fraction)
147+
(sig1,sig2)=shapefft(nsig1,nsig2,mute1,mute2,mode,thr,i)
148+
149+
150+
Greyplot(sig1,'title="Esti R 1 (iter=%g)" clip=%g'% (i+1,clip))
151+
Greyplot(sig2,'title="Esti R 2 (iter=%g)" clip=%g' % (i+1,clip))
152+
153+
sigs1.append(sig1)
154+
sigs2.append(sig2)
155+
snrsa.append(snra)
156+
snrsb.append(snrb)
157+
158+
Flow(init1+'-snrsa',snrsa,'cat axis=2 ${SOURCES[1:%g]}|math output="10*log(input)/log(10)" | transp | put n1=%g o1=0 d1=1 '%(len(snrsa),len(snrsa)))
159+
Flow(init2+'-snrsb',snrsb,'cat axis=2 ${SOURCES[1:%g]}|math output="10*log(input)/log(10)" | transp | put n1=%g o1=0 d1=1'%(len(snrsb),len(snrsb)))
160+
161+
Graph(init1+'-snrsa','title="Data error 1" label1=Iteration label2="c(n)" symbosz=5 symbol="o" min1=0 max1=%g d1=1'%niter)
162+
Graph(init2+'-snrsb','title="Data error 2" label1=Iteration label2="c(n)" symbosz=5 symbol="o" min1=0 max1=%g d1=1'%niter)
163+
164+
#Making movie
165+
Plot(init1+'-sigs1',sigs1,'Movie')
166+
Plot(init2+'-sigs2',sigs2,'Movie')
167+
Flow(deblended1,sig1,'cp')
168+
Flow(deblended2,sig2,'cp')
169+
170+
def deblendslet(unblended1,
171+
unblended2,
172+
blended1,
173+
blended2,
174+
init1,
175+
init2,
176+
deblended1,
177+
deblended2,
178+
shottime1,
179+
shottime2,
180+
mute1,
181+
mute2,
182+
n1,
183+
n2,
184+
r1,
185+
r2,
186+
padno,
187+
niter,
188+
ddip,
189+
mode,
190+
thr,
191+
clip,
192+
fhi,
193+
fraction):
194+
Flow('mask',blended1,'math output=1 | pad n2=%g'%(padno))
195+
sig1, sig2 = (init1,init2)
196+
sigs1=[]
197+
sigs2=[]
198+
sigs=[]
199+
snrsa=[]
200+
snrsb=[]
201+
Flow('zero',unblended1,'math output=0')
202+
Flow('energy1',[unblended1, 'zero'],'diff match=${SOURCES[1]}')
203+
Flow('energy2',[unblended2, 'zero'],'diff match=${SOURCES[1]}')
204+
for i in range(niter):
205+
#######################################################################################
206+
# update dip map every "ddip" iterations
207+
#######################################################################################
208+
if i % ddip ==0 :
209+
dip1=init1+'dip%g'%int(i/ddip)
210+
dip2=init2+'udip%g'%int(i/ddip)
211+
Flow(dip1,[sig1,'mask'],
212+
'''
213+
bandpass fhi=%g | pad n2=%g |
214+
dip mask=${SOURCES[1]} rect1=%g rect2=%g
215+
'''%(fhi,padno,r1,r2))
216+
Flow(dip2,[sig2,'mask'],
217+
'''
218+
bandpass fhi=%g | pad n2=%g |
219+
dip mask=${SOURCES[1]} rect1=%g rect2=%g
220+
'''%(fhi,padno,r1,r2))
221+
#######################################################################################
222+
old1,old2 = (sig1,sig2)
223+
snra=init1+'-snra%g'%i
224+
snrb=init2+'-snrb%g'%i
225+
226+
Flow(snra,[unblended1,sig1,'energy1'],'diff match=${SOURCES[1]} | math a=${SOURCES[2]} output="a/input"' )
227+
Flow(snrb,[unblended2,sig2,'energy2'],'diff match=${SOURCES[1]} | math a=${SOURCES[2]} output="a/input"' )
228+
229+
(nsig1,nsig2)=step(sig1,sig2,blended1,blended2,init1,init2,shottime1,shottime2,i,n2,fraction)
230+
(sig1,sig2)=shapeslet(nsig1,nsig2,dip1,dip2,mute1,mute2,padno,n2,mode,thr,i)
231+
232+
Greyplot(sig1,'title="Esti R 1 (iter=%g)" clip=%g'% (i+1,clip))
233+
Greyplot(sig2,'title="Esti R 2 (iter=%g)" clip=%g' % (i+1,clip))
234+
235+
sigs1.append(sig1)
236+
sigs2.append(sig2)
237+
238+
Plot(sig1+'t',[sig1,sig2],'SideBySideAniso')
239+
sigs.append(sig1+'t')
240+
241+
snrsa.append(snra)
242+
snrsb.append(snrb)
243+
244+
Flow(init1+'-snrsa',snrsa,'cat axis=2 ${SOURCES[1:%g]}|math output="10*log(input)/log(10)" | transp | put n1=%g o1=0 d1=1 '%(len(snrsa),len(snrsb)))
245+
Flow(init2+'-snrsb',snrsb,'cat axis=2 ${SOURCES[1:%g]}|math output="10*log(input)/log(10)" | transp | put n1=%g o1=0 d1=1'%(len(snrsb),len(snrsb)))
246+
247+
Graph(init1+'-snrsa','title="Data error 1" label1=Iteration label2="c(n)" symbosz=5 symbol="o" min1=0 max1=%g d1=1'%niter)
248+
Graph(init2+'-snrsb','title="Data error 2" label1=Iteration label2="c(n)" symbosz=5 symbol="o" min1=0 max1=%g d1=1'%niter)
249+
250+
#Making movie
251+
Plot(init1+'-sigs1',sigs1,'Movie')
252+
Plot(init2+'-sigs2',sigs2,'Movie')
253+
254+
Plot(init1+'-sigs',sigs,'Movie')
255+
256+
Flow(deblended1,sig1,'cp')
257+
Flow(deblended2,sig2,'cp')
258+
259+
260+
def deblendfxdecon(unblended1,
261+
unblended2,
262+
blended1,
263+
blended2,
264+
init1,
265+
init2,
266+
deblended1,
267+
deblended2,
268+
shottime1,
269+
shottime2,
270+
mute1,
271+
mute2,
272+
n1,
273+
n2,
274+
niter,
275+
clip,
276+
fraction):
277+
sig1, sig2 = (init1,init2)
278+
sigs1=[]
279+
sigs2=[]
280+
snrsa=[]
281+
snrsb=[]
282+
Flow('zero',unblended1,'math output=0')
283+
Flow('energy1',[unblended1, 'zero'],'diff match=${SOURCES[1]}')
284+
Flow('energy2',[unblended2, 'zero'],'diff match=${SOURCES[1]}')
285+
for i in range(niter):
286+
#######################################################################################
287+
old1,old2 = (sig1,sig2)
288+
snra=init1+'-snra%g'%i
289+
snrb=init2+'-snrb%g'%i
290+
291+
Flow(snra,[unblended1,sig1,'energy1'],'diff match=${SOURCES[1]} | math a=${SOURCES[2]} output="a/input"' )
292+
Flow(snrb,[unblended2,sig2,'energy2'],'diff match=${SOURCES[1]} | math a=${SOURCES[2]} output="a/input"' )
293+
294+
(nsig1,nsig2)=step(sig1,sig2,blended1,blended2,init1,init2,shottime1,shottime2,i,n2,fraction)
295+
(sig1,sig2)=shapefxdecon(nsig1,nsig2,mute1,mute2,n2,i)
296+
297+
298+
Greyplot(sig1,'title="Esti R 1 (iter=%g)" clip=%g'% (i+1,clip))
299+
Greyplot(sig2,'title="Esti R 2 (iter=%g)" clip=%g' % (i+1,clip))
300+
301+
sigs1.append(sig1)
302+
sigs2.append(sig2)
303+
snrsa.append(snra)
304+
snrsb.append(snrb)
305+
306+
Flow(init1+'-snrsa',snrsa,'cat axis=2 ${SOURCES[1:%g]}|math output="10*log(input)/log(10)" | transp | put n1=%g o1=0 d1=1 '%(len(snrsa),len(snrsb)))
307+
Flow(init2+'-snrsb',snrsb,'cat axis=2 ${SOURCES[1:%g]}|math output="10*log(input)/log(10)" | transp | put n1=%g o1=0 d1=1'%(len(snrsb),len(snrsb)))
308+
309+
Graph(init1+'-snrsa','title="Data error 1" label1=Iteration label2="c(n)" symbosz=5 symbol="o" min1=0 max1=%g d1=1'%niter)
310+
Graph(init2+'-snrsb','title="Data error 2" label1=Iteration label2="c(n)" symbosz=5 symbol="o" min1=0 max1=%g d1=1'%niter)
311+
312+
#Making movie
313+
Plot(init1+'-sigs1',sigs1,'Movie')
314+
Plot(init2+'-sigs2',sigs2,'Movie')
315+
316+
Flow(deblended1,sig1,'cp')
317+
Flow(deblended2,sig2,'cp')
318+
319+

book/tccs/deblend/fairfield-initmfnew/SConstruct

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from rsf.proj import*
22
from rsf.recipes.beg import server
33
import sys
4-
sys.path.append('../../temp/recipes')
4+
sys.path.append('../')
55
import deblend2
66

77
clip=0.0005 #display percentage
@@ -49,22 +49,17 @@ for file in [
4949
]:
5050
Fetch(file+'.segy','fairfield',server)
5151
if file == 'Z700_SimSou_754-UNBLENDED-':
52-
file1='unblended754'
52+
file1='unblended754'
5353
elif file=='Z700_SimSou_763-UNBLENDED-':
54-
file1='unblended763'
55-
#elif file=='Z700_SimSou_754-BLENDED-Close-Synch-1000dither':
56-
# file1='blended754'
57-
#elif file=='Z700_SimSou_763-BLENDED-Close-Synch-1000dither':
58-
# file1='blended763'
59-
Flow([file1,'t'+file1,file1+'.asc',file1+'.bin'],
60-
file+'.segy',
61-
'''
62-
segyread
63-
tfile=${TARGETS[1]}
64-
hfile=${TARGETS[2]}
65-
bfile=${TARGETS[3]} | scale axis=12
66-
''')
67-
Grey(file1,' title=%s clip=%g'%('',clip))
54+
file1='unblended763'
55+
56+
Flow([file1,'t'+file1,file1+'.asc',file1+'.bin'],file+'.segy','''
57+
segyread
58+
tfile=${TARGETS[1]}
59+
hfile=${TARGETS[2]}
60+
bfile=${TARGETS[3]} | scale axis=12
61+
''')
62+
Grey(file1,' title=%s clip=%g'%('',clip))
6863

6964

7065
## extract shottime#.rsf from data header file tfile#

0 commit comments

Comments
 (0)