Failed distortion correction

Summary of what happened:

Dear experts,

I’m running the latest version of fMRIprep (22.1.1), and I’m using 2 magnitude images + phase difference for distortion correction. The results are completely wrong and the corrected images are much worst than the distorted images,

Command used (and if a helper script was used, a link to the helper script or the command generated):

Version:

22.1.1

Environment (Docker, Singularity, custom installation):

Data formatted according to a validatable standard? Please provide the output of the validator:

Relevant log outputs (up to 20 lines):

Screenshots / relevant information:

Here is one example:
image

Any clue what could be the issue? Thanks in advance.

Best regards,

Manuel

Hi @mblesac,

Some other users have reported similar issues (see threads linked here).

  1. Have you tried using the most recent LTS version (20.2.7 at this time)?
  2. Have you confirmed that the phase encoding directions are correct for your fieldmap and BOLD files?
  3. Have you confirmed that fMRIPrep is using your fieldmaps and not doing the SYN-based fieldmapless method? You did not share your command, so I don’t know if you enabled it or not.
  4. Does fMRIPrep return any errors?
  5. Is this error consistent across subjects?

Best,
Steven

Hi @Steven,

Thanks for your reply, see my responses below:

Yes, and the same command produces an error:

Node: fmriprep_wf.single_subject_8043_wf.anat_preproc_wf.surface_recon_wf.autorecon1
Working directory: /EBC/home/mblesa/5_YEARS_ANALYSIS/fmriprep_wf/single_subject_8043_wf/anat_preproc_wf/surface_recon_wf/autorecon1

Node inputs:

FLAIR_file = <undefined>
T1_files = ['/EBC/home/mblesa/5_YEARS_ANALYSIS/BIDs_data/sub-8043/ses-01/anat/sub-8043_ses-01_T1w.nii.gz']
T2_file = /EBC/home/mblesa/5_YEARS_ANALYSIS/BIDs_data/sub-8043/ses-01/anat/sub-8043_ses-01_T2w.nii.gz
args = <undefined>
big_ventricles = <undefined>
brainstem = <undefined>
directive = autorecon1
environ = {}
expert = <undefined>
flags = ['-noskullstrip']
hemi = <undefined>
hippocampal_subfields_T1 = <undefined>
hippocampal_subfields_T2 = <undefined>
hires = False
mprage = <undefined>
mri_aparc2aseg = <undefined>
mri_ca_label = <undefined>
mri_ca_normalize = <undefined>
mri_ca_register = <undefined>
mri_edit_wm_with_aseg = <undefined>
mri_em_register = <undefined>
mri_fill = <undefined>
mri_mask = <undefined>
mri_normalize = <undefined>
mri_pretess = <undefined>
mri_remove_neck = <undefined>
mri_segment = <undefined>
mri_segstats = <undefined>
mri_tessellate = <undefined>
mri_watershed = <undefined>
mris_anatomical_stats = <undefined>
mris_ca_label = <undefined>
mris_fix_topology = <undefined>
mris_inflate = <undefined>
mris_make_surfaces = <undefined>
mris_register = <undefined>
mris_smooth = <undefined>
mris_sphere = <undefined>
mris_surf2vol = <undefined>
mrisp_paint = <undefined>
openmp = 16
parallel = <undefined>
steps = <undefined>
subject_id = sub-8043
subjects_dir = /EBC/home/mblesa/5_YEARS_ANALYSIS/derivatives/freesurfer
talairach = <undefined>
use_FLAIR = <undefined>
use_T2 = <undefined>
xopts = <undefined>

Traceback (most recent call last):
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 521, in run
    result = self._run_interface(execute=True)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 639, in _run_interface
    return self._run_command(execute)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 751, in _run_command
    f"Exception raised while executing Node {self.name}.\n\n{result.runtime.traceback}"
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node autorecon1.

RuntimeError: subprocess exited with code 1.

I can see in the json files that the phase encoding direction for the two magnitude images and the phase difference is i, however for the functional image is j-, is that correct? I never used this method before.

The command line is:
singularity run -C -B /EBC:/EBC,$PWD:/opt/templateflow /EBC/home/mblesa/fmriprep-22.1.1.simg $PWD/BIDs_data $PWD/derivatives participant --participant-label ${NAME} -w $PWD --nthreads 16 --fd-spike-threshold 2 --dvars-spike-threshold 3 --omp-nthreads 16 --fs-license-file /EBC/local/infantFS/freesurfer/license.txt --output-space MNI152NLin2009cAsym:res-2 T1w --stop-on-first-crash --skip_bids_validation > $PWD/derivatives/log_fMRIprep_sub-${NAME}.txt

