Skip to content

Commit 27ed544

Browse files
authored
Merge pull request #8 from mrava87/master
Added prescaled option to MDC and Marchenko
2 parents 3b55343 + 09aa507 commit 27ed544

File tree

3 files changed

+56
-23
lines changed

3 files changed

+56
-23
lines changed

pylops_distributed/waveeqprocessing/marchenko.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@ class Marchenko():
3838
nsmooth : :obj:`int`, optional
3939
Number of samples of smoothing operator to apply to window
4040
saveRt : :obj:`bool`, optional
41-
Save ``R`` and ``R^H`` to speed up the computation of adjoint of
41+
Save ``R`` and ``R^H`` to speed up the computation of the adjoint of
4242
:class:`pylops_distributed.signalprocessing.Fredholm1` (``True``) or
4343
create ``R^H`` on-the-fly (``False``) Note that ``saveRt=True`` will be
4444
faster but double the amount of required memory
45+
prescaled : :obj:`bool`, optional
46+
Apply scaling to ``R`` (``False``) or not (``False``)
47+
when performing spatial and temporal summations within the
48+
:class:`pylops.waveeqprocessing.MDC` operator. In case
49+
``prescaled=True``, the ``R`` is assumed to have been pre-scaled by
50+
the user.
4551
dtype : :obj:`bool`, optional
4652
Type of elements in input array.
4753
@@ -73,7 +79,7 @@ class Marchenko():
7379
7480
"""
7581
def __init__(self, R, nt, dt=0.004, dr=1., wav=None, toff=0.0,
76-
nsmooth=10, saveRt=True, dtype='float64'):
82+
nsmooth=10, saveRt=True, prescaled=False, dtype='float64'):
7783
# Save inputs into class
7884
self.nt = nt
7985
self.dt = dt
@@ -82,6 +88,7 @@ def __init__(self, R, nt, dt=0.004, dr=1., wav=None, toff=0.0,
8288
self.toff = toff
8389
self.nsmooth = nsmooth
8490
self.saveRt = saveRt
91+
self.prescaled = prescaled
8592
self.dtype = dtype
8693
self.explicit = False
8794

@@ -163,9 +170,11 @@ def apply_onepoint(self, trav, dist=None, G0=None, nfft=None,
163170

164171
# Create operators
165172
Rop = MDC(self.Rtwosided_fft, self.nt2, nv=1, dt=self.dt, dr=self.dr,
166-
twosided=True, conj=False, saveGt=self.saveRt)
173+
twosided=True, conj=False, saveGt=self.saveRt,
174+
prescaled=self.prescaled)
167175
R1op = MDC(self.Rtwosided_fft, self.nt2, nv=1, dt=self.dt, dr=self.dr,
168-
twosided=True, conj=True, saveGt=self.saveRt)
176+
twosided=True, conj=True, saveGt=self.saveRt,
177+
prescaled=self.prescaled)
169178
Rollop = Roll(self.nt2 * self.ns,
170179
dims=(self.nt2, self.ns),
171180
dir=0, shift=-1, dtype=self.dtype)
@@ -327,9 +336,11 @@ def apply_multiplepoints(self, trav, dist=None, G0=None, nfft=None,
327336

328337
# Create operators
329338
Rop = MDC(self.Rtwosided_fft, self.nt2, nv=nvs, dt=self.dt,
330-
dr=self.dr, twosided=True, conj=False, saveGt=self.saveRt)
339+
dr=self.dr, twosided=True, conj=False, saveGt=self.saveRt,
340+
prescaled=self.prescaled)
331341
R1op = MDC(self.Rtwosided_fft, self.nt2, nv=nvs, dt=self.dt,
332-
dr=self.dr, twosided=True, conj=True, saveGt=self.saveRt)
342+
dr=self.dr, twosided=True, conj=True, saveGt=self.saveRt,
343+
prescaled=self.prescaled)
333344
Rollop = Roll(self.ns * nvs * self.nt2,
334345
dims=(self.nt2, self.ns, nvs),
335346
dir=0, shift=-1, dtype=self.dtype)

pylops_distributed/waveeqprocessing/mdd.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
def MDC(G, nt, nv, dt=1., dr=1., twosided=True,
11-
saveGt=True, conj=False, compute=(False, False),
12-
todask=(False, False)):
11+
saveGt=True, conj=False, prescaled=False,
12+
compute=(False, False), todask=(False, False)):
1313
r"""Multi-dimensional convolution.
1414
1515
Apply multi-dimensional convolution between two datasets.
@@ -43,6 +43,11 @@ def MDC(G, nt, nv, dt=1., dr=1., twosided=True,
4343
faster but double the amount of required memory
4444
conj : :obj:`str`, optional
4545
Perform Fredholm integral computation with complex conjugate of ``G``
46+
prescaled : :obj:`bool`, optional
47+
Apply scaling to kernel (``False``) or not (``False``) when performing
48+
spatial and temporal summations. In case ``prescaled=True``, the
49+
kernel is assumed to have been pre-scaled when passed to the MDC
50+
routine.
4651
compute : :obj:`tuple`, optional
4752
Compute the outcome of forward and adjoint or simply define the graph
4853
and return a :obj:`dask.array`
@@ -57,7 +62,7 @@ def MDC(G, nt, nv, dt=1., dr=1., twosided=True,
5762
5863
"""
5964
return _MDC(G, nt, nv, dt=dt, dr=dr, twosided=twosided,
60-
transpose=False, saveGt=saveGt, conj=conj,
65+
transpose=False, saveGt=saveGt, conj=conj, prescaled=prescaled,
6166
_Identity=Identity, _Transpose=Transpose,
6267
_FFT=FFT, _Fredholm1=Fredholm1,
6368
args_Fredholm1={'chunks': ((G.chunks[0], G.shape[2], nv),

pytests/test_marchenko.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,30 @@
7474
# Load distributed Rs in frequency domain
7575
dRtwosided_fft = da.from_zarr(inputzarr)
7676

77+
par1 = {'saveRt': True, 'prescaled':False}
78+
par2 = {'saveRt': False, 'prescaled':False}
79+
par3 = {'saveRt': True, 'prescaled':True}
80+
par4 = {'saveRt': False, 'prescaled':True}
7781

78-
par1 = {'saveRt': True} # square real
79-
par2 = {'saveRt': False} # overdetermined real
8082

81-
82-
@pytest.mark.parametrize("par", [(par1), (par2)])
83+
@pytest.mark.parametrize("par", [(par1), (par2), (par3), (par4)])
8384
def test_Marchenko(par):
8485
"""Dot-test and comparison with pylops for Marchenko.apply_onepoint
8586
"""
86-
dMarchenkoWM = dMarchenko(dRtwosided_fft, nt=nt, dt=dt, dr=dr,
87+
if par['prescaled']:
88+
dRtwosided_fft_sc = np.sqrt(2 * nt - 1) * dt * dr * dRtwosided_fft
89+
Rtwosided_fft_sc = np.sqrt(2 * nt - 1) * dt * dr * Rtwosided_fft
90+
else:
91+
dRtwosided_fft_sc = dRtwosided_fft
92+
Rtwosided_fft_sc = Rtwosided_fft
93+
94+
dMarchenkoWM = dMarchenko(dRtwosided_fft_sc, nt=nt, dt=dt, dr=dr,
8795
wav=wav, toff=toff, nsmooth=nsmooth,
88-
saveRt=par['saveRt'])
96+
saveRt=par['saveRt'], prescaled=par['prescaled'])
8997

90-
MarchenkoWM = Marchenko(Rtwosided_fft, nt=nt, dt=dt, dr=dr,
91-
wav=wav, toff=toff, nsmooth=nsmooth)
98+
MarchenkoWM = Marchenko(Rtwosided_fft_sc, nt=nt, dt=dt, dr=dr,
99+
wav=wav, toff=toff, nsmooth=nsmooth,
100+
prescaled=par['prescaled'])
92101

93102
_, _, dp0_minus, dg_inv_minus, dg_inv_plus = \
94103
dMarchenkoWM.apply_onepoint(trav, nfft=2 ** 11, rtm=True, greens=True,
@@ -107,16 +116,24 @@ def test_Marchenko(par):
107116
np.linalg.norm(gsub_norm) < 1e-1
108117

109118

110-
@pytest.mark.parametrize("par", [(par1), (par2)])
111-
def test_Marchenko__multi(par):
119+
@pytest.mark.parametrize("par", [(par1), (par2), (par3), (par4)])
120+
def test_Marchenko_multi(par):
112121
"""Dot-test and comparison with pylops for Marchenko.apply_multiplepoints
113122
"""
114-
dMarchenkoWM = dMarchenko(dRtwosided_fft, nt=nt, dt=dt, dr=dr,
123+
if par['prescaled']:
124+
dRtwosided_fft_sc = np.sqrt(2 * nt - 1) * dt * dr * dRtwosided_fft
125+
Rtwosided_fft_sc = np.sqrt(2 * nt - 1) * dt * dr * Rtwosided_fft
126+
else:
127+
dRtwosided_fft_sc = dRtwosided_fft
128+
Rtwosided_fft_sc = Rtwosided_fft
129+
130+
dMarchenkoWM = dMarchenko(dRtwosided_fft_sc, nt=nt, dt=dt, dr=dr,
115131
wav=wav, toff=toff, nsmooth=nsmooth,
116-
saveRt=par['saveRt'])
132+
saveRt=par['saveRt'], prescaled=par['prescaled'])
117133

118-
MarchenkoWM = Marchenko(Rtwosided_fft, nt=nt, dt=dt, dr=dr,
119-
wav=wav, toff=toff, nsmooth=nsmooth)
134+
MarchenkoWM = Marchenko(Rtwosided_fft_sc, nt=nt, dt=dt, dr=dr,
135+
wav=wav, toff=toff, nsmooth=nsmooth,
136+
prescaled=par['prescaled'])
120137

121138
_, _, dp0_minus, dg_inv_minus, dg_inv_plus = \
122139
dMarchenkoWM.apply_multiplepoints(trav_multi, nfft=2 ** 11, rtm=True,

0 commit comments

Comments
 (0)