Files
Volve-DIA/scripts/00_data_manifest.py
lamlvh 17916650a5 Add M1: OCR hub import, WITSML, labels T1-T3, T4 questions, trial raters, draft protocol
- OCR: match the colleague's full-set Dataset Hub export to the DDRs by content
  (3,059/3,066 pages) and QC it against the HTML (CER 2.40%, exact 0.9181).
- WITSML parser and formation tops: 21 DDR wellbores with time logs, 1,384
  reports; WITSML 15/9-F-15 S is DDR 15/9-F-15.
- Deterministic labels T1-T3 (configs/labels.yaml), 1,662 T4 questions with SQL,
  pandas and raw-XML answers in full agreement.
- Trial label validation by three blind LLM raters (not an author or expert audit)
  and rater agreement script; draft protocol_v1 (not locked): split by well.
- Literature notes and BibTeX; docs, report and run_m1.sh synchronised.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 08:34:35 +00:00

89 lines
3.5 KiB
Python

"""Write a SHA-256 manifest of the Volve data this project reads, and check it against the committed manifest.
python scripts/00_data_manifest.py # create/update data_manifest/volve_dia.json
python scripts/00_data_manifest.py --check # check only; exit 1 on a missing file or a hash mismatch
Only the subtrees in SUBTREES and the single files in FILES are hashed (~20 GB, mostly WITSML); the rest of
data/Volve (well logs, seismic) is not read by this project.
"""
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 volve_dia.paths import REPO_ROOT, volve_root
MANIFEST = REPO_ROOT / "data_manifest" / "volve_dia.json"
DESCRIPTION = "Volve data village (Equinor and the Volve licence partners), CC BY-NC-SA 4.0"
SUBTREES = ["Well_technical_data", "Reports", "WITSML Realtime drilling data"]
#: Single files read from outside the subtrees: the formation tops (scripts/06_parse_witsml.py).
FILES = ["Geophysical_Interpretations/Wells/Well_picks_Volve_v1.dat"]
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 sub in SUBTREES for p in (root / sub).rglob("*") if p.is_file()]
+ [root / f for f in FILES])
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")
args = ap.parse_args()
root = volve_root()
missing_dirs = [s for s in SUBTREES if not (root / s).is_dir()] + [f for f in FILES if not (root / f).is_file()]
if missing_dirs:
print(f"missing under {root}: {missing_dirs}")
return 1
current = scan(root)
if args.check:
ref = json.loads(MANIFEST.read_text(encoding="utf-8"))["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 (("missing", missing), ("hash mismatch", changed), ("extra", extra)):
for k in items:
print(f"{name}: {k}")
print(f"{len(current)} files, {len(missing)} missing, {len(changed)} hash mismatch, {len(extra)} extra")
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),
"subtrees": SUBTREES,
"files_outside_subtrees": FILES,
"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", encoding="utf-8")
print(f"{out['n_files']} files, {out['total_bytes'] / 1e9:.2f} GB -> {MANIFEST.relative_to(REPO_ROOT)}")
return 0
if __name__ == "__main__":
sys.exit(main())