Algorithm Search⌘K

Algorithmadvanced

Parabolic Radon transform

Also called Hampson multiple attenuation.

Decompose a moveout-corrected gather into parabolic events by damped least squares, one frequency at a time, then keep the flat primaries and subtract the curved multiples.

Time
O(n (m k^2 + k^3) + n^2 (m + k)) worst · average · best
Space
O(n (m + k) + m k + k^2) extra
Where
k = the number of curvatures; m = the number of traces; n = the number of time samples
Properties
deterministicleast squareslinear in dataprimaries plus multiples equal data
Origin
Dan Hampson, 1986

The parabolic Radon transform removes multiples from a common-midpoint gather by their moveout. After normal moveout correction with the velocity of the primaries, a primary is flat, and a multiple, which travels slower, still curves down, close to a parabola t=τ+qx2t = \tau + q x^2. The method writes the gather as a sum of parabolic events, one model trace for each curvature qq, and finds the model by damped least squares. The model traces with large qq are the multiples: the method maps them back to the gather and subtracts them. Because a parabola is a time shift that does not depend on τ\tau, the least-squares problem splits into one small system per frequency. It is a seismic relative of the Radon transform of tomography, which integrates an image along straight lines; here the curves are parabolas in time and offset, and the transform is inverted by least squares, not by a filtered back projection.

In plain words

After the usual correction for distance, the echoes that went straight down and up line up flat across the record. Echoes that bounced several times arrive with a bend that remains. The method tries to explain the whole record as a sum of simple curved shapes, from flat to strongly bent. It picks the strength of every shape so that the sum matches the record as closely as possible, with a small penalty that keeps the strengths modest. Then it keeps only the strongly bent shapes, rebuilds the record they make, and subtracts it. What is left is the flat part, the echoes we want. The work is done one frequency at a time, which makes each piece small and fast.

The problem

Input: a gather di(t)d_i(t) with offsets xix_i, already corrected for normal moveout with the primary velocity; curvatures q1<⋯<qkq_1 < \cdots < q_k; a damping μ>0\mu > 0; a cut qcutq_{\text{cut}}. Output: the model mj(τ)m_j(\tau), the predicted multiples and the primaries. The forward operator is

di(t)=∑jmj(t−qjxi2),d_i(t) = \sum_j m_j(t - q_j x_i^2),

and the model minimizes ∥Lm−d∥2+μ∥m∥2\|Lm - d\|^2 + \mu\|m\|^2, a Tikhonov problem. Why parabolas: a multiple with rms velocity vmv_m and zero-offset time t0t_0 arrives at t02+x2/vm2\sqrt{t_0^2 + x^2/v_m^2}. NMO with the primary velocity vpv_p moves it to t02+x2(1/vm2−1/vp2)\sqrt{t_0^2 + x^2 (1/v_m^2 - 1/v_p^2)}, whose Taylor expansion in xx starts with t0+qx2t_0 + q x^2, q=(1/vm2−1/vp2)/(2t0)q = (1/v_m^2 - 1/v_p^2)/(2 t_0). The parabola is an approximation (a theorem for small offsets, a heuristic at far offsets, where it can be off by a large part of a period). Its gain is that a parabola is a shift by qx2q x^2 for every τ\tau, so the DFT turns the forward operator into the matrices (Lω)ij=e−iωqjxi2(L_\omega)_{ij} = e^{-i\omega q_j x_i^2}, one per frequency. A hyperbola τ2+x2/v2\sqrt{\tau^2 + x^2/v^2} shifts different τ\tau by different amounts, and its operator does not split this way.

The algorithm

  1. PARABOLIC-RADON-DEMULTIPLE(d, x, q, Δt, μ, q_cut)
  2. 1D_i ← DFT(d_i) for every trace
  3. 2for each frequency ω do
  4. 3L_ij ← exp(-i ω q_j x_i²)
  5. 4M(ω) ← solution of (Lᴴ L + μ I) M = Lᴴ D(ω)
  6. 5K_j ← M_j(ω) if q_j > q_cut, else 0
  7. 6N(ω) ← L K ▷ predicted multiples
  8. 7m ← inverse DFT of M; multiples ← inverse DFT of N
  9. 8return (m, d - multiples, multiples)

The adjoint LHL^H alone, without the solve, is the plain parabolic stack: the sum of the data along each parabola. It smears each event over many curvatures, because the parabolas through one event all collect some of its energy. The least-squares solve of line L4 focuses the model, so that the multiples can be cut from the primaries in qq. The damping μ\mu keeps the system solvable at low frequencies, where the columns of LL are nearly equal (at ω=0\omega = 0 they are all equal), and controls the amplification of noise.

Example

The parabolic approximation. A primary with vp=2500v_p = 2500 m/s and a multiple with vm=2000v_m = 2000 m/s at t0=1t_0 = 1 s. At x=2000x = 2000 m the exact residual moveout after NMO is 1+20002(1/20002−1/25002)−1=0.16619\sqrt{1 + 2000^2 (1/2000^2 - 1/2500^2)} - 1 = 0.16619 s. The parabola has q=(2.5×10−7−1.6×10−7)/2=4.5×10−8q = (2.5 \times 10^{-7} - 1.6 \times 10^{-7})/2 = 4.5 \times 10^{-8} s/m² and predicts qx2=0.18q x^2 = 0.18 s, 14 ms too much. This error is a fixed property of the approximation; the method accepts it, or it uses a qq grid wide enough to absorb it.

Separating a multiple. A gather of 16 traces at offsets 0 to 1500 m, 63 samples at Δt=8\Delta t = 8 ms, a 20 Hz Ricker wavelet. The primary is flat at τ=0.15\tau = 0.15 s. The multiple has amplitude −0.7-0.7 at τ=0.2\tau = 0.2 s and q=4×10−8q = 4 \times 10^{-8} s/m², so its moveout at 1500 m is 0.09 s, about two periods of the wavelet. The data are made with the forward operator itself, on the grid of 14 curvatures from −1×10−8-1 \times 10^{-8} to 5.5×10−85.5 \times 10^{-8} in steps of 0.5×10−80.5 \times 10^{-8} s/m². With qcut=1.2×10−8q_{\text{cut}} = 1.2 \times 10^{-8}:

damping μ\mu 0.01 0.1 1
relative error of the primaries 0.113 0.124 0.145

Before the removal, the gather differs from the true primaries by a relative error of 0.700. With μ=0.01\mu = 0.01, 65 percent of the model energy is at the three curvatures nearest the primary and 27 percent at the three nearest the multiple; for the plain stack LHdL^H d the shares are 42 and 22 percent, the rest smeared over the other curvatures. The model is not the true model (its relative error is 0.75): one step in qq moves the far trace by only 11 ms, about a fifth of the 50 ms period, so neighboring curvatures are not resolved and the energy spreads over them. These numbers are measurements on this synthetic gather.

