Download hmc/reference/scripts/bzero_check.py from neurodeskorg/webapps: direct link, hf CLI and curl.
- Browser
- Download file 996 Bytes
-
https://huggingface.co/datasets/neurodeskorg/webapps/resolve/main/hmc/reference/scripts/bzero_check.py
- Command line
-
hf download hf://datasets/neurodeskorg/webapps/hmc/reference/scripts/bzero_check.py
-
curl -L -o bzero_check.py https://huggingface.co/datasets/neurodeskorg/webapps/resolve/main/hmc/reference/scripts/bzero_check.py
996 Bytes
| """Check whether the trivial model's advanced_clip changed dataset.bzero in place.""" | |
| import sys | |
| import h5py | |
| import nibabel as nb | |
| import numpy as np | |
| gp_h5, triv_h5, triv_pred, raw = sys.argv[1:5] | |
| with h5py.File(gp_h5) as h: | |
| bz_gp = np.asarray(h["0/bzero"], dtype=np.float64) | |
| with h5py.File(triv_h5) as h: | |
| bz_tr = np.asarray(h["0/bzero"], dtype=np.float64) | |
| pred = np.asarray(nb.load(triv_pred).dataobj, dtype=np.float64) | |
| img = nb.load(raw) | |
| b0idx = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] | |
| b0 = np.asarray(img.dataobj, dtype=np.float64)[..., b0idx] | |
| for name, a in (("gp", bz_gp), ("trivial", bz_tr), ("trivial predicted", pred)): | |
| print( | |
| name, "min", a.min(), "max", a.max(), "integral", bool(np.all(a == np.round(a))) | |
| ) | |
| print("trivial bzero == trivial predicted", bool(np.array_equal(bz_tr, pred))) | |
| print("gp bzero == median of raw b0", bool(np.allclose(bz_gp, np.median(b0, axis=-1)))) | |
| print("gp bzero == mean of raw b0", bool(np.allclose(bz_gp, b0.mean(axis=-1)))) | |