Ejemplo n.º 1
0
#This part is the same as before
TR=1.89
data_rec = csv2rec('data/fmri_timeseries.csv')
roi_names= np.array(data_rec.dtype.names)
n_samples = data_rec.shape[0]
data = np.zeros((len(roi_names),n_samples))
for n_idx, roi in enumerate(roi_names):
   data[n_idx] = data_rec[roi]
data = percent_change(data)
T = UniformTimeSeries(data,sampling_interval=TR)
T.metadata['roi'] = roi_names 
C = CoherenceAnalyzer(T)
freq_idx = np.where((C.frequencies>0.02) * (C.frequencies<0.15))[0]
idx_lcau = np.where(roi_names=='lcau')[0]
idx_rcau = np.where(roi_names=='rcau')[0]
idx_lput = np.where(roi_names=='lput')[0]
idx_rput = np.where(roi_names=='rput')[0]
idx = np.hstack([idx_lcau,idx_rcau,idx_lput,idx_rput])
idx1 = np.vstack([[idx[i]]*4 for i in range(4)]).ravel()
idx2 = np.hstack(4*[idx])

#For the third dimension, take always the index of the left caudate:
idx3 = np.hstack(16*[idx_lcau])

#Extract the partial coherence and average across the frequency bands: 
coh = C.coherence_partial[idx1,idx2,idx3].reshape(4,4,C.frequencies.shape[0])
coh = np.mean(coh[:,:,freq_idx],-1) #Averaging on the last dimension

drawgraph_roi(coh,roi_names[idx])
matshow_roi(coh,roi_names[idx])
Ejemplo n.º 2
0
#This information (the sampling rate) has to be known in advance:
TR=1.89

#Load the data from the csv file:
data_rec = csv2rec('data/fmri_timeseries.csv')

#Extract information:
roi_names= np.array(data_rec.dtype.names)
n_samples = data_rec.shape[0]


#Make an empty container for the data
data = np.zeros((len(roi_names),n_samples))

for n_idx, roi in enumerate(roi_names):
   data[n_idx] = data_rec[roi]

#Normalize the data:
data = percent_change(data)

#Initialize the time-series from the normalized data:
T = UniformTimeSeries(data,sampling_interval=TR)
T.metadata['roi'] = roi_names 

#Initialize the correlation analyzer
C = CorrelationAnalyzer(T)

#Display the correlation matrix
matshow_roi(C(),roi_names,size=[10.,10.])

Ejemplo n.º 3
0
import nitime.viz
reload(nitime.viz)
from nitime.viz import matshow_roi

#This time Import the coherence analyzer 
from nitime.analysis import CoherenceAnalyzer

#This part is the same as before
TR=1.89
data_rec = csv2rec('data/fmri_timeseries.csv')
roi_names= np.array(data_rec.dtype.names)
n_samples = data_rec.shape[0]
data = np.zeros((len(roi_names),n_samples))

for n_idx, roi in enumerate(roi_names):
   data[n_idx] = data_rec[roi]

data = percent_change(data)
T = UniformTimeSeries(data,sampling_interval=TR)
T.metadata['roi'] = roi_names 
C = CoherenceAnalyzer(T)

#We look only at frequencies between 0.02 and 0.15 (the physiologically
#relevant band, see http://imaging.mrc-cbu.cam.ac.uk/imaging/DesignEfficiency:
freq_idx = np.where((C.frequencies>0.02) * (C.frequencies<0.15))[0]

#Extract the coherence and average across these frequency bands: 
coh = np.mean(C.coherence[:,:,freq_idx],-1) #Averaging on the last dimension 
matshow_roi(coh,roi_names,size=[10.,10.])