Skip to content

Commit

Permalink
feature: adapted all codes for pylopsv2
Browse files Browse the repository at this point in the history
  • Loading branch information
mrava87 committed Nov 29, 2023
1 parent 4195d56 commit 86535f8
Show file tree
Hide file tree
Showing 26 changed files with 1,143 additions and 1,477 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
name: PyMarchenko-tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]
python-version: [3.8, 3.9]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Deploy Sphinx docs to GitHub Pages

on:
push:
branches:
- main

permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements-dev.txt; fi
pip install .
- name: Build docs
run: |
sphinx-build -b html ./docs/source ./docs/build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
publish_branch: gh-pages1
personal_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build/
24 changes: 24 additions & 0 deletions .github/workflows/flake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This workflow runs Flake8 on the PR
# For more information see: https://github.com/marketplace/actions/python-flake8-lint
name: PyMarchenko-flake8

on: [push, pull_request]

jobs:
flake8-lint:
runs-on: ubuntu-latest
name: Lint
steps:
- name: Check out source repository
uses: actions/checkout@v3
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: flake8 Lint
uses: py-actions/flake8@v2
with:
ignore: "E203,E501,W503,E402"
max-line-length: "88"
path: "pymarchenko"
args: "--per-file-ignores=__init__.py:F401,F403,F405"
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,12 @@ docpush:
cd ../docs && git add . && git commit -m "Updated documentation" &&\
git push origin gh-pages && git checkout main

servedoc:
$(PYTHON) -m http.server --directory docs/build/html/

lint:
flake8 docs/ examples/ pyproximal/ pytests/ tutorials/

typeannot:
mypy pyproximal/

34 changes: 0 additions & 34 deletions docssrc/source/_templates/breadcrumbs.html

This file was deleted.

7 changes: 3 additions & 4 deletions docssrc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@