Correctness

For odd nn on a periodic time axis, the forward operator is a sum of exact band-limited shifts, its adjoint is the frequency-wise LHL^H, and the frequency-wise solve of line L4 gives the unique minimizer of ∥Lm−d∥2+μ∥m∥2\|Lm - d\|^2 + \mu\|m\|^2 over real models, the same model as the dense time-domain normal equations. The predicted multiples are LL applied to the model traces above the cut, and the returned primaries and multiples add up to the data exactly; the misfit stays with the primaries. At zero frequency every model trace gets the same mean, whatever the data. These are theorems, proved in proofs/correctness.md. That the cut in qq separates primaries from multiples is a heuristic: it needs the residual moveouts to be parabolic enough and to differ by more than about a period at the far offset.

Proof: The frequency-domain solve returns the unique damped least-squares parabolic Radon model of the gather, the forward and adjoint operators are a pair, and the multiple prediction and the primaries add up to the datafull

Setting. A gather has nxn_x real traces did_i at offsets xix_i, each with nn samples at times t Δtt\,\Delta t, t=0,…,n−1t = 0, \ldots, n - 1, and nn is odd. A model has nqn_q real traces mjm_j for the curvatures qjq_j. The DFT is Di[k]=∑tdi[t] e−2πitk/nD_i[k] = \sum_t d_i[t]\, e^{-2\pi i t k/n} and the inverse has the factor 1/n1/n. For a bin kk let ksk_s be the signed index, kk if k≤n/2k \le n/2 and k−nk - n otherwise, and ωk=2πks/(nΔt)\omega_k = 2\pi k_s/(n \Delta t). Because nn is odd, there is no bin with ks=n/2k_s = n/2, and ωn−k=−ωk\omega_{n-k} = -\omega_k for every k≠0k \ne 0. Line L3 forms the nx×nqn_x \times n_q matrix (Lk)ij=e−iωkqjxi2(L_k)_{ij} = e^{-i\omega_k q_j x_i^2}. The forward operator LL maps a model to the gather with spectra LkMkL_k M_k, where Mk=(M1[k],…,Mnq[k])TM_k = (M_1[k], \ldots, M_{n_q}[k])^T; the function adjoint maps a gather to the model with spectra LkHDkL_k^H D_k. A family of vectors (Zk)(Z_k) is conjugate symmetric if Zn−k=Zk‾Z_{n-k} = \overline{Z_k} for all kk and Z0Z_0 is real; the spectra of real signals are exactly the conjugate symmetric families. The inner product of real gathers or models is ⟨a,b⟩=∑a b\langle a, b\rangle = \sum a\, b over all traces and samples.

Claim 1 (the forward operator is a sum of shifts). For a real model, LmLm is real. If qjxi2=s Δtq_j x_i^2 = s\,\Delta t for an integer ss, the contribution of mjm_j to trace ii is mjm_j shifted by ss samples, circularly. In general it is the periodic trigonometric interpolant of mjm_j evaluated at the times t Δt−qjxi2t\,\Delta t - q_j x_i^2.

Proof. Since (Lk)ij‾=eiωkqjxi2=(Ln−k)ij\overline{(L_k)_{ij}} = e^{i\omega_k q_j x_i^2} = (L_{n-k})_{ij} and L0L_0 is real, Ln−k=Lk‾L_{n-k} = \overline{L_k}. If (Mk)(M_k) is conjugate symmetric, so is (LkMk)(L_k M_k), and its inverse DFT is real. For an integer shift, e−iωksΔt=e−2πikss/n=e−2πiks/ne^{-i\omega_k s \Delta t} = e^{-2\pi i k_s s/n} = e^{-2\pi i k s/n} because ks≡k(modn)k_s \equiv k \pmod n, and multiplying the DFT by e−2πiks/ne^{-2\pi i k s/n} shifts the signal circularly by ss samples (the shift theorem of the DFT). For a general delay τ\tau, the trigonometric polynomial p(t′)=1n∑kMj[k] eiωkt′p(t') = \frac{1}{n}\sum_k M_j[k]\, e^{i\omega_k t'} with the signed frequencies takes the value mj[t]m_j[t] at t′=t Δtt' = t\,\Delta t, and 1n∑kMj[k] e−iωkτeiωktΔt=p(t Δt−τ)\frac{1}{n}\sum_k M_j[k]\, e^{-i\omega_k \tau} e^{i\omega_k t \Delta t} = p(t\,\Delta t - \tau). □\square

Claim 2 (adjoint). For a real model mm and a real gather dd, ⟨Lm,d⟩=⟨m,LTd⟩\langle Lm, d\rangle = \langle m, L^T d\rangle, where LTdL^T d is the output of the function adjoint, which is real.

Proof. For real signals, Parseval's identity for this DFT is ∑ta[t] b[t]=1n∑kA[k]‾ B[k]\sum_t a[t]\,b[t] = \frac{1}{n}\sum_k \overline{A[k]}\, B[k]. So ⟨Lm,d⟩=1n∑k(LkMk)HDk=1n∑kMkH(LkHDk)\langle Lm, d\rangle = \frac{1}{n}\sum_k (L_k M_k)^H D_k = \frac{1}{n}\sum_k M_k^H (L_k^H D_k). The family (LkHDk)(L_k^H D_k) is conjugate symmetric, by Ln−k=Lk‾L_{n-k} = \overline{L_k} and the symmetry of (Dk)(D_k), so it is the spectrum of a real model, and the last sum is ⟨m,LTd⟩\langle m, L^T d\rangle by Parseval again. □\square

Claim 3 (the solve). Let μ>0\mu > 0. Lines L1 to L4 and L7 return the unique real model m∗m^\ast that minimizes

J(m)=∥Lm−d∥2+μ∥m∥2J(m) = \|Lm - d\|^2 + \mu \|m\|^2

over all real models. It is the solution of (LTL+μI) m=LTd(L^T L + \mu I)\, m = L^T d in the time domain.

