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>
This commit is contained in:
0
ml_porosity/baselines/__init__.py
Normal file
0
ml_porosity/baselines/__init__.py
Normal file
26
ml_porosity/baselines/attributes.py
Normal file
26
ml_porosity/baselines/attributes.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""Attribute seismic cho B0b, tính trên trace đầy đủ (cửa sổ mở rộng) rồi mới cắt cửa sổ chính."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
from scipy import signal
|
||||
|
||||
FEATURES = ("amplitude", "envelope", "cos_phase", "sin_phase", "inst_freq", "relative_ai", "twt")
|
||||
|
||||
|
||||
def trace_attributes(trace: np.ndarray, times_ms: np.ndarray, dt_ms: float = 4.0) -> np.ndarray:
|
||||
"""Ma trận (L, 7) theo thứ tự FEATURES."""
|
||||
s = np.asarray(trace, dtype=float)
|
||||
a = signal.hilbert(s)
|
||||
env = np.abs(a)
|
||||
ph = np.unwrap(np.angle(a))
|
||||
f_inst = np.gradient(ph) / (2 * np.pi * dt_ms / 1000.0)
|
||||
# tần số tức thời trọng số theo envelope rồi làm trơn 5 mẫu để bớt gai
|
||||
k = np.ones(5)
|
||||
f_inst = np.convolve(f_inst * env**2, k, "same") / (np.convolve(env**2, k, "same") + 1e-12)
|
||||
f_inst = np.clip(f_inst, 0.0, 500.0 / dt_ms)
|
||||
# relative AI: tích phân trace, bỏ xu hướng < 5 Hz
|
||||
rai = np.cumsum(s)
|
||||
sos = signal.butter(4, 5.0, btype="highpass", fs=1000.0 / dt_ms, output="sos")
|
||||
rai = signal.sosfiltfilt(sos, rai)
|
||||
return np.column_stack([s, env, np.cos(np.angle(a)), np.sin(np.angle(a)), f_inst, rai, times_ms])
|
||||
74
ml_porosity/baselines/inversion.py
Normal file
74
ml_porosity/baselines/inversion.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""B1: post-stack model-based AI inversion (PyLops) với LFM nội suy theo horizon, rồi φ = a + b·AI."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
from pylops.avo.poststack import PoststackInversion, PoststackLinearModelling
|
||||
from scipy import signal
|
||||
|
||||
from ml_porosity.data.wavelet import estimate_wavelet_ls
|
||||
|
||||
|
||||
def fill_edges(x: np.ndarray) -> np.ndarray:
|
||||
"""Thay NaN bằng nội suy tuyến tính, giữ hằng ở hai đầu."""
|
||||
x = np.asarray(x, dtype=float).copy()
|
||||
ok = np.isfinite(x)
|
||||
x[~ok] = np.interp(np.flatnonzero(~ok), np.flatnonzero(ok), x[ok])
|
||||
return x
|
||||
|
||||
|
||||
def lowpass(x: np.ndarray, f_c_hz: float, dt_ms: float = 4.0, order: int = 4) -> np.ndarray:
|
||||
sos = signal.butter(order, f_c_hz, fs=1000.0 / dt_ms, output="sos")
|
||||
return signal.sosfiltfilt(sos, x, padtype="even")
|
||||
|
||||
|
||||
def strat_map(t: np.ndarray, h_from: np.ndarray, h_to: np.ndarray) -> np.ndarray:
|
||||
"""Ánh xạ thời gian ở giếng đích sang thời gian tương đương địa tầng ở giếng nguồn: nội suy
|
||||
tuyến tính từng đoạn qua các cặp horizon (h_from → h_to), ngoài cùng thì dịch song song."""
|
||||
ok = np.isfinite(h_from) & np.isfinite(h_to)
|
||||
a, b = h_from[ok], h_to[ok]
|
||||
order = np.argsort(a)
|
||||
a, b = a[order], b[order]
|
||||
keep = np.concatenate([[True], (np.diff(a) > 0) & (np.diff(b) > 0)])
|
||||
a, b = a[keep], b[keep]
|
||||
out = np.interp(t, a, b)
|
||||
out[t < a[0]] = t[t < a[0]] + (b[0] - a[0])
|
||||
out[t > a[-1]] = t[t > a[-1]] + (b[-1] - a[-1])
|
||||
return out
|
||||
|
||||
|
||||
def build_lfm(t, target_h, target_xy, wells: dict, f_c_hz: float = 6.0, power: float = 2.0) -> np.ndarray:
|
||||
"""wells[name] = {"logai": (L,), "h": (H,), "xy": (2,)} trên cùng trục t. Trả về LFM của log(AI)."""
|
||||
num = np.zeros_like(t, dtype=float)
|
||||
den = 0.0
|
||||
for w in wells.values():
|
||||
lf = lowpass(fill_edges(w["logai"]), f_c_hz)
|
||||
tw = strat_map(t, np.asarray(target_h), np.asarray(w["h"]))
|
||||
val = np.interp(tw, t, lf)
|
||||
d = max(float(np.hypot(*(np.asarray(target_xy) - np.asarray(w["xy"])))), 1.0)
|
||||
wt = d ** (-power)
|
||||
num += wt * val
|
||||
den += wt
|
||||
return num / den
|
||||
|
||||
|
||||
def operator_reflectivity(logai: np.ndarray, nspike: int = 33) -> np.ndarray:
|
||||
"""Reflectivity theo đúng quy ước của PoststackLinearModelling (wavelet xung đơn vị)."""
|
||||
spike = np.zeros(nspike)
|
||||
spike[nspike // 2] = 1.0
|
||||
G0 = PoststackLinearModelling(spike, len(logai), explicit=True).A
|
||||
return G0 @ logai
|
||||
|
||||
|
||||
def estimate_wavelet(train_logai: list[np.ndarray], train_seis: list[np.ndarray], mask: np.ndarray,
|
||||
dt_ms: float = 4.0, length_ms: float = 128.0, damping: float = 0.05) -> np.ndarray:
|
||||
refl = [operator_reflectivity(fill_edges(m))[mask] for m in train_logai]
|
||||
return estimate_wavelet_ls(refl, [s[mask] for s in train_seis], dt_ms, length_ms, damping)
|
||||
|
||||
|
||||
def invert(seis: np.ndarray, wav: np.ndarray, lfm: np.ndarray, e: float) -> np.ndarray:
|
||||
"""log(AI) nghịch đảo: Tikhonov về LFM với epsI = e·trace(GᵀG)/n."""
|
||||
G = PoststackLinearModelling(wav, len(seis), explicit=True).A
|
||||
eps = e * np.trace(G.T @ G) / len(seis)
|
||||
m, _ = PoststackInversion(seis, wav, m0=lfm, explicit=True, epsI=eps, simultaneous=False)
|
||||
return np.asarray(m).ravel()
|
||||
Reference in New Issue
Block a user