Error during fmap2ref_apply

Summary of what happened:

I’m running DSI data using phasediff fmaps. I received an error in “fmap2ref_apply”.

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

apptainer run --containall --cleanenv -B /mystudy/bids:/bids -B /mystudy/output:/output -B /mystudy/work:/work -B /mystudy/freesurfer_license.txt:/opt/freesurfer/license.txt qsiprep_latest.sif /bids /output participant --fs-license-file /opt/freesurfer/license.txt --freesurfer-input=/bids/derivatives/freesurfer --work-dir=/work --output-resolution 1.8 --recon-spec=dsi_studio_gqi

Version:

qsiprep latest (0.20.0?)

Environment (Docker, Singularity / Apptainer, custom installation):

apptainer on ubuntu

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

PASTE VALIDATOR OUTPUT HERE

Relevant log outputs (up to 20 lines):

RuntimeError: Traceback (most recent call last):
  File "/usr/local/miniconda/lib/python3.10/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/usr/local/miniconda/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/usr/local/miniconda/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/usr/local/miniconda/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 fmap2ref_apply.

Cmdline:
	antsApplyTransforms --default-value 0 --dimensionality 3 --float 1 --input /work/qsiprep_wf/single_subject_01_wf/dwi_preproc_ses_60_wf/hmc_sdc_wf/sdc_wf/phdiff_wf/compfmap/sub-01_ses-60_phasediff_rads_unwrapped_filt_demean_maths_fmap.nii.gz --interpolation BSpline --output sub-01_ses-60_phasediff_rads_unwrapped_filt_demean_maths_fmap_trans.nii.gz --reference-image /work/qsiprep_wf/single_subject_01_wf/dwi_preproc_ses_60_wf/hmc_sdc_wf/b0_ref_to_lps/topup_imain_LPS.nii.gz --transform /work/qsiprep_wf/single_subject_01_wf/dwi_preproc_ses_60_wf/hmc_sdc_wf/sdc_wf/sdc_unwarp_wf/fmap2ref_reg/transformComposite.h5
Stdout:

Stderr:

Traceback:
	Traceback (most recent call last):
	  File "/usr/local/miniconda/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 398, in run
	    runtime = self._post_run_hook(runtime)
	  File "/usr/local/miniconda/lib/python3.10/site-packages/qsiprep/niworkflows/interfaces/registration.py", line 106, in _post_run_hook
	    return super(ANTSApplyTransformsRPT, self)._post_run_hook(runtime)
	  File "/usr/local/miniconda/lib/python3.10/site-packages/nipype/interfaces/mixins/reporting.py", line 50, in _post_run_hook
	    self._generate_report()
	  File "/usr/local/miniconda/lib/python3.10/site-packages/qsiprep/niworkflows/interfaces/report_base.py", line 61, in _generate_report
	    cuts = cuts_from_bbox(mask_nii, cuts=n_cuts)
	  File "/usr/local/miniconda/lib/python3.10/site-packages/qsiprep/niworkflows/viz/utils.py", line 215, in cuts_from_bbox
	    ras_coords.append(apply_affine(mask_nii.affine, cross).tolist())
	  File "/usr/local/miniconda/lib/python3.10/site-packages/nibabel/affines.py", line 96, in apply_affine
	    pts = pts @ rzs.T + trans[None, :]
	ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 3 is different from 4)



The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/miniconda/bin/qsiprep", line 8, in <module>
    sys.exit(main())
  File "/usr/local/miniconda/lib/python3.10/site-packages/qsiprep/cli/run.py", line 690, in main
    qsiprep_wf.run(**plugin_settings)
  File "/usr/local/miniconda/lib/python3.10/site-packages/nipype/pipeline/engine/workflows.py", line 638, in run
    runner.run(execgraph, updatehash=updatehash, config=self.config)
  File "/usr/local/miniconda/lib/python3.10/site-packages/nipype/pipeline/plugins/base.py", line 224, in run
    raise error from cause

Screenshots / relevant information:

Interestingly, if I shell into the apptainer and type that antsApplyTransforms command directly, it runs without a problem.


Hi @kjamison,

Look at this issue Dimension mismatch when using --prefer_dedicated_fmaps · Issue #597 · PennLINC/qsiprep · GitHub and ensure that your dwi and fmap affines are the same.

Best,
Steven

Hmm why would the dwi and fmap affines need to match? They are different acquisitions and presumably get coregistered inside the pipeline?

The specific line that’s raising the error is in the function cuts_from_bbox in niworkflows/viz/utils.py:

215: ras_coords.append(apply_affine(mask_nii.affine, cross).tolist())

This line only relates to visualizing for reports. And it seems that function cuts_from_bbox was changed significantly in nipreps/niworkflows back in 2020.

If I copy the new version of cuts_from_bbox from github: niworkflows/niworkflows/viz/utils.py at master · nipreps/niworkflows · GitHub and override the version in the container, it seems to fix the issue!

2 Likes

Thanks for the investigative work, @kjamison! @mattcieslak can we update this in the next release?

Definitely! @tsalo has a PR open to switch to the real niworkflows instead of the old copy we’ve been using inside qsiprep.

The dwi and fmap affines need to match (specifically if you’re doing PEPOLAR) because a repositioning of the FOV is typically accompanied by a re-shimming by the scanner. This means there will be different distortions present in your different acquisitions and the assumptions of PEPOLAR are no longer met.

The next release will offer an option to force using the differing-FOV scans using a --reckless-concatenate option

Ah right. I’m using a GRE fieldmap here, so I was confused. In any case that obviously wasn’t the issue here. Thanks for the help!