Proof. By Parseval, J(m)=1n∑k(∥LkMk−Dk∥2+μ∥Mk∥2)J(m) = \frac{1}{n}\sum_k \big(\|L_k M_k - D_k\|^2 + \mu\|M_k\|^2\big), and the term of bin kk depends only on MkM_k. Each term is a strictly convex quadratic function of the complex vector MkM_k, because LkHLk+μIL_k^H L_k + \mu I is Hermitian positive definite, and its unique minimizer is Mk∗=(LkHLk+μI)−1LkHDkM_k^\ast = (L_k^H L_k + \mu I)^{-1} L_k^H D_k, which is line L4. Taking the complex conjugate of this equation and using Ln−k=Lk‾L_{n-k} = \overline{L_k} and Dn−k=Dk‾D_{n-k} = \overline{D_k} shows Mn−k∗=Mk∗‾M_{n-k}^\ast = \overline{M_k^\ast}, and M0∗M_0^\ast is real since L0L_0 and D0D_0 are real. So (Mk∗)(M_k^\ast) is the spectrum of a real model m∗m^\ast, which line L7 returns. The family (Mk∗)(M_k^\ast) minimizes every term over all complex vectors, so m∗m^\ast minimizes JJ over the smaller set of real models; any other real model differs in some bin and has a strictly larger term there. The gradient of JJ at m∗m^\ast is 2(LTLm∗−LTd+μm∗)2(L^T L m^\ast - L^T d + \mu m^\ast) by Claim 2, and it is zero. □\square

Claim 4 (the split). Let PP keep the model traces with qj>qcutq_j > q_{\text{cut}} and set the others to zero. Lines L5, L6 and L8 return the multiples LPm∗L P m^\ast and the primaries d−LPm∗d - L P m^\ast. So the primaries and the multiples add up to dd exactly, and the primaries are L(I−P)m∗+(d−Lm∗)L(I - P) m^\ast + (d - L m^\ast): the modeled events with qj≤qcutq_j \le q_{\text{cut}} plus the part of the data that the model does not fit.

Proof. Line L5 forms the spectra of Pm∗P m^\ast, bin by bin, and line L6 multiplies them by LkL_k, which is the spectrum of LPm∗L P m^\ast. The rest is linearity of LL. □\square

So the misfit d−Lm∗d - Lm^\ast, which holds the noise and any event that is not a parabola in the range of qq, stays with the primaries. This is a design choice of the method: it removes only what it can model as a multiple.

Claim 5 (zero frequency). At k=0k = 0 all columns of L0L_0 are the vector of ones, and M0∗=Snxnq+μ(1,…,1)TM_0^\ast = \frac{S}{n_x n_q + \mu}(1, \ldots, 1)^T with S=∑iDi[0]S = \sum_i D_i[0]. So every model trace has the same mean, whatever the data, and the zero-frequency part of the data is split between primaries and multiples in the ratio of the numbers of curvatures at most and above qcutq_{\text{cut}}.

Proof. L0HL0=nx11TL_0^H L_0 = n_x \mathbf{1}\mathbf{1}^T and L0HD0=S 1L_0^H D_0 = S\,\mathbf{1}. The vector c 1c\,\mathbf{1} solves (nx11T+μI)M=S 1(n_x \mathbf{1}\mathbf{1}^T + \mu I) M = S\,\mathbf{1} when nxnqc+μc=Sn_x n_q c + \mu c = S, and the solution is unique by Claim 3. □\square

More generally, columns jj and j′j' of LkL_k differ by the phases ωk(qj−qj′)xi2\omega_k (q_j - q_{j'}) x_i^2. When ∣ωk∣ ∣qj−qj′∣ xmax⁡2|\omega_k|\,|q_j - q_{j'}|\, x_{\max}^2 is small, the two columns are nearly parallel, the normal matrix is badly conditioned, and the damping decides the split. So the method cannot be expected to separate events whose moveouts at the far offset differ by much less than one period of the dominant frequency. This is a heuristic resolution limit, not a theorem.

Claim 6 (cost). With nn samples, nxn_x traces and nqn_q curvatures, the solve costs O(n(nxnq2+nq3))O(n (n_x n_q^2 + n_q^3)) plus the transforms: nx+nqn_x + n_q forward DFTs and nx+nqn_x + n_q inverse DFTs. The direct DFT used for odd nn costs O(n2)O(n^2) per trace; an FFT costs O(nlog⁡n)O(n \log n).

Proof. For each of the nn bins, line L3 costs O(nxnq)O(n_x n_q), the normal matrix O(nxnq2)O(n_x n_q^2), the right-hand side O(nxnq)O(n_x n_q), the dense solve O(nq3)O(n_q^3), and line L6 O(nxnq)O(n_x n_q). When the qjq_j are equally spaced, (LkHLk)jj′=∑ieiωk(qj−qj′)xi2(L_k^H L_k)_{jj'} = \sum_i e^{i\omega_k (q_j - q_{j'}) x_i^2} depends only on j−j′j - j', so the matrix is Hermitian Toeplitz and a Levinson-type solver costs O(nq2)O(n_q^2) in place of O(nq3)O(n_q^3). □\square

Complexity

In the real-RAM model each frequency costs O(mk2)O(m k^2) for the normal matrix and O(k3)O(k^3) for the solve, so the solves cost O(n(mk2+k3))O(n (m k^2 + k^3)). The code uses a direct DFT for odd nn, O(n2)O(n^2) per trace; with an FFT the transforms cost O((m+k) nlog⁡n)O((m + k)\, n \log n). With equally spaced curvatures the normal matrix is Hermitian Toeplitz, and a Levinson-type solver costs O(k2)O(k^2) per frequency. Space is O(n(m+k))O(n (m + k)) for the spectra plus O(mk+k2)O(m k + k^2) for one frequency.

Properties

  • Linear in the data for fixed qq grid, μ\mu and qcutq_{\text{cut}} (a theorem).
  • Primaries plus predicted multiples equal the data (a theorem), so nothing is lost: what the model does not explain stays in the primaries.
  • Resolution in qq grows with the frequency and with the square of the largest offset; events whose far-offset moveouts differ by much less than a period are not separated (a heuristic).
  • Time-invariant: one system per frequency serves all times, so the cost does not grow with the number of events.
  • Works on gathers with irregular offsets, since the xix_i enter only through the matrix entries.

Variants and improvements

  • High-resolution or sparse Radon transforms: replace the ∥m∥2\|m\|^2 penalty by a sparsity penalty and solve by reweighted least squares, so that each event focuses at one curvature (sparse signal recovery).
  • Time-domain hyperbolic Radon transforms, as in Thorson and Claerbout (1985): exact hyperbolas, at the cost of a large coupled system solved by iterative methods.
  • Linear Radon transform (slant stack) for events that are straight lines in the gather, such as ground roll and refractions.
  • Apex-shifted parabolas for diffracted multiples.
  • Subtract the multiples with an adaptive filter in place of the plain subtraction of line L8.

When to use it

Use it in processing before stacking, on gathers where multiples and primaries differ clearly in stacking velocity, usually at medium and far offsets and at later times. It is a standard step for marine data, often after surface-related multiple elimination has removed most of the surface multiples. It does not need a model of the surface or the source, only the moveout difference.

Pitfalls

  • At near offsets the moveout difference is small, so multiples there are not removed; this is a basic limit of the method.
  • A qq grid that is too narrow cannot hold the multiples, and a grid too coarse misses their curvatures.
  • The cut qcutq_{\text{cut}} must lie between the residual moveouts of primaries and multiples; a primary with a wrong NMO velocity curves and can be cut with the multiples.
  • Too little damping amplifies noise at low frequencies; too much damping smears the model and lets energy leak across the cut.
  • Aliasing in offset: if ωqx2\omega q x^2 changes by more than π\pi between neighboring traces at the highest frequency, the transform maps energy to wrong curvatures.
  • On a periodic time axis an event near the end of the record wraps to the start; pad the traces with zeros.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

imgkit.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the imaging and inverse problems pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small images and signals for the imaging and inverse problems pages.

Conventions:
- A signal is a list of numbers. An image is a list of rows, img[i][j], with
  row i from the top and column j from the left.
- An n x n image covers the square [-1, 1]^2. The center of pixel (i, j) is
  x_j = -1 + (2 j + 1) / n and y_i = 1 - (2 i + 1) / n, so y goes up.
- DFT: X_k = sum_j x_j exp(-2 pi i j k / n), unnormalized; the inverse has
  the factor 1 / n. Index k stands for frequency k for k < n / 2 and k - n
  otherwise. fftshift moves the zero frequency to position n // 2.
- Periodic convolution kernels are stored with their center at index 0
  (wrapped around), so a delta kernel gives the identity and no shift.
