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>
117 lines
5.1 KiB
Python
117 lines
5.1 KiB
Python
"""Dựng bộ dữ liệu giếng F3 trong miền thời gian seismic.
|
||
|
||
python scripts/01_build_wells.py [--config configs/d1_f3.yaml]
|
||
|
||
Đầu ra (trong outputs/):
|
||
f3_wells.npz khóa phẳng "<giếng>/<mục>", không cần allow_pickle. Mọi chuỗi theo thời gian
|
||
nằm trên cửa sổ mở rộng `ext_window_ms`; `main_mask` đánh dấu cửa sổ chính:
|
||
seismic_patch (C, L), times_ms (L,), main_mask (L,), il, xl, x, y,
|
||
anchors_md, anchors_twt_ms, tdr/<tên>/md, tdr/<tên>/twt_ms,
|
||
<tên TDR>/<curve> (L,), horizon/<tên> (TWT ms tại giếng)
|
||
f3_wells_summary.json vị trí giếng (thật và của luận văn), số anchor, độ phủ nhãn.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import argparse
|
||
import json
|
||
|
||
import numpy as np
|
||
import yaml
|
||
|
||
from ml_porosity.data.geometry import SurveyGeometry
|
||
from ml_porosity.data.horizons import F3_HORIZONS, horizon_at
|
||
from ml_porosity.data.las_io import LEGACY_IL_XL, Well, load_td_source, load_well
|
||
from ml_porosity.data.resample import log_to_time
|
||
from ml_porosity.data.seismic_io import SeismicCube
|
||
from ml_porosity.data.tdr import TDR, calibrate_to_anchors, legacy_sonic_tdr, sonic_tdr
|
||
from ml_porosity.paths import REPO_ROOT, f3_root, outputs_dir
|
||
|
||
|
||
def build_tdrs(well: Well, names: list[str]) -> dict[str, TDR]:
|
||
cs = well.checkshot
|
||
dt = well.curve("DT")
|
||
out = {}
|
||
for name in names:
|
||
if name == "legacy":
|
||
out[name] = legacy_sonic_tdr(well.md, dt)
|
||
elif name == "calibrated":
|
||
base = sonic_tdr(well.md, dt, md0=cs.md.iloc[0], t0_ms=cs.twt_ms.iloc[0])
|
||
out[name] = calibrate_to_anchors(base, cs.md, cs.twt_ms)
|
||
elif name == "anchors":
|
||
out[name] = TDR.from_pairs(cs.to_numpy(), "anchors")
|
||
elif name == "wlt":
|
||
out[name] = TDR.from_pairs(load_td_source(well.name, "wlt"), "wlt", drop_flat=True)
|
||
else:
|
||
raise ValueError(f"TDR không hỗ trợ: {name}")
|
||
return out
|
||
|
||
|
||
def main() -> None:
|
||
ap = argparse.ArgumentParser()
|
||
ap.add_argument("--config", default=str(REPO_ROOT / "configs" / "d1_f3.yaml"))
|
||
cfg = yaml.safe_load(open(ap.parse_args().config))
|
||
|
||
geom = SurveyGeometry.from_survey(f3_root())
|
||
t0, t1 = cfg["time_window_ms"]
|
||
e0, e1 = cfg["ext_window_ms"]
|
||
arrays: dict[str, np.ndarray] = {}
|
||
summary = {"config": cfg, "wells": {}}
|
||
|
||
with SeismicCube() as cube:
|
||
win = cube.window(e0, e1)
|
||
t_win = cube.times_ms[win]
|
||
main = (t_win >= t0) & (t_win <= t1)
|
||
for name in cfg["wells"]:
|
||
w = load_well(name)
|
||
# Nhãn hài hoà theo plan mục 1.2d / D-1: PHIE_DT = −0.2018 + 0.0011·DT cho cả 4 giếng.
|
||
w.logs["PHIE_DT"] = -0.2018 + 0.0011 * w.logs["DT"]
|
||
il, xl = geom.nearest_bin(w.x, w.y)
|
||
patch = cube.patch(il, xl, cfg["patch_radius"])[:, win]
|
||
tdrs = build_tdrs(w, cfg["tdrs"])
|
||
|
||
p = f"{name}/"
|
||
arrays.update({
|
||
p + "seismic_patch": patch,
|
||
p + "times_ms": t_win,
|
||
p + "main_mask": main,
|
||
p + "il": np.int32(il), p + "xl": np.int32(xl),
|
||
p + "x": np.float64(w.x), p + "y": np.float64(w.y),
|
||
p + "anchors_md": w.checkshot.md.to_numpy(),
|
||
p + "anchors_twt_ms": w.checkshot.twt_ms.to_numpy(),
|
||
})
|
||
coverage = {}
|
||
for tname, tdr in tdrs.items():
|
||
arrays[p + f"tdr/{tname}/md"] = tdr.md
|
||
arrays[p + f"tdr/{tname}/twt_ms"] = tdr.twt_ms
|
||
for c in cfg["curves"]:
|
||
v = log_to_time(w.md, w.curve(c), tdr, t_win, **cfg["resample"])
|
||
arrays[p + f"{tname}/{c}"] = v
|
||
coverage[f"{tname}/{c}"] = round(float(np.isfinite(v[main]).mean()), 3)
|
||
for h in F3_HORIZONS:
|
||
arrays[p + f"horizon/{h}"] = np.float64(horizon_at(h, geom, [(il, xl)])[0])
|
||
|
||
info = {"x": w.x, "y": w.y, "kb": w.kb, "il": il, "xl": xl,
|
||
"n_anchors_in_window": int(w.checkshot.twt_ms.between(t0, t1).sum()),
|
||
"label_coverage": coverage}
|
||
if name in LEGACY_IL_XL:
|
||
lil, lxl = LEGACY_IL_XL[name]
|
||
lx, ly = geom.bin_to_xy(lil, lxl)
|
||
info["legacy_il_xl"] = [lil, lxl]
|
||
info["legacy_offset_km"] = round(float(np.hypot(lx - w.x, ly - w.y)) / 1000, 2)
|
||
summary["wells"][name] = info
|
||
print(f"{name}: IL/XL {il}/{xl}"
|
||
+ (f" (luận văn {info['legacy_il_xl'][0]}/{info['legacy_il_xl'][1]}, lệch {info['legacy_offset_km']} km)"
|
||
if "legacy_il_xl" in info else "")
|
||
+ f", {info['n_anchors_in_window']} anchor trong cửa sổ, "
|
||
+ f"phủ PHIE (calibrated) {coverage.get('calibrated/PHIE', float('nan')):.0%}")
|
||
|
||
out = outputs_dir()
|
||
np.savez_compressed(out / "f3_wells.npz", **arrays)
|
||
(out / "f3_wells_summary.json").write_text(json.dumps(summary, indent=1, ensure_ascii=False))
|
||
print(f"-> {out / 'f3_wells.npz'}")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|