def test_auto_scale(): """Test auto-scaling of channels for quick plotting.""" raw = read_raw_fif(raw_fname, preload=False, add_eeg_ref=False) ev = read_events(ev_fname) epochs = Epochs(raw, ev, add_eeg_ref=False) rand_data = np.random.randn(10, 100) for inst in [raw, epochs]: scale_grad = 1e10 scalings_def = dict([('eeg', 'auto'), ('grad', scale_grad), ('stim', 'auto')]) # Test for wrong inputs assert_raises(ValueError, inst.plot, scalings='foo') assert_raises(ValueError, _compute_scalings, 'foo', inst) # Make sure compute_scalings doesn't change anything not auto scalings_new = _compute_scalings(scalings_def, inst) assert_true(scale_grad == scalings_new['grad']) assert_true(scalings_new['eeg'] != 'auto') assert_raises(ValueError, _compute_scalings, scalings_def, rand_data) epochs = epochs[0].load_data() epochs.pick_types(eeg=True, meg=False) assert_raises(ValueError, _compute_scalings, dict(grad='auto'), epochs)
def test_auto_scale(): """Test auto-scaling of channels for quick plotting.""" raw = read_raw_fif(raw_fname) epochs = Epochs(raw, read_events(ev_fname)) rand_data = np.random.randn(10, 100) for inst in [raw, epochs]: scale_grad = 1e10 scalings_def = dict([('eeg', 'auto'), ('grad', scale_grad), ('stim', 'auto')]) # Test for wrong inputs pytest.raises(ValueError, inst.plot, scalings='foo') pytest.raises(ValueError, _compute_scalings, 'foo', inst) # Make sure compute_scalings doesn't change anything not auto scalings_new = _compute_scalings(scalings_def, inst) assert (scale_grad == scalings_new['grad']) assert (scalings_new['eeg'] != 'auto') pytest.raises(ValueError, _compute_scalings, scalings_def, rand_data) epochs = epochs[0].load_data() epochs.pick_types(eeg=True, meg=False) pytest.raises(ValueError, _compute_scalings, dict(grad='auto'), epochs)
def test_auto_scale(): """Test auto-scaling of channels for quick plotting.""" raw = read_raw_fif(raw_fname) epochs = Epochs(raw, read_events(ev_fname)) rand_data = np.random.randn(10, 100) for inst in [raw, epochs]: scale_grad = 1e10 scalings_def = dict([('eeg', 'auto'), ('grad', scale_grad), ('stim', 'auto')]) # Test for wrong inputs with pytest.raises(ValueError, match=r".*scalings.*'foo'.*"): inst.plot(scalings='foo') # Make sure compute_scalings doesn't change anything not auto scalings_new = _compute_scalings(scalings_def, inst) assert (scale_grad == scalings_new['grad']) assert (scalings_new['eeg'] != 'auto') with pytest.raises(ValueError, match='Must supply either Raw or Epochs'): _compute_scalings(scalings_def, rand_data) epochs = epochs[0].load_data() epochs.pick_types(eeg=True, meg=False)
def test_auto_scale(): """Test auto-scaling of channels for quick plotting.""" raw = read_raw_fif(raw_fname, preload=False) ev = read_events(ev_fname) epochs = Epochs(raw, ev) rand_data = np.random.randn(10, 100) for inst in [raw, epochs]: scale_grad = 1e10 scalings_def = dict([("eeg", "auto"), ("grad", scale_grad), ("stim", "auto")]) # Test for wrong inputs assert_raises(ValueError, inst.plot, scalings="foo") assert_raises(ValueError, _compute_scalings, "foo", inst) # Make sure compute_scalings doesn't change anything not auto scalings_new = _compute_scalings(scalings_def, inst) assert_true(scale_grad == scalings_new["grad"]) assert_true(scalings_new["eeg"] != "auto") assert_raises(ValueError, _compute_scalings, scalings_def, rand_data) epochs = epochs[0].load_data() epochs.pick_types(eeg=True, meg=False) assert_raises(ValueError, _compute_scalings, dict(grad="auto"), epochs)
def plot_epochs(epochs, picks=None, scalings=None, n_epochs=20, n_channels=20, title=None, show=True, block=False, bad_epochs_idx=None, fix_log=None): """ Visualize epochs Bad epochs can be marked with a left click on top of the epoch. Bad channels can be selected by clicking the channel name on the left side of the main axes. Calling this function drops all the selected bad epochs as well as bad epochs marked beforehand with rejection parameters. Parameters ---------- epochs : instance of Epochs The epochs object picks : array-like of int | None Channels to be included. If None only good data channels are used. Defaults to None scalings : dict | 'auto' | None Scaling factors for the traces. If any fields in scalings are 'auto', the scaling factor is set to match the 99.5th percentile of a subset of the corresponding data. If scalings == 'auto', all scalings fields are set to 'auto'. If any fields are 'auto' and data is not preloaded, a subset of epochs up to 100mb will be loaded. If None, defaults to:: dict(mag=1e-12, grad=4e-11, eeg=20e-6, eog=150e-6, ecg=5e-4, emg=1e-3, ref_meg=1e-12, misc=1e-3, stim=1, resp=1, chpi=1e-4) n_epochs : int The number of epochs per view. Defaults to 20. n_channels : int The number of channels per view. Defaults to 20. title : str | None The title of the window. If None, epochs name will be displayed. Defaults to None. show : bool Show figure if True. Defaults to True block : bool Whether to halt program execution until the figure is closed. Useful for rejecting bad trials on the fly by clicking on an epoch. Defaults to False. bad_epochs_idx : array-like | None Indices of bad epochs to show. No bad epochs to visualize if None. fix_log : array, shape (n_channels, n_epochs) | None The bad segments to show in red and the interpolated segments to show in green. Returns ------- fig : Instance of matplotlib.figure.Figure The figure. Notes ----- The arrow keys (up/down/left/right) can be used to navigate between channels and epochs and the scaling can be adjusted with - and + (or =) keys, but this depends on the backend matplotlib is configured to use (e.g., mpl.use(``TkAgg``) should work). Full screen mode can be toggled with f11 key. The amount of epochs and channels per view can be adjusted with home/end and page down/page up keys. Butterfly plot can be toggled with ``b`` key. Right mouse click adds a vertical line to the plot. """ epochs.drop_bad() scalings = _compute_scalings(scalings, epochs) scalings = _handle_default('scalings_plot_raw', scalings) projs = epochs.info['projs'] bads = np.array(list(), dtype=int) if bad_epochs_idx is not None: bads = np.array(bad_epochs_idx).astype(int) params = {'epochs': epochs, 'info': copy.deepcopy(epochs.info), 'bad_color': (0.8, 0.8, 0.8), 't_start': 0, 'histogram': None, 'bads': bads, 'fix_log': fix_log} params['label_click_fun'] = partial(_pick_bad_channels, params=params) _prepare_mne_browse_epochs(params, projs, n_channels, n_epochs, scalings, title, picks) _prepare_projectors(params) _layout_figure(params) callback_close = partial(_close_event, params=params) params['fig'].canvas.mpl_connect('close_event', callback_close) try: plt_show(show, block=block) except TypeError: # not all versions have this plt_show(show) return params['fig']