- 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>
65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
"""Synthetic seismograms and time-shift measurement between synthetic and seismic."""
|
||
|
||
from __future__ import annotations
|
||
|
||
import numpy as np
|
||
|
||
|
||
def reflectivity_from_ai(ai: np.ndarray) -> np.ndarray:
|
||
"""r[i] = (AI[i+1] − AI[i]) / (AI[i+1] + AI[i]), placed at sample i; the last sample is 0."""
|
||
ai = np.asarray(ai, dtype=float)
|
||
r = np.zeros_like(ai)
|
||
r[:-1] = (ai[1:] - ai[:-1]) / (ai[1:] + ai[:-1])
|
||
return np.nan_to_num(r)
|
||
|
||
|
||
def shift_signal(x: np.ndarray, shift_ms: float, dt_ms: float) -> np.ndarray:
|
||
"""Time-shift a series (positive = later) by linear interpolation; zero outside the support."""
|
||
t = np.arange(len(x)) * dt_ms
|
||
return np.interp(t - shift_ms, t, x, left=0.0, right=0.0)
|
||
|
||
|
||
def ncc(a: np.ndarray, b: np.ndarray) -> float:
|
||
a = a - a.mean()
|
||
b = b - b.mean()
|
||
d = np.sqrt((a * a).sum() * (b * b).sum())
|
||
return float((a * b).sum() / d) if d > 0 else float("nan")
|
||
|
||
|
||
def best_shift(syn: np.ndarray, seis: np.ndarray, dt_ms: float, max_ms: float, step_ms: float = 0.5):
|
||
"""Shift the synthetic within ±max_ms to maximise its correlation with the seismic. Returns (shift_ms, r)."""
|
||
shifts = np.arange(-max_ms, max_ms + step_ms / 2, step_ms)
|
||
rs = np.array([ncc(shift_signal(syn, s, dt_ms), seis) for s in shifts])
|
||
k = int(np.nanargmax(rs))
|
||
return float(shifts[k]), float(rs[k])
|
||
|
||
|
||
def local_shifts(
|
||
syn: np.ndarray,
|
||
seis: np.ndarray,
|
||
dt_ms: float,
|
||
win_ms: float = 120.0,
|
||
hop_ms: float = 20.0,
|
||
max_ms: float = 16.0,
|
||
):
|
||
"""Local time shifts in a sliding window (Hann taper). Returns (window centres as sample
|
||
indices, shift_ms, r). Positive means the synthetic must be shifted later to match the seismic."""
|
||
n = int(round(win_ms / dt_ms))
|
||
hop = max(1, int(round(hop_ms / dt_ms)))
|
||
taper = np.hanning(n)
|
||
centers, shifts, rs = [], [], []
|
||
pad = int(np.ceil(max_ms / dt_ms)) + 1
|
||
for i0 in range(pad, len(syn) - n - pad + 1, hop):
|
||
sl = slice(i0 - pad, i0 + n + pad)
|
||
a, b = syn[sl], seis[sl]
|
||
best = (0.0, -np.inf)
|
||
for s in np.arange(-max_ms, max_ms + 0.25, 0.5):
|
||
sa = shift_signal(a, s, dt_ms)[pad:-pad] * taper
|
||
r = ncc(sa, b[pad:-pad] * taper)
|
||
if r > best[1]:
|
||
best = (float(s), r)
|
||
centers.append(i0 + n // 2)
|
||
shifts.append(best[0])
|
||
rs.append(best[1])
|
||
return np.array(centers), np.array(shifts), np.array(rs)
|