Algorithm Search⌘K

Algorithmadvanced

Split-step Fourier migration

Also called SSF migration.

Extrapolate a wavefield in depth by a phase shift with a reference velocity in the wavenumber domain and a lateral velocity correction in space.

Time
O(z t x log x + x t log t) totalO(x log x) per_step
Space
O(t x + z x) extra
Where
t = the number of time samples; x = the number of traces; z = the number of depth steps
Properties
deterministiclateral velocityunconditionally stable
Origin
Paul L. Stoffa, Jacob T. Fokkema, Rui M. de Luna Freire, William P. Kessinger, 1990

Split-step Fourier migration extends phase-shift migration to a velocity that changes along xx. For each frequency and each depth step it does two things. First it applies the phase shift of one reference slowness s0s_0, the mean over the layer, in the wavenumber domain. Then it goes back to the space domain and multiplies every point by eiω(s(x)−s0)Δze^{i\omega(s(x) - s_0)\Delta z}, a thin-lens correction for the local slowness. When the velocity does not change along xx the correction is 1 and the method is exactly phase shift (a theorem). Otherwise it has a phase error that is zero for vertical waves and grows with the square of the propagation angle and with the velocity contrast (a theorem for one plane wave; how the errors add up in a general medium is a heuristic).

In plain words

Phase-shift migration moves the recorded wave down into the ground one step at a time, but it needs the same speed everywhere across each step. Split-step Fourier migration allows the speed to change from left to right. At each step it first moves the whole wave down as if the layer had its average speed. Then it fixes each point: where the ground is slower than average, the wave should arrive later, so the method turns the phase at that point a little more, and where the ground is faster, a little less. The fix is exact for waves that go straight up and down, and it gets worse for waves that travel at a steep angle through strong speed changes. Each step costs two fast Fourier transforms.

The problem

Given a zero-offset section d(t,x)d(t, x) and a velocity v(x,z)v(x, z) on the image grid (the value vi[j]v_i[j] for the layer iΔz≤z<(i+1)Δzi\Delta z \le z < (i + 1)\Delta z at xjx_j), find the image m(x,z)m(x, z). This is seismic migration in the exploding reflector model, so the method uses the slowness s=2/vs = 2/v of the half velocity.

The algorithm

The time transform is U(ω)=∑tu(t)e−iωtU(\omega) = \sum_t u(t)e^{-i\omega t} and the space transform uses e−ikxxe^{-i k_x x}. For a real section the negative frequencies are complex conjugates of the positive ones, so the method continues only 0<ω<ωNyquist0 < \omega < \omega_{\text{Nyquist}} and takes twice the real part.

  1. SPLIT-STEP-FOURIER-MIGRATION(d, Δt, Δx, Δz, v) ▷ v[i][j]: velocity of layer i at x_j
  2. 1P_k ← DFT in time of every trace, for every frequency index k
  3. 2for every frequency ω = ω_k with 0 < ω_k < the Nyquist frequency do ▷ p ← P_k
  4. 3for i ← 0 to n_z - 1 do
  5. 4image[i] ← image[i] + (2 / n_t) Re p
  6. 5s[j] ← 2 / v[i][j] for every j; s_0 ← mean of s
  7. 6q ← DFT(p)
  8. 7q[j] ← q[j] · exp(i sqrt(ω² s_0² - k_x,j²) Δz) for every j, or 0 where the root is not real
  9. 8p ← IDFT(q)
  10. 9p[j] ← p[j] · exp(i ω (s[j] - s_0) Δz) for every j
  11. 10return image

Line L1 transforms every trace in time once. For one frequency, the vector pp holds the field at the current depth along xx. Line L4 adds the contribution of this frequency to the image row: the field at t=0t = 0 is the sum over all frequencies divided by ntn_t, and the positive and negative frequencies together give twice the real part. Line L5 computes the slowness of the half velocity and its mean. Lines L6 to L8 are the phase shift of phase-shift migration with the reference slowness s0s_0, applied in the wavenumber domain; the evanescent waves are removed. Line L9 is the split step: a phase correction in the space domain for the difference between the local and the reference slowness.

