Exemplo n.º 1
0
def test_PSD(epochs):
    """
    Test PSD
    """
    fmin = 10
    fmax = 13
    psd_tuple = analyses.pow(epochs.epo1,
                             fmin,
                             fmax,
                             n_fft=256,
                             n_per_seg=None,
                             epochs_average=True)
    psd = psd_tuple.psd
    freq_list = psd_tuple.freq_list
    assert type(psd) == np.ndarray
    assert psd.shape == (len(epochs.epo1.info['ch_names']), len(freq_list))
    psd_tuple = analyses.pow(epochs.epo1,
                             fmin,
                             fmax,
                             n_fft=256,
                             n_per_seg=None,
                             epochs_average=False)
    psd = psd_tuple.psd
    assert psd.shape == (len(epochs.epo1), len(epochs.epo1.info['ch_names']),
                         len(freq_list))
Exemplo n.º 2
0
def test_stats(epochs):
    """
    Test stats
    """
    # with PSD from Epochs with random values
    random_r1 = utils.generate_random_epoch(epochs.epo1, mu=0, sigma=0.01)
    random_r2 = utils.generate_random_epoch(epochs.epo2, mu=4, sigma=0.01)

    fmin = 10
    fmax = 13
    psd_tuple = analyses.pow(random_r1,
                             fmin,
                             fmax,
                             n_fft=256,
                             n_per_seg=None,
                             epochs_average=False)
    psd = psd_tuple.psd

    statsCondTuple = stats.statsCond(psd, random_r1, 3000, 0.05, 0.05)
    assert statsCondTuple.T_obs.shape[0] == len(epochs.epo1.info['ch_names'])

    for i in range(0, len(statsCondTuple.p_values)):
        assert statsCondTuple.p_values[i] <= statsCondTuple.adj_p[1][i]
    assert statsCondTuple.T_obs_plot.shape[0] == len(
        epochs.epo1.info['ch_names'])

    psd_tuple2 = analyses.pow(random_r2,
                              fmin,
                              fmax,
                              n_fft=256,
                              n_per_seg=None,
                              epochs_average=False)
    psd2 = psd_tuple2.psd
    freq_list = psd_tuple2.freq_list

    data = [psd, psd2]
    con_matrixTuple = stats.con_matrix(random_r1, freq_list, draw=False)
    statscondClusterTuple = stats.statscondCluster(
        data,
        freq_list,
        scipy.sparse.bsr_matrix(con_matrixTuple.ch_con_freq),
        tail=0,
        n_permutations=3000,
        alpha=0.05)
    assert statscondClusterTuple.F_obs.shape[0] == len(
        epochs.epo1.info['ch_names'])
    for i in range(0, len(statscondClusterTuple.clusters)):
        assert len(statscondClusterTuple.clusters[i]) < len(
            epochs.epo1.info['ch_names'])
    assert statscondClusterTuple.cluster_p_values.shape[0] == len(
        statscondClusterTuple.clusters)
    assert np.mean(statscondClusterTuple.cluster_p_values) != float(0)
Exemplo n.º 3
0
def test_stats(epochs):
    """
    Test stats
    """
    fmin = 10
    fmax = 13
    psd_tuple = analyses.pow(epochs.epo1,
                             fmin,
                             fmax,
                             n_fft=256,
                             n_per_seg=None,
                             epochs_average=False)
    psd = psd_tuple.psd

    statsCondTuple = stats.statsCond(psd, epochs.epo1, 3000, 0.05, 0.05)
    assert statsCondTuple.T_obs.shape[0] == len(epochs.epo1.info['ch_names'])

    for i in range(0, len(statsCondTuple.p_values)):
        assert statsCondTuple.p_values[i] <= statsCondTuple.adj_p[1][i]
    assert statsCondTuple.T_obs_plot.shape[0] == len(
        epochs.epo1.info['ch_names'])

    psd_tuple2 = analyses.pow(epochs.epo2,
                              fmin,
                              fmax,
                              n_fft=256,
                              n_per_seg=None,
                              epochs_average=False)
    psd2 = psd_tuple2.psd
    freq_list = psd_tuple2.freq_list

    data = [psd, psd2]
    con_matrixTuple = stats.con_matrix(epochs.epo1, freq_list, draw=False)
    statscondClusterTuple = stats.statscondCluster(
        data,
        freq_list,
        scipy.sparse.bsr_matrix(con_matrixTuple.ch_con_freq),
        tail=0,
        n_permutations=3000,
        alpha=0.05)
    assert statscondClusterTuple.F_obs.shape[0] == len(
        epochs.epo1.info['ch_names'])
    for i in range(0, len(statscondClusterTuple.clusters)):
        assert len(statscondClusterTuple.clusters[i]) < len(
            epochs.epo1.info['ch_names'])
    assert statscondClusterTuple.cluster_p_values.shape[0] == len(
        statscondClusterTuple.clusters)
Exemplo n.º 4
0
plt.close("all")

# Picking the preprocessed epochs for each participant
preproc_S1 = cleaned_epochs_AR[0]
preproc_S2 = cleaned_epochs_AR[1]

# Analysing data

# Welch Power Spectral Density
# Here for ex, the frequency-band-of-interest is restricted to Alpha_Low,
# frequencies for which power spectral density is actually computed
# are returned in freq_list,
# and PSD values are averaged across epochs
psd1 = analyses.pow(preproc_S1,
                    fmin=7.5,
                    fmax=11,
                    n_fft=1000,
                    n_per_seg=1000,
                    epochs_average=True)
psd2 = analyses.pow(preproc_S2,
                    fmin=7.5,
                    fmax=11,
                    n_fft=1000,
                    n_per_seg=1000,
                    epochs_average=True)
data_psd = np.array([psd1.psd, psd2.psd])

# Connectivity

# initializing data and storage
data_inter = np.array([preproc_S1, preproc_S2])
result_intra = []