'Regions and mask do not have the same shape' error

Summary of what happened:

Hi Experts,

I ran XCP-D on fMRIPrep output, in which I have 4 functional runs: 3 task and 1 rest. The parcellation, ALFF generation, and ReHo generation was completed for 1 of my task fMRI sessions, but crashed with the error: Regions and mask do not have the same shape. I imagine this is some sort of resampling issue?

I ran fMRIPrep (23.2.1) and XCP-D (0.7.1rc5) with no extra arguments.

Thanks!

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

docker run --rm it \
	-v ~/fmriprep_test/derivatives:/fmriprep:ro \
	-v /tmp/wkdir:/work:rw \
	-v ~/fmriprep_test/xcp_d_test:/out:rw \
	-v ~/fmriprep_test/derivatives/sourcedata/freesurfer:/freesurfer:ro \
	-v ~/fmriprep_test/FS_license/license.txt:/license:ro \
	pennlinc/xcp_d:latest \
	/fmriprep /out participant \
        --fs-license-file /license

Version:

0.7.1rc5

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

Docker

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):

Node: _parcellate_data0
Working directory: /tmp/working_dir/xcp_d_0_7_wf/sub_0000012_wf/nifti_postprocess_1_wf/connectivity_wf/parcellate_data/mapflow/_parcellate_data0

Node inputs:

atlas = /out/atlases/atlas-4S1056Parcels/atlas-4S1056Parcels_space-MNI152NLin2009cAsym_dseg.nii.gz
atlas_labels = /out/atlases/atlas-4S1056Parcels/atlas-4S1056Parcels_dseg.tsv
filtered_file = /tmp/working_dir/xcp_d_0_7_wf/sub_0000012_wf/nifti_postprocess_1_wf/denoise_bold_wf/censor_interpolated_data/filtered_denoised_censored.nii.gz
mask = /fmriprep/sub-0000012/func/sub-0000012_task-rest_space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz
min_coverage = 0.5
...
Traceback:
        Traceback (most recent call last):
          File "/usr/local/miniconda/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 397, in run
            runtime = self._run_interface(runtime)
          File "/usr/local/miniconda/lib/python3.10/site-packages/xcp_d/interfaces/connectivity.py", line 102, in _run_interface
            n_voxels_in_masked_parcels = sum_masker_masked.fit_transform(atlas_img_bin)
          File "/usr/local/miniconda/lib/python3.10/site-packages/sklearn/utils/_set_output.py", line 295, in wrapped
            data_to_wrap = f(self, X, *args, **kwargs)
          File "/usr/local/miniconda/lib/python3.10/site-packages/nilearn/maskers/nifti_labels_masker.py", line 531, in fit_transform
            return self.fit(imgs).transform(
          File "/usr/local/miniconda/lib/python3.10/site-packages/nilearn/maskers/nifti_labels_masker.py", line 434, in fit
            raise ValueError(
        ValueError: Regions and mask do not have the same shape
        mask_img: /fmriprep/sub-0000012/func/sub-0000012_task-rest_space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz

Screenshots / relevant information:


Can you share the log from your failing job?

Here is one of the 126 crash files generated. The failing nodes were labeled as data, reho, or alff.



Node: _parcellate_data0
Working directory: /tmp/working_dir/xcp_d_0_7_wf/sub_0000012_wf/nifti_postprocess_1_wf/connectivity_wf/parcellate_data/mapflow/_parcellate_data0

Node inputs:

atlas = /out/atlases/atlas-4S1056Parcels/atlas-4S1056Parcels_space-MNI152NLin2009cAsym_dseg.nii.gz
atlas_labels = /out/atlases/atlas-4S1056Parcels/atlas-4S1056Parcels_dseg.tsv
filtered_file = /tmp/working_dir/xcp_d_0_7_wf/sub_0000012_wf/nifti_postprocess_1_wf/denoise_bold_wf/censor_interpolated_data/filtered_denoised_censored.nii.gz
mask = /fmriprep/sub-0000012/func/sub-0000012_task-rest_space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz
min_coverage = 0.5

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 _parcellate_data0.

Traceback:
        Traceback (most recent call last):
          File "/usr/local/miniconda/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 397, in run
            runtime = self._run_interface(runtime)
          File "/usr/local/miniconda/lib/python3.10/site-packages/xcp_d/interfaces/connectivity.py", line 102, in _run_interface
            n_voxels_in_masked_parcels = sum_masker_masked.fit_transform(atlas_img_bin)
          File "/usr/local/miniconda/lib/python3.10/site-packages/sklearn/utils/_set_output.py", line 295, in wrapped
            data_to_wrap = f(self, X, *args, **kwargs)
          File "/usr/local/miniconda/lib/python3.10/site-packages/nilearn/maskers/nifti_labels_masker.py", line 531, in fit_transform
            return self.fit(imgs).transform(
          File "/usr/local/miniconda/lib/python3.10/site-packages/nilearn/maskers/nifti_labels_masker.py", line 434, in fit
            raise ValueError(
        ValueError: Regions and mask do not have the same shape
        mask_img: /fmriprep/sub-0000012/func/sub-0000012_task-rest_space-MNI152NLin2009cAsym_desc-brain_mask.nii.gz

Thanks!

It looks like you’re processing native-resolution data. There’s a problem in XCP-D where, if different runs have different resolutions, then it will fail. See Processing native-resolution runs with different voxel sizes will fail · Issue #1069 · PennLINC/xcp_d · GitHub. Any chance your preprocessed BOLD data have different voxel sizes?

I see. Yes, this is the case. However, I’m actually only interested in the resting-state data, at least for the moment.

My resting-state data is 3.1 x 3.1 x 3.5mm. If this is the only fMRI run being processed, then this error should not arise, right?

I’m attempting to test this now – I have a separate fMRIPrep run going with the resting-state data only. Would there be a better way to tell XCP-D to run only my resting-state and ignore the other runs?

Hi @rwales,

You can use a —bids-filter-file to specify you only want to recognize certain files.

See more here: Running XCP-D — xcp_d 0.7.1rc7.dev2+gda6d5e2 documentation

Best,
Steven

(edit: fixed link)

Thank you! That link doesn’t work – I think that URL should be “xcp-d” instead of “xcp_d”.