Python mne.read_events() Examples
The following are 4
code examples of mne.read_events().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mne
, or try the search function
.
Example #1
Source File: test_write.py From mne-bids with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_write_does_not_alter_events_inplace(): """Test that writing does not modify the passed events array.""" data_path = testing.data_path() raw_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_trunc_raw.fif') events_fname = op.join(data_path, 'MEG', 'sample', 'sample_audvis_trunc_raw-eve.fif') raw = mne.io.read_raw_fif(raw_fname) events = mne.read_events(events_fname) events_orig = events.copy() bids_root = _TempDir() write_raw_bids(raw=raw, bids_basename=bids_basename, bids_root=bids_root, events_data=events, overwrite=True) assert np.array_equal(events, events_orig)
Example #2
Source File: test_mne_api.py From pactools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_raw_to_mask_pipeline(): # Smoke test for the pipeline MNE.Raw -> raw_to_mask -> Comodulogram path = mne.datasets.sample.data_path() raw_fname = path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif' event_fname = path + ('/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif') raw = mne.io.read_raw_fif(raw_fname, preload=True) events = mne.read_events(event_fname) low_sig, high_sig, mask = raw_to_mask(raw, ixs=(8, 10), events=events, tmin=-1., tmax=5.) estimator = Comodulogram( fs=raw.info['sfreq'], low_fq_range=np.linspace(1, 5, 5), low_fq_width=2., method='tort', progress_bar=False) estimator.fit(low_sig, high_sig, mask) estimator.plot(tight_layout=False) plt.close('all')
Example #3
Source File: meg_statistics.py From mmvt with GNU General Public License v3.0 | 5 votes |
def _calc_epoches(params): subject, events_id, tmin, tmax = params out_file = op.join(LOCAL_ROOT_DIR, 'epo', '{}_ecr_nTSSS_conflict-epo.fif'.format(subject)) if not op.isfile(out_file): events = mne.read_events(op.join(REMOTE_ROOT_DIR, 'events', '{}_ecr_nTSSS_conflict-eve.fif'.format(subject))) raw = mne.io.Raw(op.join(REMOTE_ROOT_DIR, 'raw', '{}_ecr_nTSSS_raw.fif'.format(subject)), preload=False) picks = mne.pick_types(raw.info, meg=True) epochs = find_epoches(raw, picks, events, events_id, tmin=tmin, tmax=tmax) epochs.save(out_file) else: epochs = mne.read_epochs(out_file) return epochs
Example #4
Source File: utils.py From mne-bids with BSD 3-Clause "New" or "Revised" License | 4 votes |
def _read_events(events_data, event_id, raw, ext, verbose=None): """Read in events data. Parameters ---------- events_data : str | array | None The events file. If a string, a path to the events file. If an array, the MNE events array (shape n_events, 3). If None, events will be inferred from the stim channel using `find_events`. event_id : dict The event id dict used to create a 'trial_type' column in events.tsv, mapping a description key to an integer valued event code. raw : instance of Raw The data as MNE-Python Raw object. ext : str The extension of the original data file. verbose : bool | str | int | None If not None, override default verbose level (see :func:`mne.verbose`). Returns ------- events : array, shape = (n_events, 3) The first column contains the event time in samples and the third column contains the event id. The second column is ignored for now but typically contains the value of the trigger channel either immediately before the event or immediately after. """ if isinstance(events_data, str): events = read_events(events_data, verbose=verbose).astype(int) elif isinstance(events_data, np.ndarray): if events_data.ndim != 2: raise ValueError('Events must have two dimensions, ' 'found %s' % events_data.ndim) if events_data.shape[1] != 3: raise ValueError('Events must have second dimension of length 3, ' 'found %s' % events_data.shape[1]) events = events_data elif 'stim' in raw: events = find_events(raw, min_duration=0.001, initial_event=True, verbose=verbose) elif ext in ['.vhdr', '.set'] and check_version('mne', '0.18'): events, event_id = events_from_annotations(raw, event_id, verbose=verbose) else: warn('No events found or provided. Please make sure to' ' set channel type using raw.set_channel_types' ' or provide events_data.') events = None return events, event_id