Or replacing 22.1.1 by 20.2.7.

No errors for the 22.1.1

Yes, I tried two different subjects and it was the same.

Best regards,

Manuel

If you are using the same command for both versions that also means you are using the same working directory for the two versions which is not recommended.

Please try the LTS version again, specifying a new working directory, and make sure that fmripre will not try to use premade Freesurfer outputs (unless you are sure that they came from the appropriate Freesurfer version, which for LTS is 6.0).

Best,
Steven

Hi,

I deleted all the folders and run it again, and still finding the same error:

Node: fmriprep_wf.single_subject_8043_wf.anat_preproc_wf.surface_recon_wf.autorecon1
Working directory: /EBC/home/mblesa/5_YEARS_ANALYSIS/fmriprep_wf/single_subject_8043_wf/anat_preproc_wf/surface_recon_wf/autorecon1

Node inputs:

FLAIR_file = <undefined>
T1_files = <undefined>
T2_file = <undefined>
args = <undefined>
big_ventricles = <undefined>
brainstem = <undefined>
directive = autorecon1
environ = {}
expert = <undefined>
flags = <undefined>
hemi = <undefined>
hippocampal_subfields_T1 = <undefined>
hippocampal_subfields_T2 = <undefined>
hires = <undefined>
mprage = <undefined>
mri_aparc2aseg = <undefined>
mri_ca_label = <undefined>
mri_ca_normalize = <undefined>
mri_ca_register = <undefined>
mri_edit_wm_with_aseg = <undefined>
mri_em_register = <undefined>
mri_fill = <undefined>
mri_mask = <undefined>
mri_normalize = <undefined>
mri_pretess = <undefined>
mri_remove_neck = <undefined>
mri_segment = <undefined>
mri_segstats = <undefined>
mri_tessellate = <undefined>
mri_watershed = <undefined>
mris_anatomical_stats = <undefined>
mris_ca_label = <undefined>
mris_fix_topology = <undefined>
mris_inflate = <undefined>
mris_make_surfaces = <undefined>
mris_register = <undefined>
mris_smooth = <undefined>
mris_sphere = <undefined>
mris_surf2vol = <undefined>
mrisp_paint = <undefined>
openmp = 16
parallel = <undefined>
steps = <undefined>
subject_id = recon_all
subjects_dir = <undefined>
talairach = <undefined>
use_FLAIR = <undefined>
use_T2 = <undefined>
xopts = <undefined>

Traceback (most recent call last):
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 521, in run
    result = self._run_interface(execute=True)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 639, in _run_interface
    return self._run_command(execute)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 751, in _run_command
    f"Exception raised while executing Node {self.name}.\n\n{result.runtime.traceback}"
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node autorecon1.

RuntimeError: subprocess exited with code 1.

It looks like the subject id is not correctly identified, am I right? The command line is the following:

/usr/local/miniconda/bin/fmriprep /EBC/home/mblesa/5_YEARS_ANALYSIS/BIDs_data /EBC/home/mblesa/5_YEARS_ANALYSIS/derivatives participant --participant-label 8043 -w /EBC/home/mblesa/5_YEARS_ANALYSIS --nthreads 16 --fd-spike-threshold 2 --dvars-spike-threshold 3 --omp-nthreads 16 --fs-license-file /EBC/local/infantFS/freesurfer/license.txt --output-space MNI152NLin2009cAsym:res-2 T1w --stop-on-first-crash

Best regards,

Manuel

It is not clear from this command what version was used.

It looks fine to me, what are you referring to?

Try the following (from this GitHub issue):

Hi,

I tried this and when using version 22.1.1 everything works, but the distortion correction fails. When using version 20.0.7 the recon-all step fails and says out of space. I don’t know what’s going on as I used the same command.

Best regards,

Manuel

Can you post the full error traceback? It is unclear whether this is related to the autorecon1 error you described before.

Also, has SYN been successful for you?

Hi,

I’ll post the full error onece I have it.

In the mean time I used SYN-SDC and the results were exactly the same. Seems that the flags --ignore fieldmaps --use-syn-sdc were ignored.

Best regards,

Manuel

I noticed this also with fmriprep v21.1.0:

Hi,

Thanks for the reply, I tried adding all the flags (--ignore fieldmaps --use-syn-sdc --force-syn) and it was an error:


