Algorithmadvanced
Surface-related multiple elimination
Also called SRME.
Predict the surface multiples by convolving the recorded data with itself over the surface positions, then remove them, exactly by one inverse per frequency or by iteration.
- Time
- O(f s^3) worst · average · best
- Space
- O(f s^2) extra
- Where
- K = the number of iterations; f = the number of frequencies; s = the number of surface positions
- Model
- Real RAM
- Properties
- data drivendeterministicexact under modelnot needs subsurface model
- Evidence
- Proof sketchCode in 1 languages
- Origin
- D. J. Verschuur, A. J. Berkhout, C. P. A. Wapenaar, 1992
Surface-related multiple elimination (SRME) removes from marine seismic data the multiples that bounced at least once at the sea surface. It needs no model of the earth. Every surface multiple is a path from the source down and up to the surface, a reflection at the surface, and a second path down and up to the receiver. Both paths are already in the data, so the data convolved with themselves, summed over all surface positions, predict the multiples. At one frequency this is a matrix product, and the data without surface multiples are , which one linear solve per frequency gives, or a Neumann series whose terms the iteration adds one by one. It works on the convolutional model extended to many sources and receivers, and it removes multiples whose period and moveout change from trace to trace, which predictive deconvolution cannot.
In plain words
At sea, sound from the source goes down, comes back up, hits the sea surface and goes down again. So each echo is followed by weaker copies: echoes of echoes. These copies confuse the picture of the rocks. Each copy is made of two trips that the recording already holds: one trip from the source to some point on the sea surface, and one from that point to the receiver. So the method builds the copies by joining every recorded trip with every other recorded trip that starts where the first ended, and adds up over all meeting points. This guess of the copies is then removed from the data. Repeating the guess with the cleaned data makes it better each time, until only the first echoes are left.
The problem
Input: the data for receivers and sources on one regular grid of surface positions; the surface operator , which holds the free-surface reflection coefficient (about ), the inverse of the source spectrum and the grid step. In practice is not known and is estimated. Output: the data without surface multiples. After the DFT in time, the data at one frequency form the matrix (rows: receivers, columns: sources), and the model is
The product sums over the surface position where the multiple meets the surface: an event of from the source to , then an event of from to the receiver. By the convolution theorem the product of spectra is a convolution in time, so the matrix product is a convolution in time and a sum in space. The model is a physical model of the surface multiples for point sources and receivers at the surface, not a theorem about real data; the direct wave, the ghosts and missing near offsets must be handled first.
The algorithm
SRME(P(ω) for every ω, a(ω), iterations K)- 1
for each frequency ω do - 2
P₀ ← P ▷ the start: the data - 3
repeat K times - 4
P₀ ← P - a P₀ P ▷ predict the multiples and subtract - 5
append P₀ to the output ▷ or P₀ ← P (I + a P)⁻¹ by one solve - 6
return the output, back in time by the inverse DFT
After one step, : the prediction is the data convolved with themselves, which removes the first-order surface multiples exactly and leaves the higher orders with wrong amplitudes. Each later step adds the next term of the series . The direct form solves for once per frequency. In practice the operator is unknown, the data are not perfect, and the prediction is subtracted with a short filter fitted so that the result has the least energy: adaptive subtraction, a heuristic.
Example
One reflector. A flat reflector with coefficient lies samples below the surface, the surface coefficient is and the source is a unit impulse, so and with . The trace has at ; on a periodic axis of 64 samples the series wraps and each value gets the factor .
| time | |||||
|---|---|---|---|---|---|
| data | 0.502 | 0.125 | 0.031 | ||
| one step, | 0.486 | 0.008 | 0.127 | ||
| direct, | 0.5 | 0 | 0 | 0 | 0 |
Without the wrap, one step gives exactly at : , , , , . The first-order multiple is gone, and the later orders are not. The direct form returns the primary alone, exact to rounding.
The iteration. With , and 32 samples, the largest error of the output after steps is (), (2), (5), (10), (20) and (40). The ratio over the last 20 steps is , the rate of Claim 4 of the proof, at the worst frequency. For the worst rate is , and the iteration does not converge at that frequency, while the direct form still works.
Adaptive subtraction. On the trace, start from , predict , and pick the scalar that minimizes , six times. The scalars are , , , , and , close to but not equal to the true , and residual multiples of about 0.02 remain. These numbers are measurements; they show why adaptive subtraction is a heuristic.
Correctness
Under the model, the data without surface multiples are whenever is invertible, and it is invertible whenever the data were made from some with invertible; the direct form is then exact. The iteration computes the partial sums of the Neumann series, and its error after steps is , so it converges when the spectral radius of is below 1, which holds exactly when every eigenvalue of has real part below . The first prediction is the multidimensional autoconvolution of the data. These are theorems, proved in proofs/correctness.md. The model itself, and the estimate of by adaptive subtraction, are not theorems: the first is a physical model, the second a heuristic.
Proof: Under the surface-multiple model P = P0 + a P0 P the data without surface multiples are P (I + a P)^(-1), the iteration gives the partial sums of a Neumann series that converge exactly when the spectral radius of aP is below 1, and the first prediction is the multidimensional autoconvolution of the datafull
Setting. Fix one frequency . The data form a complex matrix : entry is the spectrum at of the trace recorded at surface position from a source at surface position , on one grid for sources and receivers. The surface operator is a complex number; it holds the reflection coefficient of the free surface, the inverse of the source spectrum and the step of the sum over surface positions. The data without surface multiples, , are linked to by the model
(M) is the feedback model of Verschuur, Berkhout and Wapenaar (1992), with the surface and source terms folded into one scalar: every surface multiple is a full event of from the source to some surface position , a reflection there with the factor , and an event of from to the receiver. The product sums over . We take (M) as given; the claims are about what follows from it. The function srme_direct solves for ; lines L2 to L4 compute and . is the spectral radius.
Claim 1 (direct solution). If is invertible, (M) has exactly one solution, . Conversely, for any with invertible, the data satisfy (M), and then is invertible and srme_direct returns .
Proof. (M) is , which has the one solution when is invertible. For the converse, gives , which is (M). Since commutes with , also , and .
So the direct form recovers exactly whenever the data obey (M), however strong the multiples are. The function add_surface_multiples, used in the tests, is the map of the converse.
Claim 2 (the iteration gives the Neumann partial sums). For every ,
where the second formula assumes (M).
Proof. For the sum is . If the formula holds for , then , which is the sum for . For the error , subtract (M), written as , from the iteration: . And by (M). So .
Claim 3 (convergence). If , then , and for every the error is . For and , the iteration converges if and only if .
Proof. by Claim 2, and for every by Gelfand's formula . For , , which tends to if and only if .
Claim 4 (when the iteration converges). Let be given by as in Claim 1. Then if and only if every eigenvalue of has real part below .
Proof. is the rational function of , and has no pole on the spectrum of because is invertible. By the spectral mapping theorem the eigenvalues of are the . Now if and only if , that is .
For one flat reflector with coefficient under a free surface with coefficient and a unit impulse source, with and , so . At the frequencies with this is , so the iteration converges at every frequency if and only if , and the worst rate is , which is for . For the direct form of Claim 1 still works.
Claim 5 (the first prediction). The first step is , and the time-domain trace of is , the convolution in time of the trace from to with the trace from to , summed over the surface positions . For it is the autoconvolution of the trace (circular on the periodic time axis of the code).
Proof. at every frequency; by the convolution theorem of the DFT the product of spectra is the spectrum of the circular convolution of the traces, and the inverse DFT is linear.
In the one-reflector case the data trace has at time (the multiple of order ), and the trace of has there. So has : the first-order multiple () is removed exactly, the primary is kept, and the higher orders remain with changed amplitudes. The later terms of the series correct them.
Claim 6 (the least-squares scalar). The function estimate_surface_scalar returns the that minimizes over complex , namely , where .
Proof. The function is , summed over ; completing the square in gives the minimizer.
The claim is about the formula. That the minimum-energy scalar equals the true is not a theorem: the primaries left in are not orthogonal to the prediction, and the rule pulls the scalar toward a value that also removes part of them. This is why adaptive subtraction is a heuristic.
Claim 7 (cost). With frequencies and surface positions, the direct form costs and steps of the iteration cost with dense products, plus the transforms of the traces.
Proof. Each frequency needs one dense solve with right-hand sides, , or products of matrices, each.
Complexity
In the real-RAM model, with frequencies and surface positions, the direct form costs : one dense solve with right-hand sides per frequency. steps of the iteration cost . The transforms of the traces add for time samples with an FFT. Space is for the data at all frequencies. For 3D surveys counts the sources and receivers in two dimensions, so the cost is large, and the data must first be interpolated to the grid.
Properties
- Data-driven: no velocities, no subsurface model (a property of the model, not an approximation).
- Exact under the model, with the direct form (a theorem).
- Removes surface multiples of all orders and all moveouts, including multiples from dipping and curved reflectors (a consequence of the model).
- Does not remove internal multiples, which bounce only between layers below the surface.
- Needs dense sources and receivers on the same grid, including the near offsets that the recording usually misses.
Variants and improvements
- Adaptive subtraction with short filters in time and space windows, to absorb errors of the source wavelet, the surface coefficient and the data (a heuristic).
- Estimation of primaries by sparse inversion (EPSI): treat and the source as unknowns of an inversion with a sparsity prior, in place of prediction and subtraction.
- Internal multiple prediction with the same idea, using a chosen layer boundary in place of the surface.
- 3D SRME with interpolation of the missing sources and receivers.
- The same matrix calculus underlies seismic interferometry, which correlates in place of convolving.
When to use it
Use it on marine data with a strong sea floor and a free surface, where surface multiples dominate. It is usually the first step of multiple removal, before the parabolic Radon transform cleans up what remains, and before migration, which would otherwise image the multiples as false reflectors.
Pitfalls
- Missing near offsets and coarse source sampling break the sum over surface positions; interpolate first.
- The direct wave and the source ghost must be removed or modeled, or they enter the prediction.
- Adaptive subtraction can remove primaries that overlap the multiples; keep the filters short and the windows large.
- The iteration diverges at frequencies where the spectral radius of is 1 or more, as for a sea floor with a strong reflection; the direct form or adaptive damping is then needed.
- 3D effects: a 2D SRME on 3D data predicts multiples at wrong times when the surface paths leave the plane of the line.
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.
# 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
surface_related_multiple_elimination.py 96 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/surface-related-multiple-elimination/. The authors are listed in prov/JC2TNG.jsonl.
"""Surface-related multiple elimination (SRME) in the data-matrix form.
For one frequency, the data form a square matrix P: row = receiver
position, column = source position, on the same grid. The data without
surface multiples are P0, and the free surface links them by
P = P0 + a P0 P,
where the surface operator a = r / S folds the free-surface reflection
coefficient r (-1 for water over air), the inverse of the source spectrum S
and the spatial step of the sum into one number per frequency. Then
P0 = P (I + a P)^(-1). The iteration P0 <- P - a P0 P converges to it when
the spectral radius of a P is below 1. All matrices are complex lists of rows.
"""
import imgkit as ik
import imgla as la
def _sub(a, b):
return [[x - y for x, y in zip(ra, rb)] for ra, rb in zip(a, b)]
def _scale(a, s):
return [[s * x for x in row] for row in a]
def srme_iterative(p, a, iters):
"""Iterate P0 <- P - a P0 P, starting from P0 = P, for one frequency."""
p0 = [list(row) for row in p] # @line L2
for _ in range(iters): # @line L3
p0 = _sub(p, _scale(la.matmul(p0, p), a)) # @line L4
return p0
def srme_direct(p, a):
"""P0 = P (I + a P)^(-1) for one frequency, by one linear solve."""
n = len(p)
m = [[(1.0 if i == j else 0.0) + a * p[i][j] for j in range(n)] for i in range(n)]
# X (I + a P) = P is the same as (I + a P)^T X^T = P^T.
xt = la.solve(la.transpose(m), la.transpose(p))
return la.transpose(xt)
def srme(data, surface, iters=None):
"""Apply SRME at every frequency.
data is a list of matrices P(w_k), surface a list of the scalars a(w_k).
With iters=None the direct form is used, otherwise the iteration.
"""
out = []
for p, a in zip(data, surface): # @line L1
if iters is None:
out.append(srme_direct(p, a))
else:
out.append(srme_iterative(p, a, iters)) # @line L5
return out # @line L6
def add_surface_multiples(p0, a):
"""The data with surface multiples: P = (I - a P0)^(-1) P0, the inverse map of SRME."""
n = len(p0)
m = [[(1.0 if i == j else 0.0) - a * p0[i][j] for j in range(n)] for i in range(n)]
return la.solve(m, p0)
def estimate_surface_scalar(data, predicted):
"""The least-squares scalar s minimizing sum_k ||P_k - s M_k||^2 (Frobenius).
This is the minimum-energy rule of adaptive subtraction with one
complex scalar for the whole data set; it is a heuristic, not part of the
exact relation.
"""
num = 0j
den = 0.0
for p, m in zip(data, predicted):
for rp, rm in zip(p, m):
for x, y in zip(rp, rm):
num += y.conjugate() * x
den += abs(y) ** 2
return num / den
def srme_trace(trace, a=-1.0, iters=None):
"""SRME for one zero-offset trace of a 1D earth (each P is a 1 x 1 matrix).
The trace is periodic with n samples; a is the surface operator, -1 for
a unit impulse source under a free surface with r = -1. Returns the trace
without surface multiples.
"""
spec = ik.dft(trace)
data = [[[v]] for v in spec]
out = srme(data, [a] * len(spec), iters)
return [v.real for v in ik.idft([m[0][0] for m in out])]
test_surface_related_multiple_elimination.py 121 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/surface-related-multiple-elimination/. The authors are listed in prov/JC2TNG.jsonl.
import cmath
import math
import random
import imgkit as ik
import imgla as la
from surface_related_multiple_elimination import (
add_surface_multiples,
estimate_surface_scalar,
srme,
srme_direct,
srme_iterative,
srme_trace,
)
def one_reflector_spectrum(n, tau, r):
"""P = r z / (1 + r z), z = exp(-2 pi i k tau / n): one reflector under a free surface."""
out = []
for k in range(n):
z = cmath.exp(-2j * math.pi * k * tau / n)
out.append(r * z / (1 + r * z))
return out
def max_diff(a, b):
return max(abs(x - y) for ra, rb in zip(a, b) for x, y in zip(ra, rb))
def random_matrix(rng, n, scale):
return [[complex(rng.gauss(0.0, scale), rng.gauss(0.0, scale)) for _ in range(n)] for _ in range(n)]
def test_one_reflector_trace_has_the_expected_multiples():
n, tau, r = 64, 8, 0.5
tr = [v.real for v in ik.idft(one_reflector_spectrum(n, tau, r))]
# The series r, -r^2, r^3, .. wraps around the period of 64 samples.
wrap = 1.0 / (1.0 - r ** 8)
for m in range(1, 8):
assert abs(tr[m * tau] - (-1) ** (m + 1) * r ** m * wrap) < 1e-12
assert max(abs(tr[i]) for i in range(n) if i % tau) < 1e-12
def test_direct_srme_leaves_only_the_primary():
n, tau, r = 64, 8, 0.5
tr = [v.real for v in ik.idft(one_reflector_spectrum(n, tau, r))]
out = srme_trace(tr, a=-1.0)
expect = [r if i == tau else 0.0 for i in range(n)]
assert max(abs(p - q) for p, q in zip(out, expect)) < 1e-12
def test_first_prediction_is_the_autoconvolution():
n, tau, r = 64, 8, 0.5
spec = one_reflector_spectrum(n, tau, r)
tr = [v.real for v in ik.idft(spec)]
auto = ik.circ_conv(tr, tr)
pred = [v.real for v in ik.idft([s * s for s in spec])]
assert max(abs(p - q) for p, q in zip(auto, pred)) < 1e-12
# The first-order multiple r^2 at 2 tau comes from the primary convolved with itself.
assert abs(pred[2 * tau] - r * r) < 0.01
def test_iteration_converges_geometrically():
n, tau, r = 32, 4, 0.4
tr = [v.real for v in ik.idft(one_reflector_spectrum(n, tau, r))]
expect = [r if i == tau else 0.0 for i in range(n)]
errs = []
for k in (5, 10, 20, 40):
out = srme_trace(tr, a=-1.0, iters=k)
errs.append(max(abs(p - q) for p, q in zip(out, expect)))
assert errs[0] > errs[1] > errs[2] > errs[3]
assert errs[3] < 1e-6
# The worst frequency has |a P| = r / (1 - r) = 2/3.
assert errs[3] / errs[2] < (2.0 / 3.0) ** 20 * 1.5
def test_matrix_relation_and_exact_recovery():
rng = random.Random(1)
n = 4
data, surface, truth = [], [], []
for _ in range(3):
p0 = random_matrix(rng, n, 0.15)
a = cmath.exp(1j * rng.uniform(0.0, 2.0 * math.pi)) * -1.0
p = add_surface_multiples(p0, a)
rel = [[x + a * y for x, y in zip(r0, rq)] for r0, rq in zip(p0, la.matmul(p0, p))]
assert max_diff(rel, p) < 1e-12
data.append(p)
surface.append(a)
truth.append(p0)
out = srme(data, surface)
for o, t in zip(out, truth):
assert max_diff(o, t) < 1e-12
out_it = srme(data, surface, iters=60)
for o, t in zip(out_it, truth):
assert max_diff(o, t) < 1e-9
def test_direct_and_iterative_agree():
rng = random.Random(2)
p = random_matrix(rng, 5, 0.1)
a = -0.8 + 0.3j
d = srme_direct(p, a)
it = srme_iterative(p, a, 80)
assert max_diff(d, it) < 1e-10
def test_adaptive_scalar_is_close_to_the_true_operator():
# Minimum-energy subtraction is a heuristic: it lands near, not on, a = -1.
n, tau, r = 64, 8, 0.5
data = [[[v]] for v in one_reflector_spectrum(n, tau, r)]
p0 = data
s = 0j
for _ in range(6):
pred = [[[q[0][0] * p[0][0]]] for q, p in zip(p0, data)]
s = estimate_surface_scalar(data, pred)
p0 = [[[p[0][0] - s * m[0][0]]] for p, m in zip(data, pred)]
assert abs(s + 1.0) < 0.1
assert abs(s.imag) < 1e-12
History
Verschuur, Berkhout and Wapenaar (1992) published surface-related multiple elimination in its adaptive form. They wrote the data at one frequency as a matrix, modeled the surface multiples as a feedback of the data through the free surface, and removed them by a series or an iteration, with the source and surface terms estimated from the data by minimum energy. The method became a standard way to remove surface multiples from marine data.
References
- D. J. Verschuur, A. J. Berkhout and C. P. A. Wapenaar, Adaptive surface-related multiple elimination, Geophysics 57(9), 1992, 1166 to 1177, the matrix model of surface multiples, their prediction by a multidimensional convolution of the data with itself, the series and iterative forms, and the adaptive estimate of the surface operator
- Oz Yilmaz, Seismic Data Analysis, Society of Exploration Geophysicists, 2001, Investigations in Geophysics 10, the chapter on multiple attenuation (surface-related multiple elimination)
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag JC2TNG Edit this page History Report an error Markdown