A bug in an FSL function we are using has stripped our resulting NIfTIs of the correct repetition time information (TR, entry
 in the header). It says 1.0 but should be 1.5.
We have confirmation from the FSL developers that manually changing the TR inside the NIfTIs is fine.
To do this in
nibabel, I did:
def set_tr(img, tr): header = img.header.copy() zooms = header.get_zooms()[:3] + (tr,) header.set_zooms(zooms) return img.__class__(img.get_fdata().copy(), img.affine, header) niifiles = glob.glob('*.nii.gz') for niifile in niifiles: img = nb.load(niifile) fixed_img = set_tr(img, 1.5) fixed_img.to_filename(niifile)
This correctly sets the repetition time in the header. This is adapted from the response by @effigies here: BIDS Validator error: TR mismatch between NIFTI header and JSON file, and BIDS Validator is somehow finding TR=0. Best solution?
I’ve got two questions:
- Can you confirm that this is 100% correct? I admit that I’m not sure I understand the differences between
get_fdata()well enough to be confident about the usage.
- The rewritten files have different file sizes (e.g. one went from 624.1MB to 692.9MB). What is going on here? Could there be a problem?