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>
122 lines
4.3 KiB
Python
122 lines
4.3 KiB
Python
"""Đọc dữ liệu giếng F3: LAS, marker, checkshot, track và các mô hình TD.
|
||
|
||
Quy ước độ sâu: MD tính từ KB (m). Bốn giếng F3 đều thẳng đứng nên MD = TVD + 0
|
||
so với KB; TVDSS = MD − KB.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from dataclasses import dataclass, field
|
||
from pathlib import Path
|
||
|
||
import lasio
|
||
import numpy as np
|
||
import pandas as pd
|
||
|
||
from ml_porosity.paths import f3_root, f3_wells_dir
|
||
|
||
F3_WELLS = ("F02-1", "F03-2", "F03-4", "F06-1")
|
||
|
||
# Vị trí IL/XL mà luận văn dùng (test 2/prepare_data.py:17–21); chỉ để audit, không dùng.
|
||
LEGACY_IL_XL = {"F03-4": (362, 821), "F02-1": (418, 608), "F06-1": (283, 842)}
|
||
|
||
|
||
@dataclass
|
||
class Well:
|
||
name: str
|
||
x: float
|
||
y: float
|
||
kb: float
|
||
logs: pd.DataFrame # index = MD (m), cột = mnemonic, NaN thay cho NULL
|
||
units: dict[str, str] = field(default_factory=dict)
|
||
markers: pd.DataFrame | None = None # cột: md, name
|
||
checkshot: pd.DataFrame | None = None # cột: md, twt_ms (marker TD, xem plan mục 1.2e)
|
||
|
||
@property
|
||
def md(self) -> np.ndarray:
|
||
return self.logs.index.to_numpy(dtype=float)
|
||
|
||
def curve(self, name: str) -> np.ndarray:
|
||
return self.logs[name].to_numpy(dtype=float)
|
||
|
||
|
||
def read_las(path: str | Path) -> tuple[pd.DataFrame, dict[str, str], lasio.LASFile]:
|
||
las = lasio.read(str(path))
|
||
df = las.df()
|
||
df.index = df.index.astype(float)
|
||
df.index.name = "MD"
|
||
units = {c.mnemonic: (c.unit or "") for c in las.curves}
|
||
return df, units, las
|
||
|
||
|
||
def read_two_columns(path: str | Path, skip_header: bool = False) -> np.ndarray:
|
||
"""Đọc file hai cột số (depth, value). `skip_header=True` cho file OpendTect
|
||
(.wlt, .csmdl) có phần đầu kết thúc bằng dòng `!` thứ hai."""
|
||
lines = Path(path).read_text(errors="replace").splitlines()
|
||
if skip_header:
|
||
bangs = [i for i, s in enumerate(lines) if s.strip() == "!"]
|
||
lines = lines[bangs[1] + 1 :] if len(bangs) >= 2 else lines
|
||
rows = []
|
||
for s in lines:
|
||
parts = s.split()
|
||
if len(parts) >= 2:
|
||
try:
|
||
rows.append((float(parts[0]), float(parts[1])))
|
||
except ValueError:
|
||
continue
|
||
return np.asarray(rows, dtype=float)
|
||
|
||
|
||
def read_markers(path: str | Path) -> pd.DataFrame:
|
||
rows = []
|
||
for s in Path(path).read_text(errors="replace").splitlines():
|
||
s = s.strip()
|
||
if not s:
|
||
continue
|
||
depth, name = s.split(None, 1)
|
||
rows.append((float(depth), name.strip()))
|
||
return pd.DataFrame(rows, columns=["md", "name"])
|
||
|
||
|
||
def read_track(path: str | Path) -> np.ndarray:
|
||
"""Cột: X, Y, TVDSS (m), MD (m)."""
|
||
return np.loadtxt(path)
|
||
|
||
|
||
def load_well(name: str, wells_dir: Path | None = None) -> Well:
|
||
d = wells_dir or f3_wells_dir()
|
||
df, units, las = read_las(d / "Lasfiles" / f"{name}_logs.las")
|
||
track = read_track(d / "Track" / f"{name}.track")
|
||
x, y = float(track[0, 0]), float(track[0, 1])
|
||
kb = float(las.well["EKB"].value)
|
||
|
||
markers = read_markers(d / "Tops" / f"{name}_markers.txt")
|
||
# File checkshot có dòng trùng (nhiều marker cùng độ sâu) và không theo thứ tự (F03-2, F03-4).
|
||
cs = read_two_columns(d / "Checkshot" / f"{name}_TD.txt")
|
||
checkshot = (
|
||
pd.DataFrame({"md": cs[:, 0], "twt_ms": cs[:, 1] * 1000.0})
|
||
.drop_duplicates()
|
||
.sort_values("md", ignore_index=True)
|
||
)
|
||
return Well(name, x, y, kb, df, units, markers, checkshot)
|
||
|
||
|
||
def load_td_source(name: str, source: str) -> np.ndarray:
|
||
"""Cặp (MD m, TWT ms) từ một nguồn TD.
|
||
|
||
source:
|
||
"checkshot" – Checkshot/*_TD.txt (thời gian marker đã tie với horizon, giây)
|
||
"dt_model" – DT_model/*_TD.txt (ms; nguồn gốc chưa rõ, lệch checkshot, plan mục 1.2c)
|
||
"wlt" – WellInfo/*.wlt (Depth2Time model của OpendTect, giây)
|
||
"""
|
||
d = f3_wells_dir()
|
||
if source == "checkshot":
|
||
a = read_two_columns(d / "Checkshot" / f"{name}_TD.txt")
|
||
return np.column_stack([a[:, 0], a[:, 1] * 1000.0])
|
||
if source == "dt_model":
|
||
return read_two_columns(d / "DT_model" / f"{name}_TD.txt")
|
||
if source == "wlt":
|
||
a = read_two_columns(f3_root() / "WellInfo" / f"{name}.wlt", skip_header=True)
|
||
return np.column_stack([a[:, 0], a[:, 1] * 1000.0])
|
||
raise ValueError(f"nguồn TD không hợp lệ: {source}")
|