"""Facts needed to decide what to pack for the M0 upload.""" import hashlib import sys from pathlib import Path import h5py import nibabel as nb import numpy as np R = Path("/var/tmp/dwi-hmc/runs") def sha(p: Path) -> str: return hashlib.sha256(p.read_bytes()).hexdigest() for run in ("nifreeze-gp", "nifreeze-trivial-a1"): w = R / run / "work" for kind in ("sample", "predicted", "dbg"): im = nb.load(w / f"{kind}_00000.nii.gz") d = np.asarray(im.dataobj) print(run, kind, im.get_data_dtype(), d.shape, float(d.min()), float(d.max())) preds = sorted(w.glob("predicted_*.nii.gz")) shas = {sha(p) for p in preds} print(run, "predicted files", len(preds), "distinct sha", len(shas)) a = nb.load(w / "predicted_00000.nii.gz").get_fdata(dtype=np.float64) print( run, "pred f32 roundtrip max abs", float(np.abs(a.astype(np.float32).astype(np.float64) - a).max()), ) for f in (R / "nifreeze-gp" / "out").glob("*.h5"): with h5py.File(f) as h: h.visititems( lambda n, o: print( "h5", n, getattr(o, "shape", ""), getattr(o, "dtype", "") ) ) x5 = next((R / "nifreeze-gp" / "out").glob("*.x5")) with h5py.File(x5) as h: h.visititems( lambda n, o: print("x5", n, getattr(o, "shape", ""), getattr(o, "dtype", "")) ) o = nb.load(next((R / "nifreeze-gp" / "out").glob("*.nii.nii.gz"))) print("out dwi", o.shape, o.get_data_dtype()) print("input sha", sha(Path(sys.argv[1])))