Exemplo n.º 1
0
    def test_compatible_dataset(self):
        ds = FakeDataset(['left_hand', 'right_hand'], n_sessions=1)
        self.assertRaises(AssertionError, self.eval.verify, dataset=ds)

        # do not raise
        ds = FakeDataset(['left_hand', 'right_hand'], n_sessions=2)
        self.assertIsNone(self.eval.verify(dataset=ds))
Exemplo n.º 2
0
    def test_compatible_dataset(self):
        ds = FakeDataset(['left_hand', 'right_hand'], n_sessions=1)
        self.assertFalse(self.eval.is_valid(ds))

        # do not raise
        ds = FakeDataset(['left_hand', 'right_hand'], n_sessions=2)
        self.assertTrue(self.eval.is_valid(dataset=ds))
Exemplo n.º 3
0
    def test_compatible_dataset(self):
        # raise
        ds = FakeDataset(["left_hand", "right_hand"], n_subjects=1)
        self.assertFalse(self.eval.is_valid(dataset=ds))

        # do not raise
        ds = FakeDataset(["left_hand", "right_hand"], n_subjects=2)
        self.assertTrue(self.eval.is_valid(dataset=ds))
Exemplo n.º 4
0
    def test_BaseImagery_channel_order(self):
        """test if paradigm return correct channel order, see issue #227"""
        datasetA = FakeDataset(paradigm="imagery", channels=["C3", "Cz", "C4"])
        datasetB = FakeDataset(paradigm="imagery", channels=["Cz", "C4", "C3"])
        paradigm = SimpleMotorImagery(channels=["C4", "C3", "Cz"])

        ep1, _, _ = paradigm.get_data(datasetA, subjects=[1], return_epochs=True)
        ep2, _, _ = paradigm.get_data(datasetB, subjects=[1], return_epochs=True)
        self.assertEqual(ep1.info["ch_names"], ep2.info["ch_names"])
Exemplo n.º 5
0
    def test_leftright_paradigm(self):
        # we cant pass event to this class
        paradigm = LeftRightImagery()
        self.assertRaises(ValueError, LeftRightImagery, events=['a'])

        # does not accept dataset with bad event
        dataset = FakeDataset()
        self.assertRaises(AssertionError, paradigm.get_data, dataset)

        # with a good dataset
        dataset = FakeDataset(event_list=['left_hand', 'right_hand'])
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])
        self.assertEquals(len(np.unique(labels)), 2)
        self.assertEquals(list(np.unique(labels)), ['left_hand', 'right_hand'])
Exemplo n.º 6
0
    def test_BaseImagery_paradigm(self):
        class SimpleMotorImagery(BaseMotorImagery):
            def used_events(self, dataset):
                return dataset.event_id

        self.assertRaises(ValueError, SimpleMotorImagery, tmin=1, tmax=0)

        paradigm = SimpleMotorImagery()
        dataset = FakeDataset()
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # we should have all the same lenght
        self.assertEquals(len(X), len(labels), len(metadata))
        # X must be a 3D Array
        self.assertEquals(len(X.shape), 3)
        # labels must contain 3 values
        self.assertEquals(len(np.unique(labels)), 3)

        # metadata must have subjets, sessions, runs
        self.assertTrue('subject' in metadata.columns)
        self.assertTrue('session' in metadata.columns)
        self.assertTrue('run' in metadata.columns)

        # we should have only one subject in the metadata
        self.assertEquals(np.unique(metadata.subject), 1)

        # we should have two sessions in the metadata
        self.assertEquals(len(np.unique(metadata.session)), 2)

        # can work with filter bank
        paradigm = SimpleMotorImagery(filters=[[7, 12], [12, 24]])
        dataset = FakeDataset()
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 3D Array
        self.assertEquals(len(X.shape), 4)
        self.assertEquals(X.shape[-1], 2)

        # test process_raw return empty list if raw does not contain any
        # selected event. cetain runs in dataset are event specific.
        dataset = FakeDataset()
        raw = dataset.get_data([1])[1]['session_0']['run_0']
        # add something on the event channel
        raw._data[-1] *= 10
        self.assertIsNone(paradigm.process_raw(raw, dataset))
        # zeros it out
        raw._data[-1] *= 0
        self.assertIsNone(paradigm.process_raw(raw, dataset))
Exemplo n.º 7
0
 def test_LeftRightImagery_paradigm(self):
     # with a good dataset
     paradigm = LeftRightImagery()
     dataset = FakeDataset(event_list=['left_hand', 'right_hand'])
     X, labels, metadata = paradigm.get_data(dataset, subjects=[1])
     self.assertEqual(len(np.unique(labels)), 2)
     self.assertEqual(list(np.unique(labels)), ['left_hand', 'right_hand'])