"""

import cmath
import math

# ------------------------------------------------------------------ images


def new_image(n1, n2, value=0.0):
    """An n1 x n2 image (n1 rows, n2 columns) filled with value."""
    return [[value] * n2 for _ in range(n1)]


def img_add(a, b):
    """The pixelwise sum a + b."""
    return [[x + y for x, y in zip(ra, rb)] for ra, rb in zip(a, b)]


def img_scale(a, c):
    """The image c a."""
    return [[c * x for x in row] for row in a]


def img_dot(a, b):
    """<a, b> = sum conj(a_ij) b_ij."""
    return sum(x.conjugate() * y for ra, rb in zip(a, b) for x, y in zip(ra, rb))


def img_norm(a):
    """The Euclidean (Frobenius) norm of an image."""
    return math.sqrt(sum(abs(x) ** 2 for row in a for x in row))


def flatten(img):
    """Row-major vector of an image."""
    return [x for row in img for x in row]


def unflatten(v, n1, n2):
    """The n1 x n2 image of a row-major vector."""
    return [list(v[i * n2:(i + 1) * n2]) for i in range(n1)]


# ------------------------------------------------------------------ DFT


def _is_pow2(n):
    return n > 0 and n & (n - 1) == 0


def _fft_pow2(x):
    """Iterative radix-2 FFT, unnormalized forward transform."""
    n = len(x)
    a = [complex(v) for v in x]
    j = 0
    for i in range(1, n):
        bit = n >> 1
        while j & bit:
            j ^= bit
            bit >>= 1
        j |= bit
        if i < j:
            a[i], a[j] = a[j], a[i]
    size = 2
    while size <= n:
        half = size // 2
        tw = [cmath.exp(-2j * math.pi * k / size) for k in range(half)]
        for start in range(0, n, size):
            for k in range(half):
                u = a[start + k]
                v = a[start + k + half] * tw[k]
                a[start + k] = u + v
                a[start + k + half] = u - v
        size *= 2
    return a


def dft(x):
    """X_k = sum_j x_j exp(-2 pi i j k / n). Radix-2 FFT when n is a power of 2."""
    n = len(x)
    if n == 0:
        return []
    if _is_pow2(n):
        return _fft_pow2(x)
    w = [cmath.exp(-2j * math.pi * t / n) for t in range(n)]
    return [sum(x[j] * w[(j * k) % n] for j in range(n)) for k in range(n)]


def idft(xf):
    """x_j = (1/n) sum_k X_k exp(2 pi i j k / n)."""
    n = len(xf)
    if n == 0:
        return []
    y = dft([complex(v).conjugate() for v in xf])
    return [v.conjugate() / n for v in y]


def _rows_then_cols(img, f):
    rows = [f(row) for row in img]
    cols = [f(list(col)) for col in zip(*rows)]
    return [list(r) for r in zip(*cols)]


def dft2(img):
    """2D DFT: X_kl = sum_jq x_jq exp(-2 pi i (j k / n1 + q l / n2))."""
    return _rows_then_cols(img, dft)


def idft2(img):
    """Inverse 2D DFT, with the factor 1 / (n1 n2)."""
    return _rows_then_cols(img, idft)


def _shift1(x, s):
    return list(x[s:]) + list(x[:s])


def fftshift(x):
    """Move the zero frequency to position n // 2 (1D, or both axes of an image)."""
    if x and isinstance(x[0], (list, tuple)):
        rows = [fftshift(r) for r in x]
        return _shift1(rows, (len(rows) + 1) // 2)
    return _shift1(x, (len(x) + 1) // 2)


def ifftshift(x):
    """The inverse of fftshift (1D, or both axes of an image)."""
    if x and isinstance(x[0], (list, tuple)):
        rows = [ifftshift(r) for r in x]
        return _shift1(rows, len(rows) // 2)
    return _shift1(x, len(x) // 2)


def circ_conv(x, h):
    """Periodic convolution y_i = sum_j h_j x_{(i - j) mod n}, kernel centered at index 0."""
    n = len(x)
    nz = [(j, hj) for j, hj in enumerate(h) if hj != 0]
    return [sum(hj * x[(i - j) % n] for j, hj in nz) for i in range(n)]


def circ_conv2(img, h):
    """Periodic 2D convolution with the kernel h centered at index (0, 0)."""
    n1, n2 = len(img), len(img[0])
    nz = [(p, q, h[p][q]) for p in range(len(h)) for q in range(len(h[0])) if h[p][q] != 0]
    out = new_image(n1, n2)
    for i in range(n1):
        for j in range(n2):
            out[i][j] = sum(v * img[(i - p) % n1][(j - q) % n2] for p, q, v in nz)
    return out


# ------------------------------------------------------------------ phantoms


def pixel_centers(n):
    """(xs, ys): xs[j] = -1 + (2 j + 1) / n and ys[i] = 1 - (2 i + 1) / n."""
    xs = [-1.0 + (2 * j + 1) / n for j in range(n)]
    ys = [1.0 - (2 * i + 1) / n for i in range(n)]
    return xs, ys


# Rows: rho, A, B, x0, y0, phi (degrees). A is the semi-axis along the
# direction phi (counterclockwise from the x axis), B the other semi-axis.
# Geometry and densities of Shepp and Logan (1974), as reproduced in Kak and
# Slaney, Principles of Computerized Tomographic Imaging, Table 3.1. The value
# at the center (0, 0) is 2 - 0.98 = 1.02.
SHEPP_LOGAN = [
    (2.0, 0.92, 0.69, 0.0, 0.0, 90.0),
    (-0.98, 0.874, 0.6624, 0.0, -0.0184, 90.0),
    (-0.02, 0.31, 0.11, 0.22, 0.0, 72.0),
    (-0.02, 0.41, 0.16, -0.22, 0.0, 108.0),
    (0.01, 0.25, 0.21, 0.0, 0.35, 90.0),
    (0.01, 0.046, 0.046, 0.0, 0.1, 0.0),
    (0.01, 0.046, 0.046, 0.0, -0.1, 0.0),
    (0.01, 0.046, 0.023, -0.08, -0.605, 0.0),
    (0.01, 0.023, 0.023, 0.0, -0.605, 0.0),
    (0.01, 0.046, 0.023, 0.06, -0.605, 90.0),
]

# The same ellipses with the gray levels of Toft (1996), which give more
# contrast. The value at the center is 1 - 0.8 = 0.2.
MODIFIED_SHEPP_LOGAN = [
    (rho, a, b, x0, y0, phi)
    for rho, (_, a, b, x0, y0, phi) in zip(
        (1.0, -0.8, -0.2, -0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1), SHEPP_LOGAN
    )
]


def ellipse_value(x, y, table):
    """The phantom value at the point (x, y): the sum of rho over the ellipses that hold it."""
    total = 0.0
    for rho, a, b, x0, y0, phi in table:
        c, s = math.cos(math.radians(phi)), math.sin(math.radians(phi))
        dx, dy = x - x0, y - y0
        u = dx * c + dy * s
        v = -dx * s + dy * c
        if (u / a) ** 2 + (v / b) ** 2 <= 1.0:
            total += rho
    return total


def ellipse_phantom(n, table):
    """The n x n image of an ellipse table, sampled at the pixel centers."""
    xs, ys = pixel_centers(n)
    return [[ellipse_value(x, y, table) for x in xs] for y in ys]


def disk_phantom(n, radius):
    """1 at pixel centers with x^2 + y^2 <= radius^2, 0 elsewhere."""
    xs, ys = pixel_centers(n)
    r2 = radius * radius
    return [[1.0 if x * x + y * y <= r2 else 0.0 for x in xs] for y in ys]


def spikes_1d(n, positions, amplitudes):
    """A signal of length n with the given amplitudes at the given positions."""
    out = [0.0] * n
    for p, a in zip(positions, amplitudes):
        out[p] += a
    return out


# ------------------------------------------------------------------ projector


def parallel_beam_matrix(n, angles, nbins):
    """Pixel-driven discrete Radon transform of an n x n image on [-1, 1]^2.

    Each pixel center (x, y) projects to s = x cos(theta) + y sin(theta). Its
    value times the pixel area over the bin width is split linearly between
    the two nearest bin centers. The bins cover [-sqrt(2), sqrt(2)]. Row
    a * nbins + b holds angle a and bin b; column i * n + j holds pixel (i, j).
    Returns the sparse rows, each a list of (column, weight) pairs.
    Pixel-driven projection has a ripple: with a bin width close to the pixel
    size, a disk projection is off by up to about 10 percent in some bins. A
    bin of about twice the pixel size (nbins = 23 for n = 32) keeps it near
    1 percent.
    """
    xs, ys = pixel_centers(n)
    smax = math.sqrt(2.0)
    width = 2.0 * smax / nbins
    scale = (2.0 / n) ** 2 / width
    rows = []
    for theta in angles:
        c, s = math.cos(theta), math.sin(theta)
        acc = [dict() for _ in range(nbins)]
        for i, y in enumerate(ys):
            for j, x in enumerate(xs):
                t = (x * c + y * s + smax) / width - 0.5
                b0 = math.floor(t)
                frac = t - b0
                col = i * n + j
                for b, w in ((b0, 1.0 - frac), (b0 + 1, frac)):
                    if 0 <= b < nbins and w > 0.0:
                        acc[b][col] = acc[b].get(col, 0.0) + w * scale
        rows.extend(sorted(d.items()) for d in acc)
    return rows


def sp_matvec(rows, x):
    """y = A x for sparse rows of (column, weight) pairs."""
    return [sum(w * x[c] for c, w in row) for row in rows]


def sp_rmatvec(rows, y, ncols):
    """x = A^H y for sparse rows of (column, weight) pairs and ncols columns."""
    out = [0.0] * ncols
    for row, yi in zip(rows, y):
        if yi == 0:
            continue
        for c, w in row:
            out[c] += w.conjugate() * yi
    return out


# ------------------------------------------------------------------ noise


def gauss_noise(rng, shape, sigma):
    """Independent N(0, sigma^2) values: a list for an int shape, an image for (n1, n2)."""
    if isinstance(shape, int):
        return [rng.gauss(0.0, sigma) for _ in range(shape)]
    n1, n2 = shape
    return [[rng.gauss(0.0, sigma) for _ in range(n2)] for _ in range(n1)]


def _poisson_small(rng, lam):
    """Knuth's product method, exact for a mean lam <= 30."""
    limit = math.exp(-lam)
    k, p = 0, rng.random()
    while p > limit:
        k += 1
        p *= rng.random()
    return k


def poisson_sample(rng, lam):
    """An exact Poisson(lam) sample: a sum of Knuth samples with means at most 30."""
    if lam < 0:
        raise ValueError("negative mean")
    total = 0
    while lam > 30.0:
        total += _poisson_small(rng, 30.0)
        lam -= 30.0
    if lam > 0.0:
        total += _poisson_small(rng, lam)
    return total
imgla.py 259 lines
# SPDX-License-Identifier: MIT
# Shared helper of the imaging and inverse problems pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Dense linear algebra on lists of rows (float, complex or Fraction entries).

A matrix is a list of rows. A vector is a list of numbers. The inner product
is <u, v> = sum_i conj(u_i) v_i, linear in the second argument, so that the
adjoint A^H satisfies <A x, y> = <x, A^H y>.
"""

import math


def _flat(x):
    """Flatten a list of rows (an image) into one list; a vector is returned as is."""
    if x and isinstance(x[0], (list, tuple)):
        return [v for row in x for v in row]
    return x


def zeros(m, n):
    """The m x n zero matrix."""
    return [[0.0] * n for _ in range(m)]


def eye(n):
    """The n x n identity matrix."""
    out = zeros(n, n)
    for i in range(n):
        out[i][i] = 1.0
    return out


def transpose(a):
    """A^T."""
    return [list(col) for col in zip(*a)]


def conj_transpose(a):
    """A^H, the conjugate transpose."""
    return [[v.conjugate() for v in col] for col in zip(*a)]


def matmul(a, b):
    """The product A B."""
    bt = list(zip(*b))
    return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]


def matvec(a, x):
    """The product A x."""
    return [sum(v * w for v, w in zip(row, x)) for row in a]


def rmatvec(a, y):
    """The product A^H y."""
    n = len(a[0]) if a else 0
    out = [0.0] * n
    for row, yi in zip(a, y):
        if yi == 0:
            continue
        for j, v in enumerate(row):
            out[j] += v.conjugate() * yi
    return out


def dot(u, v):
    """<u, v> = sum_i conj(u_i) v_i. Images (lists of rows) are flattened."""
    return sum(a.conjugate() * b for a, b in zip(_flat(u), _flat(v)))


def norm2(x):
    """The Euclidean norm. Images (lists of rows) are flattened."""
    return math.sqrt(sum(abs(v) ** 2 for v in _flat(x)))


def solve(a, b):
    """Solve A x = b by Gaussian elimination with partial pivoting.

    b is a vector or a matrix (a list of rows). A must be square and
    nonsingular; a zero pivot raises ValueError. Fractions stay exact.
    """
    n = len(a)
    vec = not (b and isinstance(b[0], (list, tuple)))
    rhs = [[bi] for bi in b] if vec else [list(r) for r in b]
    m = [list(row) + rhs[i] for i, row in enumerate(a)]
    w = len(m[0])
    for c in range(n):
        p = max(range(c, n), key=lambda r: abs(m[r][c]))
        if m[p][c] == 0:
            raise ValueError("singular matrix")
        m[c], m[p] = m[p], m[c]
        piv = m[c][c]
        for r in range(c + 1, n):
            f = m[r][c] / piv
            if f != 0:
                mr, mc = m[r], m[c]
                for j in range(c, w):
                    mr[j] -= f * mc[j]
    x = [[0.0] * (w - n) for _ in range(n)]
    for r in range(n - 1, -1, -1):
        for j in range(w - n):
            s = m[r][n + j] - sum(m[r][k] * x[k][j] for k in range(r + 1, n))
            x[r][j] = s / m[r][r]
    return [row[0] for row in x] if vec else x


def cholesky(a):
    """Lower triangular L with A = L L^H for a Hermitian positive definite A."""
    n = len(a)
    low = zeros(n, n)
    for j in range(n):
        d = a[j][j] - sum(abs(low[j][k]) ** 2 for k in range(j))
        d = d.real if isinstance(d, complex) else d
        if not d > 0:
            raise ValueError("matrix is not positive definite")
        ljj = math.sqrt(d)
        low[j][j] = ljj
        for i in range(j + 1, n):
            s = a[i][j] - sum(low[i][k] * low[j][k].conjugate() for k in range(j))
            low[i][j] = s / ljj
    return low


def cho_solve(low, b):
    """Solve (L L^H) x = b, with L from cholesky."""
    n = len(low)
    z = [0.0] * n
    for i in range(n):
        z[i] = (b[i] - sum(low[i][k] * z[k] for k in range(i))) / low[i][i]
    x = [0.0] * n
    for i in range(n - 1, -1, -1):
        s = z[i] - sum(low[k][i].conjugate() * x[k] for k in range(i + 1, n))
        x[i] = s / low[i][i].conjugate()
    return x


def _rot_params(app, aqq, apq):
    """c, s of the Jacobi rotation that zeroes the (p, q) entry of [[app, apq], [apq, aqq]]."""
    theta = (aqq - app) / (2.0 * apq)
    t = (1.0 if theta >= 0 else -1.0) / (abs(theta) + math.sqrt(theta * theta + 1.0))
    c = 1.0 / math.sqrt(1.0 + t * t)
    return c, c * t


def sym_eig(a, tol=1e-15, max_sweeps=100):
    """Eigenvalues (ascending) and eigenvectors (as columns) of a real symmetric matrix.

    Cyclic Jacobi method. Returns (w, Q) with A = Q diag(w) Q^T.
    """
    n = len(a)
    m = [[float(v) for v in row] for row in a]
    q = eye(n)
    for _ in range(max_sweeps):
        off = sum(m[i][j] ** 2 for i in range(n) for j in range(n) if i != j)
        scale = sum(m[i][i] ** 2 for i in range(n)) + off
        if off <= (tol * tol) * scale or off == 0.0:
            break
        for p in range(n - 1):
            for r in range(p + 1, n):
                apq = m[p][r]
                if apq == 0.0:
                    continue
                c, s = _rot_params(m[p][p], m[r][r], apq)
                for k in range(n):
                    mkp, mkr = m[k][p], m[k][r]
                    m[k][p] = c * mkp - s * mkr
                    m[k][r] = s * mkp + c * mkr
                mp, mr = m[p], m[r]
                for k in range(n):
                    mpk, mrk = mp[k], mr[k]
                    mp[k] = c * mpk - s * mrk
                    mr[k] = s * mpk + c * mrk
                m[p][r] = m[r][p] = 0.0
                for k in range(n):
                    qkp, qkr = q[k][p], q[k][r]
                    q[k][p] = c * qkp - s * qkr
                    q[k][r] = s * qkp + c * qkr
    order = sorted(range(n), key=lambda i: m[i][i])
    w = [m[i][i] for i in order]
    qs = [[q[k][i] for i in order] for k in range(n)]
    return w, qs


def _complete(cols, m):
    """Replace zero columns of an m-row column list by unit vectors orthogonal to the others."""
    for idx, col in enumerate(cols):
        if any(v != 0.0 for v in col):
            continue
        for e in range(m):
            cand = [0.0] * m
            cand[e] = 1.0
            for _ in range(2):
                for jdx, other in enumerate(cols):
                    if jdx == idx or not any(v != 0.0 for v in other):
                        continue
                    h = sum(a * b for a, b in zip(other, cand))
                    cand = [a - h * b for a, b in zip(cand, other)]
            nrm = math.sqrt(sum(v * v for v in cand))
            if nrm > 0.5:
                cols[idx] = [v / nrm for v in cand]
                break
    return cols


def svd(a, tol=1e-15, max_sweeps=100):
    """Thin SVD of a real m x n matrix by one-sided Jacobi (Hestenes).

    Returns (U, S, V) with p = min(m, n): U is m x p, S a list of p values in
    descending order, V is n x p, U^T U = I, V^T V = I and A = U diag(S) V^T.
    """
    m, n = len(a), len(a[0])
    if m < n:
        v, s, u = svd(transpose(a), tol, max_sweeps)
        return u, s, v
    cols = [[float(a[i][j]) for i in range(m)] for j in range(n)]
    vcols = [[1.0 if i == j else 0.0 for i in range(n)] for j in range(n)]
    for _ in range(max_sweeps):
        rotated = False
        for p in range(n - 1):
            for r in range(p + 1, n):
                cp, cr = cols[p], cols[r]
                alpha = sum(x * x for x in cp)
                beta = sum(x * x for x in cr)
                gamma = sum(x * y for x, y in zip(cp, cr))
                if gamma == 0.0 or abs(gamma) <= tol * math.sqrt(alpha * beta):
                    continue
                rotated = True
                c, s = _rot_params(alpha, beta, gamma)
                cols[p] = [c * x - s * y for x, y in zip(cp, cr)]
                cols[r] = [s * x + c * y for x, y in zip(cp, cr)]
                vp, vr = vcols[p], vcols[r]
                vcols[p] = [c * x - s * y for x, y in zip(vp, vr)]
                vcols[r] = [s * x + c * y for x, y in zip(vp, vr)]
        if not rotated:
            break
    sig = [math.sqrt(sum(x * x for x in col)) for col in cols]
    # A column below 1e-150 times the largest one is zero to working precision;
    # its squares underflow, so its direction carries no information.
    floor = max(sig) * 1e-150 if sig else 0.0
    sig = [t if t > floor and t > 1e-150 else 0.0 for t in sig]
    order = sorted(range(n), key=lambda j: -sig[j])
    s_out = [sig[j] for j in order]
    ucols = [[x / sig[j] for x in cols[j]] if sig[j] > 0.0 else [0.0] * m for j in order]
    ucols = _complete(ucols, m)
    u = [[ucols[j][i] for j in range(n)] for i in range(m)]
    v = [[vcols[j][i] for j in order] for i in range(n)]
    return u, s_out, v


def adjoint_gap(apply_a, apply_ah, x, y):
    """|<A x, y> - <x, A^H y>| / (||A x|| ||y||) for given functions A and A^H.

    x and y may be vectors or images (lists of rows). If the denominator is
    zero, the absolute gap is returned.
    """
    ax = apply_a(x)
    gap = abs(dot(ax, y) - dot(x, apply_ah(y)))
    den = norm2(ax) * norm2(y)
    return gap / den if den > 0.0 else gap
parabolic_radon_transform.py 114 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/parabolic-radon-transform/. The authors are listed in prov/5J6KMF.jsonl.
"""The least-squares parabolic Radon transform and its use for multiple removal.

A gather is a list of traces d[i] (offset x_i), each with n samples at k * dt.
A model is a list of traces m[j] (curvature q_j in s/m^2) with n samples at
tau = k * dt. The forward operator sums the model along parabolas,

    d(t, x_i) = sum_j m(t - q_j x_i^2, q_j),

with the time shifts done exactly in the frequency domain on a periodic time
axis. For each frequency w_k = 2 pi k' / (n dt) (k' the signed index) it is
the matrix L_k[i][j] = exp(-1j w_k q_j x_i^2), and the damped least-squares
model is M_k = (L_k^H L_k + mu I)^(-1) L_k^H D_k. Use an odd n: then there is
no Nyquist bin, a real model gives real data, and the shifts are exact.
"""

import cmath
import math

import imgkit as ik
import imgla as la


def omega(k, n, dt):
    """The angular frequency of DFT bin k (signed index k or k - n)."""
    ks = k if k <= n // 2 else k - n
    return 2.0 * math.pi * ks / (n * dt)


def operator_matrix(w, offsets, qs):
    """L[i][j] = exp(-1j w q_j x_i^2)."""
    return [[cmath.exp(-1j * w * q * x * x) for q in qs] for x in offsets]


def _spectra(traces):
    return [ik.dft(tr) for tr in traces]


def _traces(spectra):
    return [[v.real for v in ik.idft(sp)] for sp in spectra]


def forward(m, offsets, qs, dt):
    """d = L m: sum the model traces along the parabolas t = tau + q x^2."""
    n = len(m[0])
    mf = _spectra(m)
    df = [[0j] * n for _ in offsets]
    for k in range(n):
        lk = operator_matrix(omega(k, n, dt), offsets, qs)
        col = la.matvec(lk, [mf[j][k] for j in range(len(qs))])
        for i in range(len(offsets)):
            df[i][k] = col[i]
    return _traces(df)


def adjoint(d, offsets, qs, dt):
    """m = L^T d: the plain parabolic stack (sum the data along each parabola)."""
    n = len(d[0])
    dfs = _spectra(d)
    mf = [[0j] * n for _ in qs]
    for k in range(n):
        lk = operator_matrix(omega(k, n, dt), offsets, qs)
        col = la.rmatvec(lk, [dfs[i][k] for i in range(len(offsets))])
        for j in range(len(qs)):
            mf[j][k] = col[j]
    return _traces(mf)


def demultiple(d, offsets, qs, dt, mu, q_cut):
    """Least-squares parabolic Radon transform and multiple removal.

    d must be NMO-corrected with the primary velocity, so the primaries are
    flat (q near 0) and the multiples curve down (q > 0). Returns
    (m, primaries, multiples): the model, d minus the predicted multiples,
    and the predicted multiples (built from the model at q_j > q_cut).
    """
    n = len(d[0])
    nq = len(qs)
    dfs = _spectra(d)  # @line L1
    mf = [[0j] * n for _ in qs]
    mulf = [[0j] * n for _ in offsets]
    for k in range(n):  # @line L2
        lk = operator_matrix(omega(k, n, dt), offsets, qs)  # @line L3
        dk = [dfs[i][k] for i in range(len(offsets))]
        lh = la.conj_transpose(lk)
        normal = la.matmul(lh, lk)
        for j in range(nq):
            normal[j][j] += mu
        mk = la.solve(normal, la.matvec(lh, dk))  # @line L4
        keep = [mk[j] if qs[j] > q_cut else 0j for j in range(nq)]  # @line L5
        dmul = la.matvec(lk, keep)  # @line L6
        for j in range(nq):
            mf[j][k] = mk[j]
        for i in range(len(offsets)):
            mulf[i][k] = dmul[i]
    m = _traces(mf)  # @line L7
    multiples = _traces(mulf)
    primaries = [[a - b for a, b in zip(tr, mt)] for tr, mt in zip(d, multiples)]
    return m, primaries, multiples  # @line L8


def residual_moveout(t0, x, v_primary, v_multiple):
    """Exact residual time of a multiple after NMO with the primary velocity.

    The multiple arrives at sqrt(t0^2 + x^2 / v_multiple^2); NMO with
    v_primary maps it to sqrt(t0^2 + x^2 (1 / v_multiple^2 - 1 / v_primary^2)).
    """
    return math.sqrt(t0 * t0 + x * x * (1.0 / v_multiple ** 2 - 1.0 / v_primary ** 2)) - t0


def parabolic_curvature(t0, v_primary, v_multiple):
    """q = (1 / v_multiple^2 - 1 / v_primary^2) / (2 t0), the small-offset parabola."""
    return (1.0 / v_multiple ** 2 - 1.0 / v_primary ** 2) / (2.0 * t0)
test_parabolic_radon_transform.py 100 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/parabolic-radon-transform/. The authors are listed in prov/5J6KMF.jsonl.

import math
import random

import imgla as la
from parabolic_radon_transform import (
    adjoint,
    demultiple,
    forward,
    parabolic_curvature,
    residual_moveout,
)


def ricker(t, f=20.0):
    a = (math.pi * f * t) ** 2
    return (1.0 - 2.0 * a) * math.exp(-a)


def flat(rows):
    return [v for r in rows for v in r]


def rel_err(a, b):
    num = math.sqrt(sum((p - q) ** 2 for p, q in zip(flat(a), flat(b))))
    return num / math.sqrt(sum(q * q for q in flat(b)))


def test_example_numbers():
    assert abs(residual_moveout(1.0, 2000.0, 2500.0, 2000.0) - 0.16619) < 1e-5
    q = parabolic_curvature(1.0, 2500.0, 2000.0)
    assert abs(q - 4.5e-8) < 1e-20
    assert abs(q * 2000.0 ** 2 - 0.18) < 1e-12


def test_integer_shift_is_exact():
    n, dt = 15, 0.004
    x = 200.0
    q = 3 * dt / (x * x)
    rng = random.Random(1)
    tr = [rng.gauss(0.0, 1.0) for _ in range(n)]
    d = forward([tr], [0.0, x], [q], dt)
    assert max(abs(a - b) for a, b in zip(d[0], tr)) < 1e-12
    shifted = [tr[(k - 3) % n] for k in range(n)]
    assert max(abs(a - b) for a, b in zip(d[1], shifted)) < 1e-12


def test_adjoint():
    rng = random.Random(2)
    n, dt = 21, 0.004
    offsets = [0.0, 150.0, 400.0, 700.0, 900.0]
    qs = [-1e-8, 0.0, 2e-8, 5e-8]
    x = [[rng.gauss(0.0, 1.0) for _ in range(n)] for _ in qs]
    y = [[rng.gauss(0.0, 1.0) for _ in range(n)] for _ in offsets]
    gap = la.adjoint_gap(lambda v: forward(v, offsets, qs, dt),
                         lambda v: adjoint(v, offsets, qs, dt), x, y)
    assert gap < 1e-12


def test_equals_dense_time_domain_least_squares():
    rng = random.Random(3)
    n, dt, mu = 7, 0.004, 0.3
    offsets = [0.0, 300.0, 600.0]
    qs = [0.0, 1.5e-8]
    d = [[rng.gauss(0.0, 1.0) for _ in range(n)] for _ in offsets]
    cols = []
    for j in range(len(qs)):
        for k in range(n):
            e = [[0.0] * n for _ in qs]
            e[j][k] = 1.0
            cols.append(flat(forward(e, offsets, qs, dt)))
    a = la.transpose(cols)
    at = cols
    normal = la.matmul(at, a)
    for i in range(len(normal)):
        normal[i][i] += mu
    m_dense = la.solve(normal, la.matvec(at, flat(d)))
    m, _, _ = demultiple(d, offsets, qs, dt, mu, q_cut=1.0)
    assert max(abs(p - q) for p, q in zip(flat(m), m_dense)) < 1e-9


def test_removes_a_curved_multiple():
    n, dt = 63, 0.008
    offsets = [100.0 * i for i in range(16)]
    qs = [-1e-8 + 0.5e-8 * j for j in range(14)]
    jp, jm = 2, 10
    model = [[0.0] * n for _ in qs]
    model[jp] = [ricker(k * dt - 0.15) for k in range(n)]
    model[jm] = [-0.7 * ricker(k * dt - 0.2) for k in range(n)]
    d = forward(model, offsets, qs, dt)
    only_primary = [row if j == jp else [0.0] * n for j, row in enumerate(model)]
    p_true = forward(only_primary, offsets, qs, dt)
    m, primaries, multiples = demultiple(d, offsets, qs, dt, 1e-2, 1.2e-8)
    assert rel_err(d, p_true) > 0.69
    assert rel_err(primaries, p_true) < 0.15
    energy = [sum(v * v for v in row) for row in m]
    assert max(range(len(qs)), key=lambda j: energy[j]) in (jp, jm)
    assert energy[jm] > 10 * energy[jm - 4]

History

Thorson and Claerbout (1985) described the velocity stack and the slant stack as inverse problems: the model is the set of events in velocity or ray parameter, and it is found by fitting the data in the least-squares sense with a prior on the model. Hampson (1986) proposed to work on gathers after NMO correction, where the residual moveout of multiples is close to a parabola. A parabolic moveout is a pure time shift, so the least-squares problem splits by frequency into small systems. This made the method fast enough for production processing, and the parabolic Radon demultiple became a standard step in seismic processing.

References

  1. Dan Hampson, Inverse velocity stacking for multiple elimination, Journal of the Canadian Society of Exploration Geophysicists 22(1), 1986, 44 to 55, the parabolic approximation of the residual moveout after NMO, the least-squares transform solved frequency by frequency, and the subtraction of the multiples
  2. Dan Hampson, Inverse velocity stacking for multiple elimination, SEG Technical Program Expanded Abstracts 1986, 422 to 424, the short conference version of the method
  3. John R. Thorson and Jon F. Claerbout, Velocity-stack and slant-stack stochastic inversion, Geophysics 50(12), 1985, 2727 to 2741, the velocity stack and the slant stack posed as inverse problems with a least-squares fit and a model prior
  4. Oz Yilmaz, Seismic Data Analysis, Society of Exploration Geophysicists, 2001, Investigations in Geophysics 10, the chapter on multiple attenuation (the parabolic Radon transform and its use to separate primaries and multiples)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.average
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example