def test_no_filter_just_algorithm(self): """Just supplying a filter but no algorithm should work. """ algorithm, filter, dataset, settings = EngineTest.simpleScenario(lambda x, y: x*2) Engine.run(algorithm, None, dataset, settings)
def test_extract_algorithm_multi_parameter(self): """Passes multiple extract parameters to the compute step. """ result = Engine.run(*EngineTest.extractMultiScenario(lambda x, y: x*2)) self.assertEqual(len(result), 3) self.assertEqual([e.point for e in result[0]], []) self.assertEqual([e.point for e in result[1]], [0, 7]) self.assertEqual([e.point for e in result[2]], [3])
def test_simple_algorithm_result_not_filtered(self): """If the dataset calls the engine with the correct parameters, then the filter method should produce the desired result. """ #import pdb; pdb.set_trace() result = Engine.run(*EngineTest.simpleScenario(lambda x, y: x*2)) self.assertEqual(len(result), 3) self.assertEqual([e.point for e in result[0]], []) self.assertEqual([e.point for e in result[1]], [7]) self.assertEqual([e.point for e in result[2]], [3])
def test_filter_points_also_removed_from_dataset_labels(self): """Filtering out events also removes the corresponding points from the labels array in the dataset. """ algorithm, filter, dataset, settings = EngineTest.simpleScenario(lambda x, y: x*2) result = Engine.run(algorithm, filter, dataset, settings) for channel, channelValue in dataset.dataSources.items(): for key, dataSource in channelValue.items(): for event in dataSource.events: self.assertTrue(channel != 1 or event.point == 7) self.assertTrue(channel != 2 or event.point == 3)
def test_intervalReturn_algorithm_computeStep_result(self): """Tests whether the correct labels are set to the dataset, given interval return values in the compute step. """ algorithm, filter, dataset, _ = EngineTest.intervalReturnScenario() #import pdb; pdb.set_trace() result = Engine.run(algorithm, filter, dataset) self.assertEqual(len(dataset.labels), 3) self.assertEqual(dataset.labels[0].tolist(), []) self.assertEqual(dataset.labels[1].tolist(), [[0,1], [7,8]]) self.assertEqual(dataset.labels[2].tolist(), [[3,4]])
def test_simple_algorithm_computeStep_result(self): """Tests whether the correct labels are set to the dataset. """ algorithm, filter, dataset, _ = EngineTest.simpleScenario(lambda x, y: x*2) # remove filter method algorithm.filter = lambda events, data: events result = Engine.run(algorithm, filter, dataset) self.assertEqual(len(dataset.labels), 3) self.assertEqual(dataset.labels[0].tolist(), []) self.assertEqual(dataset.labels[1].tolist(), [0, 7]) self.assertEqual(dataset.labels[2].tolist(), [3])
def test_filter_events_also_removed_from_dataSource(self): """Filtering out events also removes the from the dataSource. Checks every dataSource. The only events that should have remained after the filter step are at sample 7 and sample 3. """ algorithm, filter, dataset, settings = EngineTest.simpleScenario(lambda x, y: x*2) result = Engine.run(algorithm, filter, dataset, settings) for channel, channelValue in dataset.dataSources.items(): for key, dataSource in channelValue.items(): for event in dataSource.events: self.assertTrue(channel != 1 or event.point == 7) self.assertTrue(channel != 2 or event.point == 3)
def __computeEvents(self): """Computes the events given algorithm and filter. The dataset is also loaded at this step based on the path that is currently selected. The settings are inherited from the parent. Note that in this case 'parent' does not refer to a super-class but to the application calling this application. """ dataset = self.__loadDataset() try: settings = self.parent.settings return Engine.run(self.algorithm, self.filter, dataset, settings), dataset except AttributeError: return dataset.labels, dataset
def test_just_filter_no_algorithm_with_labels(self): """Just supplying a filter but no algorithm should work and return events for the labels that already are in the dataset. Also the amplitudes should be filtered. """ _, filter, dataset, settings = EngineTest.simpleScenario(lambda x, y: x*2) dataset.labels = np.array([np.array([1, 6]), np.array([]), np.array([4])]) result = Engine.run(None, filter, dataset, settings) self.assertEqual([e.point for e in result[0]], [1,6]) self.assertEqual([e.point for e in result[1]], []) self.assertEqual([e.point for e in result[2]], [4]) settings.plotFiltered = True self.assertEqual([e.amplitude for e in result[0]], [.8,1.2]) self.assertEqual([e.amplitude for e in result[1]], []) self.assertEqual([e.amplitude for e in result[2]], [1.0])
from sleepy.test.data import TestSignal from sleepy.processing.engine import Engine from sleepy.processing.algorithms.massimi import Massimi from sleepy.processing.filters.bandpass.core import BandPassFilter # Prepare the algorithm and filter instances (we keep the standard values) algorithm = Massimi().render() filter = BandPassFilter().render() # Create a dataset providing the necessary interface to use it in the Engine API dataset = TestSignal.generateDataset(scale = 2, numberOfSamples = 300, size=50) # Run the engine API with the given dataset and return a list of events detected = Engine.run(algorithm, filter, dataset) print(detected)