P0 - ml_porosity/: survey geometry, LAS/TDR/SEG-Y readers (4 ms delay fix, invalid time scalar, header LUT for incomplete cubes), anti-aliased log-to-time resampling, CNN-GRU v2 with the thesis loss, 41+ unit tests. - Full F3 Demo 2023 under data/ (text well/fault files tracked, bulk data ignored); the filtered copy and its cleanup notes are removed. - SHA-256 manifests for F3, Volve, NLOG and the thesis outputs. P1 - configs/protocol.yaml v2, locked by SHA-256 at 2026-10-26T04:28:09Z, before the first LOWO run (04:30:50Z); 05_lowo.py refuses to run on a hash mismatch. This commit postdates the runs. - Wavelet/synthetic tie QC, residual misregistration, LOWO 5 seeds for B0a, B0b, B1, B2, B3a, B3b (scripts 04-06); gate G-A: no pivot. - Volve D3: horizons, well picks, checkshots and the ST10010 cube read from data/Volve (scripts/07). - D-1 label check against measured NLOG density (scripts/08): PHIE_DT stays the primary label. - docs/plan.md, Volve and NLOG inventories, report.html. Full-text reference PDFs in refs/ stay local (ignored). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.5 KiB
Python
62 lines
2.5 KiB
Python
import numpy as np
|
|
import pytest
|
|
|
|
from ml_porosity.baselines.inversion import strat_map
|
|
from ml_porosity.data.synthetic import best_shift, local_shifts, reflectivity_from_ai, shift_signal
|
|
from ml_porosity.data.wavelet import convolve_same, estimate_wavelet_ls, ricker, rotate_phase
|
|
from ml_porosity.eval.metrics import band_metrics, gaussian_metrics, split_bands
|
|
|
|
|
|
def test_rotate_phase_180_flips_sign():
|
|
w = ricker(40)
|
|
np.testing.assert_allclose(rotate_phase(w, 180), -w, atol=1e-6)
|
|
|
|
|
|
def test_wavelet_ls_recovers_known_wavelet():
|
|
rng = np.random.default_rng(0)
|
|
w_true = rotate_phase(ricker(45), 30) * 3.0
|
|
refl = [rng.standard_normal(400) * 0.05 for _ in range(3)]
|
|
seis = [convolve_same(r, w_true) for r in refl]
|
|
w_est = estimate_wavelet_ls(refl, seis, damping=1e-6)
|
|
taper = np.hanning(len(w_true) + 2)[1:-1]
|
|
np.testing.assert_allclose(w_est, w_true * taper, atol=0.02 * np.abs(w_true).max())
|
|
|
|
|
|
def test_best_and_local_shift_find_known_shift():
|
|
rng = np.random.default_rng(1)
|
|
r = reflectivity_from_ai(np.exp(np.cumsum(rng.standard_normal(300) * 0.05)))
|
|
syn = convolve_same(r, ricker(50))
|
|
seis = shift_signal(syn, 6.0, 4.0)
|
|
sh, rr = best_shift(syn, seis, 4.0, 20.0)
|
|
assert sh == pytest.approx(6.0, abs=0.5) and rr > 0.99
|
|
_, ls, _ = local_shifts(syn, seis, 4.0, max_ms=16)
|
|
assert np.median(ls) == pytest.approx(6.0, abs=0.5)
|
|
|
|
|
|
def test_strat_map_identity_and_shift():
|
|
t = np.arange(500.0, 1200.0, 4.0)
|
|
h = np.array([600.0, 800.0, 1000.0])
|
|
np.testing.assert_allclose(strat_map(t, h, h), t)
|
|
np.testing.assert_allclose(strat_map(t, h, h + 20), t + 20)
|
|
# giãn tuyến tính giữa hai horizon
|
|
out = strat_map(np.array([700.0]), np.array([600.0, 800.0]), np.array([600.0, 1000.0]))
|
|
assert out[0] == pytest.approx(800.0)
|
|
|
|
|
|
def test_split_bands_sums_and_separates():
|
|
t = np.arange(126) * 0.004
|
|
y = np.sin(2 * np.pi * 2 * t) + 0.3 * np.sin(2 * np.pi * 40 * t)
|
|
lo, hi = split_bands(y, 6.0)
|
|
np.testing.assert_allclose(lo + hi, y, atol=1e-12)
|
|
assert np.corrcoef(hi[10:-10], 0.3 * np.sin(2 * np.pi * 40 * t)[10:-10])[0, 1] > 0.95
|
|
m = band_metrics(y, y)
|
|
assert m["band_pcc"] == pytest.approx(1.0) and m["low_rmse"] == pytest.approx(0.0)
|
|
|
|
|
|
def test_gaussian_metrics_calibrated():
|
|
rng = np.random.default_rng(0)
|
|
y = rng.standard_normal(20000)
|
|
g = gaussian_metrics(y, np.zeros_like(y), np.ones_like(y))
|
|
assert g["coverage_90"] == pytest.approx(0.90, abs=0.01)
|
|
assert g["crps"] == pytest.approx(1 / np.sqrt(np.pi), abs=0.01) # E[CRPS] khi dự báo đúng N(0, 1)
|