Пример #1
0
def test_crop_wake():
    sp = SleepPhysionet(subject_ids=[0],
                        recording_ids=[1],
                        preload=True,
                        load_eeg_only=True,
                        crop_wake_mins=30)
    sfreq = sp.datasets[0].raw.info['sfreq']
    duration_h = len(sp) / (3600 * sfreq)
    assert duration_h < 7 and duration_h > 6
Пример #2
0
def get_sleep_physionet(subject_ids=range(83), recording_ids=[1, 2]):
    bug_subjects = [13, 36, 39, 48, 52, 59, 65, 68, 69, 73, 75, 76, 78, 79]
    subject_ids = [id_ for id_ in subject_ids if id_ not in bug_subjects]

    dataset = SleepPhysionet(subject_ids=subject_ids,
                             recording_ids=recording_ids,
                             crop_wake_mins=30)
    high_cut_hz = 30

    preprocessors = [
        # convert from volt to microvolt, directly modifying the numpy array
        NumpyPreproc(fn=lambda x: x * 1e6),
        # bandpass filter
        MNEPreproc(fn='filter', l_freq=None, h_freq=high_cut_hz),
    ]
    # Transform the data
    preprocess(dataset, preprocessors)

    mapping = {  # We merge stages 3 and 4 following AASM standards.
        'Sleep stage W': 0,
        'Sleep stage 1': 1,
        'Sleep stage 2': 2,
        'Sleep stage 3': 3,
        'Sleep stage 4': 3,
        'Sleep stage R': 4
    }

    window_size_s = 30
    sfreq = 100
    window_size_samples = window_size_s * sfreq

    windows_dataset = create_windows_from_events(
        dataset,
        trial_start_offset_samples=0,
        trial_stop_offset_samples=0,
        window_size_samples=window_size_samples,
        window_stride_samples=window_size_samples,
        preload=True,
        mapping=mapping)

    preprocess(windows_dataset, [MNEPreproc(fn=zscore)])

    info = pd.read_excel('SC-subjects.xls')

    return windows_dataset, info
Пример #3
0
# train our network and the second one to evaluate performance (as in the `MNE`_
# sleep staging example).
#
# .. _MNE: https://mne.tools/stable/auto_tutorials/sample-datasets/plot_sleep.html
#
# .. note::
#    To load your own datasets either via MNE or from
#    preprocessed X/y numpy arrays, see the `MNE Dataset
#    Tutorial <./plot_mne_dataset_example.html>`__ and the `Numpy Dataset
#    Tutorial <./plot_custom_dataset_example.html>`__.
#

from braindecode.datasets.sleep_physionet import SleepPhysionet

dataset = SleepPhysionet(subject_ids=[0, 1],
                         recording_ids=[1],
                         crop_wake_mins=30)

######################################################################
# Preprocessing
# ~~~~~~~~~~~~~
#

######################################################################
# Next, we preprocess the raw data. We apply convert the data to microvolts and
# apply a lowpass filter. We omit the downsampling step of [1]_ as the Sleep
# Physionet data is already sampled at a lower 100 Hz.
#

from braindecode.datautil.preprocess import (MNEPreproc, NumpyPreproc,
                                             preprocess)
Пример #4
0
def test_sleep_physionet():
    sp = SleepPhysionet(subject_ids=[0],
                        recording_ids=[1],
                        preload=True,
                        load_eeg_only=True)
    assert isinstance(sp, BaseConcatDataset)
Пример #5
0
def test_all_signals():
    sp = SleepPhysionet(subject_ids=[0],
                        recording_ids=[1],
                        preload=True,
                        load_eeg_only=False)
    assert len(sp.datasets[0].raw.ch_names) == 7