Skip to content

Commit

Permalink
Fix epoch event tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackz314 committed Aug 8, 2022
1 parent ebf1673 commit ed8e191
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions eeglabio/tests/test_epochs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import random
import string
from os import path as op
from pathlib import Path

import mne
import numpy as np
import pytest
from mne import read_events, pick_types, Epochs, read_epochs_eeglab
Expand Down Expand Up @@ -30,6 +33,13 @@ def test_export_set(tmpdir, preload):
raw, events = _get_data()[:2]
raw.load_data()
epochs = Epochs(raw, events, preload=preload)
# annot_onsets = np.random.randint(0, len(epochs) *
# (epochs.tmax - epochs.tmin), 10)
# annot_dur = np.zeros_like(annot_onsets)
# annot_desc = [''.join(random.choices(string.ascii_letters, k=10))
# for _ in range(len(annot_onsets))]
# annot = mne.Annotations(annot_onsets, annot_dur, annot_desc)
# epochs.set_annotations(annot)
temp_fname = op.join(str(tmpdir), 'test_epochs.set')
export_mne_epochs(epochs, temp_fname)
epochs_read = read_epochs_eeglab(temp_fname)
Expand All @@ -39,8 +49,10 @@ def test_export_set(tmpdir, preload):
cart_coords_read = np.array([d['loc'][:3]
for d in epochs_read.info['chs']])
assert_allclose(cart_coords, cart_coords_read)
assert_array_equal(epochs.events[:, 0],
epochs_read.events[:, 0]) # latency
assert len(epochs) == len(epochs_read)
assert len(epochs_read.events) == len(epochs)
# assert_array_equal(epochs.events[:, 0],
# epochs_read.events[:, 0]) # latency
assert epochs.event_id.keys() == epochs_read.event_id.keys() # just keys
assert_allclose(epochs.times, epochs_read.times)
assert_allclose(epochs.get_data(), epochs_read.get_data())

0 comments on commit ed8e191

Please sign in to comment.