コード例 #1
0
    def check_trial_event_consistency(self):
        meta = load_stimuli_metadata(self.data_root, self.stimuli_version)
        sfreq = self.raw.info['sfreq']
        n_errors = 0
        for i, event in enumerate(self.trial_events[:-1]):
            event_id = event[2]
            start = event[0]
            if event_id < 1000:
                stim_id, cond = decode_event_id(event_id)
                if cond in [1, 2]:
                    field = 'length_with_cue'
                else:
                    field = 'length_without_cue'
                sample_len = sfreq * meta[stim_id][field]
            else:
                sample_len = 1

            next_start = self.trial_events[i + 1, 0]

            if next_start < start + sample_len:
                expected_len = sample_len / float(sfreq)
                event_len = (next_start - start) / float(sfreq)
                log.warn('warning: event {} starts before expected end of {}'.
                         format(self.trial_events[i + 1], event))
                log.warn(
                    'expected length: {:.3f}s, real length: {:.3f}s, delta: {:.3f}s'
                    .format(expected_len, event_len, expected_len - event_len))
                n_errors += 1
        log.info('{} problems detected.'.format(n_errors))
コード例 #2
0
ファイル: pipeline.py プロジェクト: Qi0116/deepthought
    def check_trial_event_consistency(self):
        meta = load_stimuli_metadata(self.data_root, self.stimuli_version)
        sfreq = self.raw.info['sfreq']
        n_errors = 0
        for i, event in enumerate(self.trial_events[:-1]):
            event_id = event[2]
            start = event[0]
            if event_id < 1000:
                stim_id, cond = decode_event_id(event_id)
                if cond in [1,2]:
                    field = 'length_with_cue'
                else:
                    field = 'length_without_cue'
                sample_len = sfreq * meta[stim_id][field]
            else:
                sample_len = 1

            next_start = self.trial_events[i+1, 0]

            if next_start < start + sample_len:
                expected_len = sample_len / float(sfreq)
                event_len = (next_start - start) / float(sfreq)
                log.warn('warning: event {} starts before expected end of {}'.format(self.trial_events[i+1], event))
                log.warn('expected length: {:.3f}s, real length: {:.3f}s, delta: {:.3f}s'.format(
                            expected_len, event_len, expected_len-event_len))
                n_errors += 1
        log.info('{} problems detected.'.format(n_errors))
コード例 #3
0
 def __init__(self, data_root=None):
     self.meta = dict()
     for version in [1, 2]:
         self.meta[version] = load_stimuli_metadata(data_root=data_root,
                                                    version=version)
コード例 #4
0
def get_trial_epochs(raw,
                     trial_events,
                     stim_id,
                     condition,
                     subject=None,
                     stimuli_version=None,
                     meta=None,
                     include_cue=False,
                     picks=None,
                     debug=False):

    assert subject is None or stimuli_version is None or meta is None

    if meta is None:
        if stimuli_version is None:
            if subject is None:
                raise RuntimeError(
                    'Either meta, stimuli_version or subject has to be specified.'
                )
            else:
                stimuli_version = get_stimuli_version(subject)
        meta = load_stimuli_metadata(version=stimuli_version)

    events = filter_trial_events(trial_events, [stim_id], [condition])
    if debug:
        log.debug('selected events: {}'.format(len(events)))
        log.debug(events)

    start = 0
    if condition in [1, 2]:  # cued
        if include_cue:
            stop = meta[stim_id]['length_with_cue']
        else:
            # NOTE: start > 0 does not work; need to shift event time
            offset = int(
                np.floor(meta[stim_id]['length_of_cue'] * raw.info['sfreq']))
            events[:, 0] += offset
            stop = meta[stim_id]['length_without_cue']
    else:
        stop = meta[stim_id]['length_without_cue']

    if debug:
        log.debug('start: {}  stop: {}'.format(start, stop))
        log.debug(events)

    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=[])

    epochs = mne.Epochs(raw,
                        events,
                        None,
                        tmin=start,
                        tmax=stop,
                        preload=True,
                        proj=False,
                        picks=picks,
                        verbose=False)

    if debug:
        log.debug(epochs)

    return epochs
コード例 #5
0
 def __init__(self, data_root=None):
     self.meta = dict()
     for version in [1,2]:
         self.meta[version] = load_stimuli_metadata(data_root=data_root, version=version)