MCPcopy
hub / github.com/mne-tools/mne-python / test_array_epochs

Function test_array_epochs

mne/tests/test_epochs.py:3699–3779  ·  view source on GitHub ↗

Test creating epochs from array.

(tmp_path, browser_backend)

Source from the content-addressed store, hash-verified

3697
3698
3699def test_array_epochs(tmp_path, browser_backend):
3700 """Test creating epochs from array."""
3701 # creating
3702 data = rng.random_sample((10, 20, 300))
3703 sfreq = 1e3
3704 ch_names = [f"EEG {i + 1:03}" for i in range(20)]
3705 types = ["eeg"] * 20
3706 info = create_info(ch_names, sfreq, types)
3707 events = np.c_[np.arange(1, 600, 60), np.zeros(10, int), [1, 2] * 5]
3708 epochs = EpochsArray(data, info, events, tmin)
3709 assert epochs.event_id == {"1": 1, "2": 2}
3710 assert str(epochs).startswith("<EpochsArray")
3711 # From GH#1963
3712 with pytest.raises(ValueError, match="number of events must match"):
3713 EpochsArray(data[:-1], info, events, tmin)
3714 pytest.raises(ValueError, EpochsArray, data, info, events, tmin, dict(a=1))
3715 pytest.raises(ValueError, EpochsArray, data, info, events, tmin, selection=[1])
3716 # should be fine
3717 EpochsArray(data, info, events, tmin, selection=np.arange(len(events)) + 5)
3718
3719 # saving
3720 temp_fname = tmp_path / "test-epo.fif"
3721 epochs.save(temp_fname, overwrite=True)
3722 epochs2 = read_epochs(temp_fname)
3723 data2 = epochs2.get_data()
3724 assert_allclose(data, data2)
3725 assert_allclose(epochs.times, epochs2.times)
3726 assert_equal(epochs.event_id, epochs2.event_id)
3727 assert_array_equal(epochs.events, epochs2.events)
3728
3729 # plotting
3730 epochs[0].plot(events=False)
3731
3732 # indexing
3733 assert_array_equal(np.unique(epochs["1"].events[:, 2]), np.array([1]))
3734 assert_equal(len(epochs[:2]), 2)
3735 data[0, 5, 150] = 3000
3736 data[1, :, :] = 0
3737 data[2, 5, 210] = 3000
3738 data[3, 5, 260] = 0
3739 epochs = EpochsArray(
3740 data,
3741 info,
3742 events=events,
3743 tmin=0,
3744 reject=dict(eeg=1000),
3745 flat=dict(eeg=1e-1),
3746 reject_tmin=0.1,
3747 reject_tmax=0.2,
3748 )
3749 assert_equal(len(epochs), len(events) - 2)
3750 assert_equal(epochs.drop_log[0], ["EEG 006"])
3751 assert_equal(len(epochs.drop_log), 10)
3752 assert_equal(len(epochs.events), len(epochs.selection))
3753
3754 # baseline
3755 data = np.ones((10, 20, 300))
3756 epochs = EpochsArray(data, info, events, tmin=-0.2, baseline=(None, 0))

Callers

nothing calls this directly

Calls 6

create_infoFunction · 0.90
EpochsArrayClass · 0.90
read_epochsFunction · 0.90
saveMethod · 0.45
get_dataMethod · 0.45
plotMethod · 0.45

Tested by

no test coverage detected