Beispiel #1
0
def getCorrelation(run, encoding, subject_id):
    # obtains the correlation between empirical functional connectivity and simulated functional connectivity
    key = str(run) + "_" + str(encoding) + "_" + str(subject_id) + "_rsHRF"
    input_path_sim = "weights" + key + "fMRI.txt"
    em_fc_matrix = get_FC(run, encoding, subject_id)
    sampling_interval = 0.72
    uidx = np.triu_indices(379, 1)
    em_fc_z = np.arctanh(em_fc_matrix)
    em_fc = em_fc_z[uidx]
    tsr = np.loadtxt(input_path_sim)
    T = TimeSeries(tsr, sampling_interval=sampling_interval)
    C = CorrelationAnalyzer(T)
    sim_fc = np.arctanh(C.corrcoef)[uidx]
    sim_fc = np.nan_to_num(sim_fc)
    pearson_corr, _ = stat.pearsonr(sim_fc, em_fc)
    os.remove(input_path_sim)
    return pearson_corr
def getCorrelation(group_id, subject_id):
    # obtains the correlation between empirical functional connectivity and simulated functional connectivity
    input_path_sim = "fMRI.txt"
    input_path_em = get_path(group_id, subject_id, "T1") + "FC.mat"
    em_mat = scipy.io.loadmat(input_path_em)
    em_fc_matrix = em_mat["FC_cc_DK68"]
    sampling_interval = em_mat["TR"][0][0]
    uidx = np.triu_indices(68, 1)
    em_fc_z = np.arctanh(em_fc_matrix)
    em_fc = em_fc_z[uidx]
    tsr = np.loadtxt(input_path_sim)
    T = TimeSeries(tsr, sampling_interval=sampling_interval)
    C = CorrelationAnalyzer(T)
    sim_fc = np.arctanh(C.corrcoef)[uidx]
    sim_fc = np.nan_to_num(sim_fc)
    pearson_corr, _ = stat.pearsonr(sim_fc, em_fc)
    return pearson_corr
Beispiel #3
0
def connectivity(x):
    data = np.vstack(x)
    ts = TimeSeries(data, sampling_interval=1.)
    return CorrelationAnalyzer(ts).corrcoef
Beispiel #4
0
                                     mode="mean")

    ht_pln_bs = mne.baseline.rescale(ht_pln,
                                     times,
                                     baseline=(-3.8, -3.3),
                                     mode="mean")
    ht_int_bs = mne.baseline.rescale(ht_pln,
                                     times,
                                     baseline=(-3.8, -3.3),
                                     mode="mean")

    for ts in ht_cls_bs:
        nits = TimeSeries(ts[:, tois[toi][0]:tois[toi][1]],
                          sampling_rate=1000)  # epochs_normal.info["sfreq"])

        corr_cls += [CorrelationAnalyzer(nits)]

    for ts in ht_pln_bs:
        nits = TimeSeries(ts[:, tois[toi][0]:tois[toi][1]],
                          sampling_rate=1000)  # epochs_normal.info["sfreq"])

        corr_pln += [CorrelationAnalyzer(nits)]

    for ts in ht_int_bs:
        nits = TimeSeries(ts[:, tois[toi][0]:tois[toi][1]],
                          sampling_rate=1000)  # epochs_normal.info["sfreq"])

        corr_int += [CorrelationAnalyzer(nits)]

    results_cls = np.asarray([c.corrcoef for c in corr_cls])
    results_pln = np.asarray([c.corrcoef for c in corr_pln])
Beispiel #5
0
    nx.__class__  # will raise an error if nx could not be imported in viz
    no_networkx = False
    no_networkx_msg = ''
except ImportError, e:
    no_networkx = True
    no_networkx_msg = e.args[0]

roi_names = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
data = np.random.rand(10, 1024)

T = TimeSeries(data, sampling_interval=np.pi)
T.metadata['roi'] = roi_names

#Initialize the correlation analyzer
C = CorrelationAnalyzer(T)


def test_drawmatrix_channels():
    fig01 = drawmatrix_channels(C.corrcoef,
                                roi_names,
                                size=[10., 10.],
                                color_anchor=0)


def test_plot_xcorr():
    xc = C.xcorr_norm

    fig02 = plot_xcorr(xc, ((0, 1), (2, 3)), line_labels=['a', 'b'])

Beispiel #6
0
                             verbose=True))
        # reshape ROI matrix
        allROIS = reshapeTS(t_fix)
        numRuns = allROIS.shape[1]

        corr_all[subject] = np.zeros((numRuns, len(rois), len(rois))) * np.nan
        coh_all[subject] = np.zeros((numRuns, len(rois), len(rois))) * np.nan

        # Get roi correlations and coherence
        for runNum in range(allROIS.shape[1]):
            #need to load timeseries by run
            fixTS = ts.TimeSeries(allROIS[:, runNum, :], sampling_interval=TR)
            fixTS.metadata['roi'] = roi_names

            # Get plot and correlations
            C = CorrelationAnalyzer(fixTS)
            fig01 = drawmatrix_channels(C.corrcoef,
                                        roi_names,
                                        size=[10., 10.],
                                        color_anchor=0,
                                        title='Correlation Results Run %i' %
                                        runNum)
            plt.show()
            # Save correlation
            corr_all[subject][runNum] = C.corrcoef

            # Get coherence
            Coh = CoherenceAnalyzer(fixTS)

            Coh.method['NFFT'] = NFFT
            Coh.method['n_overlap'] = n_overlap
Beispiel #7
0
def speed_connectivity(timecourses):

    ts = TimeSeries(timecourses, sampling_interval=1.)
    C = CorrelationAnalyzer(ts)

    return z_fisher(C.corrcoef)
Beispiel #8
0
            np.abs(ht_vol[:, :, :, j])**2,
            times,
            baseline=(-1.85, -1.5),
            mode="percent")

        ht_invol_bs = mne.baseline.rescale(
            np.abs(ht_invol[:, :, :, j])**2,
            times,
            baseline=(-1.85, -1.5),
            mode="percent")

        for ts in ht_vol_bs:
            nits = TimeSeries(ts[:, 768:1024],
                              sampling_rate=512)

            corr_vol += [CorrelationAnalyzer(nits)]

        for ts in ht_invol_bs:
            nits = TimeSeries(ts[:, 768:1024],
                              sampling_rate=512)

            corr_invol += [CorrelationAnalyzer(nits)]

        results_vol[band] = np.asarray([c.corrcoef for c in corr_vol])
        results_invol[band] = np.asarray([c.corrcoef for c in corr_invol])

    np.save(graph_data + "%s_vol_pow.npy" % subject,
            results_vol)
    np.save(graph_data + "%s_inv_pow.npy" % subject,
            results_invol)