Ejemplo n.º 1
0
def make_subjects_hdf5(**kwargs):
    dataset = SSVEPExo()
    data = dataset.get_data()

    for subject in data:
        session_data = data[subject]['session_0']
        make_subject_hdf5(session_data,
                          output=f'data/{subject}.hdf5',
                          **kwargs)
Ejemplo n.º 2
0
import mne
import numpy as np
from mne.time_frequency import psd_welch
from numpy.lib import stride_tricks
from scipy.signal import filtfilt, lfilter
from moabb.datasets import SSVEPExo

dataset = SSVEPExo()
event_id = dataset.event_id

def compute_mega_raw(raw, filt_method, frequencies,  order):
    from timeflux_dsp.utils.filters import construct_iir_filter
    if filt_method == 'lfilter':
        filt_method = lfilter
    elif filt_method == 'filtfilt':
        filt_method = filtfilt
    else:
        raise ValueError(f'Unknown filt_method {filt_method}')
    # read from info
    ch_names = np.array(raw.info['ch_names'])
    info_kind_dict = {2 : 'eeg', 3: 'stim'}
    ch_types = np.array([info_kind_dict.get(info['kind']) for info in raw.info['chs']])
    sfreq = raw.info['sfreq']

    _stim_data = raw._data[ch_types=='stim', :]
    _eeg_data = raw._data[ch_types=='eeg', :]
    _eeg_ch_names = ch_names[ch_types=='eeg']
    n_ch = len(_eeg_ch_names)

    # loop over frrquencies, filter and concatenate channels
Ejemplo n.º 3
0
###############################################################################
# Loading dataset
# ---------------
#
# We will load the data from the first 2 subjects of the SSVEP_Exo dataset
# and compare two algorithms on this set. One of the algorithm could only
# process class associated with a stimulation frequency, we will thus drop
# the resting class. As the resting class is the last defined class, picking
# the first three classes (out of four) allows to focus only on the stimulation
# frequency.

n_subject = 2
# for i in range(n_subject):
#     SSVEPExo()._get_single_subject_data(i + 1)
dataset = SSVEPExo()
dataset.subject_list = dataset.subject_list[:n_subject]
interval = dataset.interval
paradigm = SSVEP(fmin=10, fmax=25, n_classes=3)
paradigm_fb = FilterBankSSVEP(filters=None, n_classes=3)

# Classes are defined by the frequency of the stimulation, here we use
# the first two frequencies of the dataset, 13 and 17 Hz.
# The evaluation function uses a LabelEncoder, transforming them
# to 0 and 1

freqs = paradigm.used_events(dataset)

##############################################################################
# Create pipelines
# ----------------
Ejemplo n.º 4
0
moabb.set_log_level("info")

###############################################################################
# Loading dataset
# ---------------
#
# We will load the data from the first 2 subjects of the SSVEP_Exo dataset
# and compare two algorithms on this set. One of the algorithm could only
# process class associated with a stimulation frequency, we will thus drop
# the resting class. As the resting class is the last defined class, picking
# the first three classes (out of four) allows to focus only on the stimulation
# frequency.

n_subject = 2
for i in range(n_subject):
    SSVEPExo()._get_single_subject_data(i + 1)
dataset = SSVEPExo()
dataset.subject_list = dataset.subject_list[:n_subject]
interval = dataset.interval

###############################################################################
# Choose paradigm
# ---------------
#
# We define the paradigms (SSVEP and FilterBankSSVEP) and use the dataset
# SSVEPExo. The SSVEP paradigm applied a bandpass filter (10-25 Hz) on
# the data while the FilterBankSSVEP paradigm uses as many bandpass filters as
# there are stimulation frequencies (here 2). For each stimulation frequency
# the EEG is filtered with a 1 Hz-wide bandpass filter centered on the
# frequency. This results in n_classes copies of the signal, filtered for each
# class, as used in filterbank motor imagery paradigms.
Ejemplo n.º 5
0
            n_trials, n_freqs, n_channels, n_times = sig_ext.shape
            X_sig = sig_ext.reshape((n_trials, n_channels * n_freqs, n_times))
        X_sig = np.concatenate([X_sig[i, :, :] for i in range(X_sig.shape[0])],
                               axis=1)
        cov = Covariances(estimator='lwf').transform(
            X_sig.reshape((1, *(X_sig.shape))))
        cov_list.append(cov)
    return np.concatenate(cov_list, axis=0)


metric = 'logdet'  #'riemann' #

##############################################################
# Load SSVEP database
paradigm = BaseSSVEP()
SSVEPExo().download(update_path=False, verbose=False)
datasets = SSVEPExo()

X, y, metadata = paradigm.get_data(dataset=datasets)
# with gzip.open('SSVEPExo.pkz', 'wb') as f:
#     o = {'X':X, 'y':y, 'metadata':metadata}
#     pickle.dump(o, f)
# with gzip.open('SSVEPExo.pkz', 'rb') as f:
#     o = pickle.load(f)
# X, y, metadata = o['X'], o['y'], o['metadata']

n_subjects = len(np.unique(np.array(metadata['subject'])))

##############################################################
# Aggregate all signals for a class from subjects
# and compute covmats. Then, compute dist between cov and
Ejemplo n.º 6
0
def timeWindowInit(inlet):

    sample, timestamp = inlet.pull_sample()
    time_window = np.array(sample)

    sample, timestamp = inlet.pull_sample()
    sample = np.array(sample)
    return np.column_stack((sample, time_window))


###############################################################################
## Option to online retraining
retrain = True

## FIles to offilne base
dataset = SSVEPExo(subjects=11)
interval = dataset.interval

paradigm_fb = FilterBankSSVEP(filters=None, n_classes=4)

filtered_db = paradigm_fb.get_data(dataset, return_epochs=False)

pipeline = make_pipeline(
    ExtendedSSVEPSignal(),
    Covariances(estimator="lwf"),
    TangentSpace(),
    LogisticRegression(solver="lbfgs", multi_class="auto"),
)

model = pipeline.fit()