def test_handle_events_reading(tmpdir): """Test reading events from a BIDS events.tsv file.""" # We can use any `raw` for this raw = _read_raw_fif(raw_fname) # Create an arbitrary events.tsv file, to test we can deal with 'n/a' # make sure we can deal w/ "#" characters events = { 'onset': [11, 12, 'n/a'], 'duration': ['n/a', 'n/a', 'n/a'], 'trial_type': ["rec start", "trial #1", "trial #2!"] } events_fname = tmpdir.mkdir('bids1') / 'sub-01_task-test_events.json' _to_tsv(events, events_fname) raw = _handle_events_reading(events_fname, raw) events, event_id = mne.events_from_annotations(raw) # Test with a `stim_type` column instead of `trial_type`. events = { 'onset': [11, 12, 'n/a'], 'duration': ['n/a', 'n/a', 'n/a'], 'stim_type': ["rec start", "trial #1", "trial #2!"] } events_fname = tmpdir.mkdir('bids2') / 'sub-01_task-test_events.json' _to_tsv(events, events_fname) with pytest.warns(RuntimeWarning, match='This column should be renamed'): raw = _handle_events_reading(events_fname, raw) events, event_id = mne.events_from_annotations(raw) # Test with same `trial_type` referring to different `value` events = { 'onset': [11, 12, 13], 'duration': ['n/a', 'n/a', 'n/a'], 'trial_type': ["event1", "event1", "event2"], 'value': [1, 2, 3] } events_fname = tmpdir.mkdir('bids3') / 'sub-01_task-test_events.json' _to_tsv(events, events_fname) raw = _handle_events_reading(events_fname, raw) events, event_id = mne.events_from_annotations(raw) assert len(events) == 3 assert 'event1/1' in event_id assert 'event1/2' in event_id # The event with unique value mapping should not be renamed assert 'event2' in event_id # Test without any kind of event description. events = {'onset': [11, 12, 'n/a'], 'duration': ['n/a', 'n/a', 'n/a']} events_fname = tmpdir.mkdir('bids4') / 'sub-01_task-test_events.json' _to_tsv(events, events_fname) raw = _handle_events_reading(events_fname, raw) events, event_id = mne.events_from_annotations(raw) ids = list(event_id.keys()) assert len(ids) == 1 assert ids == ['n/a']
def test_handle_events_reading(): """Test reading events from a BIDS events.tsv file.""" # We can use any `raw` for this raw = mne.io.read_raw_fif(raw_fname) # Create an arbitrary events.tsv file, to test we can deal with 'n/a' events = {'onset': [11, 12, 13], 'duration': ['n/a', 'n/a', 'n/a']} tmp_dir = _TempDir() events_fname = op.join(tmp_dir, 'sub-01_task-test_events.json') _to_tsv(events, events_fname) raw = _handle_events_reading(events_fname, raw) events, event_id = mne.events_from_annotations(raw)
def test_handle_events_reading(): """Test reading events from a BIDS events.tsv file.""" # We can use any `raw` for this raw = mne.io.read_raw_fif(raw_fname) # Create an arbitrary events.tsv file, to test we can deal with 'n/a' # make sure we can deal w/ "#" characters events = { 'onset': [11, 12, 'n/a'], 'duration': ['n/a', 'n/a', 'n/a'], 'trial_type': ["rec start", "trial #1", "trial #2!"] } tmp_dir = _TempDir() events_fname = op.join(tmp_dir, 'sub-01_task-test_events.json') _to_tsv(events, events_fname) raw = _handle_events_reading(events_fname, raw) events, event_id = mne.events_from_annotations(raw)
path = op.join(bids_root, f"sub-{subject}", 'meg') events_fname = op.join(path, f"sub-{subject}_task-{task}_events.tsv") fname_raw = op.join(path, f"sub-{subject}_task-{task}_meg.fif") fname_mp_raw = op.join(path, f"sub-{subject}_task-{task}_split-01_meg.fif") fname_proj = op.join(path, f"sub-{subject}_task-{task}_proj.fif") if not op.exists(fname_proj) or redo: # pca input is from fixation cross to three hashes # no language involved # TODO: replace path with basename try: raw = mne.io.read_raw_fif(fname_raw) except FileNotFoundError: raw = mne.io.read_raw_fif(fname_mp_raw) # TODO: replace with proper solution raw = _handle_events_reading(events_fname, raw) events, event_id = mne.events_from_annotations(raw) event_id = {key: value for key, value in event_id.items() if key in evts_labels} epochs = mne.Epochs(raw, events, event_id, tmin=-.2, tmax=1, baseline=baseline, reject=reject, verbose=False) # compute the SSP evoked = epochs.average() ev_proj = evoked.copy().crop(-.1, .03) projs = mne.compute_proj_evoked(ev_proj, n_mag=3) # apply projector individually evokeds = [evoked.copy().add_proj(proj).apply_proj() for proj in projs] # 1. plot before and after summary