Пример #1
0
    def test_getattr(self):
        # Test the
        # Set up a fake dir structure to generate an aligned fixmat
        img_per_cat = {1: range(1, 11), 2: range(1, 11)}
        features = ['a', 'b']
        path, ftrpath = test_loader.create_tmp_structure(img_per_cat,
                                                         features=features)
        l = loader.LoadFromDisk(impath=path, ftrpath=ftrpath, size=(100, 100))
        inp = stimuli.Categories(l, img_per_cat, features)
        fm = fixmat.TestFixmatFactory(categories=[1, 2],
                                      filenumbers=range(1, 11),
                                      subjectindices=[1, 2, 3, 4, 5, 6],
                                      params={
                                          'pixels_per_degree': 10,
                                          'image_size': [100, 100]
                                      },
                                      categories_obj=inp)

        fm_err = fixmat.TestFixmatFactory(categories=[1, 2],
                                          filenumbers=range(1, 11),
                                          subjectindices=[1, 2, 3, 4, 5, 6],
                                          params={
                                              'pixels_per_degree': 10,
                                              'image_size': [100, 100]
                                          })

        # Now let's check if we can access all the images
        # and all the features.
        fm.add_feature_values(['a', 'b'])
        self.assertRaises(RuntimeError,
                          lambda: fm_err.add_feature_values(['a', 'b']))
        for cat_mat, cat_inp in fm.by_cat():
            self.assertEquals(cat_mat.category[0], cat_inp.category)
            for img_mat, img_inp in cat_mat.by_filenumber():
                self.assertEquals(img_mat.filenumber[0], img_inp.image)
        self.assertEquals(len(fm.a), len(fm.x))
        self.assertEquals(len(fm.b), len(fm.x))
        # Let's also check if make_reg_data works
        a, b = fm.make_reg_data(features)
        self.assertEquals(a.shape[1], len(fm.x))
        self.assertEquals(a.shape[0], len(features))
        self.assertEquals(b.shape[1], len(fm.x))
        self.assertEquals(b.shape[0], len(features))
        self.assertEquals(b.sum(), a.sum())
        a, b = fm.make_reg_data(features, all_controls=True)
        self.assertEquals(a.shape[1], len(fm.x))
        self.assertEquals(a.shape[0], len(features))
        self.assertEquals(b.shape[1], len(fm.x))
        self.assertEquals(b.shape[0], len(features))
        self.assertEquals(b.sum(), a.sum())
        test_loader.rm_tmp_structure(path)
        test_loader.rm_tmp_structure(ftrpath)
Пример #2
0
 def setUp(self):
     self.features = range(1, 11)
     self.inputs = {
         'a': {
             1: self.features,
             2: self.features,
             3: self.features
         },
         'b': {
             10: self.features
         }
     }
     self.test_loader = loader.TestLoader(self.inputs)
     self.inp = stimuli.Categories(self.test_loader, self.inputs)
Пример #3
0
 def test_fixations(self):
     img_per_cat = {7: range(1, 65), 8: range(1, 65)}
     l = loader.TestLoader(img_per_cat, size=(10, 10))
     with NamedTemporaryFile(mode='w', prefix='fix_occ_test',
                             suffix='.mat') as ntf:
         ntf.write(get_data('ocupy.tests', 'fixmat_demo.mat'))
         ntf.seek(0)
         fm = fixmat.FixmatFactory(ntf.name)
     fm = fm[fm.category > 0]
     inp = stimuli.FixmatStimuliFactory(fm, l)
     # Now we can iterate over the input object and get fixations on each image
     for cat in inp:
         for img in cat:
             self.assertEqual(img.fixations.filenumber[0], img.image)
             self.assertEqual(img.fixations.category[0], img.category)
     inp = stimuli.Categories(l, img_per_cat)
     self.assertRaises(RuntimeError, lambda: inp.fixations)
     self.assertRaises(RuntimeError, lambda: inp[7].fixations)
     self.assertRaises(RuntimeError, lambda: inp[7][1].fixations)
Пример #4
0
 def test_general(self):
     #Create an input object: There are two ways, one is the
     features = ['a', 'b', 'c', 'd']
     img_per_cat = {7: range(1, 65), 8: range(1, 65)}
     l = loader.TestLoader(img_per_cat, features, size=(10, 10))
     inp = stimuli.Categories(l, img_per_cat, features)
     # In this case it should have two categories (2,9) with 10 and 50 images
     # Let's check this
     self.assert_(7 in inp.categories())
     self.assert_(8 in inp.categories())
     self.assertEquals(len(inp[7].images()), 64)
     self.assertEquals(len(inp[8].images()), 64)
     # Good, now we can access some data
     img = inp[7][16].data
     self.assertTrue(img.shape[0] == 10 and img.shape[1] == 10)
     # In general we can use [] to access elements in the object
     # But we can also iterate trough these objects
     # This should take a long time because it loads all images
     # from disk
     for cat in inp:
         for img in cat:
             img.image
             img.category
             img.data