Exemplo n.º 8
0
    def test_BaseP300_paradigm(self):
        paradigm = SimpleP300()
        dataset = FakeDataset(paradigm="p300",
                              event_list=["Target", "NonTarget"])
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # we should have all the same length
        self.assertEqual(len(X), len(labels), len(metadata))
        # X must be a 3D Array
        self.assertEqual(len(X.shape), 3)
        # labels must contain 2 values (Target/NonTarget)
        self.assertEqual(len(np.unique(labels)), 2)
        # metadata must have subjets, sessions, runs
        self.assertTrue("subject" in metadata.columns)
        self.assertTrue("session" in metadata.columns)
        self.assertTrue("run" in metadata.columns)
        # we should have only one subject in the metadata
        self.assertEqual(np.unique(metadata.subject), 1)
        # we should have two sessions in the metadata
        self.assertEqual(len(np.unique(metadata.session)), 2)
        # should return epochs
        epochs, _, _ = paradigm.get_data(dataset,
                                         subjects=[1],
                                         return_epochs=True)
        self.assertIsInstance(epochs, BaseEpochs)
Exemplo n.º 9
0
    def test_SSVEP_paradigm(self):
        paradigm = SSVEP(n_classes=None)
        dataset = FakeDataset(event_list=["13", "15", "17", "19"],
                              paradigm="ssvep")
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # Verify that they have the same length
        self.assertEqual(len(X), len(labels), len(metadata))
        # X must be a 3D array
        self.assertEqual(len(X.shape), 3)
        # labels must contain 4 values, defined in the dataset
        self.assertEqual(len(np.unique(labels)), 4)
        # metadata must have subjets, sessions, runs
        self.assertTrue("subject" in metadata.columns)
        self.assertTrue("session" in metadata.columns)
        self.assertTrue("run" in metadata.columns)
        # Only one subject in the metadata
        self.assertEqual(np.unique(metadata.subject), 1)
        # We should have two sessions in the metadata
        self.assertEqual(len(np.unique(metadata.session)), 2)
        # should return epochs
        epochs, _, _ = paradigm.get_data(dataset,
                                         subjects=[1],
                                         return_epochs=True)
        self.assertIsInstance(epochs, BaseEpochs)
Exemplo n.º 10
0
    def test_fake_dataset(self):
        """this test will insure the basedataset works"""
        n_subjects = 3
        n_sessions = 2
        n_runs = 2

        for paradigm in ['imagery', 'p300']:

            ds = FakeDataset(n_sessions=n_sessions,
                             n_runs=n_runs,
                             n_subjects=n_subjects,
                             paradigm=paradigm)
            data = ds.get_data()

            # we should get a dict
            self.assertTrue(isinstance(data, dict))

            # we get the right number of subject
            self.assertEqual(len(data), n_subjects)

            # right number of session
            self.assertEqual(len(data[1]), n_sessions)

            # right number of run
            self.assertEqual(len(data[1]['session_0']), n_runs)

            # We should get a raw array at the end
            self.assertEqual(type(data[1]['session_0']['run_0']),
                             mne.io.RawArray)

            # bad subject id must raise error
            self.assertRaises(ValueError, ds.get_data, [1000])
Exemplo n.º 11
0
    def test_BaseSSVEP_specified_nclasses(self):
        # Set the number of classes
        paradigm = BaseSSVEP(n_classes=3)
        dataset = FakeDataset(event_list=["13", "15", "17", "19"], paradigm="ssvep")
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # labels must contain 3 values
        self.assertEqual(len(np.unique(labels)), 3)
Exemplo n.º 12
0
    def test_BaseP300_channel_order(self):
        """test if paradigm return correct channel order, see issue #227"""
        datasetA = FakeDataset(
            paradigm="p300",
            channels=["C3", "Cz", "C4"],
            event_list=["Target", "NonTarget"],
        )
        datasetB = FakeDataset(
            paradigm="p300",
            channels=["Cz", "C4", "C3"],
            event_list=["Target", "NonTarget"],
        )
        paradigm = SimpleP300(channels=["C4", "C3", "Cz"])

        ep1, _, _ = paradigm.get_data(datasetA, subjects=[1], return_epochs=True)
        ep2, _, _ = paradigm.get_data(datasetB, subjects=[1], return_epochs=True)
        self.assertEqual(ep1.info["ch_names"], ep2.info["ch_names"])
