def test_get_similar_images(self): collection1 = Collection(name='Collection1', owner=self.u1, DOI='10.3389/fninf.2015.00099') collection1.save() collection2 = Collection(name='Collection2', owner=self.u1, DOI='10.3389/fninf.2015.00089') collection2.save() app_path = os.path.abspath(os.path.dirname(__file__)) image1 = save_statmap_form(image_path=os.path.join( app_path, 'test_data/statmaps/all.nii.gz'), collection=collection1, image_name="image1") image2 = save_statmap_form(image_path=os.path.join( app_path, 'test_data/statmaps/all.nii.gz'), collection=collection2, image_name="image2") similar_images = get_similar_images(int(image1.pk)) print "Success for this test means the pandas DataFrame shows the copy in first position with score of 1" self.assertEqual(similar_images['image_id'][0], int(image2.pk)) self.assertEqual(similar_images['score'][0], 1)
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=",")
def test_get_similar_images(self): collection1 = Collection(name='Collection1', owner=self.u1, DOI='10.3389/fninf.2015.00099') collection1.save() collection2 = Collection(name='Collection2', owner=self.u1, DOI='10.3389/fninf.2015.00089') collection2.save() app_path = os.path.abspath(os.path.dirname(__file__)) image1 = save_statmap_form(image_path=os.path.join(app_path, 'test_data/statmaps/all.nii.gz'), collection=collection1, image_name="image1") image2 = save_statmap_form(image_path=os.path.join(app_path, 'test_data/statmaps/all.nii.gz'), collection=collection2, image_name="image2") similar_images = get_similar_images(int(image1.pk)) print "Success for this test means the pandas DataFrame shows the copy in first position with score of 1" self.assertEqual(similar_images['image_id'][0], int(image2.pk)) self.assertEqual(similar_images['score'][0], 1)