Node Name: fmriprep_22_1_wf.single_subject_8043_wf.func_preproc_ses_01_task_restpixar1_wf.output_select
File: /EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/derivatives/sub-8043/log/20230216-161922_54cf993a-d7d2-4483-ada2-203a8cfef3aa/crash-20230216-213210-s1474782-output_select-cd53050a-3d23-41bd-8f2f-10ad61a68662.txt
Working Directory: /EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/func_preproc_ses_01_task_restpixar1_wf/output_select
Inputs:
fmap: ['/EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/fmap_preproc_wf/wf_auto_00001/unwarp/clipped_plumb_field.nii.gz']
fmap_coeff: [['/EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/fmap_preproc_wf/wf_auto_00001/bs_filter/fmap_syn0Warp_Hz_trans_coeff000.nii.gz', '/EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/fmap_preproc_wf/wf_auto_00001/bs_filter/fmap_syn0Warp_Hz_trans_coeff001.nii.gz']]
fmap_mask: ['/EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/fmap_preproc_wf/wf_auto_00001/zooms_bmask/sub-8043_ses-01_T1w_corrected_xform_rbrainmask_trans_uint8_trans.nii.gz']
fmap_ref: ['/EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/fmap_preproc_wf/wf_auto_00001/unwarp/clipped_plumb_unwarped.nii.gz']
key: auto_00000
keys: ['auto_00001']
sdc_method: ['FLB ("fieldmap-less", SyN-based)']
Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/plugins/multiproc.py", line 344, in _send_procs_to_workers
    self.procs[jobid].run(updatehash=updatehash)
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node output_select.

Traceback:
	Traceback (most recent call last):
	  File "/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 401, in run
	    outputs = self.aggregate_outputs(runtime)
	  File "/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 430, in aggregate_outputs
	    predicted_outputs = self._list_outputs()  # Predictions from _list_outputs
	  File "/opt/conda/lib/python3.9/site-packages/niworkflows/interfaces/utility.py", line 217, in _list_outputs
	    index = self.inputs.keys.index(self.inputs.key)
	ValueError: 'auto_00000' is not in list

Best regards,

Manuel

Hi,

I followed the steps in here. When I executed the first time the autorecon command, the license was not found, then I put it in the correct place and still crashes. See the full log attached. Any clue?

Best regards,

Manuel
log.txt (70.6 KB)

I am a bit confused because I thought the error you were referencing was in 20.2.7 (LTS), but the log says you were using fmriprep 22.1.1. What happens in 20.2.7?

Hi,

Probably that was my mistake explaining what I did:

Hi,

Thanks for the reply, I tried adding all the flags (–ignore fieldmaps --use-syn-sdc --force-syn) and it was an error:

Node Name: fmriprep_22_1_wf.single_subject_8043_wf.func_preproc_ses_01_task_restpixar1_wf.output_select
File: /EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/derivatives/sub-8043/log/20230216-161922_54cf993a-d7d2-4483-ada2-203a8cfef3aa/crash-20230216-213210-s1474782-output_select-cd53050a-3d23-41bd-8f2f-10ad61a68662.txt
Working Directory: /EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/func_preproc_ses_01_task_restpixar1_wf/output_select
Inputs:
fmap: [’/EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/fmap_preproc_wf/wf_auto_00001/unwarp/clipped_plumb_field.nii.gz’]
fmap_coeff: [[’/EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/fmap_preproc_wf/wf_auto_00001/bs_filter/fmap_syn0Warp_Hz_trans_coeff000.nii.gz’, ‘/EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/fmap_preproc_wf/wf_auto_00001/bs_filter/fmap_syn0Warp_Hz_trans_coeff001.nii.gz’]]
fmap_mask: [’/EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/fmap_preproc_wf/wf_auto_00001/zooms_bmask/sub-8043_ses-01_T1w_corrected_xform_rbrainmask_trans_uint8_trans.nii.gz’]
fmap_ref: [’/EBC/home/mblesa/5_YEARS_ANALYSIS/TEST/fmriprep_22_1_wf/single_subject_8043_wf/fmap_preproc_wf/wf_auto_00001/unwarp/clipped_plumb_unwarped.nii.gz’]
key: auto_00000
keys: [‘auto_00001’]
sdc_method: [‘FLB (“fieldmap-less”, SyN-based)’]
Traceback (most recent call last):
File “/opt/conda/lib/python3.9/site-packages/nipype/pipeline/plugins/multiproc.py”, line 344, in _send_procs_to_workers
self.procs[jobid].run(updatehash=updatehash)
File “/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py”, line 527, in run
result = self._run_interface(execute=True)
File “/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py”, line 645, in _run_interface
return self._run_command(execute)
File “/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py”, line 771, in _run_command
raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node output_select.