Exemplo n.º 13
0
    def test_BaseSSVEP_nclasses_default(self):
        # Default is with 2 classes
        paradigm = BaseSSVEP()
        dataset = FakeDataset(event_list=['13', '15', '17', '19'],
                              paradigm='ssvep')
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # labels must contain 2 values, as n_classes is 2 by default
        self.assertEqual(len(np.unique(labels)), 2)
Exemplo n.º 14
0
    def test_BaseImagery_filters(self):
        # can work with filter bank
        paradigm = SimpleMotorImagery(filters=[[7, 12], [12, 24]])
        dataset = FakeDataset(paradigm='imagery')
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 4D Array
        self.assertEqual(len(X.shape), 4)
        self.assertEqual(X.shape[-1], 2)
Exemplo n.º 15
0
    def test_FilterBankMotorImagery_paradigm(self):
        # can work with filter bank
        paradigm = FilterBankMotorImagery()
        dataset = FakeDataset(paradigm='imagery')
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 4D Array
        self.assertEqual(len(X.shape), 4)
        self.assertEqual(X.shape[-1], 6)
Exemplo n.º 16
0
    def test_filter_bank_mi(self):
        # can work with filter bank
        paradigm = FilterBankMotorImagery()
        dataset = FakeDataset()
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 3D Array
        self.assertEquals(len(X.shape), 4)
        self.assertEquals(X.shape[-1], 6)

        # can work with filter bank
        paradigm = FilterBankLeftRightImagery()
        dataset = FakeDataset(event_list=['left_hand', 'right_hand'])
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 3D Array
        self.assertEquals(len(X.shape), 4)
        self.assertEquals(X.shape[-1], 6)
Exemplo n.º 17
0
 def test_P300_paradigm(self):
     # with a good dataset
     paradigm = P300()
     dataset = FakeDataset(event_list=['Target', 'NonTarget'],
                           paradigm='p300')
     X, labels, metadata = paradigm.get_data(dataset, subjects=[1])
     self.assertEqual(len(np.unique(labels)), 2)
     self.assertEqual(list(np.unique(labels)),
                      sorted(['Target', 'NonTarget']))
Exemplo n.º 18
0
    def test_FilterBankLeftRightImagery_paradigm(self):
        # can work with filter bank
        paradigm = FilterBankLeftRightImagery()
        dataset = FakeDataset(event_list=["left_hand", "right_hand"])
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 4D Array
        self.assertEqual(len(X.shape), 4)
        self.assertEqual(X.shape[-1], 6)
Exemplo n.º 19
0
    def test_BaseSSVEP_nclasses_default(self):
        # Default is with 3 classes
        paradigm = BaseSSVEP()
        dataset = FakeDataset(paradigm="ssvep")
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # labels must contain all 3 classes of dataset,
        # as n_classes is "None" by default (taking all classes)
        self.assertEqual(len(np.unique(labels)), 3)
Exemplo n.º 20
0
    def test_FilterBankSSVEP_filters(self):
        # can work with filter bank
        paradigm = FilterBankSSVEP(filters=[(10.5, 11.5), (12.5, 13.5)])
        dataset = FakeDataset(event_list=['13', '15', '17'], paradigm='ssvep')
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 4D array with d=2 as last dimension for the 2 filters
        self.assertEqual(len(X.shape), 4)
        self.assertEqual(X.shape[-1], 2)
Exemplo n.º 21
0
    def test_BaseP300_filters(self):
        # can work with filter bank
        paradigm = SimpleP300(filters=[[1, 12], [12, 24]])
        dataset = FakeDataset(paradigm='p300',
                              event_list=['Target', 'NonTarget'])
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 4D Array
        self.assertEqual(len(X.shape), 4)
        self.assertEqual(X.shape[-1], 2)
Exemplo n.º 22
0
    def test_BaseSSVEP_filters(self):
        # Accept filters
        paradigm = BaseSSVEP(filters=[(10.5, 11.5), (12.5, 13.5)])
        dataset = FakeDataset(paradigm='ssvep')
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 4D array
        self.assertEqual(len(X.shape), 4)
        # Last dim should be 2 as the number of filters
        self.assertEqual(X.shape[-1], 2)
Exemplo n.º 23
0
 def test_P300_paradigm(self):
     # with a good dataset
     paradigm = P300()
     dataset = FakeDataset(event_list=["Target", "NonTarget"], paradigm="p300")
     X, labels, metadata = paradigm.get_data(dataset, subjects=[1])
     self.assertEqual(len(np.unique(labels)), 2)
     self.assertEqual(list(np.unique(labels)), sorted(["Target", "NonTarget"]))
     # should return epochs
     epochs, _, _ = paradigm.get_data(dataset, subjects=[1], return_epochs=True)
     self.assertIsInstance(epochs, BaseEpochs)
