def test_plot_events(): event_labels = {'aud_l': 1, 'aud_r': 2, 'vis_l': 3, 'vis_r': 4} color = {1: 'green', 2: 'yellow', 3: 'red', 4: 'c'} raw = _get_raw() events = _get_events() plot_events(events, raw.info['sfreq'], raw.first_samp) warnings.simplefilter('always', UserWarning) with warnings.catch_warnings(record=True): plot_events(events, raw.info['sfreq'], raw.first_samp, event_id=event_labels) plot_events(events, raw.info['sfreq'], raw.first_samp, color=color) plot_events(events, raw.info['sfreq'], raw.first_samp, event_id=event_labels, color=color) assert_raises(ValueError, plot_events, events, raw.info['sfreq'], raw.first_samp, event_id={'aud_l': 1}, color=color) assert_raises(ValueError, plot_events, events, raw.info['sfreq'], raw.first_samp, event_id={'aud_l': 111}, color=color)
def test_plot_events(): """Test plotting events """ event_labels = {"aud_l": 1, "aud_r": 2, "vis_l": 3, "vis_r": 4} color = {1: "green", 2: "yellow", 3: "red", 4: "c"} raw = _get_raw() events = _get_events() plot_events(events, raw.info["sfreq"], raw.first_samp) warnings.simplefilter("always", UserWarning) with warnings.catch_warnings(record=True): plot_events(events, raw.info["sfreq"], raw.first_samp, event_id=event_labels) plot_events(events, raw.info["sfreq"], raw.first_samp, color=color) plot_events(events, raw.info["sfreq"], raw.first_samp, event_id=event_labels, color=color) assert_raises( ValueError, plot_events, events, raw.info["sfreq"], raw.first_samp, event_id={"aud_l": 1}, color=color ) assert_raises( ValueError, plot_events, events, raw.info["sfreq"], raw.first_samp, event_id={"aud_l": 111}, color=color )
reject=dict(grad=4000e-13, eog=150e-6), decim=1, isi_max=2.0, proj=None) rt_epochs.start() for ii, ev in enumerate(rt_epochs.iter_evoked()): print("Just got epoch %d" % (ii + 1)) ev.pick_types(meg=True, eog=False) if ii == 0: evoked = ev else: evoked = mne.combine_evoked([evoked, ev], weights='nave') ax[0].cla() ax[1].cla() # clear axis plot_events(rt_epochs.events[-5:], sfreq=ev.info['sfreq'], first_samp=-rt_client.tmin_samp, axes=ax[0]) # plot on second subplot evoked.plot(axes=ax[1], selectable=False, time_unit='s') ax[1].set_title('Evoked response for gradiometer channels' '(event_id = %d)' % event_id) plt.pause(0.05 / speedup) plt.draw() rt_epochs.stop()
def test_plot_events(): """Test plotting events.""" event_labels = {'aud_l': 1, 'aud_r': 2, 'vis_l': 3, 'vis_r': 4} color = {1: 'green', 2: 'yellow', 3: 'red', 4: 'c'} raw = _get_raw() events = _get_events() plot_events(events, raw.info['sfreq'], raw.first_samp) plot_events(events, raw.info['sfreq'], raw.first_samp, equal_spacing=False) # Test plotting events without sfreq plot_events(events, first_samp=raw.first_samp) with pytest.warns(RuntimeWarning, match='will be ignored'): plot_events(events, raw.info['sfreq'], raw.first_samp, event_id=event_labels) with pytest.warns(RuntimeWarning, match='Color is not available'): plot_events(events, raw.info['sfreq'], raw.first_samp, color=color) with pytest.warns(RuntimeWarning, match='event .* missing'): plot_events(events, raw.info['sfreq'], raw.first_samp, event_id=event_labels, color=color) with pytest.warns(RuntimeWarning, match='event .* missing'): pytest.raises(ValueError, plot_events, events, raw.info['sfreq'], raw.first_samp, event_id={'aud_l': 1}, color=color) pytest.raises(ValueError, plot_events, events, raw.info['sfreq'], raw.first_samp, event_id={'aud_l': 111}, color=color) plt.close('all')
def test_plot_events(): """Test plotting events.""" event_labels = {'aud_l': 1, 'aud_r': 2, 'vis_l': 3, 'vis_r': 4} color = {1: 'green', 2: 'yellow', 3: 'red', 4: 'c'} raw = _get_raw() events = _get_events() plot_events(events, raw.info['sfreq'], raw.first_samp) plot_events(events, raw.info['sfreq'], raw.first_samp, equal_spacing=False) # Test plotting events without sfreq plot_events(events, first_samp=raw.first_samp) warnings.simplefilter('always', UserWarning) with warnings.catch_warnings(record=True): plot_events(events, raw.info['sfreq'], raw.first_samp, event_id=event_labels) plot_events(events, raw.info['sfreq'], raw.first_samp, color=color) plot_events(events, raw.info['sfreq'], raw.first_samp, event_id=event_labels, color=color) pytest.raises(ValueError, plot_events, events, raw.info['sfreq'], raw.first_samp, event_id={'aud_l': 1}, color=color) pytest.raises(ValueError, plot_events, events, raw.info['sfreq'], raw.first_samp, event_id={'aud_l': 111}, color=color) plt.close('all')
# create the real-time epochs object and start acquisition rt_epochs = RtEpochs(rt_client, event_id, tmin, tmax, stim_channel='STI 014', picks=picks, reject=dict(grad=4000e-13, eog=150e-6), decim=1, isi_max=2.0, proj=None) rt_epochs.start() for ii, ev in enumerate(rt_epochs.iter_evoked()): print("Just got epoch %d" % (ii + 1)) ev.pick_types(meg=True, eog=False) if ii == 0: evoked = ev else: evoked = mne.combine_evoked([evoked, ev], weights='nave') ax[0].cla() ax[1].cla() # clear axis plot_events(rt_epochs.events[-5:], sfreq=ev.info['sfreq'], first_samp=-rt_client.tmin_samp, axes=ax[0]) # plot on second subplot evoked.plot(axes=ax[1], selectable=False, time_unit='s') ax[1].set_title('Evoked response for gradiometer channels' '(event_id = %d)' % event_id) plt.pause(0.05 / speedup) plt.draw() rt_epochs.stop()
def test_plot_events(): """Test plotting events.""" event_labels = {'aud_l': 1, 'aud_r': 2, 'vis_l': 3, 'vis_r': 4} color = {1: 'green', 2: 'yellow', 3: 'red', 4: 'c'} raw = _get_raw() events = _get_events() fig = plot_events(events, raw.info['sfreq'], raw.first_samp) assert fig.axes[0].get_legend() is not None # legend even with no event_id plot_events(events, raw.info['sfreq'], raw.first_samp, equal_spacing=False) # Test plotting events without sfreq plot_events(events, first_samp=raw.first_samp) with pytest.warns(RuntimeWarning, match='will be ignored'): fig = plot_events(events, raw.info['sfreq'], raw.first_samp, event_id=event_labels) assert fig.axes[0].get_legend() is not None with pytest.warns(RuntimeWarning, match='Color was not assigned'): plot_events(events, raw.info['sfreq'], raw.first_samp, color=color) with pytest.warns(RuntimeWarning, match=r'vent \d+ missing from event_id'): plot_events(events, raw.info['sfreq'], raw.first_samp, event_id=event_labels, color=color) multimatch = r'event \d+ missing from event_id|in the color dict but is' with pytest.warns(RuntimeWarning, match=multimatch): plot_events(events, raw.info['sfreq'], raw.first_samp, event_id={'aud_l': 1}, color=color) with pytest.raises(ValueError, match='from event_id is not present in'): plot_events(events, raw.info['sfreq'], raw.first_samp, event_id={'aud_l': 111}, color=color) with pytest.raises(ValueError, match='No events'): plot_events(np.empty((0, 3))) plt.close('all')
tmax, stim_channel='STI 014', picks=picks, reject=dict(grad=4000e-13, eog=150e-6), decim=1, isi_max=10.0, proj=None) # start the acquisition rt_epochs.start() for ii, ev in enumerate(rt_epochs.iter_evoked()): print("Just got epoch %d" % (ii + 1)) if ii > 0: ev += evoked evoked = ev ax[0].cla(), ax[1].cla() # clear axis plot_events(rt_epochs.events[-5:], ev.info['sfreq'], axes=ax[0]) evoked.plot(axes=ax[1]) # plot on second subplot ax[1].set_title('Evoked response for gradiometer channels' '(event_id = %d)' % event_id) plt.pause(0.05) plt.draw() plt.close()
from mne.io import concatenate_raws, read_raw_edf #raw_files = [read_raw_edf(f, preload=True) for f in raw_fnames] raw = read_raw_edf("./data/S001R06.edf", preload=True) #raw = concatenate_raws(raw_files) raw.plot() print(raw.info) from mne import find_events from mne.viz import plot_events event_id = dict(hands=2, feet=3) events = find_events(raw, shortest_event=0, stim_channel='STI 014') plot_events(events, raw.info['sfreq'], event_id=event_id) from mne import Epochs, pick_types picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False, exclude='bads') tmin, tmax = -1., 4. epochs = Epochs(raw, events, event_id, tmin,
############################################################################### # Note that the result of the loading process is an # :class:`mne.EpochsArray` containing the data ready to interface # with MNE-Python. print(limo_epochs) ############################################################################### # Visualize events # ---------------- # # We can visualise the distribution of the face events contained in the # ``limo_epochs`` structure. Events should appear clearly grouped, as the # epochs are ordered by condition. fig = plot_events(limo_epochs.events, event_id=limo_epochs.event_id) fig.suptitle("Distribution of events in LIMO epochs") ############################################################################### # As it can be seen above, conditions are coded as ``Face/A`` and ``Face/B``. # Information about the phase-coherence of the presented faces is stored in the # epochs metadata. These information can be easily accessed by calling # ``limo_epochs.metadata``. As shown below, the epochs metadata also contains # information about the presented faces for convenience. print(limo_epochs.metadata.head()) ############################################################################### # Now let's take a closer look at the information in the epochs # metadata.
# create the real-time epochs object rt_epochs = RtEpochs(rt_client, event_id, tmin, tmax, stim_channel='STI 014', picks=picks, reject=dict(grad=4000e-13, eog=150e-6), decim=1, isi_max=10.0, proj=None) # start the acquisition rt_epochs.start() for ii, ev in enumerate(rt_epochs.iter_evoked()): print("Just got epoch %d" % (ii + 1)) if ii > 0: ev += evoked evoked = ev ax[0].cla(), ax[1].cla() # clear axis plot_events(rt_epochs.events[-5:], ev.info['sfreq'], axes=ax[0]) evoked.plot(axes=ax[1]) # plot on second subplot ax[1].set_title('Evoked response for gradiometer channels' '(event_id = %d)' % event_id) plt.pause(0.05) plt.draw() plt.close()
def test_plot_events(): raw = _get_raw() events = _get_events() plot_events(events, raw.info['sfreq'], raw.first_samp)
def PreProcess(raw, event_id, plot_psd=False, filter_data=True, filter_range=(1, 30), plot_events=False, epoch_time=(-.2, 1), baseline=(-.2, 0), rej_thresh_uV=200, rereference=False, emcp_raw=False, emcp_epochs=False, epoch_decim=1, plot_electrodes=False, plot_erp=False): sfreq = raw.info['sfreq'] #create new output freq for after epoch or wavelet decim nsfreq = sfreq / epoch_decim tmin = epoch_time[0] tmax = epoch_time[1] if filter_range[1] > nsfreq: filter_range[ 1] = nsfreq / 2.5 #lower than 2 to avoid aliasing from decim?? #pull event names in order of trigger number event_names = ['A_error', 'B_error'] i = 0 for key, value in sorted(event_id.items(), key=lambda x: (x[1], x[0])): event_names[i] = key i += 1 #Filtering if rereference: print('Rerefering to average mastoid') raw = mastoidReref(raw) if filter_data: print('Filtering Data Between ' + str(filter_range[0]) + ' and ' + str(filter_range[1]) + ' Hz.') raw.filter(filter_range[0], filter_range[1], method='iir', verbose='WARNING') if plot_psd: raw.plot_psd(fmin=filter_range[0], fmax=nsfreq / 2) #Eye Correction if emcp_raw: print('Raw Eye Movement Correction') raw = GrattonEmcpRaw(raw) #Epoching events = find_events(raw, shortest_event=1) color = {1: 'red', 2: 'black'} #artifact rejection rej_thresh = rej_thresh_uV * 1e-6 #plot event timing if plot_events: viz.plot_events(events, sfreq, raw.first_samp, color=color, event_id=event_id) #Constructevents epochs = Epochs(raw, events=events, event_id=event_id, tmin=tmin, tmax=tmax, baseline=baseline, preload=True, reject={'eeg': rej_thresh}, verbose=False, decim=epoch_decim) print('Remaining Trials: ' + str(len(epochs))) if emcp_epochs: print('Epochs Eye Movement Correct') epochs = GrattonEmcpEpochs(epochs) evoked_dict = { event_names[0]: epochs[event_names[0]].average(), event_names[1]: epochs[event_names[1]].average() } ## plot ERP at each electrode if plot_electrodes: picks = pick_types(evoked_dict[event_names[0]].info, meg=False, eeg=True, eog=False) fig_zero = evoked_dict[event_names[0]].plot(spatial_colors=True, picks=picks) fig_zero = evoked_dict[event_names[1]].plot(spatial_colors=True, picks=picks) ## plot ERP in each condition on same plot if plot_erp: #find the electrode most miximal on the head (highest in z) picks = np.argmax([ evoked_dict[event_names[0]].info['chs'][i]['loc'][2] for i in range(len(evoked_dict[event_names[0]].info['chs'])) ]) colors = {event_names[0]: "Red", event_names[1]: "Blue"} viz.plot_compare_evokeds(evoked_dict, colors=colors, picks=picks, split_legend=True) return epochs
def test_plot_events(): """Test plotting events.""" event_labels = {'aud_l': 1, 'aud_r': 2, 'vis_l': 3, 'vis_r': 4} color = {1: 'green', 2: 'yellow', 3: 'red', 4: 'c'} raw = _get_raw() events = _get_events() plot_events(events, raw.info['sfreq'], raw.first_samp) plot_events(events, raw.info['sfreq'], raw.first_samp, equal_spacing=False) # Test plotting events without sfreq plot_events(events, first_samp=raw.first_samp) warnings.simplefilter('always', UserWarning) with warnings.catch_warnings(record=True): plot_events(events, raw.info['sfreq'], raw.first_samp, event_id=event_labels) plot_events(events, raw.info['sfreq'], raw.first_samp, color=color) plot_events(events, raw.info['sfreq'], raw.first_samp, event_id=event_labels, color=color) assert_raises(ValueError, plot_events, events, raw.info['sfreq'], raw.first_samp, event_id={'aud_l': 1}, color=color) assert_raises(ValueError, plot_events, events, raw.info['sfreq'], raw.first_samp, event_id={'aud_l': 111}, color=color) plt.close('all')