BIDS validator giving error for TR

Hi folks, we are trying to organize some data into BIDS, however, getting an error message on the RepetitionTime during validation:
“Repetition time was not defined in seconds, milliseconds or microseconds in the scan's header.”

The functional file header seems to have correct TR, as observed with pixdim4 in fslinfo
fslinfo

Here’s the json file:
json_info

We tried changing it to millseconds (i.e., 800), but still same issue.

Any idea what might be happening and why BIDS validation failed?

This probably refers to the xyzt_units field of the NIfTI file missing a temporal code. You almost certainly want it set to mm/s.

I ran into a similar problem and wanted to share a fix as I wasn’t able to find a straightforward python solution anywhere and had to look at the nibabel source code to find the correct unit codes.

from bids import BIDSLayout
import nibabel as nb

def set_xyzt_units(img, xyz='mm', t='sec'):
    header = img.header.copy()
    header.set_xyzt_units(xyz=xyz, t=t)
    return img.__class__(img.get_data().copy(), img.affine, header)    

def fix_xyzt_units(bids_root):
    layout = BIDSLayout(bids_root)
    for nii in layout.get(extensions=['.nii', '.nii.gz']):
        metadata = layout.get_metadata(nii.path)
        img = nb.load(nii.path)
        fixed_img = set_xyzt_units(img)
        fixed_img.to_filename(nii.path)
3 Likes

I have the same problem an fix it with this Matlab code:

filename=“T1.nii.gz”

V = niftiread(filename);

info = niftiinfo(filename);

if info.raw.xyzt_units == 0
info.raw.xyzt_units = 10;
info.SpaceUnits = ‘Millimeter’;
info.TimeUnits = ‘Second’;
end

niftiwrite(V,‘T1fix’,info,‘Compressed’,true)