Algorithm Search⌘K

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
Properties
deterministiclinear in dataneeds velocity
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: mm traces, each with a source position ss, a receiver position gg and nn samples at the interval Δt\Delta t; a bin width bb; and a stacking velocity v(t0)v(t_0) for each bin, from semblance velocity analysis. Output: for each midpoint bin, one trace SS at zero offset, and the fold FjF_j of each sample. The model behind it is that after NMO every trace of the bin holds the same primary reflections aja_j plus noise eije_{ij} that is independent between traces. Under that model the stack is the average of FjF_j independent measurements of aja_j.

The algorithm

  1. CMP-STACK(traces, Δt, v, b, s_max)
  2. 1bins ← group the traces by round(((s + g)/2 - origin) / b), keep x = |g - s|
  3. 2for each bin B in increasing order do
  4. 3total_j ← 0; fold_j ← 0 for every sample j
  5. 4for each trace (x, d) in B do
  6. 5(c, live) ← NMO(d, Δt, x, v_B, s_max) ▷ live_j = 0 if muted or past the record
  7. 6for j ← 0 to n - 1 do if live_j then total_j ← total_j + c_j; fold_j ← fold_j + 1
  8. 7S_B,j ← total_j / fold_j where fold_j > 0, else 0
  9. 8return (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 nr=48n_r = 48 receivers every Δg=25\Delta g = 25 m, and the shots are Δs=50\Delta s = 50 m apart. The bin width is Δg/2=12.5\Delta g/2 = 12.5 m. Each shot moves the 48 midpoints by 50/12.5=450/12.5 = 4 bins, so a bin in the middle of the line is hit by every fourth trace position of 48, and the full fold is

F=nr Δg2 Δs=48⋅252⋅50=12.F = \frac{n_r\,\Delta g}{2\,\Delta s} = \frac{48 \cdot 25}{2 \cdot 50} = 12.

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 Δt=4\Delta t = 4 ms, and one reflection with a 25 Hz Ricker wavelet at t0=0.6t_0 = 0.6 s on the hyperbola with v=2200v = 2200 m/s. The stack at t0=0.6t_0 = 0.6 s, for several trial velocities:

vv (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 σ=0.5\sigma = 0.5 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 0.5/12=0.1440.5/\sqrt{12} = 0.144. The ratio of the peak to the noise rises from about 2 to about 6.7, a gain of 3.4, near 12=3.46\sqrt{12} = 3.46. 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 aj+eija_j + e_{ij} with the same aja_j and independent noise of variance at most σ2\sigma^2, the stack has mean aja_j and variance at most σ2/Fj\sigma^2/F_j: the amplitude ratio of signal to noise grows by at least Fj\sqrt{F_j}. 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 nrΔg/(2Δs)n_r \Delta g / (2 \Delta s) when 2Δs/Δg2\Delta s/\Delta g divides nrn_r. 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 mm traces. Trace ii has the source position sis_i, the receiver position gig_i and nn samples at times k Δtk\,\Delta t. The midpoint is (si+gi)/2(s_i + g_i)/2 and the offset is xi=∣gi−si∣x_i = |g_i - s_i|. The bins have width bb and start at the origin oo. NMO with a stretch mute (line L5) returns, for each output sample jj, a value cijc_{ij} and a flag ℓij∈{0,1}\ell_{ij} \in \{0, 1\}: ℓij=0\ell_{ij} = 0 when the sample is muted or when its input time is after the end of the record. The fold of a bin at sample jj is Fj=∑iℓijF_j = \sum_i \ell_{ij} over the traces of the bin.

Claim 1 (sorting). Line L1 puts every trace in exactly one bin, the bin round⁡(((si+gi)/2−o)/b)\operatorname{round}(((s_i + g_i)/2 - o)/b), with its offset xix_i.

Proof. The function midpoint_bin is a function of the trace, so each trace gets one index, and sort_by_midpoint appends the pair (xi,samples)(x_i, \text{samples}) to the list of that index and to no other list. □\square

Claim 2 (the stack is the mean of the live samples). For each bin, lines L3 to L7 return Sj=1Fj∑iℓijcijS_j = \frac{1}{F_j}\sum_i \ell_{ij} c_{ij} when Fj>0F_j > 0 and Sj=0S_j = 0 when Fj=0F_j = 0, and they return FjF_j 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 cijc_{ij} to the sum of sample jj and 11 to its count exactly when ℓij=1\ell_{ij} = 1. After the last trace, the sum of sample jj is ∑iℓijcij\sum_i \ell_{ij} c_{ij} and the count is FjF_j. Line L7 divides when Fj>0F_j > 0. 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 aa, then Sj=aS_j = a. □\square

Claim 3 (signal and noise). Assume that after NMO every live sample of the bin at time jj is cij=aj+eijc_{ij} = a_j + e_{ij}, where aja_j is the same on all traces (the event is flat, Claim 2 of the NMO proof) and the eije_{ij}, i=1,…,Fji = 1, \ldots, F_j, are independent with mean 00 and variance at most σ2\sigma^2. Then SjS_j has mean aja_j and variance at most σ2/Fj\sigma^2 / F_j. So the ratio of the signal amplitude to the noise standard deviation grows by at least the factor Fj\sqrt{F_j} over one trace with noise variance σ2\sigma^2.

Proof. By Claim 2, Sj=aj+1Fj∑ieijS_j = a_j + \frac{1}{F_j}\sum_i e_{ij}. Its mean is aja_j because each eije_{ij} has mean 00. The variance of a sum of independent terms is the sum of the variances, so Var⁡Sj=1Fj2∑iVar⁡eij≤σ2/Fj\operatorname{Var} S_j = \frac{1}{F_j^2}\sum_i \operatorname{Var} e_{ij} \le \sigma^2/F_j. □\square

The hypothesis holds for noise that is independent from trace to trace and white with variance σ2\sigma^2 on each input trace. NMO reads the output sample jj of trace ii from two neighboring input samples of the same trace, with weights 1−f1 - f and ff, so the noise of that sample has variance ((1−f)2+f2)σ2≤σ2((1 - f)^2 + f^2)\sigma^2 \le \sigma^2, 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 Fj\sqrt{F_j}.

Claim 4 (the nominal fold). Let every shot use the same spread of nrn_r receivers with spacing Δg\Delta g at fixed offsets o0+q Δgo_0 + q\,\Delta g, q=0,…,nr−1q = 0, \ldots, n_r - 1, from the shot, and let the shots be Δs\Delta s apart. Let the bin width be h=Δg/2h = \Delta g/2, and let r=Δs/h=2Δs/Δgr = \Delta s / h = 2\Delta s/\Delta g be an integer that divides nrn_r. Then every bin that is not near the ends of the line holds exactly nr/r=nrΔg/(2Δs)n_r/r = n_r \Delta g / (2 \Delta s) traces.

Proof. Shot kk is at k Δsk\,\Delta s, and its trace qq has the midpoint k Δs+o0/2+q hk\,\Delta s + o_0/2 + q\,h. In units of hh from the midpoint o0/2o_0/2 of trace 00 of shot 00, this is the integer p=kr+qp = k r + q. A bin pp receives the trace (k,q)(k, q) exactly when q=p−krq = p - k r and 0≤q≤nr−10 \le q \le n_r - 1, that is when krk r lies in the set of nrn_r consecutive integers {p−nr+1,…,p}\{p - n_r + 1, \ldots, p\}. When rr divides nrn_r, any nrn_r consecutive integers contain exactly nr/rn_r/r multiples of rr. Away from the ends of the line, every such multiple krk r belongs to a recorded shot, so the bin holds nr/rn_r/r traces. □\square

Claim 5 (cost). With mm traces of nn samples, the stack of the whole line costs O(mn)O(m n) operations plus the cost of sorting, which is O(m)O(m) expected with a hash table and O(mlog⁡m)O(m \log m) with a comparison sort of the bin indices.

Proof. Every trace is corrected once (Claim 6 of the NMO proof, O(n)O(n)) and added once (O(n)O(n)). The divisions of line L7 cost O(n)O(n) per bin, and there are at most mm bins. □\square

Complexity

In the real-RAM model, the NMO correction and the sum cost O(n)O(n) per trace, so O(mn)O(m n) for the survey. The sort costs O(mlog⁡m)O(m \log m) with a comparison sort and O(m)O(m) expected with a hash table. The output has one trace per bin, at most O(mn)O(m n) numbers; a survey with fold FF has about m/Fm/F 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 FF traces to one: the stack throws away the offset dimension, and with it the information on amplitude change with offset.
  • The gain of F\sqrt{F} 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 F\sqrt{F}. 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.

common_midpoint_stacking.pyI0RawGitHub
# 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

  1. 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
  2. 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)
  3. 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
  4. 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.

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