Beispiel #1
0
    def generate_beat_events(self, verbose=None):

        assert self.filtered is True
        assert self.downsampled is False
        raw = self.raw

        ## generate beat events and epochs before downsampling
        # read trial events

        if hasattr(self, 'trial_events'):
            trial_events = self.trial_events
        else:
            trial_events = mne.find_events(raw, stim_channel='STI 014', shortest_event=0)

        # generate simple beat events with same ID (10000)
        beat_events = generate_beat_events(trial_events,
                                           version=self.stimuli_version,
                                           beat_event_id_generator=simple_beat_event_id_generator,
                                           verbose=verbose)

        # FIXME: read from settings
        picks = mne.pick_types(raw.info, meg=False, eeg=True, eog=True, stim=True, exclude=[])
        event_id = None # any
        tmin = -0.2  # start of each epoch (200ms before the trigger)
        tmax = 0.8  # end of each epoch (600ms after the trigger) - longest beat is 0.57s long
        detrend = 0 # remove dc
        # reject = dict(eog=250e-6) # TODO: optionally reject epochs
        beat_epochs = mne.Epochs(raw, beat_events, event_id,
                                      tmin, tmax, preload=True,
                                      proj=False, picks=picks, verbose=False)
        print beat_epochs

        self.beat_epochs = beat_epochs
    def generate_beat_events(self, verbose=None):

        assert self.filtered is True
        assert self.downsampled is False
        raw = self.raw

        ## generate beat events and epochs before downsampling
        # read trial events

        if hasattr(self, 'trial_events'):
            trial_events = self.trial_events
        else:
            trial_events = mne.find_events(raw, stim_channel='STI 014', shortest_event=0)

        # generate simple beat events with same ID (10000)
        beat_events = generate_beat_events(trial_events,
                                           version=self.stimuli_version,
                                           beat_event_id_generator=simple_beat_event_id_generator,
                                           verbose=verbose)

        # FIXME: read from settings
        picks = mne.pick_types(raw.info, meg=False, eeg=True, eog=True, stim=True, exclude=[])
        event_id = None # any
        tmin = -0.2  # start of each epoch (200ms before the trigger)
        tmax = 0.8  # end of each epoch (600ms after the trigger) - longest beat is 0.57s long
        detrend = 0 # remove dc
        # reject = dict(eog=250e-6) # TODO: optionally reject epochs
        beat_epochs = mne.Epochs(raw, beat_events, event_id,
                                      tmin, tmax, preload=True,
                                      proj=False, picks=picks, verbose=False)
        print beat_epochs

        self.beat_epochs = beat_epochs
Beispiel #3
0
def load_and_preprocess_raw(subject,
                            # default preprocessing params for BCMI 2015 experiments
                            onsets='audio',
                            interpolate_bad_channels=True,
                            reference_mastoids=True,
                            l_freq=0.5,
                            h_freq=30,
                            sfreq=64,
                            ica_cleaning=True,
                            verbose=None,
                            ):

    raw, trial_events = preprocessing.load_and_preprocess_raw(
        subject,
        onsets=onsets,
        interpolate_bad_channels=interpolate_bad_channels,
        reference_mastoids=reference_mastoids,
        l_freq=l_freq, h_freq=h_freq,
        sfreq=sfreq,
        ica_cleaning=ica_cleaning,
        verbose=verbose)

    stimuli_version = get_stimuli_version(subject)

    # generate beat events - we need them to find the downbeat times
    beat_events = generate_beat_events(trial_events,
                                       include_cue_beats=False, # IMPORTANT!!!
    #                                    beat_event_id_generator=simple_beat_event_id_generator, # -> event_id=10000
                                       exclude_stimulus_ids=[],
                                       exclude_condition_ids=[],
                                       verbose=verbose,
                                       version=stimuli_version)

    if verbose:
        log.debug('beat events: {}'.format(beat_events.shape))

    return raw, trial_events, beat_events
Beispiel #4
0
def get_subject_beat_epochs(
        subject,
        raw,
        events=None,
        tmin=-0.2,
        tmax=0.3,
        stimulus_ids='any',  # 1..4, 11..14, 21..24
        conditions='any',  # 1..4
        beat_counts='any',  # 1..4
        cue_value='any',  # 0=cue, 1=regular
        picks=None,
        verbose=False):

    version = get_stimuli_version(subject)
    sfreq = raw.info['sfreq']

    if events is None:
        trial_events = mne.find_events(raw,
                                       stim_channel='STI 014',
                                       shortest_event=0,
                                       verbose=verbose)
    else:
        trial_events = events

    beat_events = generate_beat_events(
        trial_events,
        include_cue_beats=True,
        sr=sfreq,
        version=version,
    )
    #         print beat_events.shape

    # optional filtering
    beat_events = filter_beat_events(beat_events,
                                     stimulus_ids=stimulus_ids,
                                     conditions=conditions,
                                     beat_counts=beat_counts,
                                     cue_value=cue_value)
    #         print beat_events.shape

    if picks is None:
        # default: all EEG channels including bad/interpolated
        picks = mne.pick_types(raw.info,
                               meg=False,
                               eeg=True,
                               eog=False,
                               stim=False,
                               exclude=[])

    # extract epochs from raw data
    epochs = mne.Epochs(raw,
                        beat_events,
                        event_id=None,
                        tmin=tmin,
                        tmax=tmax,
                        preload=True,
                        proj=False,
                        picks=picks,
                        verbose=None)

    return epochs