Files
Volve-DIA/scripts/00_data_manifest.py
lamlvh a3c175638f Add P0 infrastructure for the Volve-DIA benchmark
Set up the data, parsing and quality-control layer for a public benchmark
on the Volve daily drilling reports (DDR) and WITSML real-time data.

- Data manifest with SHA-256 hashes of the three Volve subtrees in use.
- DDR XML parser into DuckDB (1,759 reports, 26 wellbores, 23,447
  activities, 17 tables) with locked expected counts.
- Render QC of the publisher HTML against the XML (272,544 items).
- OCR client for the shared chandra vLLM service, with a page cache keyed
  on model, prompt hash, dpi, max_tokens and temperature, and OCR QC
  against the HTML on a 26-report pilot.
- Run logging (scripts/runlog.sh, logs/index.csv), the P0 runner and
  40 tests.
- Research plan, technical overview and progress page (in Vietnamese).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 12:52:22 +00:00

85 lines
3.1 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 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"]
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())
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()]
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,
"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())