Files
ML-Porosity/ml_porosity/data/resample.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

55 lines
1.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Depth-to-time conversion of logs onto the seismic time axis, with anti-alias filtering.
The thesis point-interpolates 0.15 m log samples directly to 4 ms (prepare_data.py:203–204),
which causes aliasing (plan §1.1 #8). Here the log is first mapped onto a fine time grid,
low-pass filtered with a zero-phase Butterworth filter (sosfiltfilt) at `cutoff_frac`·Nyquist
of the target grid, and only then resampled.
"""
from __future__ import annotations
import numpy as np
from scipy import signal
from ml_porosity.data.tdr import TDR
def log_to_time(
md: np.ndarray,
values: np.ndarray,
tdr: TDR,
t_out_ms: np.ndarray,
fine_dt_ms: float = 0.25,
cutoff_frac: float = 0.8,
order: int = 6,
) -> np.ndarray:
"""Log values at `t_out_ms` (regular grid). NaN where the log has no coverage.
Internal gaps in the log are linearly interpolated before filtering, and target
samples falling inside a gap are reset to NaN afterwards."""
md = np.asarray(md, dtype=float)
v = np.asarray(values, dtype=float)
ok = np.isfinite(v)
t_log = tdr.time_at(md[ok])
v = v[ok]
if v.size < 2:
return np.full(t_out_ms.shape, np.nan)
dt_out = float(t_out_ms[1] - t_out_ms[0])
t_fine = np.arange(t_log[0], t_log[-1] + fine_dt_ms / 2, fine_dt_ms)
v_fine = np.interp(t_fine, t_log, v)
if t_fine.size > 3 * (order + 1):
nyq_out = 0.5 / dt_out
nyq_fine = 0.5 / fine_dt_ms
sos = signal.butter(order, cutoff_frac * nyq_out / nyq_fine, output="sos")
v_fine = signal.sosfiltfilt(sos, v_fine)
out = np.interp(t_out_ms, t_fine, v_fine, left=np.nan, right=np.nan)
# Set to NaN the target samples lying in log gaps longer than one target sample.
gaps = np.flatnonzero(np.diff(t_log) > dt_out)
for g in gaps:
out[(t_out_ms > t_log[g]) & (t_out_ms < t_log[g + 1])] = np.nan
return out