- P2: SMC tie posterior (numpy + torch), RML/soft-DTW losses, bank training, D2 synthetic generator, scripts 09-13, protocol_p2 (locked) and its outcome (G-B failed; H1 not rejected, H3 rejected, H4 not rejected). - Diagnosis on dev realizations 900/901 only (scripts 14-17, run_p3_dev.sh): posterior screen, SMC stability (P = 1024, K = 1), sigma_a misspecification stress and training, H3 with the SMC posterior, F3 placement on sigma_post. - protocol_p3: H2 split into H2a (posterior-mean labels vs point ties) and H2b (RML vs posterior mean as a function of sigma_post); H3 descriptive only; sigma_a arm; new D2 config d2_synth_p3.yaml; main grid on realizations 8-15. Locked by configs/protocol_p3.sha256 and tag protocol-p3. - runlog: per-run logs and runtime index (logs/index.csv). - Docs: plan §12 items 10-11, theory, technical overview, report; wording aligned with Gunning & Glinsky (2006): the tie posterior is not claimed as new. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
"""Wavelets: Ricker, zero-phase statistical wavelet, constant phase rotation, and well-based estimation.
|
||
|
||
All wavelets have an odd number of samples, are centred, and are sampled at `dt_ms`.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import numpy as np
|
||
from scipy import signal
|
||
from scipy.linalg import toeplitz
|
||
|
||
|
||
def ricker(f_peak_hz: float, dt_ms: float = 4.0, length_ms: float = 128.0) -> np.ndarray:
|
||
n = int(round(length_ms / dt_ms)) // 2
|
||
t = np.arange(-n, n + 1) * dt_ms / 1000.0
|
||
a = (np.pi * f_peak_hz * t) ** 2
|
||
return (1 - 2 * a) * np.exp(-a)
|
||
|
||
|
||
def rotate_phase(w: np.ndarray, phase_deg: float) -> np.ndarray:
|
||
"""Constant phase rotation: w·cos φ − H[w]·sin φ (H: Hilbert transform)."""
|
||
h = np.imag(signal.hilbert(w))
|
||
p = np.deg2rad(phase_deg)
|
||
return w * np.cos(p) - h * np.sin(p)
|
||
|
||
|
||
def statistical_wavelet(traces: np.ndarray, dt_ms: float = 4.0, length_ms: float = 128.0) -> np.ndarray:
|
||
"""Zero-phase wavelet whose amplitude spectrum equals the mean spectrum of the traces
|
||
(Hann taper), normalised to unit peak."""
|
||
traces = np.atleast_2d(traces)
|
||
nt = traces.shape[1]
|
||
nfft = int(2 ** np.ceil(np.log2(4 * nt)))
|
||
spec = np.mean(np.abs(np.fft.rfft(traces * np.hanning(nt), nfft)), axis=0)
|
||
w = np.fft.fftshift(np.fft.irfft(spec, nfft))
|
||
n = int(round(length_ms / dt_ms)) // 2
|
||
c = nfft // 2
|
||
w = w[c - n : c + n + 1] * np.hanning(2 * n + 1)
|
||
return w / np.max(np.abs(w))
|
||
|
||
|
||
def estimate_wavelet_ls(
|
||
reflectivity: list[np.ndarray],
|
||
seismic: list[np.ndarray],
|
||
dt_ms: float = 4.0,
|
||
length_ms: float = 128.0,
|
||
damping: float = 0.05,
|
||
) -> np.ndarray:
|
||
"""Wavelet (amplitude in seismic units) minimising Σ‖s − w∗r‖² + ε‖w‖² over multiple wells.
|
||
|
||
Toeplitz normal equations built from the autocorrelation of r and the r–s cross-correlation;
|
||
ε is relative to the diagonal. Series must be finite and pairwise of equal length."""
|
||
n = int(round(length_ms / dt_ms)) // 2
|
||
m = 2 * n + 1
|
||
R = np.zeros(m)
|
||
g = np.zeros(m)
|
||
for r, s in zip(reflectivity, seismic):
|
||
L = len(r)
|
||
acf = np.correlate(r, r, mode="full")[L - 1 : L - 1 + m]
|
||
R += acf
|
||
ccf = np.correlate(s, r, mode="full") # ccf[L-1+k] = Σ s[i+k] r[i]
|
||
g += ccf[L - 1 - n : L + n]
|
||
A = toeplitz(R)
|
||
A[np.diag_indices(m)] += damping * R[0]
|
||
w = np.linalg.solve(A, g)
|
||
return w * np.hanning(m + 2)[1:-1]
|
||
|
||
|
||
def convolve_same(r: np.ndarray, w: np.ndarray) -> np.ndarray:
|
||
return np.convolve(r, w, mode="same")
|