Fmriprep nipype.workflow ERROR: ValueError: Affine for image 2 does not match affine for first image

Hi there,

I was running one subject on fmriprep and firstly everything went great except for the SDC. The output data were generated successfully but the SDC wasn’t performed.

My data tree is listed as follow:
├── dataset_description.json
├── README
└── sub-00084
├── ses-01
│ ├── anat
│ │ ├── sub-00084_ses-01_T1w.json
│ │ ├── sub-00084_ses-01_T1w.nii.gz
│ │ ├── sub-00084_ses-01_T2w.json
│ │ └── sub-00084_ses-01_T2w.nii.gz
│ ├── fmap
│ │ ├── sub-00084_ses-01_magnitude1.json
│ │ ├── sub-00084_ses-01_magnitude1.nii.gz
│ │ ├── sub-00084_ses-01_magnitude2.json
│ │ ├── sub-00084_ses-01_magnitude2.nii.gz
│ │ ├── sub-00084_ses-01_phasediff.json
│ │ └── sub-00084_ses-01_phasediff.nii.gz
│ └── func
│ ├── sub-00084_ses-01_task-PE_run-1_bold.json
│ ├── sub-00084_ses-01_task-PE_run-1_bold.nii.gz
│ ├── sub-00084_ses-01_task-PE_run-2_bold.json
│ ├── sub-00084_ses-01_task-PE_run-2_bold.nii.gz
│ ├── sub-00084_ses-01_task-PE_run-3_bold.json
│ ├── sub-00084_ses-01_task-PE_run-3_bold.nii.gz
│ ├── sub-00084_ses-01_task-PE_run-4_bold.json
│ ├── sub-00084_ses-01_task-PE_run-4_bold.nii.gz
│ ├── sub-00084_ses-01_task-PE_run-5_bold.json
│ ├── sub-00084_ses-01_task-PE_run-5_bold.nii.gz
│ ├── sub-00084_ses-01_task-PE_run-6_bold.json
│ ├── sub-00084_ses-01_task-PE_run-6_bold.nii.gz
│ ├── sub-00084_ses-01_task-PE_run-7_bold.json
│ └── sub-00084_ses-01_task-PE_run-7_bold.nii.gz
└── ses-02
├── anat
│ ├── sub-00084_ses-02_T1w.json
│ ├── sub-00084_ses-02_T1w.nii.gz
│ ├── sub-00084_ses-02_T2w.json
│ └── sub-00084_ses-02_T2w.nii.gz
├── fmap
│ ├── sub-00084_ses-02_magnitude1.json
│ ├── sub-00084_ses-02_magnitude1.nii.gz
│ ├── sub-00084_ses-02_magnitude2.json
│ ├── sub-00084_ses-02_magnitude2.nii.gz
│ ├── sub-00084_ses-02_phasediff.json
│ └── sub-00084_ses-02_phasediff.nii.gz
└── func
├── sub-00084_ses-02_task-PE_run-1_bold.json
├── sub-00084_ses-02_task-PE_run-1_bold.nii.gz
├── sub-00084_ses-02_task-PE_run-2_bold.json
├── sub-00084_ses-02_task-PE_run-2_bold.nii.gz
├── sub-00084_ses-02_task-PE_run-3_bold.json
├── sub-00084_ses-02_task-PE_run-3_bold.nii.gz
├── sub-00084_ses-02_task-PE_run-4_bold.json
├── sub-00084_ses-02_task-PE_run-4_bold.nii.gz
├── sub-00084_ses-02_task-PE_run-5_bold.json
├── sub-00084_ses-02_task-PE_run-5_bold.nii.gz
├── sub-00084_ses-02_task-PE_run-6_bold.json
├── sub-00084_ses-02_task-PE_run-6_bold.nii.gz
├── sub-00084_ses-02_task-PE_run-7_bold.json
└── sub-00084_ses-02_task-PE_run-7_bold.nii.gz

So I followed this answer Susceptibility distortion failed by defining the “IntendedFor" and “B0FieldIdentifier” in all of my fmaps json files, and “B0FieldSource” in all my BOLD json files.

