"""Compare the raw DWI grid with QSIPrep's conformed (LPS) grid. Usage: python -I conform_facts.py RAW CONFORMED.""" import sys import nibabel as nb import numpy as np raw = nb.load(sys.argv[1]) con = nb.load(sys.argv[2]) print("raw", raw.shape, raw.get_data_dtype(), nb.aff2axcodes(raw.affine)) print(np.array2string(raw.affine, precision=6)) print("conformed", con.shape, con.get_data_dtype(), nb.aff2axcodes(con.affine)) print(np.array2string(con.affine, precision=6)) print("scl", con.header["scl_slope"], con.header["scl_inter"]) ornt = nb.orientations.ornt_transform( nb.io_orientation(raw.affine), nb.io_orientation(con.affine) ) r = nb.orientations.apply_orientation(np.asanyarray(raw.dataobj), ornt) c = np.asanyarray(con.dataobj) print("max abs diff after reorientation", np.abs(r.astype(np.float64) - c).max())