Fmriprep error: Reference passed is not aligned with spline grids

There are multiple sets of fmap files for that subject

i believe the error you experienced maybe specific to the *acq-SEfmapBOLD* files. When I first ran fMRIprep on this subject, i deleted the *acq-SEfmapBOLD* files, and kept the *acq-GEfmap* files. That was when i encountered the “Reference passed is not aligned with spline grids” error.

In my second attempt i did the reverse, deleting *acq-GEfmap* and kept *acq-SEfmapBOLD*, and i think had a similar error to the one you encountered here. I cant verify exactly the error because i’ve deleted the output; i’m tight on storage space. But i vaguely recalled some kind of indexing error.

I also limited my run to the GEfmap files. Could you run the following script on your output directory?

#!/bin/env python
# /// script
# requires-python = ">=3.13"
# dependencies = ["nibabel", "typer"]
# ///
from pathlib import Path

import nibabel as nb
import typer


def main(paths: list[Path]) -> None:
    for path in paths:
        img = nb.load(path)
        axcodes = nb.aff2axcodes(img.affine)

        print(f"{path}: {axcodes}")


if __name__ == "__main__":
    typer.run(main)

e.g.,

$ python summary.py /path/to/outputs/**/*.nii.gz

@Patricia_Fernandes I think I will need a subject. I’m having trouble figuring out how to get my data in the same state as yours to reproduce this.

