In [1]:
import glob, os, sys
import numpy as np
from nilearn.image import resample_img, index_img
import nibabel as nib
from nilearn.input_data import NiftiLabelsMasker

Read data path and define result path


In [2]:
DATA_DIR = 'U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed'
crosscorr = 'data/data_cross_corr_Bzdok_DMN16_preprocessed'
nMasks = 16 #for sanity check

Create a list of atlas names


In [3]:
atlas_nii = sorted(glob.glob('Bzdok_DMN/*.nii.gz'))
atlas_names = [roi.split(os.sep)[-1].split('.nii.gz')[0]  for roi in atlas_nii]
atlas_names = np.array(atlas_names)
# np.save(crosscorr+'_ROIS', atlas_names)

In [4]:
print atlas_names


['PMC-1' 'PMC-2' 'PMC-3' 'PMC-4' 'TPJ_left-1' 'TPJ_left-2' 'TPJ_right-1'
 'TPJ_right-2' 'dMPFC-1' 'dMPFC-3' 'vMPFC_Left_1' 'vMPFC_Left_2'
 'vMPFC_Left_3' 'vMPFC_Right_1' 'vMPFC_Right_2' 'vMPFC_Right_3']

Create label nifti image


In [4]:
rs_niis = sorted(glob.glob(DATA_DIR + os.sep + '*.nii.gz'))
tmp_nii_path = rs_niis[0]
tmp_nii = nib.load(tmp_nii_path)

label_atlas = np.zeros(tmp_nii.shape[:3], dtype=np.int)
for i_roi, cur_roi in enumerate(atlas_nii):
    # reshape the data (put the mask on the particiapnt's data, matching the coordinates and shapes)
    re_cur_roi = resample_img(
        img=cur_roi,
        target_affine=tmp_nii.get_affine(),
        target_shape=tmp_nii.shape[:3],
        interpolation='nearest'
    )

    # binarize the data
    cur_data = re_cur_roi.get_data()
    if cur_data.ndim > 3:
        cur_data = cur_data[..., 0]
    cur_data_bin = np.array(cur_data > 0, dtype=np.int)
    label_atlas[cur_data_bin > 0] = i_roi + 1
#     re_cur_roi = nib.Nifti1Image(
#         cur_data_bin,
#         affine=tmp_nii.get_affine(),
#         header=tmp_nii.get_header()
#     )
    
#     # dump to disk
#     re_atlas_nii
#     re_cur_roi.to_filename('ReSample_Masks\\Yeo7LiberalMask_%i_%s.nii.gz'%(i+1, atlas_names[i])
label_atlas_nii = nib.Nifti1Image(
    label_atlas,
    affine=tmp_nii.affine,
    header=tmp_nii.header
)
# label_atlas_nii.to_filename('BzdokDMN16_labels.nii.gz')
masker = NiftiLabelsMasker(labels_img=label_atlas_nii, standardize=True,
                           memory='nilearn_cache', verbose=0)
masker.fit()


C:\Users\hw1012\AppData\Local\Continuum\Anaconda2\lib\site-packages\ipykernel\__main__.py:10: DeprecationWarning: get_affine method is deprecated.
Please use the ``img.affine`` property instead.

* deprecated from version: 2.1
* Will raise <class 'nibabel.deprecator.ExpiredDeprecationError'> as of version: 4.0
Out[4]:
NiftiLabelsMasker(background_label=0, detrend=False, high_pass=None,
         labels_img=<nibabel.nifti1.Nifti1Image object at 0x0000000008CB5160>,
         low_pass=None, mask_img=None, memory='nilearn_cache',
         memory_level=1, resampling_target='data', smoothing_fwhm=None,
         standardize=True, t_r=None, verbose=0)

In [56]:
from nilearn import plotting
import matplotlib.pyplot as plt

plotting.plot_roi(label_atlas_nii, 
                  draw_cross=False,
                  colorbar=True,
                  display_mode='x',
                  cut_coords=(5, 64, 18),
                 vmax=17, vmin=0).savefig('Results/ROI_x.png', dpi=300)
plotting.show()

plotting.plot_roi(label_atlas_nii, 
                  draw_cross=False,
                  colorbar=True,
                  display_mode='y',
                  cut_coords=(5, 64, 18),
                 vmax=17, vmin=0).savefig('Results/ROI_y.png', dpi=300)
plotting.show()

plotting.plot_roi(label_atlas_nii, 
                  draw_cross=False,
                  colorbar=True,
                  display_mode='z',
                  cut_coords=(5, 64, 18),
                 vmax=17, vmin=0).savefig('Results/ROI_z.png', dpi=300)
plotting.show()


Extract time series and compute network connectivities per particiapnt


In [94]:
corr_mat_vect_list = []
ind_list = []
FD_corr_mat_lst = []

FD = np.load('./data/CS1_FD.npy') # framewise displacement 

for i_rs_img, rs_img in enumerate(rs_niis):
    print('%i/%i: %s' % (i_rs_img + 1, len(rs_niis), rs_img))
    rs_reg_ts = masker.transform(rs_img)

    corr_mat = np.corrcoef(rs_reg_ts.T)
    triu_inds = np.triu_indices(corr_mat.shape[0], 1)
    corr_mat_vect = corr_mat[triu_inds]
    corr_mat_vect_list.append(corr_mat_vect)
    
    # how framewise displacement correlates with the signal from each node.
    FD_corr = np.hstack((rs_reg_ts, FD[i_rs_img:i_rs_img+1, :].T))
    FD_corr_mat = np.corrcoef(FD_corr.T)
    FD_corr_mat_lst.append(FD_corr_mat)
    
corr_mat_vect_array = np.array(corr_mat_vect_list)
FD_corr_mat = np.array(FD_corr_mat_lst)

#demean
corr_mat_vect_array[np.isnan(corr_mat_vect_array)] = 1
# np.save(crosscorr, corr_mat_vect_array)


