'Correlation heatmap of many datasets

I am working with niftis (Neuroimaging format) looking at 3D volumes of the brain.

I want to compare experiments with brain activity.

Therefore I have about 20 experiment files in nifti format.

and 4 brain activity files also in nifti format.

They have the same dimension of the brain and show some values in specific areas/pixels of the brain.

How can I plot a sns.heatmap, that has on the x-axis all experiments, and on the y-axis all activity files. I then want to see a heatmap correlation map, with plotted correlation values in heatmap colors.

I just found sns.heatmap plots for pandas dataframes. Can someone help?

I started with

import nibabel as nib

exp1 = nib.load("exp1.nii")
exp1= exp1.get_fdata()

act1 = nib.load('act1.nii.gz')
act1 = act1.get_fdata()

exp1, und act1 are read in as float64 of dimension (57, 66, 40).

Has someone an idea?

Example data:

act1[20,:,:]
Out[4]: 
array([[ 0.02153977,  0.03817031,  0.10424001, ...,  1.38311863,
         0.86190647,  0.36399585],
       [ 0.02117901,  0.03277704,  0.05148495, ...,  0.47603241,
         0.36187041,  0.16624629],
       [ 0.01256184,  0.02604919,  0.0477814 , ...,  0.13270944,
         0.11138337,  0.0545687 ],
       ...,
       [-1.        , -1.        , -1.        , ..., -1.        ,
        -1.        , -1.        ],
       [-1.        , -1.        , -1.        , ..., -1.        ,
        -1.        , -1.        ],
       [-1.        , -1.        , -1.        , ..., -1.        ,
        -1.        , -1.        ]])

exp1[20,:,:]
Out[8]: 
array([[0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0.23, 0.21, 0.11],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.]])


Solution 1:[1]

If you want to plot the correlation matrix using sns/seaborn you need to first extract the BOLD signal in the image(.nii) format that you have.

You can use the nilearn package to extract the BOLD time series signal for a specific atlas of interest (like AAL atlas which consists of 90 ROIs)

Then you can plot the correlation to see the correlations between the ROIs.

Hope this helps

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abhishek Patil