Fmriprep error: Reference passed is not aligned with spline grids

Summary of what happened:

Hello,

I’m using fmriprep with docker and I’ve been having problems with SDC using phasediff.

In another thread related to similar SDC problems (Fieldmap correction gone wrong - #18 by effigies) someone recommended to use the pre-release 23.0.2a2, but when I run it I always get the same error.

Does anyone know what the problem might be in any of these cases?
Thank you in advance!

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

docker run -ti --rm \
    -v /media/patricia/data/fmriprep_data:/data:ro \
    -v /media/patricia/data/output_fmriprep:/out \
    -v /home/patricia/freesurfer/license.txt:/opt/freesurfer/license.txt:ro \
    nipreps/fmriprep:23.2.0a2 \
    /data /out/fmriprep \
    participant --participant-label sub-05 \

Version:

23.2.0a2

Environment (Docker, Singularity, custom installation):

Docker

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

File Path: Task scans should have a corresponding events.tsv file. If this is a resting state scan you can ignore this warning or rename the task to include the word "rest".

	Type:		Warning
	File:		sub-05_task-SubRiskRun1_bold.nii.gz
	Location:		f/sub-05/func/sub-05_task-SubRiskRun1_bold.nii.gz
	Reason:		Task scans should have a corresponding events.tsv file. It can be included one of the following locations: /events.tsv, /task-SubRiskRun1_events.tsv, /sub-05/sub-05_events.tsv, /sub-05/sub-05_task-SubRiskRun1_events.tsv, /sub-05/func/sub-05_events.tsv, /sub-05/func/sub-05_task-SubRiskRun1_events.tsv
	Type:		Warning
	File:		sub-05_task-SubRiskRun2_bold.nii.gz
	Location:		f/sub-05/func/sub-05_task-SubRiskRun2_bold.nii.gz
	Reason:		Task scans should have a corresponding events.tsv file. It can be included one of the following locations: /events.tsv, /task-SubRiskRun2_events.tsv, /sub-05/sub-05_events.tsv, /sub-05/sub-05_task-SubRiskRun2_events.tsv, /sub-05/func/sub-05_events.tsv, /sub-05/func/sub-05_task-SubRiskRun2_events.tsv
	Type:		Warning
	File:		sub-05_task-SubRiskRun3_bold.nii.gz
	Location:		f/sub-05/func/sub-05_task-SubRiskRun3_bold.nii.gz
	Reason:		Task scans should have a corresponding events.tsv file. It can be included one of the following locations: /events.tsv, /task-SubRiskRun3_events.tsv, /sub-05/sub-05_events.tsv, /sub-05/sub-05_task-SubRiskRun3_events.tsv, /sub-05/func/sub-05_events.tsv, /sub-05/func/sub-05_task-SubRiskRun3_events.tsv
	Type:		Warning
	File:		sub-05_task-SubRiskRun4_bold.nii.gz
	Location:		f/sub-05/func/sub-05_task-SubRiskRun4_bold.nii.gz
	Reason:		Task scans should have a corresponding events.tsv file. It can be included one of the following locations: /events.tsv, /task-SubRiskRun4_events.tsv, /sub-05/sub-05_events.tsv, /sub-05/sub-05_task-SubRiskRun4_events.tsv, /sub-05/func/sub-05_events.tsv, /sub-05/func/sub-05_task-SubRiskRun4_events.tsv

======================================================


File Path: The Authors field of dataset_description.json should contain an array of fields - with one author per field. This was triggered based on the presence of only one author field. Please ignore if all contributors are already properly listed.

	Type:		Warning

======================================================

Relevant log outputs (up to 20 lines):

Node: fmriprep_23_2_wf.sub_05_wf.bold_task_subriskrun1_wf.bold_native_wf.boldref_fmap
Working directory: /tmp/work/fmriprep_23_2_wf/sub_05_wf/bold_task_subriskrun1_wf/bold_native_wf/boldref_fmap
Node inputs:
fmap_ref_file =
in_coeffs =
inverse = [True]
target_ref_file =
transforms =
Traceback (most recent call last):
File “/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/plugins/multiproc.py”, line 67, in run_node
result[“result”] = node.run(updatehash=updatehash)
File “/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py”, line 527, in run
result = self._run_interface(execute=True)
File “/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py”, line 645, in _run_interface
return self._run_command(execute)
File “/opt/conda/envs/fmriprep/lib/python3.10/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 boldref_fmap.
Traceback:
Traceback (most recent call last):
File “/opt/conda/envs/fmriprep/lib/python3.10/site-packages/nipype/interfaces/base/core.py”, line 397, in run
runtime = self._run_interface(runtime)
File “/opt/conda/envs/fmriprep/lib/python3.10/site-packages/fmriprep/interfaces/resampling.py”, line 169, in _run_interface
fieldmap = reconstruct_fieldmap(
File “/opt/conda/envs/fmriprep/lib/python3.10/site-packages/fmriprep/interfaces/resampling.py”, line 661, in reconstruct_fieldmap
raise ValueError(‘Reference passed is not aligned with spline grids’)
ValueError: Reference passed is not aligned with spline grids

Screenshots / relevant information:

I first tried version 23.1.4 and later version 20.2.3 - you can see how both output look in the images below with both versions on the same subject.

With v. 23.1.4

With v.20.2.3

Hi @Patricia_Fernandes,

I have reformatted your post according to the Software Support post template. You can see that there was information you left out. Please add this missing information by editing your post so we have the information we need to help you. I would also try 23.2.0a2 or the unstable branch as they are more recent.

Best,
Steven

Hi Steven,

Thank you! Already edited the post.
Actually I did try v. 23.2.0a2 not v. 23.2.0a1, wrote it incorrectly but already edited.

Thanks! Can you try adding a working directory with the -w argument (making sure to mount it with -v like you do for other important drives)? And put the working directory somewhere outside the BIDS directory.

Also, can you provide the output of tree on one of the subject directories (raw data)? Just so we can see what kind of fmaps they are?

This is going to result from fieldmap coefficient files being misaligned with your fieldmap reference image. This generally shouldn’t happen, but the error is there to catch this case rather than proceed as if everything is okay.

Can you show the fslhd output of all of your fieldmap files?

I’ve added the working directory and fmriprep is now running. Should I be looking for something in specific?

.
├── anat
│   ├── sub-05_acq-t1mpragesagp2iso_T1w.json
│   └── sub-05_acq-t1mpragesagp2iso_T1w.nii.gz
├── fmap
│   ├── sub-05_acq-grefieldmapping_magnitude1.json
│   ├── sub-05_acq-grefieldmapping_magnitude1.nii.gz
│   ├── sub-05_acq-grefieldmapping_magnitude2.json
│   ├── sub-05_acq-grefieldmapping_magnitude2.nii.gz
│   ├── sub-05_acq-grefieldmapping_phasediff.json
│   └── sub-05_acq-grefieldmapping_phasediff.nii.gz
├── func
│   ├── sub-05_task-SubRiskRun1_bold.json
│   ├── sub-05_task-SubRiskRun1_bold.nii.gz
│   ├── sub-05_task-SubRiskRun2_bold.json
│   ├── sub-05_task-SubRiskRun2_bold.nii.gz
│   ├── sub-05_task-SubRiskRun3_bold.json
│   ├── sub-05_task-SubRiskRun3_bold.nii.gz
│   ├── sub-05_task-SubRiskRun4_bold.json
│   └── sub-05_task-SubRiskRun4_bold.nii.gz
└── sub-05_scans.tsv

Hi,

Magnitude 1 fieldmap

izeof_hdr	348
data_type	INT16
dim0		3
dim1		64
dim2		64
dim3		42
dim4		1
dim5		1
dim6		1
dim7		1
vox_units	mm
time_units	s
datatype	4
nbyper		2
bitpix		16
pixdim0		-1.000000
pixdim1		3.906250
pixdim2		3.906250
pixdim3		3.750000
pixdim4		0.407000
pixdim5		0.000000
pixdim6		0.000000
pixdim7		0.000000
vox_offset	352
cal_max		0.000000
cal_min		0.000000
scl_slope	1.000000
scl_inter	0.000000
phase_dim	1
freq_dim	2
slice_dim	3
slice_name	Unknown
slice_code	0
slice_start	0
slice_end	0
slice_duration	0.000000
toffset		0.000000
intent		Unknown
intent_code	0
intent_name	
intent_p1	0.000000
intent_p2	0.000000
intent_p3	0.000000
qform_name	Scanner Anat
qform_code	1
qto_xyz:1	0.014590 0.008369 3.749965 -80.353645 
qto_xyz:2	-3.382880 -1.953107 0.016147 161.022079 
qto_xyz:3	-1.953125 3.382912 0.000045 -34.618317 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 
qform_xorient	Anterior-to-Posterior
qform_yorient	Inferior-to-Superior
qform_zorient	Left-to-Right
sform_name	Scanner Anat
sform_code	1
sto_xyz:1	0.014590 0.008369 3.749966 -80.353645 
sto_xyz:2	-3.382880 -1.953107 0.016147 161.022079 
sto_xyz:3	-1.953126 3.382912 0.000045 -34.618317 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Anterior-to-Posterior
sform_yorient	Inferior-to-Superior
sform_zorient	Left-to-Right
file_type	NIFTI-1+
file_code	1
descrip		TE=4.9;Time=182615.655
aux_file	

magnitude 2 fieldmap

filename	/media/patricia/data/fmriprep_data/sub-05/fmap/sub-05_acq-grefieldmapping_magnitude2.nii.gz

sizeof_hdr	348
data_type	INT16
dim0		3
dim1		64
dim2		64
dim3		42
dim4		1
dim5		1
dim6		1
dim7		1
vox_units	mm
time_units	s
datatype	4
nbyper		2
bitpix		16
pixdim0		-1.000000
pixdim1		3.906250
pixdim2		3.906250
pixdim3		3.750000
pixdim4		0.407000
pixdim5		0.000000
pixdim6		0.000000
pixdim7		0.000000
vox_offset	352
cal_max		0.000000
cal_min		0.000000
scl_slope	1.000000
scl_inter	0.000000
phase_dim	1
freq_dim	2
slice_dim	3
slice_name	Unknown
slice_code	0
slice_start	0
slice_end	0
slice_duration	0.000000
toffset		0.000000
intent		Unknown
intent_code	0
intent_name	
intent_p1	0.000000
intent_p2	0.000000
intent_p3	0.000000
qform_name	Scanner Anat
qform_code	1
qto_xyz:1	0.014590 0.008369 3.749965 -80.353645 
qto_xyz:2	-3.382880 -1.953107 0.016147 161.022079 
qto_xyz:3	-1.953125 3.382912 0.000045 -34.618317 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 
qform_xorient	Anterior-to-Posterior
qform_yorient	Inferior-to-Superior
qform_zorient	Left-to-Right
sform_name	Scanner Anat
sform_code	1
sto_xyz:1	0.014590 0.008369 3.749966 -80.353645 
sto_xyz:2	-3.382880 -1.953107 0.016147 161.022079 
sto_xyz:3	-1.953126 3.382912 0.000045 -34.618317 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Anterior-to-Posterior
sform_yorient	Inferior-to-Superior
sform_zorient	Left-to-Right
file_type	NIFTI-1+
file_code	1
descrip		TE=7.4;Time=182616.065
aux_file	

phasediff fieldmap

filename	/media/patricia/data/fmriprep_data/sub-05/fmap/sub-05_acq-grefieldmapping_phasediff.nii.gz

sizeof_hdr	348
data_type	INT16
dim0		3
dim1		64
dim2		64
dim3		42
dim4		1
dim5		1
dim6		1
dim7		1
vox_units	mm
time_units	s
datatype	4
nbyper		2
bitpix		16
pixdim0		-1.000000
pixdim1		3.906250
pixdim2		3.906250
pixdim3		3.750000
pixdim4		0.407000
pixdim5		0.000000
pixdim6		0.000000
pixdim7		0.000000
vox_offset	352
cal_max		0.000000
cal_min		0.000000
scl_slope	2.000000
scl_inter	-4096.000000
phase_dim	1
freq_dim	2
slice_dim	3
slice_name	Unknown
slice_code	0
slice_start	0
slice_end	0
slice_duration	0.000000
toffset		0.000000
intent		Unknown
intent_code	0
intent_name	
intent_p1	0.000000
intent_p2	0.000000
intent_p3	0.000000
qform_name	Scanner Anat
qform_code	1
qto_xyz:1	0.014590 0.008369 3.749965 -80.353645 
qto_xyz:2	-3.382880 -1.953107 0.016147 161.022079 
qto_xyz:3	-1.953125 3.382912 0.000045 -34.618317 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 
qform_xorient	Anterior-to-Posterior
qform_yorient	Inferior-to-Superior
qform_zorient	Left-to-Right
sform_name	Scanner Anat
sform_code	1
sto_xyz:1	0.014590 0.008369 3.749966 -80.353645 
sto_xyz:2	-3.382880 -1.953107 0.016147 161.022079 
sto_xyz:3	-1.953126 3.382912 0.000045 -34.618317 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Anterior-to-Posterior
sform_yorient	Inferior-to-Superior
sform_zorient	Left-to-Right
file_type	NIFTI-1+
file_code	1
descrip		TE=7.4;Time=182616.065
aux_file```

Hey @effigies @Steven ,

Sorry to bother.
Does the info I posted help in any way? Or would you have any other suggestions? It’s worth adding that this error did not happend when I tried other versions (mentioned in the original post) with the exact same data.

Thank you!

Yes, this error is new, but it’s not obvious why it’s happening, given that your inputs are what they are. Could you share the same outputs for all the files in the fmap/ output subdirectory?

Yes, below are all the fslhd outputs from the /fmap output files.

filename	/media/patricia/data/output_fmriprep/fmriprep/sub-05/fmap/sub-05_acq-grefieldmapping_fmapid-phasedifffmap5_desc-coeff0_fieldmap.nii.gz

sizeof_hdr	348
data_type	FLOAT32
dim0		3
dim1		4
dim2		5
dim3		9
dim4		1
dim5		1
dim6		1
dim7		1
vox_units	mm
time_units	Unknown
datatype	16
nbyper		4
bitpix		32
pixdim0		1.000000
pixdim1		100.000000
pixdim2		100.000000
pixdim3		40.000000
pixdim4		1.000000
pixdim5		1.000000
pixdim6		1.000000
pixdim7		1.000000
vox_offset	352
cal_max		0.000000
cal_min		0.000000
scl_slope	1.000000
scl_inter	0.000000
phase_dim	0
freq_dim	0
slice_dim	0
slice_name	Unknown
slice_code	0
slice_start	0
slice_end	0
slice_duration	0.000000
toffset		0.000000
intent		Unknown
intent_code	0
intent_name	
intent_p1	0.000000
intent_p2	0.000000
intent_p3	0.000000
qform_name	Scanner Anat
qform_code	1
qto_xyz:1	99.999069 -0.373512 0.085699 -152.350510 
qto_xyz:2	0.430595 86.601730 -19.999817 -100.580582 
qto_xyz:3	0.001213 50.000004 34.641014 -228.145035 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 
qform_xorient	Left-to-Right
qform_yorient	Posterior-to-Anterior
qform_zorient	Inferior-to-Superior
sform_name	Scanner Anat
sform_code	1
sto_xyz:1	99.999069 -0.373512 0.085699 -152.350510 
sto_xyz:2	0.430595 86.601730 -19.999811 -100.580582 
sto_xyz:3	0.001213 50.000019 34.641018 -228.145035 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Left-to-Right
sform_yorient	Posterior-to-Anterior
sform_zorient	Inferior-to-Superior
file_type	NIFTI-1+
file_code	1
descrip		
aux_file
filename	/media/patricia/data/output_fmriprep/fmriprep/sub-05/fmap/sub-05_acq-grefieldmapping_fmapid-phasedifffmap5_desc-coeff1_fieldmap.nii.gz

sizeof_hdr	348
data_type	FLOAT32
dim0		3
dim1		12
dim2		18
dim3		27
dim4		1
dim5		1
dim6		1
dim7		1
vox_units	mm
time_units	Unknown
datatype	16
nbyper		4
bitpix		32
pixdim0		1.000000
pixdim1		16.000000
pixdim2		16.000000
pixdim3		10.000000
pixdim4		1.000000
pixdim5		1.000000
pixdim6		1.000000
pixdim7		1.000000
vox_offset	352
cal_max		0.000000
cal_min		0.000000
scl_slope	1.000000
scl_inter	0.000000
phase_dim	0
freq_dim	0
slice_dim	0
slice_name	Unknown
slice_code	0
slice_start	0
slice_end	0
slice_duration	0.000000
toffset		0.000000
intent		Unknown
intent_code	0
intent_name	
intent_p1	0.000000
intent_p2	0.000000
intent_p3	0.000000
qform_name	Scanner Anat
qform_code	1
qto_xyz:1	15.999851 -0.059762 0.021425 -90.525856 
qto_xyz:2	0.068895 13.856277 -4.999954 -59.888367 
qto_xyz:3	0.000194 8.000001 8.660254 -170.163513 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 
qform_xorient	Left-to-Right
qform_yorient	Posterior-to-Anterior
qform_zorient	Inferior-to-Superior
sform_name	Scanner Anat
sform_code	1
sto_xyz:1	15.999851 -0.059762 0.021425 -90.525856 
sto_xyz:2	0.068895 13.856277 -4.999953 -59.888367 
sto_xyz:3	0.000194 8.000003 8.660254 -170.163513 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Left-to-Right
sform_yorient	Posterior-to-Anterior
sform_zorient	Inferior-to-Superior
file_type	NIFTI-1+
file_code	1
descrip		
aux_file
sizeof_hdr	348
data_type	INT16
dim0		3
dim1		64
dim2		64
dim3		42
dim4		1
dim5		1
dim6		1
dim7		1
vox_units	mm
time_units	Unknown
datatype	4
nbyper		2
bitpix		16
pixdim0		-1.000000
pixdim1		3.906250
pixdim2		3.906250
pixdim3		3.750000
pixdim4		1.000000
pixdim5		1.000000
pixdim6		1.000000
pixdim7		1.000000
vox_offset	352
cal_max		0.000000
cal_min		0.000000
scl_slope	1.000000
scl_inter	0.000000
phase_dim	1
freq_dim	2
slice_dim	3
slice_name	Unknown
slice_code	0
slice_start	0
slice_end	0
slice_duration	0.000000
toffset		0.000000
intent		Unknown
intent_code	0
intent_name	
intent_p1	0.000000
intent_p2	0.000000
intent_p3	0.000000
qform_name	Scanner Anat
qform_code	1
qto_xyz:1	0.014590 0.008369 3.749965 -80.353645 
qto_xyz:2	-3.382880 -1.953107 0.016147 161.022079 
qto_xyz:3	-1.953125 3.382912 0.000045 -34.618317 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 
qform_xorient	Anterior-to-Posterior
qform_yorient	Inferior-to-Superior
qform_zorient	Left-to-Right
sform_name	Scanner Anat
sform_code	1
sto_xyz:1	0.014590 0.008369 3.749966 -80.353645 
sto_xyz:2	-3.382880 -1.953107 0.016147 161.022079 
sto_xyz:3	-1.953126 3.382912 0.000045 -34.618317 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Anterior-to-Posterior
sform_yorient	Inferior-to-Superior
sform_zorient	Left-to-Right
file_type	NIFTI-1+
file_code	1
descrip		TE=4.9;Time=182615.655
aux_file
filename	/media/patricia/data/output_fmriprep/fmriprep/sub-05/fmap/sub-05_acq-grefieldmapping_fmapid-phasedifffmap5_desc-preproc_fieldmap.nii.gz

sizeof_hdr	348
data_type	FLOAT32
dim0		4
dim1		42
dim2		64
dim3		64
dim4		1
dim5		1
dim6		1
dim7		1
vox_units	mm
time_units	Unknown
datatype	16
nbyper		4
bitpix		32
pixdim0		1.000000
pixdim1		3.750000
pixdim2		3.906250
pixdim3		3.906250
pixdim4		1.000000
pixdim5		1.000000
pixdim6		1.000000
pixdim7		1.000000
vox_offset	352
cal_max		0.000000
cal_min		0.000000
scl_slope	1.000000
scl_inter	0.000000
phase_dim	0
freq_dim	0
slice_dim	0
slice_name	Unknown
slice_code	0
slice_start	0
slice_end	0
slice_duration	0.000000
toffset		0.000000
intent		Unknown
intent_code	0
intent_name	
intent_p1	0.000000
intent_p2	0.000000
intent_p3	0.000000
qform_name	Scanner Anat
qform_code	1
qto_xyz:1	3.749966 -0.014590 0.008369 -79.434456 
qto_xyz:2	0.016147 3.382880 -1.953107 -52.099358 
qto_xyz:3	0.000045 1.953125 3.382912 -157.665237 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 
qform_xorient	Left-to-Right
qform_yorient	Posterior-to-Anterior
qform_zorient	Inferior-to-Superior
sform_name	Scanner Anat
sform_code	1
sto_xyz:1	3.749966 -0.014590 0.008369 -79.434456 
sto_xyz:2	0.016147 3.382880 -1.953107 -52.099358 
sto_xyz:3	0.000045 1.953126 3.382912 -157.665237 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Left-to-Right
sform_yorient	Posterior-to-Anterior
sform_zorient	Inferior-to-Superior
file_type	NIFTI-1+
file_code	1
descrip		2203.11-dirty 2023-08-23T14:21:21+01:00
aux_file```

Okay. So it looks like we’re not updating the reference image. I’m a bit surprised that the difference is enough to cause this bug, but I’ll see what needs to be done. Thanks for this, and I’ll let you know if I need anything else from you.

Thank you!
Please let me know when it’s fixed.

Hi @effigies ,

Sorry to bother again.
I noticed there’s a new pre-release. Is this issue fixed in it? I can’t really figure it out from the release notes.

Thank you :slight_smile:

Unfortunately, I have not had time to get to this.

I had the same issue, although I used a PEPolar SDC strategy. I solved it by reorienting the images using fslreorient2std before running fMRIPrep.

I don’t know if this would help you, but may help the devs finding the problem :confused: