File size: 1,528 Bytes
a4ba047 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | """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])))
|