Problems with applying the AAL template

When I used the MSDL template, I had no problems, but when I switched to the AAl template, I had the following problems.
Downloading data from http://www.gin.cnrs.fr/AAL_files/aal_for_SPM12.tar.gz
Downloaded 225702 of ? bytes. …done. (5 seconds, 0 min)
Extracting data from C:\Users\bb/nilearn_data\aal_SPM12\3d9806fc1addf495fd688a71eed4b1b7\aal_for_SPM12.tar.gz… done.
[NiftiMapsMasker.fit_transform] loading regions from C:\Users\bb/nilearn_data\aal_SPM12\aal\atlas\AAL.nii
Traceback (most recent call last):
File “D:/Pycharm project/fMRI/feature/test.py”, line 18, in
time_series = masker.fit_transform(data)
File “D:\Conda_env\brainNet\lib\site-packages\nilearn\input_data\nifti_maps_masker.py”, line 225, in fit_transform
return self.fit().transform(imgs, confounds=confounds)
File “D:\Conda_env\brainNet\lib\site-packages\nilearn\input_data\nifti_maps_masker.py”, line 176, in fit
self.maps_img_ = _utils.check_niimg_4d(self.maps_img, dtype=self.dtype)
File “D:\Conda_env\brainNet\lib\site-packages\nilearn_utils\niimg_conversions.py”, line 356, in check_niimg_4d
dtype=dtype)
File “D:\Conda_env\brainNet\lib\site-packages\nilearn_utils\niimg_conversions.py”, line 276, in check_niimg
raise DimensionError(len(niimg.shape), ensure_ndim)
nilearn._utils.exceptions.DimensionError: Input data has incompatible dimensionality: Expected dimension is 4D and you provided a 3D image. See http://nilearn.github.io/manipulating_images/input_output.html.

Process finished with exit code 1

atlas = datasets.fetch_atlas_aal(version='SPM12')
atlas_filename = atlas.maps
labels = atlas.labels
data = image.load_img("./CovRegressed2_4DVolume.nii")
masker = NiftiMapsMasker(maps_img=atlas_filename, standardize=True,
                     memory='nilearn_cache', verbose=5)

time_series = masker.fit_transform(data)

correlation_measure = ConnectivityMeasure(kind='correlation')
correlation_matrix = correlation_measure.fit_transform([time_series])[0]

# Display the correlation matrix

# Mask out the major diagonal
plt.imshow(correlation_matrix, interpolation="nearest", cmap="RdBu_r",
       vmax=0.8, vmin=-0.8)

# Add labels and adjust margins
x_ticks = plt.xticks(range(len(labels) - 1), labels[1:], rotation=90)
y_ticks = plt.yticks(range(len(labels) - 1), labels[1:])
plt.gca().yaxis.tick_right()
plt.subplots_adjust(left=.01, bottom=.3, top=.99, right=.62)
plt.show()

coords = atlas.region_coords
plotting.plot_connectome(correlation_matrix, coords,
                     edge_threshold="80%", colorbar=True)

plotting.show()

Hi @bin !

Your code is using NiftiMapsMasker which is intended for use with probabilistic atlases like MSDL.

To use AAL, you’d want to use NiftiLabelsMasker instead.

Hope that helps,

Elizabeth

2 Likes

And just as a follow-up: for a bit more detail on the differences between probabilistic atlases (like MSDL) and deterministic atlases (like AAL), this section of the Nilearn user guide might be helpful !

http://nilearn.github.io/connectivity/functional_connectomes.html

Elizabeth