def test_to_epoch(self): seg = Segment(name="test") event = Event(times=np.array([5.0, 12.0, 23.0, 45.0]), units="ms", labels=np.array(["A", "B", "C", "D"])) event.segment = seg # Mode 1 epoch = event.to_epoch() self.assertIsInstance(epoch, Epoch) assert_array_equal(epoch.times.magnitude, np.array([5.0, 12.0, 23.0])) assert_array_equal(epoch.durations.magnitude, np.array([7.0, 11.0, 22.0])) assert_array_equal(epoch.labels, np.array(['A-B', 'B-C', 'C-D'])) # Mode 2 epoch = event.to_epoch(pairwise=True) assert_array_equal(epoch.times.magnitude, np.array([5.0, 23.0])) assert_array_equal(epoch.durations.magnitude, np.array([7.0, 22.0])) assert_array_equal(epoch.labels, np.array(['A-B', 'C-D'])) # Mode 3 (scalar) epoch = event.to_epoch(durations=2.0 * pq.ms) assert_array_equal(epoch.times.magnitude, np.array([5.0, 12.0, 23.0, 45.0])) assert_array_equal(epoch.durations.magnitude, np.array([2.0, 2.0, 2.0, 2.0])) self.assertEqual(epoch.durations.size, 4) assert_array_equal(epoch.labels, np.array(['A', 'B', 'C', 'D'])) # Mode 3 (array) epoch = event.to_epoch(durations=np.array([2.0, 3.0, 4.0, 5.0]) * pq.ms) assert_array_equal(epoch.times.magnitude, np.array([5.0, 12.0, 23.0, 45.0])) assert_array_equal(epoch.durations.magnitude, np.array([2.0, 3.0, 4.0, 5.0])) assert_array_equal(epoch.labels, np.array(['A', 'B', 'C', 'D'])) # Error conditions self.assertRaises(ValueError, event.to_epoch, pairwise=True, durations=2.0 * pq.ms) odd_event = Event(times=np.array([5.0, 12.0, 23.0]), units="ms", labels=np.array(["A", "B", "C"])) self.assertRaises(ValueError, odd_event.to_epoch, pairwise=True)
def test_to_epoch(self): seg = Segment(name="test") event = Event(times=np.array([5.0, 12.0, 23.0, 45.0]), units="ms", labels=np.array(["A", "B", "C", "D"])) event.segment = seg # Mode 1 epoch = event.to_epoch() self.assertIsInstance(epoch, Epoch) assert_array_equal(epoch.times.magnitude, np.array([5.0, 12.0, 23.0])) assert_array_equal(epoch.durations.magnitude, np.array([7.0, 11.0, 22.0])) assert_array_equal(epoch.labels, np.array(['A-B', 'B-C', 'C-D'])) # Mode 2 epoch = event.to_epoch(pairwise=True) assert_array_equal(epoch.times.magnitude, np.array([5.0, 23.0])) assert_array_equal(epoch.durations.magnitude, np.array([7.0, 22.0])) assert_array_equal(epoch.labels, np.array(['A-B', 'C-D'])) # Mode 3 (scalar) epoch = event.to_epoch(durations=2.0 * pq.ms) assert_array_equal(epoch.times.magnitude, np.array([5.0, 12.0, 23.0, 45.0])) assert_array_equal(epoch.durations.magnitude, np.array([2.0, 2.0, 2.0, 2.0])) self.assertEqual(epoch.durations.size, 4) assert_array_equal(epoch.labels, np.array(['A', 'B', 'C', 'D'])) # Mode 3 (array) epoch = event.to_epoch(durations=np.array([2.0, 3.0, 4.0, 5.0]) * pq.ms) assert_array_equal(epoch.times.magnitude, np.array([5.0, 12.0, 23.0, 45.0])) assert_array_equal(epoch.durations.magnitude, np.array([2.0, 3.0, 4.0, 5.0])) assert_array_equal(epoch.labels, np.array(['A', 'B', 'C', 'D'])) # Error conditions self.assertRaises(ValueError, event.to_epoch, pairwise=True, durations=2.0 * pq.ms) odd_event = Event(times=np.array([5.0, 12.0, 23.0]), units="ms", labels=np.array(["A", "B", "C"])) self.assertRaises(ValueError, odd_event.to_epoch, pairwise=True)
def test_event_to_epoch(self): seg = Segment(name="test") # event = Event(times=np.array([5.0, 12.0, 23.0, 45.0]), units="ms", labels=np.array(["A", "B", "C", "D"])) event = Event(times=np.array([5.0, 12.0, 23.0, 45.0]), units="ms", labels=np.array(["A", "B", "C", "D"])) print("event : " + str(event)) event.segment = seg epoch = event.to_epoch() print("epoch.magnitude : " + str(epoch.durations.magnitude)) print("np.array([7.0, 11.0, 22.0]) : " + str(np.array([7.0, 11.0, 22.0]))) assert_array_equal(epoch.durations.magnitude, np.array([7.0, 11.0, 22.0])) self.assertEqual(str(type(epoch).__name__), 'Epoch') pass