(fmriprepenv) [junhong.yu@hpc-wfly-h001 output]$ python summary.py sub-010088/ses-01/func/*.nii.gz
sub-010088/ses-01/func/sub-010088_ses-01_task-rest_acq-AP_run-01_desc-brain_mask.nii.gz: ('L', 'S', 'P')
sub-010088/ses-01/func/sub-010088_ses-01_task-rest_acq-AP_run-01_desc-coreg_boldref.nii.gz: ('L', 'S', 'P')
sub-010088/ses-01/func/sub-010088_ses-01_task-rest_acq-AP_run-01_desc-hmc_boldref.nii.gz: ('L', 'S', 'P')
sub-010088/ses-01/func/sub-010088_ses-01_task-rest_acq-AP_run-01_space-MNI152NLin6Asym_boldref.nii.gz: ('R', 'A', 'S')
sub-010088/ses-01/func/sub-010088_ses-01_task-rest_acq-AP_run-01_space-MNI152NLin6Asym_desc-brain_mask.nii.gz: ('R', 'A', 'S')

the full error log from sub-10088.html
Node Name: fmriprep_24_0_wf.sub_010088_wf.bold_ses_01_task_rest_acq_AP_run_01_wf.bold_native_wf.boldref_fmap

File: <workdir>/sub-010088/log/20241025-161033_4cc10f6d-a6a7-40c3-b396-c25cc709ce2f/crash-20241025-162128-junhong.yu-boldref_fmap-028017f1-65b6-4d78-be14-25048f587163.txt
Working Directory: /home/junhong.yu/NC/work/fmriprep_24_0_wf/sub_010088_wf/bold_ses_01_task_rest_acq_AP_run_01_wf/bold_native_wf/boldref_fmap
Inputs:

    fmap_ref_file:
    in_coeffs:
    inverse: [True]
    target_ref_file:
    transforms:

Traceback (most recent call last):
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/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 "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/interfaces/base/core.py", line 397, in run
	    runtime = self._run_interface(runtime)
	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/fmriprep/interfaces/resampling.py", line 171, in _run_interface
	    fieldmap = reconstruct_fieldmap(
	               ^^^^^^^^^^^^^^^^^^^^^
	  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/fmriprep/interfaces/resampling.py", line 674, in reconstruct_fieldmap
	    raise ValueError('Reference passed is not aligned with spline grids')
	ValueError: Reference passed is not aligned with spline grids

Node Name: fmriprep_24_0_wf.sub_010088_wf.bold_ses_01_task_rest_acq_AP_run_01_wf.bold_anat_wf.fmap_recon

File: <workdir>/sub-010088/log/20241025-161033_4cc10f6d-a6a7-40c3-b396-c25cc709ce2f/crash-20241025-193434-junhong.yu-fmap_recon-a5754951-5c75-43e9-ad3e-0cf271a18ee6.txt
Working Directory: /home/junhong.yu/NC/work/fmriprep_24_0_wf/sub_010088_wf/bold_ses_01_task_rest_acq_AP_run_01_wf/bold_anat_wf/fmap_recon
Inputs:

    fmap_ref_file:
    in_coeffs:
    inverse: [False]
    target_ref_file:
    transforms:

Traceback (most recent call last):
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/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 fmap_recon.

Traceback:
	Traceback (most recent call last):
	  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/interfaces/base/core.py", line 397, in run
	    runtime = self._run_interface(runtime)
	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/fmriprep/interfaces/resampling.py", line 171, in _run_interface
	    fieldmap = reconstruct_fieldmap(
	               ^^^^^^^^^^^^^^^^^^^^^
	  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/fmriprep/interfaces/resampling.py", line 674, in reconstruct_fieldmap
	    raise ValueError('Reference passed is not aligned with spline grids')
	ValueError: Reference passed is not aligned with spline grids

Node Name: fmriprep_24_0_wf.sub_010088_wf.bold_ses_01_task_rest_acq_AP_run_01_wf.bold_std_wf.fmap_recon

File: <workdir>/sub-010088/log/20241025-161033_4cc10f6d-a6a7-40c3-b396-c25cc709ce2f/crash-20241025-201525-junhong.yu-fmap_recon.a0-3fbd5aeb-b9ad-46c6-9b9f-b25ecfeb567d.txt
Working Directory: /home/junhong.yu/NC/work/fmriprep_24_0_wf/sub_010088_wf/bold_ses_01_task_rest_acq_AP_run_01_wf/bold_std_wf/_in_tuple_MNI152NLin6Asym.resnative/fmap_recon
Inputs:

    fmap_ref_file:
    in_coeffs:
    inverse: [False]
    target_ref_file:
    transforms:

Traceback (most recent call last):
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/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 fmap_recon.

Traceback:
	Traceback (most recent call last):
	  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/nipype/interfaces/base/core.py", line 397, in run
	    runtime = self._run_interface(runtime)
	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/fmriprep/interfaces/resampling.py", line 171, in _run_interface
	    fieldmap = reconstruct_fieldmap(
	               ^^^^^^^^^^^^^^^^^^^^^
	  File "/home/junhong.yu/fmriprepenv/lib64/python3.11/site-packages/fmriprep/interfaces/resampling.py", line 674, in reconstruct_fieldmap
	    raise ValueError('Reference passed is not aligned with spline grids')
	ValueError: Reference passed is not aligned with spline grids

I’m running fMRIprep with a previously computed freesurfer output directory if it matters

Thanks. I’ll give it another try. I didn’t run FreeSurfer, for speed, but I’m surprised that it didn’t work.

Just a note that I wasn’t able to replicate this issue in the development version on either of your datasets. I’m trying again with 24.1.1.

Hi there, I am running into this exact same issue in 24.1.1 for a couple of subjects with PE fieldmaps. Did you find any fix for this?

No, I haven’t been able to replicate the problem. Feel free to send me data, and I’ll see if I can replicate it.

Note that today is my last working day of the year, so any fixes would come in January at the earliest.

Hello! Did you manage to solve this? I’m preprocessing at the moment ~25 participants of which 3 have this issue. They were all scanned on the same scanner with the same sequences (though for some the scan had to be restarted- but for others where that was the case, it worked anyway). (I’m using fmriprpe 23.2.1 and thinking whether I should upgrade to fix this).

Ok, so I spent ages trying to track this down because I’m new to fmriprep and I didn’t know where to look. I’ve inspected ~10 subjects/sessions that are ok, and they all have in the .json file of the phasediff (having done BIDS preprocessing) ‘InPlanePhaseEncodingDirectionDICOM’: ‘COL’ and all the participants/sessions that crash have ‘ROW’ there.

I’ve just asked the people who scanned this whether they know how this can be. It seems strange to me - everyone was run with the same protocol…

I think this may be resolved in the next release (fix: Detect and apply precomputed fieldmaps by effigies · Pull Request #3439 · nipreps/fmriprep · GitHub). Fieldmaps in, e.g., RAS/LPS would not hit the issue, but those in PSL or other rotated orientations would hit the error.

25.0.0 is due out this week.

that sounds great that an update might fix it. just to make sure I understand - as far as I know (from the person who scanned, that wasn’t me), all people were scanned with the same protocol. Is it even possible that the InPlanePhaseEncodingDirectionDICOM (sform_yorient and sform_zorient with fslhd) would be different across people/sessions? Or is it more likely that somehow the dicom to nifti conversion (in BIDS) misrecognizes this somehow?

(I’ve checked and it’s different for the field maps and also the epic)

I would imagine this could happen through slight differences in the setup at the scanner or using different versions of converters for batches of subjects. I would go back and look at the DICOMs, rather than guess. You may want to reconvert and compare.

1 Like

thanks. I’ve reconverted (redid all files for the people in question, the ‘good’ and the ‘bad’ sessions) and the issue persists.

In FSLeyes, the AP and SI labels are wrong (top of the head is labeled as ‘P’). Reading the FSL documentation it says that’s very bad (and that fslswapdim can fix it, but that it’s easy to mess it up; though I guess I could use the approach described here to check that I didn’t mess up left-to right [the structural I have is correct] Frontiers | Beware (Surprisingly Common) Left-Right Flips in Your MRI Data: An Efficient and Robust Method to Check MRI Dataset Consistency Using AFNI).

I imagine if I fix the .nii.gz file this way, this won’t be able to run with fmriprep anymore, right?

We’re emailing the head of the scanner to see whether anyone else has encountered this problem and whether they have a proposed way to fix this (as I think we’re using a sequence that also many others are using).