Dimension mismatch error when using field maps (phasediff or 2 phase fmaps) for sdc

Summary of what happened:

Hi, I am trying to run qsiprep on some legacy diffusion data from our lab with 2 phase fieldmaps (and 2 magnitude images) for sdc. I get a dimension mismatch error when it runs the antsApplyTransforms command (see crash log below) and I’m not sure how to resolve the issue. I also tried running qsiprep on the phasediff fieldmap calculated from the 2 phase images (using scripts provided by our imaging center) and I get the same error. My dwi and fmap images have the same spatial resolution and dimensions. Any advice would be appreciated!

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

qsiprep-docker <input_dir> <output_dir> participant --output-resolution 1.875 --fs-license-file <freesurfer_home/license.txt>

Version:

qsiprep v0.19.1

Environment (Docker, Singularity, custom installation):

Docker

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

This dataset appears to be BIDS compatible.

Relevant log outputs (up to 20 lines):

Cmdline:
	antsApplyTransforms --default-value 0 --dimensionality 3 --float 1 --input /tmp/work/qsiprep_wf/single_subject_02_wf/dwi_preproc_dir_PA_wf/hmc_sdc_wf/sdc_wf/phdiff_wf/compfmap/sub-02_phasediff_rads_unwrapped_filt_demean_maths_fmap.nii.gz --interpolation BSpline --output sub-02_phasediff_rads_unwrapped_filt_demean_maths_fmap_trans.nii.gz --reference-image /tmp/work/qsiprep_wf/single_subject_02_wf/dwi_preproc_dir_PA_wf/hmc_sdc_wf/b0_ref_to_lps/topup_imain_LPS.nii.gz --transform /tmp/work/qsiprep_wf/single_subject_02_wf/dwi_preproc_dir_PA_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.8/site-packages/nipype/interfaces/base/core.py", line 398, in run
	    runtime = self._post_run_hook(runtime)
	  File "/usr/local/miniconda/lib/python3.8/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.8/site-packages/nipype/interfaces/mixins/reporting.py", line 50, in _post_run_hook
	    self._generate_report()
	  File "/usr/local/miniconda/lib/python3.8/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.8/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.8/site-packages/nibabel/affines.py", line 97, 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)

Screenshots / relevant information:

Hi,
I’m getting the same error message. Did you find a solution at the end?

Hi @Akram + @jhau ,

Can you provide the affines of your dwi and phasediff files? Likely due to a mismatch.

Best,
Steven

Hi @Steven,

dwi
[[-1.99975872e+00 -3.10655050e-02  0.00000000e+00  1.26434464e+02]
 [-3.10655050e-02  1.99975872e+00 -0.00000000e+00 -1.06629974e+02]
 [ 0.00000000e+00  0.00000000e+00  2.00000000e+00 -3.75346489e+01]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00  1.00000000e+00]]
and phasediff
[[-2.99963808e+00 -4.65982556e-02  0.00000000e+00  1.30480591e+02]
 [-4.65982556e-02  2.99963808e+00 -0.00000000e+00 -1.09567505e+02]
 [ 0.00000000e+00  0.00000000e+00  3.00000000e+00 -4.20346489e+01]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00  1.00000000e+00]]

Does this mean I should use --ignore fieldmaps ?

Thank you

Hi @Akram,

You have some options:

1: Make a copy of your fmap data (so you can maintain the original version somewhere), and try copying the affine from your DWI to the fmap data, and run again (use a fresh working directory). Do NOT copy the affine from fmap to DWI as for this to be valid, you have to additionally rotate the b-matrix which can be a pain. If you try this, keep me updated, as I was interested in trying this on one of my datasets.

2: Try to add --ignore fieldmaps --use-syn-sdc --force-syn to use the fieldmapless method

3: Try to use Synb0-Disco to generate a fieldmap, which should be BIDS-ified as a reverse phase encoded epi.nii.gz (not a magnitude/phasediff) (or wait for it to get incorporated into qsiprep, which is a work in progress).

Best,
Steven

Hi @Steven,

I am using the 2 phases sdc method. The affines of my dwi and fmap input images are below:

>>> img_dwi.affine
array([[  -1.875     ,   -0.        ,    0.        ,  121.40599823],
       [   0.        ,    1.875     ,    0.        , -119.06300354],
       [   0.        ,    0.        ,    2.        ,  -57.15650177],
       [   0.        ,    0.        ,    0.        ,    1.        ]])
>>> img_phase1.affine
array([[  -1.875     ,   -0.        ,    0.        ,  121.40599823],
       [   0.        ,    1.875     ,    0.        , -119.06300354],
       [   0.        ,    0.        ,    2.        ,  -57.15650177],
       [   0.        ,    0.        ,    0.        ,    1.        ]])
>>> img_phase2.affine
array([[  -1.875     ,   -0.        ,    0.        ,  121.40599823],
       [   0.        ,    1.875     ,    0.        , -119.06300354],
       [   0.        ,    0.        ,    2.        ,  -57.15650177],
       [   0.        ,    0.        ,    0.        ,    1.        ]])
>>> img_magnitude1.affine
array([[  -1.875     ,   -0.        ,    0.        ,  121.40599823],
       [   0.        ,    1.875     ,    0.        , -119.06300354],
       [   0.        ,    0.        ,    2.        ,  -57.15650177],
       [   0.        ,    0.        ,    0.        ,    1.        ]])
>>> img_magnitude2.affine
array([[  -1.875     ,   -0.        ,    0.        ,  121.40599823],
       [   0.        ,    1.875     ,    0.        , -119.06300354],
       [   0.        ,    0.        ,    2.        ,  -57.15650177],
       [   0.        ,    0.        ,    0.        ,    1.        ]])

Thanks,
Jan

I wonder if your magnitude images are strange and maybe there is an issue creating a brain mask for them.

It’s ok if phase1/phase2 or phasediff fmaps have a different spatial resolution than the dwi. That is only an issue when using epi fmaps.

Hi @Steven,

I appreciate your help and explanation.

I tried the first one but still got the same error. I checked and the affine was changed in fmap data accordingly.

I probably go with the second option.

Best,
Akram

Hi @mattcieslak,

There is bit of visible motion artifact but the magnitude images overall look OK for generating a brain mask. See screenshots below.

magnitude1.nii.gz

magnitude2.nii.gz

I will try on a few more subjects.

As a follow up, it turns out that when I run the exact same antsRegistration command outside of QSIPrep, even when using the QSIPrep container, the command completes successfully.