Files
ML-Porosity/scripts/00_data_manifest.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

84 lines
3.2 KiB
Python

"""Ghi manifest SHA-256 cho một bộ dữ liệu và đối chiếu với manifest đã commit.
python scripts/00_data_manifest.py # tạo/cập nhật manifest F3
python scripts/00_data_manifest.py --check # chỉ kiểm tra, exit 1 nếu lệch
python scripts/00_data_manifest.py --dataset volve # tương tự cho data/Volve
python scripts/00_data_manifest.py --dataset nlog # tương tự cho data/NLOG
"""
from __future__ import annotations
import argparse
import hashlib
import json
import sys
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime, timezone
from pathlib import Path
from ml_porosity.paths import REPO_ROOT, f3_root, nlog_root, volve_root
DATASETS = {
"f3": (f3_root, "f3_demo_2023.json", "F3 Demo 2023 (dGB Earth Sciences / TerraNubis), CC BY-SA 3.0"),
"volve": (volve_root, "volve.json", "Volve data village (Equinor), giấy phép HRS / CC BY-NC-SA 4.0"),
"nlog": (nlog_root, "nlog.json", "NLOG (TNO), LAS và TD công khai của giếng F3; URL ở docs/research/f3-nlog-inventory.xlsx"),
}
def sha256(path: Path, chunk: int = 1 << 22) -> str:
h = hashlib.sha256()
with path.open("rb") as f:
while block := f.read(chunk):
h.update(block)
return h.hexdigest()
def scan(root: Path) -> dict[str, dict]:
files = sorted(p for p in root.rglob("*") if p.is_file())
with ThreadPoolExecutor(max_workers=8) as ex:
digests = list(ex.map(sha256, files))
return {
p.relative_to(root).as_posix(): {"size_bytes": p.stat().st_size, "sha256": d}
for p, d in zip(files, digests)
}
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--check", action="store_true")
ap.add_argument("--dataset", choices=sorted(DATASETS), default="f3")
args = ap.parse_args()
root_fn, manifest_name, description = DATASETS[args.dataset]
manifest = REPO_ROOT / "data_manifest" / manifest_name
root = root_fn()
current = scan(root)
if args.check:
ref = json.loads(manifest.read_text())["files"]
missing = sorted(set(ref) - set(current))
changed = sorted(k for k in set(ref) & set(current) if ref[k]["sha256"] != current[k]["sha256"])
extra = sorted(set(current) - set(ref))
for name, items in (("thiếu", missing), ("khác hash", changed), ("thừa", extra)):
for k in items:
print(f"{name}: {k}")
print(f"{len(current)} file, {len(missing)} thiếu, {len(changed)} khác hash, {len(extra)} thừa")
return 1 if (missing or changed) else 0
out = {
"dataset": description,
"root": root.relative_to(REPO_ROOT).as_posix() if root.is_relative_to(REPO_ROOT) else str(root),
"created_utc": datetime.now(timezone.utc).isoformat(timespec="seconds"),
"n_files": len(current),
"total_bytes": sum(v["size_bytes"] for v in current.values()),
"files": current,
}
manifest.parent.mkdir(parents=True, exist_ok=True)
manifest.write_text(json.dumps(out, indent=1, ensure_ascii=False) + "\n")
print(f"{out['n_files']} file, {out['total_bytes'] / 1e9:.2f} GB -> {manifest.relative_to(REPO_ROOT)}")
return 0
if __name__ == "__main__":
sys.exit(main())