Traceback:
Traceback (most recent call last):
File “/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/core.py”, line 401, in run
outputs = self.aggregate_outputs(runtime)
File “/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/core.py”, line 430, in aggregate_outputs
predicted_outputs = self._list_outputs() # Predictions from _list_outputs
File “/opt/conda/lib/python3.9/site-packages/niworkflows/interfaces/utility.py”, line 217, in _list_outputs
index = self.inputs.keys.index(self.inputs.key)
ValueError: ‘auto_00000’ is not in list
Best regards,

Manuel

here I’m indeed using the 22.1.1 when I was trying to follow the advice of @jsein trying to use --ignore fieldmaps --use-syn-sdc --force-syn.

In here:

I’m using the 20.2.7 to try to solve why freesurfer isn’t working. I hope this helps.

Best regards,

Manuel

Hi,

I investigated this issue:

If i run versions 20.0.7 or the 21.0.4 I found the same problem. The surface reconstruction fails:

CV of field change: 0.000927078
evaluate_field: posixio.c:210: px_pgin: Assertion `*posp == ((off_t)(-1)) || *posp == lseek(nciop->fd, 0, 1)' failed.
nu_evaluate: crashed while running evaluate_field (termination status=134)
nu_correct: crashed while running nu_evaluate (termination status=65280)
ERROR: nu_correct
Linux EBC33 4.4.0-186-generic #216-Ubuntu SMP Wed Jul 1 05:34:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

recon-all -s sub-8043 exited with ERRORS at Thu Feb 23 15:23:12 GMT 2023

For more details, see the log file /EBC/home/mblesa/5_YEARS_ANALYSIS/derivatives2/sourcedata/freesurfer/sub-8043/scripts/recon-all.log
To report a problem, see http://surfer.nmr.mgh.harvard.edu/fswiki/BugReporting

Standard error:

Return code: 1

However, when I run the command with sudo, everything works as expected. This is what I run:

export SINGULARITYENV_TEMPLATEFLOW_HOME=$PWD/fmriprep/.cache/templateflow

SINGULARITY_TMPDIR=$PWD SINGULARITY_CACHEDIR=$PWD singularity run -C -B /EBC:/EBC,$PWD:/opt/templateflow /EBC/home/mblesa/fmriprep-21.0.4.simg $PWD/BIDs_data $PWD/derivatives2 participant --participant-label ${NAME} -w $PWD --nthreads 16 --fd-spike-threshold 2 --dvars-spike-threshold 3 --omp-nthreads 16 --fs-license-file /EBC/local/infantFS/freesurfer/license.txt --output-space MNI152NLin2009cAsym:res-2 T1w --stop-on-first-crash > $PWD/derivatives2/log_fMRIprep_sub-${NAME}.txt

Any clue? Thanks in advance.

Best regards,

Manuel

I posted this previously but without the proper permissions on the links. I’m hoping someone has some insight!
I have encountered fmriprep distortion correction issues, most recently with fmriprep 23.1.4. See fmriprepSDC.pdf 1 for some nice pictures and details of the commands.

Additionally, the MRI protocols for both the good dataset and the bad dataset have been uploaded with the fmriprep and mriqc reports and figures for the bad dataset: fmriprep_sdc_reports_protocols.zip

My best guess is that the bad dataset has an orientation problem, or a partial volume problem (top of head and part of cerebellum are missing)…but I’m just guessing here. I’d appreciate any input or ideas. Surely I’m missing something!

Thank you,

Dianne

1 Like

Hi Dianne,

I’m struggling with the same issues although, having a bit more luck with synsdc than you report indicates you’re having. I think its worth trying out fmriprep v20.2.7 LTS, which I’m planning on running to.

Relatedly, is there a quantifiable way to decide between these approaches other than visual inspection?

Hi @foldes.andrei,

You could calculate the dice coefficient between the bold ref and the T1 image.

Best,
Steven

2 Likes

Do DICE coefficients work for non-masks? I’ve always used DICE and JACCARD to compare mask images.

Hi @Dianne_Patterson,

I should have been more clear - as you alluded to, you would use the BOLD ref mask and T1 mask. Maybe a more complicated mutual information approach could be used on the actual bold ref and T1 images, but I’d need to think more about that.

Best,
Steven

1 Like