At first it went smoothly. Seems like it identified the fmap estimators to correct the bold data:

ndyx@R940xa:~$ fmriprep-docker /Data/NDYX/PE_task/QC20211209/bidsdata_test /Data/NDYX/PE_task/QC20211209/derivatives participant --participant-label 00084 --fs-license-file /Data/NDYX/PE_task/QC20211209/license.txt --fs-no-reconall --longitudinal --ignore slicetiming --bold2t1w-dof 6 --skip-bids-validation --output-spaces MNI152NLin6Asym:res-2 MNI152NLin2009cAsym
RUNNING: docker run --rm -e DOCKER_VERSION_8395080871=20.10.18 -it -v /Data/NDYX/PE_task/QC20211209/license.txt:/opt/freesurfer/license.txt:ro -v /Data/NDYX/PE_task/QC20211209/bidsdata_test:/data:ro -v /Data/NDYX/PE_task/QC20211209/derivatives:/out nipreps/fmriprep:22.0.1 /data /out participant --participant-label 00084 --fs-no-reconall --longitudinal --ignore slicetiming --bold2t1w-dof 6 --skip-bids-validation --output-spaces MNI152NLin6Asym:res-2 MNI152NLin2009cAsym
220927-03:56:11,601 nipype.workflow IMPORTANT:
Running fMRIPrep version 22.0.1

     License NOTICE ##################################################
     fMRIPrep 22.0.1
     Copyright 2022 The NiPreps Developers.
     
     This product includes software developed by
     the NiPreps Community (https://nipreps.org/).
     
     Portions of this software were developed at the Department of
     Psychology at Stanford University, Stanford, CA, US.
     
     This software redistributes the versioneer Python package, which is
     Public domain source code.
     
     This software is also distributed as a Docker container image.
     The bootstraping file for the image ("Dockerfile") is licensed
     under the MIT License.
     
     This software may be distributed through an add-on package called
     "Docker Wrapper" that is under the BSD 3-clause License.
     #################################################################

220927-03:56:11,772 nipype.workflow IMPORTANT:
Building fMRIPrep’s workflow:
* BIDS dataset path: /data.
* Participant list: [‘00084’].
* Run identifier: 20220927-035515_8f7032fd-6412-4230-ac7c-dd0af55d6a1c.
* Output spaces: MNI152NLin6Asym:res-2 MNI152NLin2009cAsym:res-native.
* Pre-run FreeSurfer’s SUBJECTS_DIR: /out/sourcedata/freesurfer.
220927-03:56:14,904 nipype.workflow INFO:
B0 field inhomogeneity map will be estimated with the following 1 estimators: [<EstimatorType.PHASEDIFF: 3>].
220927-03:56:15,425 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-01_task-PE_run-1_bold.nii.gz.
220927-03:56:15,425 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-01/func/sub-00084_ses-01_task-PE_run-1_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:16,800 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-01_task-PE_run-2_bold.nii.gz.
220927-03:56:16,800 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-01/func/sub-00084_ses-01_task-PE_run-2_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:18,4 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-01_task-PE_run-3_bold.nii.gz.
220927-03:56:18,4 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-01/func/sub-00084_ses-01_task-PE_run-3_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:19,205 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-01_task-PE_run-4_bold.nii.gz.
220927-03:56:19,205 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-01/func/sub-00084_ses-01_task-PE_run-4_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:20,734 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-01_task-PE_run-5_bold.nii.gz.
220927-03:56:20,735 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-01/func/sub-00084_ses-01_task-PE_run-5_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:21,939 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-01_task-PE_run-6_bold.nii.gz.
220927-03:56:21,939 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-01/func/sub-00084_ses-01_task-PE_run-6_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:23,138 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-01_task-PE_run-7_bold.nii.gz.
220927-03:56:23,139 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-01/func/sub-00084_ses-01_task-PE_run-7_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:24,334 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-02_task-PE_run-1_bold.nii.gz.
220927-03:56:24,334 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-02/func/sub-00084_ses-02_task-PE_run-1_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:25,530 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-02_task-PE_run-2_bold.nii.gz.
220927-03:56:25,530 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-02/func/sub-00084_ses-02_task-PE_run-2_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:26,724 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-02_task-PE_run-3_bold.nii.gz.
220927-03:56:26,724 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-02/func/sub-00084_ses-02_task-PE_run-3_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:27,982 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-02_task-PE_run-4_bold.nii.gz.
220927-03:56:27,983 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-02/func/sub-00084_ses-02_task-PE_run-4_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:29,652 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-02_task-PE_run-5_bold.nii.gz.
220927-03:56:29,653 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-02/func/sub-00084_ses-02_task-PE_run-5_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:30,840 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-02_task-PE_run-6_bold.nii.gz.
220927-03:56:30,840 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-02/func/sub-00084_ses-02_task-PE_run-6_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:32,28 nipype.workflow INFO:
No single-band-reference found for sub-00084_ses-02_task-PE_run-7_bold.nii.gz.
220927-03:56:32,28 nipype.workflow INFO:
Found usable B0-map (fieldmap) estimator(s) <phasediff_fmap0> to correct </data/sub-00084/ses-02/func/sub-00084_ses-02_task-PE_run-7_bold.nii.gz> for susceptibility-derived distortions.
220927-03:56:33,108 nipype.workflow INFO:
Setting-up fieldmap “phasediff_fmap0” (EstimatorType.PHASEDIFF) with <sub-00084_ses-01_magnitude1.nii.gz, sub-00084_ses-01_magnitude2.nii.gz, sub-00084_ses-01_phasediff.nii.gz, sub-00084_ses-02_magnitude1.nii.gz, sub-00084_ses-02_magnitude2.nii.gz, sub-00084_ses-02_phasediff.nii.gz>
220927-03:56:50,705 nipype.workflow INFO:
fMRIPrep workflow graph with 3157 nodes built successfully.
220927-03:57:49,358 nipype.workflow IMPORTANT:
fMRIPrep started!

However it crashed after a few hours, the errors were listed as below:

Errors
Node Name: fmriprep_22_0_wf.single_subject_00084_wf.fmap_preproc_wf.wf_phasediff_fmap0.magnitude_wf.magmrg
File: /out/sub-00084/log/20220927-035515_8f7032fd-6412-4230-ac7c-dd0af55d6a1c/crash-20220927-035854-root-magmrg-236dc2d7-cf57-48c2-9791-ac168c22637c.txt
Working Directory: /tmp/work/fmriprep_22_0_wf/single_subject_00084_wf/fmap_preproc_wf/wf_phasediff_fmap0/magnitude_wf/magmrg
Inputs:
grand_mean_scaling: False
hmc: False
in_files: [’/data/sub-00084/ses-01/fmap/sub-00084_ses-01_magnitude1.nii.gz’, ‘/data/sub-00084/ses-01/fmap/sub-00084_ses-01_magnitude2.nii.gz’, ‘/data/sub-00084/ses-02/fmap/sub-00084_ses-02_magnitude1.nii.gz’, ‘/data/sub-00084/ses-02/fmap/sub-00084_ses-02_magnitude2.nii.gz’]
in_mask:
to_ras: False
zero_based_avg: True
Traceback (most recent call last):
File “/opt/conda/lib/python3.9/site-packages/nipype/pipeline/plugins/multiproc.py”, line 67, in run_node
result[“result”] = node.run(updatehash=updatehash)
File “/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py”, line 524, in run
result = self._run_interface(execute=True)
File “/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py”, line 642, in _run_interface
return self._run_command(execute)
File “/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py”, line 750, in _run_command
raise NodeExecutionError(
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node magmrg.

Traceback (most recent call last):
File “/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/core.py”, line 398, in run
runtime = self._run_interface(runtime)
File “/opt/conda/lib/python3.9/site-packages/niworkflows/interfaces/images.py”, line 149, in _run_interface
filenii = nb.concat_images(nii_list)
File “/opt/conda/lib/python3.9/site-packages/nibabel/funcs.py”, line 141, in concat_images
raise ValueError(f’Affine for image {i} does not match affine for first image’)
ValueError: Affine for image 2 does not match affine for first image

Any ideas on how to fix this?

Thanks in advance!