File size: 1,072 Bytes
d950cc4 | 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 | """Checks for the degibbs slab reference (issue #432). Prints JSON facts."""
import json
import sys
import nibabel as nib
import numpy as np
slab_in, slab_out, slab_1t, full_out, z0, z1 = sys.argv[1:7]
z0, z1 = int(z0), int(z1)
a = nib.load(slab_in)
o = nib.load(slab_out)
x = np.asanyarray(a.dataobj).astype(np.float64)
y = np.asanyarray(o.dataobj)
t = np.asanyarray(nib.load(slab_1t).dataobj)
f = np.asanyarray(nib.load(full_out).dataobj)[:, :, z0:z1, :]
facts = {
"output_dtype": str(y.dtype),
"output_shape": list(y.shape),
"affine_equal": bool(np.allclose(a.affine, o.affine, atol=1e-5)),
"max_abs_diff_vs_full_volume_run": float(np.abs(y - f).max()),
"max_abs_diff_vs_one_thread_run": float(np.abs(y - t).max()),
"nrmse_vs_input": float(np.sqrt(np.mean((y - x) ** 2)) / np.sqrt(np.mean(x**2))),
"output_descrip": o.header["descrip"].tobytes().rstrip(b"\0").decode(),
"output_scl": [float(o.header["scl_slope"]), float(o.header["scl_inter"])],
"output_extensions": len(o.header.extensions),
}
print(json.dumps(facts, indent=2))
|