1/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\001_R4087_MNI152_2mm_prepro_filtered_func_data.nii.gz
2/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\002_R4088_MNI152_2mm_prepro_filtered_func_data.nii.gz
3/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\003_R4076_MNI152_2mm_prepro_filtered_func_data.nii.gz
4/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\004_R3529_MNI152_2mm_prepro_filtered_func_data.nii.gz
5/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\005_R4071_MNI152_2mm_prepro_filtered_func_data.nii.gz
6/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\006_R3392_MNI152_2mm_prepro_filtered_func_data.nii.gz
7/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\007_R4064_MNI152_2mm_prepro_filtered_func_data.nii.gz
8/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\008_R4079_MNI152_2mm_prepro_filtered_func_data.nii.gz
9/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\009_R4086_MNI152_2mm_prepro_filtered_func_data.nii.gz
10/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\010_R4091_MNI152_2mm_prepro_filtered_func_data.nii.gz
11/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\011_R4068_MNI152_2mm_prepro_filtered_func_data.nii.gz
12/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\012_R4085_MNI152_2mm_prepro_filtered_func_data.nii.gz
13/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\013_R2904_MNI152_2mm_prepro_filtered_func_data.nii.gz
14/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\014_R4080_MNI152_2mm_prepro_filtered_func_data.nii.gz
15/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\015_R4119_MNI152_2mm_prepro_filtered_func_data.nii.gz
16/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\016_R4122_MNI152_2mm_prepro_filtered_func_data.nii.gz
17/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\017_R4099_MNI152_2mm_prepro_filtered_func_data.nii.gz
18/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\018_R4120_MNI152_2mm_prepro_filtered_func_data.nii.gz
19/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\019_R4095_MNI152_2mm_prepro_filtered_func_data.nii.gz
20/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\020_R4121_MNI152_2mm_prepro_filtered_func_data.nii.gz
21/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\021_R4132_MNI152_2mm_prepro_filtered_func_data.nii.gz
22/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\022_R4007_MNI152_2mm_prepro_filtered_func_data.nii.gz
23/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\023_R3678_MNI152_2mm_prepro_filtered_func_data.nii.gz
24/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\024_R3773_MNI152_2mm_prepro_filtered_func_data.nii.gz
25/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\025_R3385_MNI152_2mm_prepro_filtered_func_data.nii.gz
26/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\026_R4065_MNI152_2mm_prepro_filtered_func_data.nii.gz
27/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\027_R4136_MNI152_2mm_prepro_filtered_func_data.nii.gz
28/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\028_R4135_MNI152_2mm_prepro_filtered_func_data.nii.gz
29/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\029_R4139_MNI152_2mm_prepro_filtered_func_data.nii.gz
30/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\030_R4142_MNI152_2mm_prepro_filtered_func_data.nii.gz
31/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\031_R4131_MNI152_2mm_prepro_filtered_func_data.nii.gz
32/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\032_R4062_MNI152_2mm_prepro_filtered_func_data.nii.gz
33/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\033_R4133_MNI152_2mm_prepro_filtered_func_data.nii.gz
34/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\034_R4157_MNI152_2mm_prepro_filtered_func_data.nii.gz
35/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\035_R4158_MNI152_2mm_prepro_filtered_func_data.nii.gz
36/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\036_R4137_MNI152_2mm_prepro_filtered_func_data.nii.gz
37/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\037_R4160_MNI152_2mm_prepro_filtered_func_data.nii.gz
38/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\038_R4164_MNI152_2mm_prepro_filtered_func_data.nii.gz
39/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\039_R4143_MNI152_2mm_prepro_filtered_func_data.nii.gz
40/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\040_R4146_MNI152_2mm_prepro_filtered_func_data.nii.gz
41/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\041_R4156_MNI152_2mm_prepro_filtered_func_data.nii.gz
42/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\042_R4166_MNI152_2mm_prepro_filtered_func_data.nii.gz
43/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\043_R3316_MNI152_2mm_prepro_filtered_func_data.nii.gz
44/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\044_R3111_MNI152_2mm_prepro_filtered_func_data.nii.gz
45/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\045_R4172_MNI152_2mm_prepro_filtered_func_data.nii.gz
46/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\046_R3946_MNI152_2mm_prepro_filtered_func_data.nii.gz
47/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\047_R4140_MNI152_2mm_prepro_filtered_func_data.nii.gz
48/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\048_R4165_MNI152_2mm_prepro_filtered_func_data.nii.gz
49/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\049_R3761_MNI152_2mm_prepro_filtered_func_data.nii.gz
50/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\050_R4167_MNI152_2mm_prepro_filtered_func_data.nii.gz
51/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\051_R4162_MNI152_2mm_prepro_filtered_func_data.nii.gz
52/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\052_R2555_MNI152_2mm_prepro_filtered_func_data.nii.gz
53/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\053_R4060_MNI152_2mm_prepro_filtered_func_data.nii.gz
54/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\054_R4181_MNI152_2mm_prepro_filtered_func_data.nii.gz
55/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\055_R4179_MNI152_2mm_prepro_filtered_func_data.nii.gz
56/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\056_R4174_MNI152_2mm_prepro_filtered_func_data.nii.gz
57/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\057_R3557_MNI152_2mm_prepro_filtered_func_data.nii.gz
58/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\058_R2595_MNI152_2mm_prepro_filtered_func_data.nii.gz
59/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\059_R3262_MNI152_2mm_prepro_filtered_func_data.nii.gz
60/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\060_R4191_MNI152_2mm_prepro_filtered_func_data.nii.gz
61/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\061_R4192_MNI152_2mm_prepro_filtered_func_data.nii.gz
62/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\062_R4196_MNI152_2mm_prepro_filtered_func_data.nii.gz
63/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\063_R4193_MNI152_2mm_prepro_filtered_func_data.nii.gz
64/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\064_R4168_MNI152_2mm_prepro_filtered_func_data.nii.gz
65/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\065_R4194_MNI152_2mm_prepro_filtered_func_data.nii.gz
66/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\066_R4052_MNI152_2mm_prepro_filtered_func_data.nii.gz
67/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\067_R4202_MNI152_2mm_prepro_filtered_func_data.nii.gz
68/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\068_R4204_MNI152_2mm_prepro_filtered_func_data.nii.gz
69/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\069_R4205_MNI152_2mm_prepro_filtered_func_data.nii.gz
70/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\070_R3630_MNI152_2mm_prepro_filtered_func_data.nii.gz
71/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\071_R4209_MNI152_2mm_prepro_filtered_func_data.nii.gz
72/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\072_R4215_MNI152_2mm_prepro_filtered_func_data.nii.gz
73/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\073_R4221_MNI152_2mm_prepro_filtered_func_data.nii.gz
74/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\074_R4211_MNI152_2mm_prepro_filtered_func_data.nii.gz
75/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\075_R3517_MNI152_2mm_prepro_filtered_func_data.nii.gz
76/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\076_R4222_MNI152_2mm_prepro_filtered_func_data.nii.gz
77/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\077_R4232_MNI152_2mm_prepro_filtered_func_data.nii.gz
78/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\078_R3380_MNI152_2mm_prepro_filtered_func_data.nii.gz
79/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\079_R4241_MNI152_2mm_prepro_filtered_func_data.nii.gz
80/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\080_R4248_MNI152_2mm_prepro_filtered_func_data.nii.gz
81/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\081_R4240_MNI152_2mm_prepro_filtered_func_data.nii.gz
82/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\082_R4239_MNI152_2mm_prepro_filtered_func_data.nii.gz
83/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\083_R4249_MNI152_2mm_prepro_filtered_func_data.nii.gz
84/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\084_R4217_MNI152_2mm_prepro_filtered_func_data.nii.gz
85/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\085_R4238_MNI152_2mm_prepro_filtered_func_data.nii.gz
86/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\086_R4250_MNI152_2mm_prepro_filtered_func_data.nii.gz
87/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\087_R3884_MNI152_2mm_prepro_filtered_func_data.nii.gz
88/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\088_R4265_MNI152_2mm_prepro_filtered_func_data.nii.gz
89/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\089_R4269_MNI152_2mm_prepro_filtered_func_data.nii.gz
90/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\090_R4260_MNI152_2mm_prepro_filtered_func_data.nii.gz
91/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\091_R3904_MNI152_2mm_prepro_filtered_func_data.nii.gz
92/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\092_R4258_MNI152_2mm_prepro_filtered_func_data.nii.gz
93/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\093_R4277_MNI152_2mm_prepro_filtered_func_data.nii.gz
94/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\094_R4255_MNI152_2mm_prepro_filtered_func_data.nii.gz
95/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\095_R4268_MNI152_2mm_prepro_filtered_func_data.nii.gz
96/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\096_R4213_MNI152_2mm_prepro_filtered_func_data.nii.gz
97/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\097_R3891_MNI152_2mm_prepro_filtered_func_data.nii.gz
98/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\098_R4242_MNI152_2mm_prepro_filtered_func_data.nii.gz
99/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\099_R4271_MNI152_2mm_prepro_filtered_func_data.nii.gz
100/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\100_R4253_MNI152_2mm_prepro_filtered_func_data.nii.gz
101/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\101_R4251_MNI152_2mm_prepro_filtered_func_data.nii.gz
102/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\102_R4254_MNI152_2mm_prepro_filtered_func_data.nii.gz
103/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\103_R4256_MNI152_2mm_prepro_filtered_func_data.nii.gz
104/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\104_R4235_MNI152_2mm_prepro_filtered_func_data.nii.gz
105/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\105_R4270_MNI152_2mm_prepro_filtered_func_data.nii.gz
106/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\106_R4220_MNI152_2mm_prepro_filtered_func_data.nii.gz
107/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\107_R4264_MNI152_2mm_prepro_filtered_func_data.nii.gz
108/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\108_R4267_MNI152_2mm_prepro_filtered_func_data.nii.gz
109/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\109_R4272_MNI152_2mm_prepro_filtered_func_data.nii.gz
110/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\110_R4046_MNI152_2mm_prepro_filtered_func_data.nii.gz
111/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\111_R4266_MNI152_2mm_prepro_filtered_func_data.nii.gz
112/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\112_R4047_MNI152_2mm_prepro_filtered_func_data.nii.gz
113/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\113_R4006_MNI152_2mm_prepro_filtered_func_data.nii.gz
114/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\114_R4273_MNI152_2mm_prepro_filtered_func_data.nii.gz
115/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\115_R4236_MNI152_2mm_prepro_filtered_func_data.nii.gz
116/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\116_R4275_MNI152_2mm_prepro_filtered_func_data.nii.gz
117/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\117_R4276_MNI152_2mm_prepro_filtered_func_data.nii.gz
118/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\118_R3576_MNI152_2mm_prepro_filtered_func_data.nii.gz
119/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\119_R4282_MNI152_2mm_prepro_filtered_func_data.nii.gz
120/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\120_R3922_MNI152_2mm_prepro_filtered_func_data.nii.gz
121/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\121_R4279_MNI152_2mm_prepro_filtered_func_data.nii.gz
122/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\122_R3906_MNI152_2mm_prepro_filtered_func_data.nii.gz
123/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\123_R4283_MNI152_2mm_prepro_filtered_func_data.nii.gz
124/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\124_R4281_MNI152_2mm_prepro_filtered_func_data.nii.gz
125/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\125_R4280_MNI152_2mm_prepro_filtered_func_data.nii.gz
126/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\126_R4295_MNI152_2mm_prepro_filtered_func_data.nii.gz
127/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\127_R4286_MNI152_2mm_prepro_filtered_func_data.nii.gz
128/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\128_R4301_MNI152_2mm_prepro_filtered_func_data.nii.gz
129/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\129_R4300_MNI152_2mm_prepro_filtered_func_data.nii.gz
130/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\130_R4298_MNI152_2mm_prepro_filtered_func_data.nii.gz
131/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\131_R4294_MNI152_2mm_prepro_filtered_func_data.nii.gz
132/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\132_R4306_MNI152_2mm_prepro_filtered_func_data.nii.gz
133/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\133_R4292_MNI152_2mm_prepro_filtered_func_data.nii.gz
134/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\134_R4148_MNI152_2mm_prepro_filtered_func_data.nii.gz
135/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\135_R4293_MNI152_2mm_prepro_filtered_func_data.nii.gz
136/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\136_R4302_MNI152_2mm_prepro_filtered_func_data.nii.gz
137/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\137_R4233_MNI152_2mm_prepro_filtered_func_data.nii.gz
138/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\138_R4296_MNI152_2mm_prepro_filtered_func_data.nii.gz
139/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\139_R4308_MNI152_2mm_prepro_filtered_func_data.nii.gz
140/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\140_R4316_MNI152_2mm_prepro_filtered_func_data.nii.gz
141/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\141_R4321_MNI152_2mm_prepro_filtered_func_data.nii.gz
142/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\142_R4309_MNI152_2mm_prepro_filtered_func_data.nii.gz
143/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\143_R4312_MNI152_2mm_prepro_filtered_func_data.nii.gz
144/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\144_R4304_MNI152_2mm_prepro_filtered_func_data.nii.gz
145/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\145_R4307_MNI152_2mm_prepro_filtered_func_data.nii.gz
146/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\146_R4305_MNI152_2mm_prepro_filtered_func_data.nii.gz
147/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\147_R4315_MNI152_2mm_prepro_filtered_func_data.nii.gz
148/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\148_R4310_MNI152_2mm_prepro_filtered_func_data.nii.gz
149/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\149_R4323_MNI152_2mm_prepro_filtered_func_data.nii.gz
150/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\150_R4314_MNI152_2mm_prepro_filtered_func_data.nii.gz
151/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\151_R4053_MNI152_2mm_prepro_filtered_func_data.nii.gz
152/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\152_R4320_MNI152_2mm_prepro_filtered_func_data.nii.gz
153/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\153_R4318_MNI152_2mm_prepro_filtered_func_data.nii.gz
154/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\154_R4319_MNI152_2mm_prepro_filtered_func_data.nii.gz
155/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\155_R4332_MNI152_2mm_prepro_filtered_func_data.nii.gz
156/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\156_R4313_MNI152_2mm_prepro_filtered_func_data.nii.gz
157/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\157_R3338_MNI152_2mm_prepro_filtered_func_data.nii.gz
158/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\158_R4328_MNI152_2mm_prepro_filtered_func_data.nii.gz
159/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\159_R4322_MNI152_2mm_prepro_filtered_func_data.nii.gz
160/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\160_R4333_MNI152_2mm_prepro_filtered_func_data.nii.gz
161/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\161_R4311_MNI152_2mm_prepro_filtered_func_data.nii.gz
162/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\162_R3899_MNI152_2mm_prepro_filtered_func_data.nii.gz
163/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\163_R3931_MNI152_2mm_prepro_filtered_func_data.nii.gz
164/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\164_R4317_MNI152_2mm_prepro_filtered_func_data.nii.gz
165/165: U:/Projects/CS_Analysis/CS_data/CS_brain_preprocessed\165_R4037_MNI152_2mm_prepro_filtered_func_data.nii.gz

