def _fit(self, X, y):
        """fit and return epochs."""
        epochs, cov_signal = get_epochs_and_cov(X, y, self.window)

        xd = Xdawn(n_components=self.nfilters, signal_cov=cov_signal,
                   correct_overlap=False)
        xd.fit(epochs)

        P = []
        for eid in getEventNames():
            P.append(np.dot(xd.filters_[eid][:, 0:self.nfilters].T,
                            xd.evokeds_[eid].data))
        self.P = np.concatenate(P, axis=0)
        self.labels_train = epochs.events[:, -1]
        return epochs
Example #2
0
def spatial_filter(raw, epochs):
    print('spatial filtering using xDawn')
    picks = pick_types(raw.info,
                       meg=False,
                       eeg=True,
                       stim=False,
                       eog=False,
                       exclude='bads')
    signal_cov = compute_raw_covariance(raw, picks=picks)
    xd = Xdawn(n_components=2, signal_cov=signal_cov)
    print('fiting xDawn')
    xd.fit(epochs)
    print('epoch denoising started')
    epochs_denoised = xd.apply(epochs)
    print('epoch_denoise complete')
    return epochs_denoised
Example #3
0
    def _fit(self, X, y):
        """fit and return epochs."""
        epochs, cov_signal = get_epochs_and_cov(X, y, self.window)

        xd = Xdawn(n_components=self.nfilters,
                   signal_cov=cov_signal,
                   correct_overlap=False)
        xd.fit(epochs)

        P = []
        for eid in getEventNames():
            P.append(
                np.dot(xd.filters_[eid][:, 0:self.nfilters].T,
                       xd.evokeds_[eid].data))
        self.P = np.concatenate(P, axis=0)
        self.labels_train = epochs.events[:, -1]
        return epochs
Example #4
0
    def _fit(self, X, y):
        """fit and return epochs."""
        epochs, cov_signal = get_epochs_and_cov(X, y, self.window)
        # pdb.set_trace()
        # TODO: Try to understand what is Xdawn (something that improve SSRN by spatial information?)

        xd = Xdawn(n_components=self.nfilters, signal_cov=cov_signal,
                   correct_overlap=False)
        xd.fit(epochs)

        P = []
        for eid in getEventNames():
            # set_breakpoint('xd info in getEVetnNames for-lop');
            # pdb.set_trace()
            P.append(np.dot(xd.filters_[eid][:, 0:self.nfilters].T,
                            xd.evokeds_[eid].data))
        self.P = np.concatenate(P, axis=0)
        self.labels_train = epochs.events[:, -1]
        # pdb.set_trace()
        return epochs
Example #5
0
                   exclude='bads')
# Epoching
epochs = Epochs(raw,
                events,
                event_id,
                tmin,
                tmax,
                proj=False,
                picks=picks,
                baseline=None,
                preload=True,
                verbose=False)

# Plot image epoch before xdawn
plot_epochs_image(epochs['vis_r'], picks=[230], vmin=-500, vmax=500)

# Estimates signal covariance
signal_cov = compute_raw_covariance(raw, picks=picks)

# Xdawn instance
xd = Xdawn(n_components=2, signal_cov=signal_cov)

# Fit xdawn
xd.fit(epochs)

# Denoise epochs
epochs_denoised = xd.apply(epochs)

# Plot image epoch after Xdawn
plot_epochs_image(epochs_denoised['vis_r'], picks=[230], vmin=-500, vmax=500)
        picks_train = pick_types(raw_train.info, eeg=True)
        picks_val = pick_types(raw_val.info, eeg=True)
        #picks_test = pick_types(raw_test.info, eeg=True)

        data_train = raw_train._data[picks_train].T
        labels_train = raw_train._data[32:].T

        data_val = raw_val._data[picks_val].T
        labels_val = raw_val._data[32:].T

        #data_test = raw_test._data[picks_test].T
        #labels_test = None
        train_epochs, train_cov_signal = get_epochs_and_cov(raw_train, picks_train, WINDOW)
        xd = Xdawn(n_components=NFILTERS, signal_cov=train_cov_signal, correct_overlap=False)
        xd.fit(train_epochs)

        val_epochs, val_cov_signal = get_epochs_and_cov(raw_val, picks_val, WINDOW)
        xd = Xdawn(n_components=NFILTERS, signal_cov=val_cov_signal, correct_overlap=False)
        xd.fit(val_epochs)

        P = []
        for eid in getEventNames():
            P.append(np.dot(xd.filters_[eid][:, 0:NFILTERS].T, xd.evokeds_[eid].data))

        print ("Saving data for subject{0} in files".format(subject))
        np.save('data/processed/subj{0}_train_data.npy'.format(subject), train_epochs._data)
        np.save('data/processed/subj{0}_train_labels.npy'.format(subject), train_epochs.events)

        np.save('data/processed/subj{0}_val_data.npy'.format(subject), val_epochs._data)
        np.save('data/processed/subj{0}_val_labels.npy'.format(subject), val_epochs.events)
# Setup for reading the raw data
raw = io.read_raw_fif(raw_fname, preload=True)
raw.filter(1, 20)  # replace baselining with high-pass
events = read_events(event_fname)

raw.info['bads'] = ['MEG 2443']  # set bad channels
picks = pick_types(raw.info, meg=True, eeg=False, stim=False, eog=False,
                   exclude='bads')
# Epoching
epochs = Epochs(raw, events, event_id, tmin, tmax, proj=False,
                picks=picks, baseline=None, preload=True,
                verbose=False)

# Plot image epoch before xdawn
plot_epochs_image(epochs['vis_r'], picks=[230], vmin=-500, vmax=500)

# Estimates signal covariance
signal_cov = compute_raw_covariance(raw, picks=picks)

# Xdawn instance
xd = Xdawn(n_components=2, signal_cov=signal_cov)

# Fit xdawn
xd.fit(epochs)

# Denoise epochs
epochs_denoised = xd.apply(epochs)

# Plot image epoch after Xdawn
plot_epochs_image(epochs_denoised['vis_r'], picks=[230], vmin=-500, vmax=500)