Files
ML-Porosity/ml_porosity/baselines/attributes.py
lamlvh cee2ff0859 P2 diagnosis on dev, P3 dev experiments, lock protocol_p3
- 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>
2026-10-27 06:03:33 +00:00

27 lines
1.2 KiB
Python

"""Seismic attributes for B0b, computed on the full trace (extended window) before cropping to the main window."""
from __future__ import annotations
import numpy as np
from scipy import signal
FEATURES = ("amplitude", "envelope", "cos_phase", "sin_phase", "inst_freq", "relative_ai", "twt")
def trace_attributes(trace: np.ndarray, times_ms: np.ndarray, dt_ms: float = 4.0) -> np.ndarray:
"""(L, 7) matrix in the order of FEATURES."""
s = np.asarray(trace, dtype=float)
a = signal.hilbert(s)
env = np.abs(a)
ph = np.unwrap(np.angle(a))
f_inst = np.gradient(ph) / (2 * np.pi * dt_ms / 1000.0)
# envelope-weighted instantaneous frequency, smoothed over 5 samples to suppress spikes
k = np.ones(5)
f_inst = np.convolve(f_inst * env**2, k, "same") / (np.convolve(env**2, k, "same") + 1e-12)
f_inst = np.clip(f_inst, 0.0, 500.0 / dt_ms)
# relative AI: integrated trace with the < 5 Hz trend removed
rai = np.cumsum(s)
sos = signal.butter(4, 5.0, btype="highpass", fs=1000.0 / dt_ms, output="sos")
rai = signal.sosfiltfilt(sos, rai)
return np.column_stack([s, env, np.cos(np.angle(a)), np.sin(np.angle(a)), f_inst, rai, times_ms])