In [95]:
# plot the average network strength 
# and the correlation between framewise displacement and TS of the ROIs

atlas_names = [roi.split(os.sep)[-1].split('.nii.gz')[0]  for roi in atlas_nii] + ['FD by TS']
mean_NetworkStrength = np.mean(FD_corr_mat, axis=0)

import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams.update({'font.size': 10})
plt.matshow(mean_NetworkStrength, vmin=-1, vmax=1, cmap=plt.cm.RdBu_r)
# plt.plot([-0.5, n_areas-0.5], [-0.5, n_areas-0.5], ls='--', c='.3')
plt.xticks(range(mean_NetworkStrength.shape[0]), atlas_names, rotation=90)
plt.yticks(range(mean_NetworkStrength.shape[1]), atlas_names)
plt.colorbar()
plt.show()
# plt.savefig('./Results/RemoveHighFD/FDbyTS_nodeSignal_corrmat.png', bbox_inches='tight', dpi=150)



In [10]:
# save all combinations
reg_reg_names = [atlas_names[a] + ' vs ' + atlas_names[b] for (a,b) in zip(triu_inds[0], triu_inds[1])]
np.save(crosscorr+'_keys', reg_reg_names)

Create a total network mask


In [44]:
network_nii = np.zeros(tmp_nii.shape[:3], dtype=np.int)
network_nii[label_atlas>0] = 1
network_mask = nib.Nifti1Image(
    network_nii,
    affine=tmp_nii.affine,
    header=tmp_nii.header
)
network_mask.to_filename('BzdokDMN16_network_mask.nii.gz')