sphinx_gallery_conf = {
# path to your examples scripts
'examples_dirs': ['../../examples', '../../tutorials',],
'examples_dirs': ['../../tutorials',],
# path where to save gallery generated examples
'gallery_dirs': ['gallery', 'tutorials'],
'gallery_dirs': ['tutorials',],
'filename_pattern': '\.py',
# Remove the "Download all examples" button from the top level gallery
'download_all_examples': False,
Expand Down Expand Up @@ -134,8 +134,7 @@
# links
'doc_path': 'docs/source',
'galleries': sphinx_gallery_conf['gallery_dirs'],
'gallery_dir': dict(zip(sphinx_gallery_conf['gallery_dirs'],
sphinx_gallery_conf['examples_dirs'])),
'gallery_dir': sphinx_gallery_conf['gallery_dirs'],
'github_project': 'PyLops',
'github_repo': 'pymarchenko',
'github_version': 'main',
Expand Down
6 changes: 0 additions & 6 deletions examples/README.txt

This file was deleted.

239 changes: 94 additions & 145 deletions notebooks/Marchenko.ipynb

Large diffs are not rendered by default.

70 changes: 29 additions & 41 deletions notebooks/Marchenko_demultiple.ipynb

Large diffs are not rendered by default.

150 changes: 58 additions & 92 deletions notebooks/Marchenko_iterative.ipynb

Large diffs are not rendered by default.

766 changes: 408 additions & 358 deletions notebooks/Marchenko_missing.ipynb

Large diffs are not rendered by default.

407 changes: 182 additions & 225 deletions notebooks/Rayleigh_Marchenko.ipynb

Large diffs are not rendered by default.

59 changes: 23 additions & 36 deletions notebooks/Rayleigh_Marchenko_wavsep.ipynb

Large diffs are not rendered by default.

298 changes: 123 additions & 175 deletions notebooks/Rayleigh_Marchenko_with_pythonsep.ipynb

Large diffs are not rendered by default.

47 changes: 45 additions & 2 deletions pymarchenko/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from multiprocessing import set_start_method
from multiprocessing import get_context
from scipy.signal import convolve, filtfilt
from pylops.waveeqprocessing.marchenko import directwave#, Marchenko
from pylops.waveeqprocessing.marchenko import directwave
from pylops.waveeqprocessing.mdd import MDD
from pymarchenko.marchenko import Marchenko
from pymarchenko.raymarchenko import RayleighMarchenko
Expand Down Expand Up @@ -111,7 +111,49 @@ def MarchenkoImaging(vsx, vsz, r, s, dr, dt, nt, vel,
Parameters
----------
vsx : :obj:`numpy.ndarray`
X-coordinates of virtual sources
vsz : :obj:`numpy.ndarray`
Z-coordinates of virtual sources
r : :obj:`numpy.ndarray`
Receiver array
s : :obj:`numpy.ndarray`
Source array
dr : :obj:`float`
Sampling of receiver integration axis
dt : :obj:`float`
Sampling of time integration axis
nt : :obj:`int`
Number of samples in time (not required if ``R`` is in time)
vel : :obj:`numpy.ndarray`
Velocity model
toff : :obj:`float`
Time-offset to apply to traveltime
nsmooth : :obj:`int`
Number of samples of smoothing operator to apply to window
wav : :obj:`numpy.ndarray`, optional
Wavelet to apply to direct arrival when created using ``trav``
wav_c : :obj:`int`
Index of center of wavelet
nfmax : :obj:`int`
Index of max frequency to include in deconvolution process
igaths : :obj:`list`, optional
Indices of x-axis along which to compute angle gathers
nalpha : :obj:`int`
Indices of x-axis along which to compute angle gathers
jt : :obj:`int`
Subsampling to apply to time axis of inputs wavefields for MDD
data : :obj:`numpy.ndarray`
Reflection data
kind : :obj:`str`, optional
Marchenko algorithm to apply (``mck``, ``nmck``, or ``rmck``)
niter : :obj:`int`, optional
Number of iterations of Marchenko scheme
nproc : :obj:`int`, optional
Number of processes
nthread : :obj:`int`, optional
Number of threads per process
Returns
-------
iss : :obj:`numpy.ndarray`
Expand All @@ -122,6 +164,7 @@ def MarchenkoImaging(vsx, vsz, r, s, dr, dt, nt, vel,
Single-scattering angle gathers
amck : :obj:`numpy.ndarray`, optional
Marchenko angle gathers
"""
# Set threads
os.environ["OMP_NUM_THREADS"] = str(nthreads)
Expand Down
29 changes: 14 additions & 15 deletions pymarchenko/marchenko.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from pylops import Diagonal, Identity, Block, BlockDiag, Restriction
from pylops.waveeqprocessing.mdd import MDC
from pylops.waveeqprocessing.marchenko import directwave
from pylops.optimization.solver import cgls
from pylops.optimization.sparsity import FISTA
from pylops.optimization.basic import cgls
from pylops.optimization.sparsity import fista
from pylops.utils.backend import get_array_module, get_module_name, \
to_cupy_conditional

Expand Down Expand Up @@ -230,8 +230,7 @@ def __init__(self, R, dt=0.004, nt=None, dr=1.,
if self.isava is None:
self.Iop = Identity(self.nr * self.nt2)
else:
self.Iop = Restriction(self.nr * self.nt2, isava,
dims=(self.nt2, self.nr), dir=1)
self.Iop = Restriction((self.nt2, self.nr), isava, axis=1)
if S is not None:
self.Sop = BlockDiag([S, S])

Expand Down Expand Up @@ -268,9 +267,9 @@ def apply_onepoint(self, trav, G0=None, nfft=None, rtm=False, greens=False,
**kwargs_solver
Arbitrary keyword arguments for chosen solver
(:py:func:`scipy.sparse.linalg.lsqr` and
:py:func:`pylops.optimization.solver.cgls` are used as default
:py:func:`pylops.optimization.basic.cgls` are used as default
for numpy and cupy `data`, respectively.
:py:func:`pylops.optimization.sparsity.FISTA` is used when a
:py:func:`pylops.optimization.sparsity.fista` is used when a
sparsifying transform ``S`` is provided).
Returns
Expand Down Expand Up @@ -305,13 +304,13 @@ def apply_onepoint(self, trav, G0=None, nfft=None, rtm=False, greens=False,

# Create operators
Rop = MDC(self.Rtwosided_fft, self.nt2, nv=1, dt=self.dt, dr=self.dr,
twosided=False, conj=False, transpose=False,
twosided=False, conj=False,
saveGt=self.saveRt, prescaled=self.prescaled,
usematmul=usematmul, dtype=self.dtype)
usematmul=usematmul)
R1op = MDC(self.Rtwosided_fft, self.nt2, nv=1, dt=self.dt, dr=self.dr,
twosided=False, conj=True, transpose=False,
twosided=False, conj=True,
saveGt=self.saveRt, prescaled=self.prescaled,
usematmul=usematmul, dtype=self.dtype)
usematmul=usematmul)
Wop = Diagonal(w.T.ravel())
if self.isava is not None:
Wsop = Diagonal(w[self.isava].T.ravel())
Expand Down Expand Up @@ -367,7 +366,7 @@ def apply_onepoint(self, trav, G0=None, nfft=None, rtm=False, greens=False,
x0=self.ncp.zeros(2*(2*self.nt-1)*self.nr, dtype=self.dtype),
**kwargs_solver)[0]
else:
f1_inv = FISTA(Mop * self.Sop, d.ravel(), **kwargs_solver)[0]
f1_inv = fista(Mop * self.Sop, d.ravel(), **kwargs_solver)[0]
f1_inv = self.Sop * f1_inv

f1_inv = f1_inv.reshape(2 * self.nt2, self.nr)
Expand Down Expand Up @@ -475,12 +474,12 @@ def apply_multiplepoints(self, trav, G0=None, nfft=None,
# Create operators
Rop = MDC(self.Rtwosided_fft, self.nt2, nv=nvs,
dt=self.dt, dr=self.dr, twosided=False,
conj=False, transpose=False, prescaled=self.prescaled,
usematmul=usematmul, dtype=self.dtype)
conj=False, prescaled=self.prescaled,
usematmul=usematmul)
R1op = MDC(self.Rtwosided_fft, self.nt2, nv=nvs,
dt=self.dt, dr=self.dr, twosided=False,
conj=True, transpose=False, prescaled=self.prescaled,
usematmul=usematmul, dtype=self.dtype)
conj=True, prescaled=self.prescaled,
usematmul=usematmul)
Wop = Diagonal(w.transpose(2, 0, 1).ravel())
Iop = Identity(self.nr * nvs * self.nt2)
Mop = Block([[Iop, -1 * Wop * Rop],
Expand Down
20 changes: 10 additions & 10 deletions pymarchenko/mme.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pylops import Diagonal, Identity, Block, BlockDiag
from pylops.waveeqprocessing.mdd import MDC
from pylops.waveeqprocessing.marchenko import directwave
from pylops.optimization.solver import cgls
from pylops.optimization.basic import cgls
from pylops.utils.backend import get_array_module, get_module_name, \
to_cupy_conditional

Expand Down Expand Up @@ -249,13 +249,13 @@ def apply_onesrc(self, Rsrc, usematmul=False, trcomp=False, ntmax=None,

# Create operators
Rop = MDC(self.Rtwosided_fft, self.nt2, nv=1, dt=self.dt, dr=self.dr,
twosided=False, conj=False, transpose=False,
twosided=False, conj=False,
saveGt=self.saveRt, prescaled=self.prescaled,
usematmul=usematmul, dtype=self.dtype)
usematmul=usematmul)
R1op = MDC(self.Rtwosided_fft, self.nt2, nv=1, dt=self.dt, dr=self.dr,
twosided=False, conj=True, transpose=False,
twosided=False, conj=True,
saveGt=self.saveRt, prescaled=self.prescaled,
usematmul=usematmul, dtype=self.dtype)
usematmul=usematmul)

# Run estimate over time steps
U_sub_minus = np.zeros((self.nr, self.nt), dtype=self.dtype)
Expand Down Expand Up @@ -303,7 +303,7 @@ def _apply_onetime_multisrc(self, t0, Rop, R1op, Rsrcs, n_iter=10):
return U_sub_minus

def apply_multisrc(self, Rsrcs, usematmul=False, trcomp=False, ntmax=None,
n_iter=10):
n_iter=10):
r"""Marchenko Multiple elimination for multiple shot gathers
Solve the Marchenko Multiple elimination problem via
Expand Down Expand Up @@ -345,13 +345,13 @@ def apply_multisrc(self, Rsrcs, usematmul=False, trcomp=False, ntmax=None,
# Create operators
nsrc = Rsrcs.shape[0]
Rop = MDC(self.Rtwosided_fft, self.nt2, nv=nsrc, dt=self.dt, dr=self.dr,
twosided=False, conj=False, transpose=False,
twosided=False, conj=False,
saveGt=self.saveRt, prescaled=self.prescaled,
usematmul=usematmul, dtype=self.dtype)
usematmul=usematmul)
R1op = MDC(self.Rtwosided_fft, self.nt2, nv=nsrc, dt=self.dt, dr=self.dr,
twosided=False, conj=True, transpose=False,
twosided=False, conj=True,
saveGt=self.saveRt, prescaled=self.prescaled,
usematmul=usematmul, dtype=self.dtype)
usematmul=usematmul)

# Run estimate over time steps
U_sub_minus = np.zeros((nsrc, self.nr, self.nt), dtype=self.dtype)
Expand Down
10 changes: 5 additions & 5 deletions pymarchenko/neumarchenko.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pylops import Diagonal, Identity, Block, BlockDiag
from pylops.waveeqprocessing.mdd import MDC
from pylops.waveeqprocessing.marchenko import directwave
from pylops.optimization.solver import cgls
from pylops.optimization.basic import cgls
from pylops.utils.backend import get_array_module, get_module_name, \
to_cupy_conditional

Expand Down Expand Up @@ -233,13 +233,13 @@ def apply_onepoint(self, trav, G0=None, nfft=None, rtm=False, greens=False,

# Create operators
Rop = MDC(self.Rtwosided_fft, self.nt2, nv=1, dt=self.dt, dr=self.dr,
twosided=False, conj=False, transpose=False,
twosided=False, conj=False,
saveGt=self.saveRt, prescaled=self.prescaled,
usematmul=usematmul, dtype=self.dtype)
usematmul=usematmul)
R1op = MDC(self.Rtwosided_fft, self.nt2, nv=1, dt=self.dt, dr=self.dr,
twosided=False, conj=True, transpose=False,
twosided=False, conj=True,
saveGt=self.saveRt, prescaled=self.prescaled,
usematmul=usematmul, dtype=self.dtype)
usematmul=usematmul)
Wop = Diagonal(w.T.flatten())

# Create input focusing function
Expand Down
Loading

0 comments on commit 86535f8

Please sign in to comment.