Created
September 30, 2015 15:24
-
-
Save pravsripad/b765300c5bb6870a163f to your computer and use it in GitHub Desktop.
koln_xcorr_networks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!usr/bin/env python | |
import numpy as np | |
import pyunicorn | |
import matplotlib.pyplot as pl | |
''' | |
# make a big bad ass array with all the subjects | |
for subj in range(1, 11): | |
print '>Running for subject %d' %(subj) | |
data = np.loadtxt('fmri_subject_%d.txt' % subj) | |
big_data[subj - 1] = data.T | |
np.save('all_fmri_data.npy') | |
''' | |
# reading our data | |
data = np.loadtxt('all_fmri_data.npy') | |
def prepare_xcorr_network(data, thresh_val=95, save_name='test.gml'): | |
''' Read data and save the network as gml. ''' | |
xcorr = np.corrcoef(data.T) | |
# performing cross correlation | |
xcorr = np.abs(xcorr) | |
xcorr = xcorr - np.eye(len(xcorr)) | |
print 'Maximum value is %f and minimum value is %f' % (xcorr.min(), xcorr.max()) | |
# set the threshold percentile | |
thresh = np.percentile(xcorr, thresh_val) | |
# binary matrix | |
xcorr_bin = xcorr >= thresh | |
link_weights = np.abs(xcorr_bin) | |
channel_names = range(0, xcorr.shape[0]) | |
channel_names = [str(i) for i in channel_names] | |
# initialiying the network | |
net = pyunicorn.Network(xcorr_bin) | |
net.set_link_attribute(attribute_name="weight", values=link_weights) | |
net.set_node_attribute(attribute_name="label", values=channel_names) | |
if save_name: | |
print 'Saving the file...' | |
net.save(save_name) # save the network | |
for subj in range(1, 11): | |
print '>Running for subject %d' %(subj) | |
data = np.loadtxt('fmri_subject_%d.txt' % subj) | |
print data.shape | |
print '' | |
prepare_xcorr_network(data, thresh_val=95, save_name=None) | |
#prepare_xcorr_network(data, thresh_val=95, save_name='fmri_subj_%d.gml' % subj) | |
#plotting the image | |
#pl.imshow(xcorr) | |
#pl.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment