def __init__(self, subject, settings=dict()): self.subject = subject self.settings = settings if 'debug' in settings: configure_custom(settings['debug']) else: configure_custom(debug=True) if 'mne_log_level' in settings: mne.set_log_level(settings['mne_log_level']) else: mne.set_log_level('INFO') if 'sfreq' in settings: self.downsample_sfreq = settings['sfreq'] else: self.downsample_sfreq = 64 if 'layout' in settings: self.layout = settings['layout'] else: self.layout = mne.channels.read_layout('biosemi.lay') if 'data_root' in settings: self.data_root = settings['data_root'] else: self.data_root = os.path.join(deepthought.DATA_PATH, 'OpenMIIR') # load stimuli metadata version self.stimuli_version = get_stimuli_version(subject) # initial state self.raw = None self.ica = None self.filtered = False self.downsampled = False
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
def process(self, target, metadata): subject = metadata['subject'] stimulus_id = metadata['stimulus_id'] version = get_stimuli_version(subject) bpm = self.meta[version][stimulus_id]['bpm'] return bpm
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
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