BIDS Validation Error REPETITION_TIME_MISMATCH preventing fmriprep from running

Hello,

Answers to a previous question suggested that a mismatch in RepetitionTime between the BIDS json sidecar and NIFTI header should not prevent fmriprep from running.

However, I am running into exactly this issue. Has something changed? Is this behavior intended?

  1. The TRs in my niftis are incorrect. The nifti header says 1000ms whereas the json sidecar says 2.4 seconds.

1: [ERR] Repetition time did not match between the scan’s header and the associated JSON metadata file. (code: 12 - REPETITION_TIME_MISMATCH)

Unfortunately fmriprep 1.2.5 fails to run due to this error

Traceback (most recent call last):
File “/usr/local/miniconda/bin/fmriprep”, line 11, in
sys.exit(main())
File “/usr/local/miniconda/lib/python3.6/site-packages/fmriprep/cli/run.py”, line 353, in main
validate_input_dir(exec_env, opts.bids_dir, opts.participant_label)
File “/usr/local/miniconda/lib/python3.6/site-packages/fmriprep/cli/run.py”, line 534, in validate_input_dir
subprocess.check_call([‘bids-validator’, bids_dir, ‘-c’, temp.name])
File “/usr/local/miniconda/lib/python3.6/subprocess.py”, line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command ‘[‘bids-validator’, ‘/scratch/to/mypath’, ‘-c’, ‘/tmp/tmplq537tw3’]’ returned non-zero exit status 1.
Sentry is attempting to send 1 pending error messages

I will of course look into correcting the nifti headers to get around this. But I am guessing some recent bug fixes might have had an unintended consequence.

Update: I don’t encounter this problem with fmriprep-1.2.3.

Hi @mnarayan, you are right. That PR introduced the full validator as a preliminary step. You can workaround that using the --skip-bids-validation argument in you command line.

However, I’d strongly recommend to fix those NIfTI headers to match the sidecar JSON.

1 Like

BTW, I’ve opened https://github.com/poldracklab/fmriprep/issues/1484 based on the hardly interpretable output you are getting.

1 Like

Having the same issue with ABCD data, somehow the nifti headers ended up with TR=0, but the accompanying .json files are correct. Is it safe to bypass BIDS validation, and fmriprep will using the .json information, rather than the nifti headers?

I’ve informed them but it would be fast to not fix all the nifti headers for them.

Yes, so long you are aware you are entering danger zone :slight_smile:

1 Like

Hi Oesteban,

We are encountering the same problem with incorrect Nifti headers. Also our json files have the incorrect TR (3.9 instead of 1.98). We wrote a script to change the TR to the correct one for the json files. However, we cannot find any clues on how to change Nifti header information without opening the text editor. We have a lot of fMRIs, so it is not feasible to change them all by hand… Do you have any suggestions?
Thanks in advance!

Best,
Julia

I would suggest the following using pybids and nibabel:

from pathlib import Path
import bids
import numpy as np

layout = bids.BIDSLayout("/path/to/dataset")
bold_images = layout.get(suffix="bold", extension=[".nii", ".nii.gz"])
for bold in bold_images:
    TR = bold.get_metadata()["RepetitionTime"]
    img = bold.get_image()
    zooms = img.header.get_zooms()
    if not np.isclose(zooms[3], TR):
        old_path = Path(bold)
        new_path = bold.with_name(f"{old_path.stem}_fixed.nii.gz")
        img.header.set_zooms(zooms[:3] + (TR,))
        img.to_filename(new_path)

This Python script will create a new image with an additional _fixed suffix when the TR does not match the pixdim[4] field. I would recommend taking this route and reviewing all such changed files before overwriting the old files. If you want to overwrite directly, other steps will need to be taken to ensure that you don’t delete the data before you read it.

Hi Effigies,

I am running into the same problem with a mismatch between nifti header’s 4th voxel dimension (0s) and its associated json file repetition time 3.196s.
I have found a way to edit the 4th dimension in the nifti header through mango software following Neuroimaging Core Docs - https://neuroimaging-core-docs.readthedocs.io/en/latest/pages/mango.html#nifti-hdr. Does it seem reasonable to you?
Thank you in advance
Jakub

Sure, you can use any tool that will do the job.

Wonderful. Thanks again.