Example

One plane wave by hand. Take ω=100\omega = 100 rad/s, Δz=10\Delta z = 10 m, a reference half velocity of 1500 m/s (s0=1/1500s_0 = 1/1500 s/m) and a local half velocity of 1250 m/s (s=1/1250s = 1/1250 s/m), and the wavenumber kx=0.04k_x = 0.04 rad/m, which is a wave at 30 degrees in the local medium. The exact phase over one step is 100.082−0.042=0.692810\sqrt{0.08^2 - 0.04^2} = 0.6928 rad. The split step gives 100.066672−0.042+100⋅(0.0008−0.0006667)⋅10=0.5333+0.1333=0.666710\sqrt{0.06667^2 - 0.04^2} + 100 \cdot (0.0008 - 0.0006667) \cdot 10 = 0.5333 + 0.1333 = 0.6667 rad. The error is −0.0262-0.0262 rad per step. The leading term of the error formula below gives 10⋅0.042/(2⋅100)⋅(1250−1500)=−0.02010 \cdot 0.04^2/(2 \cdot 100) \cdot (1250 - 1500) = -0.020 rad. For a vertical wave (kx=0k_x = 0) the error is zero.

Tests. For a velocity that changes only with depth (2500 m/s over 3000 m/s), the image equals the phase-shift image computed from the same positive frequencies within 10−910^{-9}. For a velocity 3000+300cos⁡(2πj/32)3000 + 300\cos(2\pi j/32) m/s that changes along xx and a flat reflector at 240 m, every column of the image peaks at the right depth row (a measurement on this case).

Correctness

The full proof is in proofs/correctness.md.

  • What the code computes (theorem). Line L10 returns (2/nt)Re⁡∑0<k<nt/2pk(i)(2/n_t)\operatorname{Re}\sum_{0 < k < n_t/2} p_k^{(i)}, where pk(i)p_k^{(i)} is the trace spectrum at index kk after ii split steps. Because the step for −ω-\omega is the complex conjugate of the step for ω\omega, this is the field at t=0t = 0 of the continued data without the zero and Nyquist frequencies.
  • Exact for v(z)v(z) (theorem). If the velocity does not change along xx in any layer, then s=s0s = s_0, line L9 does nothing, and the method is phase-shift migration.
  • Phase error for one plane wave (theorem). In a layer of slowness ss treated with the reference s0s_0, the error of one step is Δz(ω2s02−kx2+ω(s−s0)−ω2s2−kx2)\Delta z\big(\sqrt{\omega^2 s_0^2 - k_x^2} + \omega(s - s_0) - \sqrt{\omega^2 s^2 - k_x^2}\big). It is zero for kx=0k_x = 0 or s=s0s = s_0, and its leading term is Δz kx22ω(1s−1s0)\Delta z\,\frac{k_x^2}{2\omega}\big(\frac{1}{s} - \frac{1}{s_0}\big).
  • Stability (theorem). Every factor has modulus at most 1, so no step increases the energy, for any Δz\Delta z.

That the local plane-wave errors stay small in a smooth medium with moderate contrast is a heuristic, supported by the cosine test above.

Proof: Correctness of split-step Fourier migrationfull

Setting. The model is the exploding reflector model with the slowness s(x,z)=2/v(x,z)s(x, z) = 2/v(x, z) of the half velocity. The velocity is constant in depth inside each layer zi≤z<zi+1z_i \le z < z_{i+1}, with the values si[j]s_i[j] at xj=jΔxx_j = j\Delta x, and s0,i=1nx∑jsi[j]s_{0,i} = \frac{1}{n_x}\sum_j s_i[j] is the reference slowness of line L5. The time transform is U(ω)=∑u(t) e−iωtU(\omega) = \sum u(t)\, e^{-i\omega t}, and ωk=2πk/(ntΔt)\omega_k = 2\pi k/(n_t\Delta t). For a frequency ω\omega and a layer ii, one step of the method is the linear map Aω,iA_{\omega, i} of lines L6 to L9:

Aω,i p=Λω,i  IDFT(Φω,i  DFT(p)),A_{\omega, i}\, p = \Lambda_{\omega, i}\; \mathrm{IDFT}\big(\Phi_{\omega, i}\; \mathrm{DFT}(p)\big),

where Φω,i\Phi_{\omega, i} multiplies entry jj by eiω2s0,i2−kx,j2 Δze^{i\sqrt{\omega^2 s_{0,i}^2 - k_{x,j}^2}\,\Delta z} if the root is real and by 0 otherwise, and Λω,i\Lambda_{\omega, i} multiplies entry jj by eiω(si[j]−s0,i)Δze^{i\omega(s_i[j] - s_{0,i})\Delta z}.

Theorem 1 (what the code computes). Let pk(i)=Aωk,i−1⋯Aωk,0 pk(0)p_k^{(i)} = A_{\omega_k, i-1}\cdots A_{\omega_k, 0}\, p_k^{(0)}, where pk(0)[j]p_k^{(0)}[j] is the DFT of trace jj at index kk (line L1). Then line L10 returns

m[i][j]=2ntRe⁡∑0<k<nt/2pk(i)[j].m[i][j] = \frac{2}{n_t} \operatorname{Re} \sum_{0 < k < n_t/2} p_k^{(i)}[j].

Proof. Line L2 runs over k=1,…,⌈nt/2⌉−1k = 1, \ldots, \lceil n_t/2\rceil - 1, which is the set 0<k<nt/20 < k < n_t/2. Fix kk. By induction on ii, at the start of pass ii of line L3 the array pp is pk(i)p_k^{(i)}: it is pk(0)p_k^{(0)} before pass 0, and lines L6 to L9 apply Aωk,iA_{\omega_k, i} once (line L7 is Φ\Phi, line L9 is Λ\Lambda). Line L4 adds 2ntRe⁡pk(i)[j]\frac{2}{n_t}\operatorname{Re} p_k^{(i)}[j] to row ii before the step. The loops have a fixed number of passes, so the algorithm stops. ■\blacksquare

Lemma 1 (the positive frequencies are enough). Let qkq_k be any family of continued fields with qnt−k=qk‾q_{n_t - k} = \overline{q_k} (the symmetry of the DFT of real traces). Then the inverse DFT in time at t=0t = 0 is

1nt∑k=0nt−1qk=1nt(q0+[ qnt/2 ]+2Re⁡∑0<k<nt/2qk),\frac{1}{n_t}\sum_{k=0}^{n_t - 1} q_k = \frac{1}{n_t}\Big(q_0 + [\,q_{n_t/2}\,] + 2\operatorname{Re}\sum_{0 < k < n_t/2} q_k\Big),

where the term in brackets is present only for even ntn_t.

Proof. Pair the index kk with nt−kn_t - k for 0<k<nt/20 < k < n_t/2; each pair adds qk+qk‾=2Re⁡qkq_k + \overline{q_k} = 2\operatorname{Re} q_k. The indices 00 and nt/2n_t/2 are their own partners. □\square

The continuation keeps the symmetry: the step for −ω-\omega uses kz=−ω2s02−kx2k_z = -\sqrt{\omega^2 s_0^2 - k_x^2} and the factor e−iω(s−s0)Δze^{-i\omega(s - s_0)\Delta z}, and both factors depend on kxk_x only through kx2k_x^2, so A−ω,i pˉ=Aω,i p‾A_{-\omega, i}\,\bar{p} = \overline{A_{\omega, i}\, p}. So by Lemma 1, Theorem 1 gives the field at t=0t = 0 of the continued data after the frequency ω=0\omega = 0 and (for even ntn_t) the Nyquist frequency are removed. The image is real.

