Skip to content

Commit 87b9be6

Browse files
authored
Merge pull request #600 from mrava87/fix-devitoimport
bug: move _CustomSource to private file
2 parents b199b3a + ad54bb5 commit 87b9be6

File tree

2 files changed

+49
-43
lines changed

2 files changed

+49
-43
lines changed

pylops/waveeqprocessing/_twoway.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from examples.seismic.utils import PointSource
2+
3+
4+
class _CustomSource(PointSource):
5+
"""Custom source
6+
7+
This class creates a Devito symbolic object that encapsulates a set of
8+
sources with a user defined source signal wavelet ``wav``
9+
10+
Parameters
11+
----------
12+
name : :obj:`str`
13+
Name for the resulting symbol.
14+
grid : :obj:`devito.types.grid.Grid`
15+
The computational domain.
16+
time_range : :obj:`examples.seismic.source.TimeAxis`
17+
TimeAxis(start, step, num) object.
18+
wav : :obj:`numpy.ndarray`
19+
Wavelet of size
20+
21+
"""
22+
23+
__rkwargs__ = PointSource.__rkwargs__ + ["wav"]
24+
25+
@classmethod
26+
def __args_setup__(cls, *args, **kwargs):
27+
kwargs.setdefault("npoint", 1)
28+
29+
return super().__args_setup__(*args, **kwargs)
30+
31+
def __init_finalize__(self, *args, **kwargs):
32+
super().__init_finalize__(*args, **kwargs)
33+
34+
self.wav = kwargs.get("wav")
35+
36+
if not self.alias:
37+
for p in range(kwargs["npoint"]):
38+
self.data[:, p] = self.wavelet
39+
40+
@property
41+
def wavelet(self):
42+
"""Return user-provided wavelet"""
43+
return self.wav

pylops/waveeqprocessing/twoway.py

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__all__ = ["AcousticWave2D"]
22

3-
from typing import Tuple
3+
from typing import Any, NewType, Tuple
44

55
import numpy as np
66

@@ -14,49 +14,12 @@
1414
if devito_message is None:
1515
from examples.seismic import AcquisitionGeometry, Model
1616
from examples.seismic.acoustic import AcousticWaveSolver
17-
from examples.seismic.utils import PointSource
1817

18+
from ._twoway import _CustomSource
19+
else:
20+
AcousticWaveSolver = Any
1921

20-
class _CustomSource(PointSource):
21-
"""Custom source
22-
23-
This class creates a Devito symbolic object that encapsulates a set of
24-
sources with a user defined source signal wavelet ``wav``
25-
26-
Parameters
27-
----------
28-
name : :obj:`str`
29-
Name for the resulting symbol.
30-
grid : :obj:`devito.types.grid.Grid`
31-
The computational domain.
32-
time_range : :obj:`examples.seismic.source.TimeAxis`
33-
TimeAxis(start, step, num) object.
34-
wav : :obj:`numpy.ndarray`
35-
Wavelet of size
36-
37-
"""
38-
39-
__rkwargs__ = PointSource.__rkwargs__ + ["wav"]
40-
41-
@classmethod
42-
def __args_setup__(cls, *args, **kwargs):
43-
kwargs.setdefault("npoint", 1)
44-
45-
return super().__args_setup__(*args, **kwargs)
46-
47-
def __init_finalize__(self, *args, **kwargs):
48-
super().__init_finalize__(*args, **kwargs)
49-
50-
self.wav = kwargs.get("wav")
51-
52-
if not self.alias:
53-
for p in range(kwargs["npoint"]):
54-
self.data[:, p] = self.wavelet
55-
56-
@property
57-
def wavelet(self):
58-
"""Return user-provided wavelet"""
59-
return self.wav
22+
AcousticWaveSolverType = NewType("AcousticWaveSolver", AcousticWaveSolver)
6023

6124

6225
class AcousticWave2D(LinearOperator):
@@ -327,7 +290,7 @@ def srcillumination_allshots(self, savewav: bool = False) -> None:
327290
self.src_wavefield.append(src_wav)
328291
self.src_illumination += src_ill
329292

330-
def _born_oneshot(self, solver: AcousticWaveSolver, dm: NDArray) -> NDArray:
293+
def _born_oneshot(self, solver: AcousticWaveSolverType, dm: NDArray) -> NDArray:
331294
"""Born modelling for one shot
332295
333296
Parameters

0 commit comments

Comments
 (0)