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)
def test_directory_stimuli_factory(self): 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.DirectoryStimuliFactory(l) for cat in img_per_cat.keys(): inp[cat] for img in img_per_cat[cat]: inp[cat][img] inp[cat][img]["a"] inp[cat][img].data test_loader.rm_tmp_structure(path) test_loader.rm_tmp_structure(ftrpath)
def test_directory_stimuli_factory(self): 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.DirectoryStimuliFactory(l) for cat in img_per_cat.keys(): inp[cat] for img in img_per_cat[cat]: inp[cat][img] inp[cat][img]['a'] inp[cat][img].data test_loader.rm_tmp_structure(path) test_loader.rm_tmp_structure(ftrpath)
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)