Algorithmintro
Common midpoint stacking
Also called CMP stacking.
Sort the traces of a survey by source-receiver midpoint, NMO-correct each gather and average it, which forms a zero-offset section and lowers random noise by the square root of the fold.
- Time
- O(m n + m log m) worst · averageO(m n) best
- Space
- O(m n) extra
- Where
- m = the number of traces in the survey; n = the number of samples per trace
- Model
- Real RAM
- Properties
- deterministiclinear in dataneeds velocity
- Evidence
- Proof sketchCode in 1 languages
- Origin
- W. Harry Mayne, 1962
Common midpoint (CMP) stacking forms a seismic section from a multichannel survey. It collects the traces whose source and receiver share the same midpoint, corrects each one for its offset with normal moveout correction, and averages them. The average is an estimate of the zero-offset trace at that midpoint, with random noise reduced and some multiples weakened. The number of traces in the average is the fold. The older name common-depth-point stacking assumes flat layers, where all traces of a midpoint reflect from the same point; with dip they do not, which is one reason for prestack seismic migration.
In plain words
A survey shoots many times and records each shot on many receivers, so the same piece of ground under a surface point is seen many times, each time with a different distance between shot and receiver. Pick all the recordings whose shot and receiver are centered on that point. Correct each one for its extra travel time, so that the echoes line up. Then add them and divide by their number. The echoes are the same on every recording and stay. The random noise is different on every recording and partly cancels. Twelve recordings cut the random noise to less than a third. Echoes that bounced more than once line up less well and get weaker.
The problem
Input: traces, each with a source position , a receiver position and samples at the interval ; a bin width ; and a stacking velocity for each bin, from semblance velocity analysis. Output: for each midpoint bin, one trace at zero offset, and the fold of each sample. The model behind it is that after NMO every trace of the bin holds the same primary reflections plus noise that is independent between traces. Under that model the stack is the average of independent measurements of .
The algorithm
CMP-STACK(traces, Δt, v, b, s_max)- 1
bins ← group the traces by round(((s + g)/2 - origin) / b), keep x = |g - s| - 2
for each bin B in increasing order do - 3
total_j ← 0; fold_j ← 0 for every sample j - 4
for each trace (x, d) in B do - 5
(c, live) ← NMO(d, Δt, x, v_B, s_max) ▷ live_j = 0 if muted or past the record - 6
for j ← 0 to n - 1 do if live_j then total_j ← total_j + c_j; fold_j ← fold_j + 1 - 7
S_B,j ← total_j / fold_j where fold_j > 0, else 0 - 8
return (S_B, fold_B) for every bin B
Line L1 is the CMP sort. Lines L4 to L6 correct and sum the traces of one bin, and line L7 divides by the live fold of each sample, not by the number of traces. Where the stretch mute removed the far traces, a shallow sample is the mean of fewer traces, but its amplitude is right. Line L6 counts a sample as dead when its input time falls after the end of the record, for the same reason.
Example
The fold. A 2D line has a spread of receivers every m, and the shots are m apart. The bin width is m. Each shot moves the 48 midpoints by bins, so a bin in the middle of the line is hit by every fourth trace position of 48, and the full fold is
Near the ends of the line the fold ramps up from 1 to 12.
A gather. Take 12 traces at offsets 0, 100, ..., 1100 m with ms, and one reflection with a 25 Hz Ricker wavelet at s on the hyperbola with m/s. The stack at s, for several trial velocities:
| (m/s) | 1700 | 2000 | 2200 | 2400 | 3000 |
|---|---|---|---|---|---|
| stack at 0.6 s | 0.161 | 0.247 | 0.947 | 0.276 | 0.188 |
With the correct velocity the stack keeps 95 percent of the amplitude; the loss of 5 percent is the error of linear interpolation of a 25 Hz wavelet at 4 ms. A velocity 10 percent off leaves residual moveout, and the misaligned wavelets cancel. This sensitivity is what velocity analysis uses.
The noise. Add independent Gaussian noise with to each trace (seed 3). In a window after the event, the standard deviation is 0.485 on the zero-offset trace and 0.141 on the stack, close to . The ratio of the peak to the noise rises from about 2 to about 6.7, a gain of 3.4, near . This is a measurement on one seed; Claim 3 of the proof gives the expected value.
Correctness
Line L1 puts every trace in the bin of its midpoint, and lines L3 to L7 return, at each sample, the mean of the live NMO-corrected samples of the bin. If after NMO every live sample is with the same and independent noise of variance at most , the stack has mean and variance at most : the amplitude ratio of signal to noise grows by at least . Linear interpolation does not break the hypothesis, because it mixes samples of the same trace only and does not raise their variance. For a fixed spread rolled along the line, the full fold is when divides . The proofs are in proofs/correctness.md.
Proof: CMP stacking groups each trace into its midpoint bin, returns the mean of the live NMO-corrected samples, and under independent noise lowers the noise standard deviation by the square root of the foldfull
Setting. A 2D line has traces. Trace has the source position , the receiver position and samples at times . The midpoint is and the offset is . The bins have width and start at the origin . NMO with a stretch mute (line L5) returns, for each output sample , a value and a flag : when the sample is muted or when its input time is after the end of the record. The fold of a bin at sample is over the traces of the bin.
Claim 1 (sorting). Line L1 puts every trace in exactly one bin, the bin , with its offset .
Proof. The function midpoint_bin is a function of the trace, so each trace gets one index, and sort_by_midpoint appends the pair to the list of that index and to no other list.
Claim 2 (the stack is the mean of the live samples). For each bin, lines L3 to L7 return when and when , and they return as the fold.
Proof. Line L3 starts with zero sums and zero counts. Each pass of the loop L4 corrects one trace (L5), and the loop L6 adds to the sum of sample and to its count exactly when . After the last trace, the sum of sample is and the count is . Line L7 divides when . Dividing by the live fold, not by the number of traces, keeps the amplitude of an event that is muted on some traces: if every live sample equals , then .
Claim 3 (signal and noise). Assume that after NMO every live sample of the bin at time is , where is the same on all traces (the event is flat, Claim 2 of the NMO proof) and the , , are independent with mean and variance at most . Then has mean and variance at most . So the ratio of the signal amplitude to the noise standard deviation grows by at least the factor over one trace with noise variance .
Proof. By Claim 2, . Its mean is because each has mean . The variance of a sum of independent terms is the sum of the variances, so .
The hypothesis holds for noise that is independent from trace to trace and white with variance on each input trace. NMO reads the output sample of trace from two neighboring input samples of the same trace, with weights and , so the noise of that sample has variance , and samples of different traces stay independent. The hypothesis fails for coherent noise (ground roll, multiples, noise from one shot recorded on many traces): such noise is not independent between the traces of a bin, and the stack does not reduce it by .
Claim 4 (the nominal fold). Let every shot use the same spread of receivers with spacing at fixed offsets , , from the shot, and let the shots be apart. Let the bin width be , and let be an integer that divides . Then every bin that is not near the ends of the line holds exactly traces.
Proof. Shot is at , and its trace has the midpoint . In units of from the midpoint of trace of shot , this is the integer . A bin receives the trace exactly when and , that is when lies in the set of consecutive integers . When divides , any consecutive integers contain exactly multiples of . Away from the ends of the line, every such multiple belongs to a recorded shot, so the bin holds traces.
Claim 5 (cost). With traces of samples, the stack of the whole line costs operations plus the cost of sorting, which is expected with a hash table and with a comparison sort of the bin indices.
Proof. Every trace is corrected once (Claim 6 of the NMO proof, ) and added once (). The divisions of line L7 cost per bin, and there are at most bins.
Complexity
In the real-RAM model, the NMO correction and the sum cost per trace, so for the survey. The sort costs with a comparison sort and expected with a hash table. The output has one trace per bin, at most numbers; a survey with fold has about bins. Stacking is cheap next to migration; most of the work of a stacked section is the velocity analysis that comes before it.
Properties
- Linear in the data, for fixed velocities and mutes.
- It reduces traces to one: the stack throws away the offset dimension, and with it the information on amplitude change with offset.
- The gain of in signal to noise is a theorem under the noise model of independent traces, not a property of every data set.
- Primaries flattened by NMO add in phase. Multiples have a lower stacking velocity, keep residual moveout and are attenuated, which Mayne pointed out; the attenuation depends on the offset range and is not complete.
- With dipping layers, the traces of a midpoint reflect from different points (reflection point smear).
Variants and improvements
- Weighted stacks: weight the traces by an estimate of their noise level, or use a median or trimmed mean against bursts of noise.
- Common reflection surface and multifocusing stacks: sum along surfaces over neighboring midpoints, with more parameters than one velocity.
- Dip moveout before stacking removes the dip dependence of the stacking velocity.
- Prestack migration replaces NMO and stacking when the subsurface is complex; the stack is then formed after migration, in common image gathers.
When to use it
Use it to get a first image of a survey with many folds and reflectors that are close to flat, and as the input of poststack Kirchhoff migration. It is also the quality control of a velocity model: a good velocity gives a sharp stack.
Pitfalls
- A bin with low fold, at the ends of the line or in gaps, has more noise. Do not compare amplitudes across bins with different fold without care.
- Wrong velocities lower the stack amplitude and the frequency content, even when the event is still visible.
- The divisor must be the live fold. Dividing by the number of traces makes the muted top of the section too weak.
- Coherent noise, such as ground roll, does not fall by . Remove it before the stack.
- Static shifts from the near surface misalign the traces just as a wrong velocity does. Correct them before the stack.
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
# Part of https://algorithm.tamnd.com/common-midpoint-stacking/. The authors are listed in prov/RJJQ5H.jsonl.
"""Common-midpoint (CMP) stacking.
A trace is a tuple (s, g, samples): the source and receiver positions along
the line in m, and the samples at two-way times k * dt. The traces are
grouped by midpoint (s + g) / 2, NMO-corrected with the offset |g - s| and
a velocity v(t0), muted where the NMO stretch is too large, and summed. The
sum is divided by the live fold, the number of unmuted traces at each sample.
"""
import math
def _interp(trace, dt, t):
n = len(trace)
u = t / dt
if n < 2 or u < 0.0 or u > n - 1:
return 0.0
k = min(int(math.floor(u)), n - 2)
f = u - k
return (1.0 - f) * trace[k] + f * trace[k + 1]
def _nmo(trace, dt, x, vel, stretch_max):
"""NMO correction with a stretch mute. Returns (samples, live flags).
A sample is not live when it is muted or when its input time falls after
the end of the record.
"""
out, live = [0.0] * len(trace), [0] * len(trace)
tmax = (len(trace) - 1) * dt
for j in range(len(trace)):
t0 = j * dt
v = vel[j] if isinstance(vel, (list, tuple)) else vel
t = math.sqrt(t0 * t0 + (x / v) ** 2)
if stretch_max is not None and (t - t0) > stretch_max * t0:
continue
if t > tmax * (1.0 + 1e-12):
continue
out[j] = _interp(trace, dt, t)
live[j] = 1
return out, live
def midpoint_bin(s, g, bin_width, origin=0.0):
"""The index of the midpoint bin of a trace: round(((s + g) / 2 - origin) / bin_width)."""
return int(round(((s + g) / 2.0 - origin) / bin_width))
def sort_by_midpoint(traces, bin_width, origin=0.0):
"""Group traces into CMP bins: a dict from bin index to a list of (offset, samples)."""
bins = {}
for s, g, samples in traces:
b = midpoint_bin(s, g, bin_width, origin)
bins.setdefault(b, []).append((abs(g - s), samples))
return bins
def stack_gather(gather, dt, vel, stretch_max=None):
"""NMO-correct and stack one CMP gather given as a list of (offset, samples).
Returns (stack, fold), where fold[j] is the number of live traces at
sample j and stack[j] is their mean (0 where fold[j] = 0).
"""
n = len(gather[0][1])
total = [0.0] * n # @line L3
fold = [0] * n
for x, samples in gather: # @line L4
c, live = _nmo(samples, dt, x, vel, stretch_max) # @line L5
for j in range(n): # @line L6
if live[j]:
total[j] += c[j]
fold[j] += 1
stack = [total[j] / fold[j] if fold[j] > 0 else 0.0 for j in range(n)] # @line L7
return stack, fold
def cmp_stack(traces, dt, vel, bin_width, origin=0.0, stretch_max=None):
"""Stack a whole line. Returns a dict from bin index to (stack, fold).
vel is a constant, a list v(t0) used for every bin, or a dict from bin
index to such a constant or list.
"""
bins = sort_by_midpoint(traces, bin_width, origin) # @line L1
out = {}
for b in sorted(bins): # @line L2
v = vel[b] if isinstance(vel, dict) else vel
out[b] = stack_gather(bins[b], dt, v, stretch_max)
return out # @line L8
def nominal_fold(n_receivers, receiver_spacing, shot_spacing):
"""The full fold n_r dg / (2 ds) of a 2D line with a fixed spread rolled along by ds."""
return n_receivers * receiver_spacing / (2.0 * shot_spacing)
test_common_midpoint_stacking.py 121 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/common-midpoint-stacking/. The authors are listed in prov/RJJQ5H.jsonl.
import math
import random
from common_midpoint_stacking import (
cmp_stack,
midpoint_bin,
nominal_fold,
sort_by_midpoint,
stack_gather,
)
def ricker(t, f=25.0):
a = (math.pi * f * t) ** 2
return (1.0 - 2.0 * a) * math.exp(-a)
def event_trace(x, t0, v, dt, n, amp=1.0):
tx = math.sqrt(t0 * t0 + (x / v) ** 2)
return [amp * ricker(k * dt - tx) for k in range(n)]
def test_nominal_fold_value():
assert nominal_fold(48, 25.0, 50.0) == 12.0
def test_fold_of_a_rolled_spread():
# End-on spread: 48 receivers every 25 m from 100 m behind each shot; shots every 50 m.
counts = {}
for i in range(60):
s = 50.0 * i
for k in range(48):
g = s + 100.0 + 25.0 * k
b = midpoint_bin(s, g, 12.5)
counts[b] = counts.get(b, 0) + 1
assert max(counts.values()) == 12
full = [b for b, c in counts.items() if c == 12]
assert len(full) > 100
assert sum(counts.values()) == 60 * 48
def test_sort_by_midpoint_groups_and_offsets():
traces = [(0.0, 100.0, [1.0]), (25.0, 75.0, [2.0]), (50.0, 50.0, [3.0]), (0.0, 50.0, [4.0])]
bins = sort_by_midpoint(traces, 25.0)
assert sorted(bins) == [1, 2]
assert sorted(x for x, _ in bins[2]) == [0.0, 50.0, 100.0]
assert bins[1] == [(50.0, [4.0])]
def test_stack_recovers_the_zero_offset_event():
dt, n = 0.004, 300
offsets = [100.0 * i for i in range(12)]
gather = [(x, event_trace(x, 0.6, 2200.0, dt, n)) for x in offsets]
stack, fold = stack_gather(gather, dt, 2200.0)
assert fold[:250] == [12] * 250
assert stack[150] > 0.9
wrong, _ = stack_gather(gather, dt, 1700.0)
assert max(wrong) < 0.8
def test_noise_falls_like_one_over_root_fold():
rng = random.Random(7)
n, sigma = 4000, 1.0
for nf in (4, 16):
gather = [(0.0, [rng.gauss(0.0, sigma) for _ in range(n)]) for _ in range(nf)]
stack, _ = stack_gather(gather, 0.004, 2000.0)
var = sum(v * v for v in stack) / n
assert abs(var * nf - sigma * sigma) < 0.12
def test_snr_gain_with_signal():
rng = random.Random(8)
nf, n, sigma = 9, 3000, 0.5
signal = [math.sin(0.05 * k) for k in range(n)]
gather = [(0.0, [s + rng.gauss(0.0, sigma) for s in signal]) for _ in range(nf)]
stack, _ = stack_gather(gather, 0.004, 2000.0)
noise_in = math.sqrt(sum((a - s) ** 2 for a, s in zip(gather[0][1], signal)) / n)
noise_out = math.sqrt(sum((a - s) ** 2 for a, s in zip(stack, signal)) / n)
assert abs(noise_in / noise_out - math.sqrt(nf)) < 0.3
def test_interpolation_does_not_raise_the_noise():
rng = random.Random(9)
n, nf = 1500, 10
gather = [(150.0 * i, [rng.gauss(0.0, 1.0) for _ in range(n)]) for i in range(nf)]
stack, _ = stack_gather(gather, 0.004, 2000.0)
var = sum(v * v for v in stack[500:]) / (n - 500)
assert var < 1.1 / nf
def test_live_fold_normalization_keeps_the_amplitude():
dt, n = 0.004, 400
offsets = [100.0 * i for i in range(10)]
gather = [(x, [1.0] * n) for x in offsets]
stack, fold = stack_gather(gather, dt, 2000.0, stretch_max=0.25)
assert fold[10] < 10 and fold[300] == 10 and fold[-1] == 1
for j in range(n):
if fold[j] > 0:
assert abs(stack[j] - 1.0) < 1e-12
else:
assert stack[j] == 0.0
# Dividing by the nominal fold instead would dim the shallow part.
assert fold[20] * stack[20] / 10 < 0.9
def test_cmp_stack_of_a_line():
dt, n, v = 0.004, 250, 2000.0
traces = []
for i in range(8):
s = 50.0 * i
for k in range(8):
g = s + 25.0 * k
x = g - s
traces.append((s, g, event_trace(x, 0.5, v, dt, n)))
out = cmp_stack(traces, dt, v, 12.5)
assert sum(len(fold) and max(fold) for _, fold in out.values()) == 64
for b, (stack, fold) in out.items():
assert stack[125] > 0.9
History
Mayne (1962) described the common reflection point method: record each subsurface point several times with different source-receiver pairs, correct for moveout and sum. He showed that the sum attenuates multiples and random noise. The method spread with digital recording and processing in the 1960s. Taner and Koehler (1969) made the choice of the stacking velocity a computed velocity spectrum.
References
- W. Harry Mayne, Common reflection point horizontal data stacking techniques, Geophysics 27(6), 1962, 927 to 938, the common reflection point geometry, the sum of corrected traces and its attenuation of multiples and random noise
- Oz Yilmaz, Seismic Data Analysis, Society of Exploration Geophysicists, 2001, Investigations in Geophysics 10, the chapter on velocity analysis and statics corrections (CMP sorting, fold, NMO and stacking)
- M. Turhan Taner and Fulton Koehler, Velocity spectra, digital computer derivation and applications of velocity functions, Geophysics 34(6), 1969, 859 to 881, the stack along trial hyperbolas as a function of velocity
- Peter M. Shearer, Introduction to Seismology, 2nd edition, Cambridge University Press, 2009, Chapter 7 (reflection seismology, common midpoint stacking)
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 RJJQ5H Edit this page History Report an error Markdown