Beispiel #1
0
def plotScalpmapsOddball(epo, epo_t, clab, mrk_class, intervals, mnt):

    lim_min, lim_max = 100, -100
    for mrk_cl in np.unique(mrk_class):
        epo_cls = np.mean(epo[:, :, mrk_class == mrk_cl], axis=2)
        for ival in intervals:
            idx_range = np.where((epo_t >= ival[0]) & (epo_t <= ival[1]))
            epo_cls_ival = np.mean(epo_cls[idx_range, :], axis=0)
            lim_min = np.min(
                epo_cls_ival) if np.min(epo_cls_ival) < lim_min else lim_min
            lim_max = np.max(
                epo_cls_ival) if np.max(epo_cls_ival) > lim_max else lim_max

    for mrk_cl in np.unique(mrk_class):
        label = 'Target' if mrk_cl == 0 else 'Non-Target'
        epo_cls = np.mean(epo[:, :, mrk_class == mrk_cl], axis=2)
        print(epo_cls.shape)
        for ival in intervals:
            plt.figure(figsize=(6, 6))
            idx_range = np.where((epo_t >= ival[0]) & (epo_t <= ival[1]))
            print(epo_cls[idx_range, :].shape)
            epo_cls_ival = np.mean(epo_cls[idx_range, :].squeeze(), axis=0)
            print(epo_cls_ival.shape)
            plt.title(''.join(
                [label, ', Interval ',
                 str(ival[0]), ' - ',
                 str(ival[1])]))
            bci.scalpmap(mnt,
                         epo_cls_ival,
                         clim=[lim_min, lim_max],
                         cb_label='µV',
                         clab=clab)
Beispiel #2
0
def performPCA(X,mnt=None):
    Xmean = np.mean(X,axis=1)
    
    Xm = X-Xmean[:,np.newaxis]
    d,v=np.linalg.eig(np.cov(X))
    print(d)
    for i in range(v.shape[0]):
        plt.figure()
        bci.scalpmap(mnt,v[:,i])
    return d,v
Beispiel #3
0
def plotPrincipalComponents(cnt, mnt, clab, n=3):
    X = cnt
    Xmean = np.mean(X, axis=1)
    X = X - Xmean[:, np.newaxis]
    d, v = np.linalg.eig(np.cov(X))

    for i in range(n):
        plt.figure(figsize=(6, 6))
        plt.title(''.join(
            ['Component #',
             str(i + 1), ', std:',
             str(np.sqrt(d[i]))]))
        bci.scalpmap(mnt, v[:, i], clim='sym', cb_label='[a.u.]', clab=clab)

    return d, v
Beispiel #4
0
def plotScalpmapsArtifact(epo, epo_t, clab, mrk_class, intervals, mnt):

    fig, axs = plt.subplots(len(np.unique(mrk_class)),
                            len(intervals) + 1,
                            figsize=(24, 8))

    for i, mrk_cl in zip(range(len(np.unique(mrk_class))),
                         np.unique(mrk_class)):
        epo_cls = np.mean(epo[:, :, mrk_class == mrk_cl], axis=2)
        lim_min, lim_max = 0, 0
        print(artifactDict[mrk_cl])
        for j, ival in zip(range(len(intervals)), intervals):
            idx_range = np.where((epo_t >= ival[0]) & (epo_t <= ival[1]))

            epo_cls_ival = np.mean(epo_cls[idx_range, :].squeeze(), axis=0)
            lim_min = np.min(
                epo_cls_ival) if np.min(epo_cls_ival) < lim_min else lim_min
            lim_max = np.max(
                epo_cls_ival) if np.max(epo_cls_ival) > lim_max else lim_max

            #axs[i,j].title(''.join(['Interval',str(ival[0]),' - ',str(ival[1])]))
            pcm = bci.scalpmap(mnt,
                               epo_cls_ival,
                               clim=[lim_min, lim_max],
                               cb_label='µV',
                               ax=axs[i, j])
        axs[i, len(intervals)].axis('off')
        fig.colorbar(pcm, shrink=.6, ax=axs[i, len(intervals)])

    fig.tight_layout(pad=0.0)

    plt.show()
Beispiel #5
0
    # Get the indexes of the 6 maximum eigenvalues
    eigidx = np.argsort(ddif)[-numCSP:]

    # Spatial filtering of signals
    CSPs = apply_spatial_filter(epo, W[:, eigidx])

    AllCSP = apply_spatial_filter(epo, W)
    A = np.dot(np.dot(np.cov(epo.reshape(epo.shape[1], -1)), W),
               np.linalg.inv(np.cov(AllCSP.reshape(epo_o.shape[1], -1))))

    plt.figure(figsize=(8, 8))
    n = 221
    for i in range(eigidx.shape[0]):
        plt.subplot(n + i)
        plt.title('CSP filter ' + str(4 - i))
        bci.scalpmap(mnt, A[:, eigidx[i]], clim='sym', cb_label='[a.u.]')

    epoCSP = np.abs(signal.hilbert(CSPs, axis=0))

    aveCSPsT = np.mean(epoCSP[:, :, mrk_class == 0], axis=2)
    aveCSPsArtifact = np.mean(epoCSP[:, :, mrk_class == 1], axis=2)

    plt.figure(figsize=(10, 8))
    n = 221
    for i in range(eigidx.shape[0]):
        plt.subplot(n + i)
        plt.title('Averaged ERD, EigNum =  ' + str(eigidx[i]))
        plt.plot(epo_t_o, aveCSPsT[:, i], label='target')
        plt.plot(epo_t_o,
                 aveCSPsArtifact[:, i],
                 label=str(artifactDict[artifact]))