Theorem 2 (exact when the velocity does not change along xx). If si[j]=sis_i[j] = s_i for all jj in every layer, the output is the phase-shift image of the same data without the frequency 0 and the Nyquist frequency. In particular, for a velocity v(z)v(z) the method is exact in the sense of the proof of phase-shift migration.

Proof. Then s0,i=sis_{0,i} = s_i, so Λω,i=I\Lambda_{\omega, i} = I, and Aω,iA_{\omega, i} is the inverse DFT of the phase shift with kz=ω2si2−kx2k_z = \sqrt{\omega^2 s_i^2 - k_x^2}, the evanescent parts set to zero. For ω>0\omega > 0 and si=2/vis_i = 2/v_i this is sgn⁡(ω)ω2/vi′2−kx2\operatorname{sgn}(\omega)\sqrt{\omega^2/v_i'^2 - k_x^2} with vi′=vi/2v_i' = v_i/2: the factor of the phase-shift loop invariant, applied in the xx domain. Apply Lemma 1 to both methods. □\square

Theorem 3 (the phase error for a plane wave). Suppose a layer has the constant slowness ss but the step uses a reference s0s_0 (as happens locally where s(x)s(x) differs from its mean). For a propagating plane wave eikxxe^{i k_x x} with both roots real, the step gives the phase Δz(ω2s02−kx2+ω(s−s0))\Delta z\big(\sqrt{\omega^2 s_0^2 - k_x^2} + \omega(s - s_0)\big), while the exact phase is Δzω2s2−kx2\Delta z\sqrt{\omega^2 s^2 - k_x^2}. The error

E=Δz(ω2s02−kx2+ω(s−s0)−ω2s2−kx2)E = \Delta z\Big(\sqrt{\omega^2 s_0^2 - k_x^2} + \omega(s - s_0) - \sqrt{\omega^2 s^2 - k_x^2}\Big)

is 0 when kx=0k_x = 0 or s=s0s = s_0, and

E=Δz kx22ω(1s−1s0)+O(Δz kx4ω3)(1s3+1s03).E = \Delta z\,\frac{k_x^2}{2\omega}\Big(\frac{1}{s} - \frac{1}{s_0}\Big) + O\Big(\Delta z\,\frac{k_x^4}{\omega^3}\Big)\Big(\frac{1}{s^3} + \frac{1}{s_0^3}\Big).

Proof. For kx=0k_x = 0 the two roots are ωs0\omega s_0 and ωs\omega s, and the sum cancels. For s=s0s = s_0 the correction is 0 and the roots agree. For the expansion use ω2a2−kx2=ωa−kx22ωa+O(kx4ω3a3)\sqrt{\omega^2 a^2 - k_x^2} = \omega a - \frac{k_x^2}{2\omega a} + O\big(\frac{k_x^4}{\omega^3 a^3}\big) for a=s0a = s_0 and a=sa = s; the terms ωs0\omega s_0, ω(s−s0)\omega(s - s_0) and −ωs-\omega s cancel. □\square

So the error grows with the square of the propagation angle (kx=ωssin⁡θk_x = \omega s \sin\theta) and with the slowness contrast ∣1/s−1/s0∣|1/s - 1/s_0|. Vertical waves are always continued exactly. How these local errors add up in a medium with a smooth s(x)s(x) is not proved here; the statement that the method is accurate for moderate contrasts and angles is a heuristic, supported by the test with a lateral cosine velocity (every column focuses at the true depth).

Energy. Φ\Phi multiplies the propagating coefficients by numbers of modulus 1 and removes the others, and Λ\Lambda has modulus 1 everywhere. So each step does not increase the energy ∑j∣p[j]∣2\sum_j |p[j]|^2, and the method is unconditionally stable for every Δz\Delta z.

Complexity

  • Real-ram, with FFTs. Line L1 costs O(nxntlog⁡nt)O(n_x n_t \log n_t). Each depth step for one frequency costs two FFTs of length nxn_x and O(nx)O(n_x) phase factors, O(nxlog⁡nx)O(n_x \log n_x). With about nt/2n_t/2 frequencies and nzn_z steps the total is O(nzntnxlog⁡nx)O(n_z n_t n_x \log n_x).
  • Against phase shift. Phase shift costs O(nx)O(n_x) per step and frequency once the data are in the wavenumber domain, so the split step costs a factor log⁡nx\log n_x more for its two transforms.
  • Space. One complex vector per frequency during its loop, and the image.

Properties

  • Lateral velocity. The correction uses the local slowness at every point, so the image follows lateral velocity changes, with an error that depends on the angle and the contrast.
  • Exact vertical propagation. Waves that travel straight up are continued exactly in any v(x,z)v(x, z).
  • Unconditionally stable. All factors have modulus at most 1.
  • Frequencies are independent. Each frequency is continued alone, so the loop at line L2 runs in parallel without communication.
  • Periodic in xx. The DFT in line L6 makes the field periodic along the line; pad with zeros or taper the edges.

Variants and improvements

  • Several reference velocities. Phase shift plus interpolation (Gazdag and Sguazzero 1984) runs the phase shift with a few reference velocities and interpolates at each xx; this reduces the error for large contrasts.
  • Fourier finite difference. Add a finite-difference correction term to the split step to reduce the angle error, in the spirit of finite-difference migration.
  • Generalized screen methods. Higher-order terms in the expansion of the square root about the reference slowness improve wide-angle accuracy.
  • Prestack migration. The same step continues the source and the receiver wavefields separately in shot-profile migration, followed by the imaging condition.
  • The angular spectrum method. The reference step alone is the angular spectrum propagator of optics, and the split step is the beam propagation method used for optical fibers and turbulence.

When to use it

Use split-step Fourier migration when the velocity changes along xx but not too strongly, and when one-way migration is enough (no turning waves). It costs little more than phase shift and handles lateral changes that phase shift and Stolt migration cannot. For strong contrasts, such as salt bodies, use several reference velocities, a Fourier finite-difference correction, or reverse-time migration.

Pitfalls

  • A reference far from the local velocity. Taking s0s_0 in line L5 from one corner of the layer instead of its mean makes ∣s−s0∣|s - s_0| large and the angle error large everywhere. Use the mean (or several references), as in line L5.
  • The correction in the wrong domain. Applying the factor of line L9 in the wavenumber domain, before line L8, multiplies wavenumbers by a function of xx, which has no meaning. Apply it after the inverse transform of line L8.
  • The full velocity. Using s=1/vs = 1/v in line L5 doubles every depth. Zero-offset data need s=2/vs = 2/v.
  • Dropping the factor 2. Line L4 continues only the positive frequencies; without the factor 2/nt2/n_t the image has half its amplitude.

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
split_step_fourier_migration.py 71 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/split-step-fourier-migration/. The authors are listed in prov/C572NA.jsonl.
"""Split-step Fourier migration of a zero-offset section for a velocity v(x, z).

Conventions (the imaging and inverse problems pages):
- data[k][j] is the zero-offset sample at the two-way time t = k * dt and the
  surface position x = j * dx. vel[i][j] is the velocity (m/s) between the
  depths i dz and (i + 1) dz at x = j dx. image[i][j] is the image at depth i dz.
- U(omega) = sum u(t) exp(-i omega t); the x transform uses exp(-i kx x).
- Exploding reflector model: the slowness used is s = 2 / v (the slowness of
  the half velocity v / 2). Downward continuation by dz multiplies by
  exp(+i kz dz), kz = sgn(omega) sqrt(omega^2 s0^2 - kx^2).
- One step: a phase shift with the reference slowness s0 (the mean of s over
  x in the layer) in the (omega, kx) domain, then the correction
  exp(i omega (s(x) - s0) dz) in the (omega, x) domain.
- Only the frequencies 0 < omega < the Nyquist frequency are continued. The
  data are real, so the image is (2 / nt) Re sum over these frequencies.

Cost per frequency and depth step: two FFTs of length nx and O(nx) phase
factors, so O(nz * nt * nx log nx) in total with radix-2 FFTs.
"""

import cmath
import math

from imgkit import dft, idft


def kx_values(nx, dx):
    """The angular wavenumbers of the DFT indices 0 .. nx - 1."""
    return [2.0 * math.pi * (j if 2 * j < nx else j - nx) / (nx * dx) for j in range(nx)]


def split_step_fourier_migration(data, dt, dx, dz, vel):
    """Migrate a zero-offset section with the split-step Fourier method.

    data: nt x nx real samples; vel: nz x nx velocities. Returns the nz x nx
    image. Precondition: dt, dx, dz > 0 and every velocity > 0.
    """
    nt, nx = len(data), len(data[0])
    nz = len(vel)
    kxs = kx_values(nx, dx)
    spectra = [dft([data[k][j] for k in range(nt)]) for j in range(nx)]  # @line L1
    image = [[0.0] * nx for _ in range(nz)]
    for k in range(1, (nt + 1) // 2):  # @line L2
        omega = 2.0 * math.pi * k / (nt * dt)
        p = [spectra[j][k] for j in range(nx)]
        for i in range(nz):  # @line L3
            for j in range(nx):
                image[i][j] += 2.0 * p[j].real / nt  # @line L4
            s = [2.0 / v for v in vel[i]]
            s0 = sum(s) / nx  # @line L5
            q = dft(p)  # @line L6
            for j in range(nx):
                arg = (omega * s0) ** 2 - kxs[j] ** 2
                q[j] = q[j] * cmath.exp(1j * math.sqrt(arg) * dz) if arg > 0.0 else 0j  # @line L7
            p = idft(q)  # @line L8
            for j in range(nx):
                p[j] *= cmath.exp(1j * omega * (s[j] - s0) * dz)  # @line L9
    return image  # @line L10


def phase_error(omega, s, s0, kx, dz):
    """The phase error of one split step for a plane wave in a medium of slowness s.

    The exact phase is dz sqrt(omega^2 s^2 - kx^2); the split step gives
    dz (sqrt(omega^2 s0^2 - kx^2) + omega (s - s0)). Both roots must be real.
    """
    exact = math.sqrt((omega * s) ** 2 - kx * kx)
    approx = math.sqrt((omega * s0) ** 2 - kx * kx) + omega * (s - s0)
    return dz * (approx - exact)
test_split_step_fourier_migration.py 82 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/split-step-fourier-migration/. The authors are listed in prov/C572NA.jsonl.
import cmath
import math
import unittest

from imgkit import dft, idft
from split_step_fourier_migration import kx_values, phase_error, split_step_fourier_migration

NT, DT = 64, 0.004


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


def phase_shift_oracle(data, dt, dx, dz, vz):
    """Phase shift over the positive frequencies for a velocity v(z) only."""
    nt, nx = len(data), len(data[0])
    kxs = kx_values(nx, dx)
    spectra = [dft([data[k][j] for k in range(nt)]) for j in range(nx)]
    image = [[0.0] * nx for _ in vz]
    for k in range(1, (nt + 1) // 2):
        w = 2.0 * math.pi * k / (nt * dt)
        q = dft([spectra[j][k] for j in range(nx)])
        for i, v in enumerate(vz):
            p = idft(q)
            for j in range(nx):
                image[i][j] += 2.0 * p[j].real / nt
            s = 2.0 / v
            for j in range(nx):
                a = (w * s) ** 2 - kxs[j] ** 2
                q[j] = q[j] * cmath.exp(1j * math.sqrt(a) * dz) if a > 0.0 else 0j
    return image


class TestSplitStepFourierMigration(unittest.TestCase):
    def test_equals_phase_shift_when_v_depends_on_z_only(self):
        nx, dx, dz = 16, 10.0, 6.0
        data = [[0.0] * nx for _ in range(NT)]
        for j in range(nx):
            t0 = 2.0 * math.hypot(150.0, j * dx - 80.0) / 3000.0
            for k in range(NT):
                data[k][j] = ricker(k * DT - t0, 25.0)
        vz = [2500.0] * 10 + [3000.0] * 20
        a = split_step_fourier_migration(data, DT, dx, dz, [[v] * nx for v in vz])
        b = phase_shift_oracle(data, DT, dx, dz, vz)
        for i in range(len(vz)):
            for j in range(nx):
                self.assertAlmostEqual(a[i][j], b[i][j], delta=1e-9)

    def test_lateral_velocity_flat_reflector(self):
        # A flat reflector at z0 = 240 m under v(x) = 3000 + 300 cos(2 pi x / L):
        # the times 2 z0 / v(x) vary with x, and the split-step correction
        # brings every column back to row z0 / dz = 40.
        nx, dx, dz, nz = 32, 20.0, 6.0, 48
        vx = [3000.0 + 300.0 * math.cos(2.0 * math.pi * j / nx) for j in range(nx)]
        data = [[ricker(k * DT - 480.0 / vx[j], 25.0) for j in range(nx)] for k in range(NT)]
        img = split_step_fourier_migration(data, DT, dx, dz, [vx[:] for _ in range(nz)])
        for j in range(nx):
            self.assertEqual(max(range(nz), key=lambda i: img[i][j]), 40)

    def test_phase_error(self):
        w, dz = 2.0 * math.pi * 20.0, 6.0
        # Exact for vertical waves and for the reference slowness.
        self.assertAlmostEqual(phase_error(w, 1e-3, 8e-4, 0.0, dz), 0.0, places=12)
        self.assertAlmostEqual(phase_error(w, 1e-3, 1e-3, 0.05, dz), 0.0, places=12)
        # The error grows with the angle and with the slowness contrast.
        e1 = abs(phase_error(w, 1e-3, 9e-4, 0.03, dz))
        e2 = abs(phase_error(w, 1e-3, 9e-4, 0.06, dz))
        e3 = abs(phase_error(w, 1e-3, 8e-4, 0.06, dz))
        self.assertLess(e1, e2)
        self.assertLess(e2, e3)

    def test_kx_values(self):
        ks = kx_values(4, 1.0)
        self.assertEqual([round(k / (math.pi / 2.0)) for k in ks], [0, 1, -2, -1])


if __name__ == "__main__":
    unittest.main()

History

The split-step Fourier method was used to solve parabolic wave equations in underwater acoustics and optics in the 1970s, where it propagates a field by alternating a free-space step in the wavenumber domain with a phase screen in space. Stoffa, Fokkema, de Luna Freire and Kessinger (1990) brought it to seismic migration as a cheap way to handle lateral velocity changes in phase-shift migration. Later work added finite-difference corrections and higher-order screens for wider angles.

References

  1. P. L. Stoffa, J. T. Fokkema, R. M. de Luna Freire and W. P. Kessinger, Split-step Fourier migration, Geophysics 55(4), 1990, 410 to 421, the split-step downward continuation with a reference slowness and a space-domain correction
  2. Jeno Gazdag, Wave equation migration with the phase-shift method, Geophysics 43(7), 1978, 1342 to 1351, the phase shift that the method uses for the reference slowness
  3. Oz Yilmaz, Seismic Data Analysis, Society of Exploration Geophysicists, 2001, Chapter 4 (migration), frequency-space and frequency-wavenumber methods for lateral velocity changes

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.per_step
  • a full proof of time.total
  • 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