Ok, quick outline:

  1. Have the network to left
  2. Have the network time series top center
  3. Take three time windows
  4. Have the seed map and winner takes all for each window in stack mid/bottom center
  5. Have the average winner takes all / scores on right

In [1]:
# Imports
import os
import glob
import numpy as np
import pandas as pd
import nibabel as nib
import brainbox as bb
import statsmodels.api as sm
from scipy import stats as st
from matplotlib import gridspec
from scipy import cluster as scl
from nilearn import plotting as nlp
from matplotlib import pyplot as plt
from sklearn import linear_model as slin
from statsmodels.sandbox import stats as sts
from matplotlib.colors import LinearSegmentedColormap


/home/surchs/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/__init__.py:1011: UserWarning: Duplicate key in file "/home/surchs/.config/matplotlib/matplotlibrc", line #405
  (fname, cnt))

In [2]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [3]:
# Paths
mask_path = '/data1/abide/Mask/mask_data_specific.nii.gz'
prior_path = '/data1/cambridge/template/template_cambridge_basc_multiscale_sym_scale012.nii.gz'
pheno_path = '/data1/abide/Pheno/merged_pheno.csv'
sub_path = ''

In [4]:
# Get the mask
m_img = nib.load(mask_path)
mask = m_img.get_data()!=0

In [5]:
# Get the subjects
pheno = pd.read_csv(pheno_path)

In [6]:
# Go through pheno and get the subjects
path_list = list()
for index, row in pheno.iterrows():
    # Get the path
    img_path = glob.glob(os.path.join(data_path, '*', name_template.format(row['SUB_ID'])))
    if img_path:
        path_list.append(img_path[0])

In [7]:
# Get the prior and turn network 8 into an image
prior_img = nib.load(prior_path)
prior = prior_img.get_data()
net8 = np.zeros_like(prior)
net8[prior==8] = 1
net8_vol = nib.Nifti1Image(net8, affine=prior_img.get_affine(), header=prior_img.get_header())

In [8]:
# Show the network
nlp.plot_glass_brain(net8_vol, cmap=cm.Blues, vmin=0, vmax=1)


Out[8]:
<nilearn.plotting.displays.OrthoProjector at 0x710b6d0>

In [24]:
# Get all the subjects into a voxel by time matrix
n_vox = np.sum(mask)
n_sub = len(path_list)
n_img = 50
data = np.zeros((n_vox, n_sub, n_img))
drop_list = list()
for index, s_path in enumerate(path_list):
    if index == 20:
        break
    f_net = nib.load(s_path).get_data()
    if not f_net.shape[3] >= n_img:
        print('dropped {}'.format(s_path))
        drop_list.append(index)
        continue
    data[:, index, :] = f_net[...,:n_img][mask]

In [26]:
use_data = np.delete(data, np.arange(20,823),1)

In [44]:
# Show the network average time series
net8_mask = net8[mask] == 1
avg_time = np.mean(use_data[net8_mask,...],0)

In [53]:
plt.plot(avg_time[0,:])


Out[53]:
[<matplotlib.lines.Line2D at 0x8da9250>]

In [49]:
avg_time.shape


Out[49]:
(20, 50)

In [52]:
plt.plot(np.mean(avg_time,0))


Out[52]:
[<matplotlib.lines.Line2D at 0xacf91d0>]

In [ ]: