Esempio n. 1
0
                else:
                    continue

        params = dict(Fs=4096.0, fpass=[5, 600], tapers=[1, 1], pad=1,
                      Npairs=2000, itc=1)
        nPerDraw = 400
        nDraws = 100

        print 'Running Pairwise Spectrum Estimation'
        (pS, f) = spectral.mtpspec(x, params, verbose='DEBUG')

        print 'Running Raw Spectrum Estimation'
        (Sraw, f) = spectral.mtspecraw(x, params, verbose=True)

        print 'Running Mean Spectrum Estimation'
        (S, N, f) = spectral.mtspec(x, params, verbose=True)

        print 'Running CPCA PLV Estimation'
        (cplv, f) = spectral.mtcpca(x, params, verbose=True)

        # print 'Running CPCA Power Estimation'
        # (cpow, f) = spectral.mtcspec(x, params, verbose=True)

        # Saving Results
        res = dict(pS=pS, cplv=cplv, Sraw=Sraw, f=f, S=S, N=N)
        # res = dict(cpow = cpow, f = f)
        save_name = subj + condstem + '.mat'

        if (not os.path.isdir(respath)):
            os.mkdir(respath)
        if (not os.path.isdir(resonly_backup)):
Esempio n. 2
0
def bdf2mat(froot, fs, Fs_new, hpf, t_stim, topchans, trial_name):
    full_raw, full_eves = EEGconcatenateFolder(froot,
                                               nchans=34,
                                               refchans=['EXG1', 'EXG2'],
                                               exclude=[],
                                               fs_new=Fs_new)

    event_id = {'Positive': 1}

    epochs = mne.Epochs(full_raw,
                        full_eves,
                        event_id,
                        tmin=t_stim[0],
                        tmax=t_stim[1],
                        reject_tmax=1.3,
                        picks=topchans,
                        reject=dict(eeg=100e-6))
    epochs.load_data()
    epochs_filtered = epochs.filter(hpf, None)

    pos_data = epochs_filtered.get_data()

    event_id = {'Negative': 2}

    epochs = mne.Epochs(full_raw,
                        full_eves,
                        event_id,
                        tmin=t_stim[0],
                        tmax=t_stim[1],
                        reject_tmax=1.3,
                        picks=topchans,
                        reject=dict(eeg=100e-6))
    epochs.load_data()
    epochs_filtered = epochs.filter(hpf, None)

    neg_data = epochs_filtered.get_data()

    neg_l = len(neg_data)
    pos_l = len(pos_data)

    length = (neg_l >= pos_l) * pos_l + (neg_l < pos_l) * neg_l

    tot_arr = np.zeros(2 * length, dtype=np.object)

    ind = 0

    for i in range(0, length):

        tot_arr[ind] = pos_data[i]
        tot_arr[ind + 1] = neg_data[i]
        ind = ind + 2

    os.chdir(froot)
    savemat(trial_name + '_Data_full.mat',
            {(trial_name + '_tot_arr'): tot_arr})

    ###########################PLOT SPECTROGRAM/PLV####################################

    x = np.add(neg_data[:length, :, :], pos_data[:length, :, :])

    params = dict(Fs=4e3, tapers=[1, 1], fpass=[0, 1000], itc=0)

    S_psd, N_psd, f_psd = mtspec(x, params)
    mt_plv, f_plv = mtplv(x, params)

    fig, ax = plt.subplots(num=2, figsize=(12, 8))
    ax.plot(f_psd, np.subtract(S_psd, N_psd))
    #ax.plot(f_psd, N_psd)
    ax.grid(color='k', linestyle='-', linewidth=1)
    ax.set_xlabel('Freq (Hz)', fontsize=18)
    ax.set_ylabel('PSD', fontsize=18)
    ax.set_xlim([70., 500.])
    ax.set_title('psd all')

    fig, ax = plt.subplots(num=1, figsize=(12, 8))
    ax.plot(f_plv, mt_plv)
    #ax.plot(f_psd, N_psd)
    ax.grid(color='k', linestyle='-', linewidth=1)
    ax.set_xlabel('Freq (Hz)', fontsize=18)
    ax.set_ylabel('PLV', fontsize=18)
    ax.set_xlim([70., 500.])
    ax.set_title('PLV all')
epochs = mne.Epochs(raw,
                    eves,
                    1,
                    tmin=-0.1,
                    proj=False,
                    tmax=1.2,
                    baseline=(-0.1, 0.0),
                    picks=31,
                    reject=dict(eeg=200e-6))
evoked = epochs.average()
params = dict(Fs=raw.info['sfreq'], tapers=[1, 1], fpass=[70, 1000], itc=0)
x = epochs.get_data()
x = x[:, :32, :]
x = x.transpose((1, 0, 2))
plv, f_plv = mtplv(x[30, :, :], params)
S_psd, N_psd, f_psd = mtspec(x[30, :, :], params)

if plotYes:
    fig, ax = plt.subplots(num=1, figsize=(12, 8))
    ax.plot(f_plv, plv)
    ax.grid(color='k', linestyle='-', linewidth=1)
    ax.set_xlabel('Freq (Hz)', fontsize=18)
    ax.set_ylabel('PLV', fontsize=18)
    ax.set_xlim([70., 500.])
    ax.set_title('plv all')
    if saveYes:
        plt.savefig(dir_dict['figOut'] + 'plv_all.png')

if plotYes:
    fig, ax = plt.subplots(num=2, figsize=(12, 8))
    ax.plot(f_psd, S_psd)