Files
ML-Porosity/tests/test_volve_io.py
lamlvh a76e61398a P0 + P1: ml_porosity package, audited F3 data, LOWO baselines, protocol v2
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>
2026-10-26 08:41:11 +00:00

86 lines
3.9 KiB
Python

import numpy as np
import pytest
import yaml
from ml_porosity.data.geometry import SurveyGeometry
from ml_porosity.data.seismic_io import SeismicCube
from ml_porosity.data.volve_io import VOLVE_KEY_WELLS, read_checkshot, read_horizon, read_well_picks
from ml_porosity.paths import REPO_ROOT, volve_root
GI = volve_root() / "Geophysical_Interpretations"
HUGIN = GI / "Horizons/Horizons_TWT/Official_Horizons/Hugin_Fm_Top+ST10010ZC11_Near_190314+STAT+TIME.dat"
PICKS = GI / "Wells/Well_picks_Volve_v1.dat"
CFG = yaml.safe_load((REPO_ROOT / "configs/d3_volve.yaml").read_text())
VSP = volve_root() / CFG["well_logs_dir"]
CUBE = volve_root() / CFG["cube"]
pytestmark = pytest.mark.skipif(not GI.exists(), reason="thiếu data/Volve/Geophysical_Interpretations")
@pytest.fixture(scope="module")
def hugin():
return read_horizon(HUGIN)
@pytest.fixture(scope="module")
def picks():
return read_well_picks(PICKS)
def test_from_points_recovers_affine():
g0 = SurveyGeometry((1000.0, 3.0, -12.0), (5000.0, 12.0, 3.0), (0, 0, 1), (0, 0, 1), (0, 0, 0))
il, xl = np.meshgrid(np.arange(10, 20), np.arange(100, 130, 2))
g = SurveyGeometry.from_points(il, xl, *g0.bin_to_xy(il, xl))
assert g.x_coef == pytest.approx(g0.x_coef) and g.y_coef == pytest.approx(g0.y_coef)
assert g.il_range == (10, 19, 1) and g.xl_range == (100, 128, 2)
def test_horizon_grid_is_st10010(hugin):
assert hugin.survey == "ST10010" and hugin.domain == "TIME"
g = hugin.geometry()
assert g.bin_spacing() == pytest.approx((12.5, 12.5), abs=1e-3)
x, y = g.bin_to_xy(hugin.il, hugin.xl)
assert np.hypot(x - hugin.x, y - hugin.y).max() < 0.05
i = len(hugin.z) // 2
assert hugin.at(hugin.il[i], hugin.xl[i], radius=0) == pytest.approx(hugin.z[i])
assert np.isnan(hugin.at(0, 0))
def test_well_picks(picks):
assert len(picks) == 409 and picks.well.nunique() == 35
assert set(VOLVE_KEY_WELLS) <= set(picks.well)
assert picks.twt_ms.notna().sum() > 300
deep = picks[picks.well.isin(VOLVE_KEY_WELLS) & picks.twt_ms.between(2280, 2900) & ~picks.qlf.isin(["NL", "NR"])]
assert deep.groupby("well").md.nunique().min() >= 6
@pytest.mark.skipif(not VSP.exists(), reason="thiếu data/Volve/Well_logs_pr_WELL")
def test_checkshot_md_reference(picks):
"""F-15 A: checkshot ghi MD từ MSL, picks lấy TWT từ chính checkshot này nên khớp 0 ms khi MD đã quy về RKB."""
cs = read_checkshot(VSP / "15_9-F-15 A/08.VSP_VELOCITY/TZV_TIME_CHECKSHOT_1.ASC")
p = picks[(picks.well == "NO 15/9-F-15 A") & picks.twt_ms.notna() & picks.md.between(cs.md.min(), cs.md.max())]
assert len(p) >= 5
assert np.abs(p.twt_ms - np.interp(p.md, cs.md, cs.twt_ms)).max() < 0.5
@pytest.mark.skipif(not VSP.exists(), reason="thiếu data/Volve/Well_logs_pr_WELL")
def test_f11t2_picks_vs_nivsp(picks):
cs = read_checkshot(VSP / "15_9-F-11 T2/08.VSP_VELOCITY/TZV_TIME_CHECKSHOT_1.ASC")
p = picks[(picks.well == "NO 15/9-F-11 T2") & picks.twt_ms.notna() & picks.md.between(cs.md.min(), cs.md.max())]
assert len(p) >= 5
assert np.abs(p.twt_ms - np.interp(p.md, cs.md, cs.twt_ms)).max() < 7
@pytest.mark.skipif(not CUBE.exists(), reason="thiếu cube ST10010")
def test_volve_cube(hugin):
"""Byte 215 = 3 không phải scalar thời gian hợp lệ; segyio vẫn nhân delrt với nó nên t0 = 12 ms, đúng là 4 ms
(EBCDIC C11). Cube thiếu 26 trace ở rìa nên phải đọc theo bảng IL/XL từ header."""
with SeismicCube(CUBE) as c:
assert (c.times_ms[0], c.times_ms[-1], c.dt_ms) == (4.0, 3400.0, 4.0)
assert (c.ilines[0], c.ilines[-1], c.xlines[0], c.xlines[-1]) == (9961, 10361, 1961, 2680)
with pytest.raises(KeyError):
c.trace(9961, 1961)
assert c.trace(10150, 2250).shape == (850,)
x, y = c.coords(10150, 2250)
gx, gy = hugin.geometry().bin_to_xy(10150, 2250)
assert np.hypot(x - gx, y - gy) < 0.5