Exemplo n.º 24
0
    def test_FilterBankSSVEP_paradigm(self):
        # FilterBankSSVEP with all events
        paradigm = FilterBankSSVEP(n_classes=None)
        dataset = FakeDataset(event_list=['13', '15', '17', '19'],
                              paradigm='ssvep')
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 4D array
        self.assertEqual(len(X.shape), 4)
        # X must be a 4D array with d=4 as last dimension for the 4 events
        self.assertEqual(X.shape[-1], 4)
Exemplo n.º 25
0
    def test_LeftRightImagery_paradigm(self):
        # with a good dataset
        paradigm = LeftRightImagery()
        dataset = FakeDataset(event_list=["left_hand", "right_hand"], paradigm="imagery")
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        self.assertEqual(len(np.unique(labels)), 2)
        self.assertEqual(list(np.unique(labels)), ["left_hand", "right_hand"])
        # should return epochs
        epochs, _, _ = paradigm.get_data(dataset, subjects=[1], return_epochs=True)
        self.assertIsInstance(epochs, BaseEpochs)
Exemplo n.º 26
0
 def test_baseImagery_wrongevent(self):
     # test process_raw return empty list if raw does not contain any
     # selected event. cetain runs in dataset are event specific.
     paradigm = SimpleMotorImagery(filters=[[7, 12], [12, 24]])
     dataset = FakeDataset(paradigm="imagery")
     raw = dataset.get_data([1])[1]["session_0"]["run_0"]
     # add something on the event channel
     raw._data[-1] *= 10
     self.assertIsNone(paradigm.process_raw(raw, dataset))
     # zeros it out
     raw._data[-1] *= 0
     self.assertIsNone(paradigm.process_raw(raw, dataset))
Exemplo n.º 27
0
    def test_BaseImagery_filters(self):
        # can work with filter bank
        paradigm = SimpleMotorImagery(filters=[[7, 12], [12, 24]])
        dataset = FakeDataset(paradigm="imagery")
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 4D Array
        self.assertEqual(len(X.shape), 4)
        self.assertEqual(X.shape[-1], 2)
        # should return epochs
        epochs, _, _ = paradigm.get_data(dataset, subjects=[1], return_epochs=True)
        self.assertIsInstance(epochs, BaseEpochs)
Exemplo n.º 28
0
    def test_BaseP300_filters(self):
        # can work with filter bank
        paradigm = SimpleP300(filters=[[1, 12], [12, 24]])
        dataset = FakeDataset(paradigm="p300", event_list=["Target", "NonTarget"])
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 4D Array
        self.assertEqual(len(X.shape), 4)
        self.assertEqual(X.shape[-1], 2)
        # should return epochs
        epochs, _, _ = paradigm.get_data(dataset, subjects=[1], return_epochs=True)
        self.assertIsInstance(epochs, BaseEpochs)
Exemplo n.º 29
0
 def test_BaseP300_wrongevent(self):
     # test process_raw return empty list if raw does not contain any
     # selected event. cetain runs in dataset are event specific.
     paradigm = SimpleP300(filters=[[1, 12], [12, 24]])
     dataset = FakeDataset(paradigm="p300", event_list=["Target", "NonTarget"])
     raw = dataset.get_data([1])[1]["session_0"]["run_0"]
     # add something on the event channel
     raw._data[-1] *= 10
     self.assertIsNone(paradigm.process_raw(raw, dataset))
     # zeros it out
     raw._data[-1] *= 0
     self.assertIsNone(paradigm.process_raw(raw, dataset))
Exemplo n.º 30
0
    def test_FilterBankSSVEP_filters(self):
        # can work with filter bank
        paradigm = FilterBankSSVEP(filters=[(10.5, 11.5), (12.5, 13.5)])
        dataset = FakeDataset(event_list=["13", "15", "17"], paradigm="ssvep")
        X, labels, metadata = paradigm.get_data(dataset, subjects=[1])

        # X must be a 4D array with d=2 as last dimension for the 2 filters
        self.assertEqual(len(X.shape), 4)
        self.assertEqual(X.shape[-1], 2)
        # should return epochs
        epochs, _, _ = paradigm.get_data(dataset, subjects=[1], return_epochs=True)
        self.assertIsInstance(epochs, BaseEpochs)