Example #1
0
def createFeatures(subjects=None, resample_dim=[4, 4, 4]):
    clearDB()
    if os.path.isfile('/code/neurovault/apps/statmaps/tests/features'+str(subjects)+str(resample_dim)+'.npy'): #and subjects == None:
        return np.load('/code/neurovault/apps/statmaps/tests/features'+str(subjects)+str(resample_dim)+'.npy').T, \
               pickle.load(open('/code/neurovault/apps/statmaps/tests/dict_feat'+str(subjects)+str(resample_dim)+'.p',"rb" ))
    else:
        feature_dimension = get_feature_dimension(resample_dim)
        features = np.empty([feature_dimension, subjects]) #4*4*4 = 28549 #16*16*16 = 450
        dict_feat = {}
        u1 = User.objects.create(username='******')
        for i, file in enumerate(os.listdir('/code/neurovault/apps/statmaps/tests/bench/images/')):
            # print 'Adding subject ' + file
            print i
            randomCollection = Collection(name='random' + file, owner=u1, DOI='10.3389/fninf.2015.00008' + str(i))
            randomCollection.save()
            image = save_statmap_form(image_path=os.path.join('/code/neurovault/apps/statmaps/tests/bench/images/', file),
                                      collection=randomCollection, image_name=file, ignore_file_warning=True)
            if not image.reduced_representation or not os.path.exists(image.reduced_representation.path):
                image = save_resampled_transformation_single(image.pk, resample_dim)
            features[:, i] = np.load(image.reduced_representation.file)
            dict_feat[i] = int(file.split(".")[0])
            if i == subjects-1:
                features[np.isnan(features)] = 0
                np.save('/code/neurovault/apps/statmaps/tests/features'+str(subjects)+str(resample_dim)+'.npy', features)
                pickle.dump(dict_feat,open('/code/neurovault/apps/statmaps/tests/dict_feat'+str(subjects)+str(resample_dim)+'.p',"wb" ))
                return features.T, dict_feat
    def handle(self, *args, **options):
        down_data()

        clearDB()
        app_path = '/code/neurovault/apps/statmaps/tests/bench'
        u1 = User.objects.create(username='******')

        num_files = len(os.listdir(os.path.join(app_path, 'images/')))
        index_table = np.zeros(num_files)
        query_table = np.zeros(num_files)

        for i, file in enumerate(os.listdir(os.path.join(app_path, 'images/'))):
            #print 'Adding subject ' + file
            randomCollection = Collection(name='random' + file, owner=u1, DOI='10.3389/fninf.2015.00008' + str(i))
            randomCollection.save()

            t = Timer()
            with t:
                image = save_statmap_form(
                    image_path=os.path.join(app_path, 'images/', file),
                    collection=randomCollection,
                    image_name=file,
                    ignore_file_warning=True)
            index_table[i] = t.interval
            np.save(os.path.join(app_path, 'results_index'+ str(datetime.datetime.utcnow())[:10]), index_table)

            factory = RequestFactory()
            request = factory.get('/images/' + str(i) + '/find_similar')
            t = Timer()
            with t:
                _dummy = find_similar(request, image.pk)
            query_table[i] = t.interval
            np.save(os.path.join(app_path, 'results_query' + str(datetime.datetime.utcnow())[:10]), query_table)
Example #3
0
    def handle(self, *args, **options):
        down_data()

        clearDB()
        User.objects.all().delete()
        app_path = '/code/neurovault/apps/statmaps/tests/bench'
        u1 = User.objects.create(username='******')

        num_files = len(os.listdir(os.path.join(app_path, 'images/')))
        index_table = np.zeros(num_files)
        query_table = np.zeros(num_files)

        for i, file in enumerate(os.listdir(os.path.join(app_path, 'images/'))):
            #print 'Adding subject ' + file
            randomCollection = Collection(name='random' + file, owner=u1, DOI='10.3389/fninf.2015.00008' + str(i))
            randomCollection.save()

            t = Timer()
            with t:
                image = save_statmap_form(
                    image_path=os.path.join(app_path, 'images/', file),
                    collection=randomCollection,
                    image_name=file,
                    ignore_file_warning=True)
            index_table[i] = t.interval
            np.savetxt(os.path.join(app_path, 'results_index'+ str(datetime.datetime.utcnow())[:10] + '.csv'),
                       index_table, delimiter=",")

            t = Timer()
            with t:
                _dummy = get_similar_images(int(image.pk))
            query_table[i] = t.interval
            np.savetxt(os.path.join(app_path, 'results_query' + str(datetime.datetime.utcnow())[:10] + '.csv'),
                       query_table, delimiter=",")
Example #4
0
def get_feature_dimension(resample_dim):
    u1 = User.objects.create(username='******'+str(resample_dim))
    for file in os.listdir('/code/neurovault/apps/statmaps/tests/bench/images/'):
        randomCollection = Collection(name='random' + file, owner=u1, DOI='10.3389/fninf.2015.00008' + file)
        randomCollection.save()
        image = save_statmap_form(image_path=os.path.join('/code/neurovault/apps/statmaps/tests/bench/images/', file),
                                  collection=randomCollection, image_name=file, ignore_file_warning=True)
        if not image.reduced_representation or not os.path.exists(image.reduced_representation.path):
            image = save_resampled_transformation_single(image.pk, resample_dim)
        feature = np.load(image.reduced_representation.file)
        dimension = feature.shape[0]
        clearDB()
        break
    return dimension
    def handle(self, *args, **options):
        clearDB()
        app_path = '/code/neurovault/apps/statmaps/tests/bench'
        u1 = User.objects.create(username='******')

        dict_feat = {}

        for i, file in enumerate(os.listdir(os.path.join(app_path, 'images/'))):
            #print 'Adding subject ' + file
            randomCollection = Collection(name='random' + file, owner=u1, DOI='10.3389/fninf.2015.00008' + str(i))
            randomCollection.save()

            t = Timer()
            with t:
                image = save_statmap_form(
                    image_path=os.path.join(app_path, 'images/', file),
                    collection=randomCollection,
                    image_name=file,
                    ignore_file_warning=True)
            dict_feat[i] = image.pk
            print i
            if i == 939:
                pickle.dump(dict_feat, open('/code/neurovault/apps/statmaps/tests/dict_feat_localhost.p', "wb"))
                break
 def tearDown(self):
     clearDB()
Example #7
0
 def tearDown(self):
     clearDB()
 def tearDown(self):
     shutil.rmtree(self.tmpdir)
     clearDB()
Example #9
0
 def tearDown(self):
     shutil.rmtree(self.tmpdir)
     clearDB()
 def tearDownClass(cls):
     clearDB()
     cls.user.delete()
Example #11
0
 def tearDownClass(cls):
     clearDB()
     cls.user.delete()