def test_add_DOI(self): collection1 = Collection(name='Collection1', owner=self.u1, private=False) collection1.save() collection2 = Collection(name='Collection2', owner=self.u1, private=False) 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/motor_lips.nii.gz'), collection=collection2, image_name="image2") comparison = Comparison.objects.filter(image1=image1, image2=image2) self.assertEqual(len(comparison), 0) print "without DOI: %s" % Comparison.objects.all().count() collection = Collection.objects.get(pk=collection1.pk) collection.DOI = '10.3389/fninf.2015.00020' collection.save() print "with DOI: %s" % Comparison.objects.all().count() print collection.basecollectionitem_set.instance_of(Image).all() comparison = Comparison.objects.filter(image1=image1, image2=image2) self.assertEqual(len(comparison), 1)
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 setUp(self): self.test_path = os.path.abspath(os.path.dirname(__file__)) self.user = User.objects.create_user('NeuroGuy') self.user.save() self.client = Client() self.client.login(username=self.user) self.coll1 = Collection(owner=self.user, name="Test Collection 1") self.coll1.save() self.coll2 = Collection(owner=self.user, name="Test Collection 2") self.coll2.save()
def test_fetch_my_collections(self): self.client.force_authenticate(user=self.user) # Create a private collection private_collection = Collection( owner=self.user, name='Private Collection', private=True, private_token=generate_url_token() ) private_collection.save() response = self.client.get('/api/my_collections/', follow=True) self.assertEqual(len(response.data['results']), 2) collection_map = dict((x['id'], x) for x in response.data['results']) self.assertEqual(collection_map[self.coll.id]['id'], self.coll.id) self.assertEqual(collection_map[self.coll.id]['private'], False) self.assertEqual( collection_map[private_collection.id]['private'], True ) # Create and share a new collection with our user sharer_user = User.objects.create_user('Sharer') sharer_user.save() shared_collection = Collection( owner=sharer_user, name='Shared Test Collection' ) shared_collection.save() shared_collection.contributors.add(self.user) # Re-fetch the data response = self.client.get('/api/my_collections/', follow=True) user_collections_ids = sorted([ self.coll.id, shared_collection.id, private_collection.id ]) result_collection_ids = sorted( x['id'] for x in response.data['results'] ) self.assertEqual( len(response.data['results']), len(user_collections_ids) ) self.assertListEqual(user_collections_ids, result_collection_ids)
def setUp(self): print "\n\n### TESTING COUNTER ###" self.test_path = os.path.abspath(os.path.dirname(__file__)) self.user = User.objects.create(username='******') self.client = Client() self.client.login(username=self.user) self.Collection1 = Collection(name='Collection1', owner=self.user, DOI='10.3389/fninf.2015.00008') self.Collection1.save() self.Collection2 = Collection(name='Collection2', owner=self.user, DOI='10.3389/fninf.2015.00009') self.Collection2.save() self.Collection3 = Collection(name='Collection3', owner=self.user, DOI='10.3389/fninf.2015.00011') self.Collection3.save()
def setUp(self): self.factory = RequestFactory() self.test_path = os.path.abspath(os.path.dirname(__file__)) self.user = User.objects.create(username='******') self.client = Client() self.client.login(username=self.user) self.Collection1 = Collection(name='Collection1', owner=self.user) self.Collection1.save() self.unorderedAtlas = Atlas(name='unorderedAtlas', description='', collection=self.Collection1) self.unorderedAtlas.file = SimpleUploadedFile( 'VentralFrontal_thr75_summaryimage_2mm.nii.gz', file( os.path.join( self.test_path, 'test_data/api/VentralFrontal_thr75_summaryimage_2mm.nii.gz' )).read()) self.unorderedAtlas.label_description_file = SimpleUploadedFile( 'test_VentralFrontal_thr75_summaryimage_2mm.xml', file( os.path.join( self.test_path, 'test_data/api/unordered_VentralFrontal_thr75_summaryimage_2mm.xml' )).read()) self.unorderedAtlas.save() self.Collection2 = Collection(name='Collection2', owner=self.user) self.Collection2.save() self.orderedAtlas = Atlas( name='orderedAtlas', collection=self.Collection2, label_description_file='VentralFrontal_thr75_summaryimage_2mm.xml') self.orderedAtlas.file = SimpleUploadedFile( 'VentralFrontal_thr75_summaryimage_2mm.nii.gz', file( os.path.join( self.test_path, 'test_data/api/VentralFrontal_thr75_summaryimage_2mm.nii.gz' )).read()) self.orderedAtlas.label_description_file = SimpleUploadedFile( 'test_VentralFrontal_thr75_summaryimage_2mm.xml', file( os.path.join( self.test_path, 'test_data/api/VentralFrontal_thr75_summaryimage_2mm.xml') ).read()) self.orderedAtlas.save()
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_missing_required_permissions(self): self.client.force_authenticate(user=self.user) other_user = User.objects.create_user('OtherGuy') other_user.save() other_collection = Collection(owner=other_user, name="Another Test Collection") other_collection.save() url = '/api/collections/%s/images/' % other_collection.pk fname = self.abs_data_path('statmaps/motor_lips.nii.gz') post_dict = { 'name': 'test map', 'modality': 'fMRI-BOLD', 'map_type': 'T', 'file': SimpleUploadedFile(fname, open(fname).read()) } response = self.client.post(url, post_dict, format='multipart') self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.data, { 'detail': 'You do not have permission to perform this action.' })
def test_fetch_my_collections(self): self.client.force_authenticate(user=self.user) response = self.client.get('/api/my_collections/', follow=True) self.assertEqual(len(response.data['results']), 1) self.assertEqual(response.data['results'][0]['id'], self.coll.id) # Create and share a new collection with our user sharer_user = User.objects.create_user('Sharer') sharer_user.save() shared_collection = Collection(owner=sharer_user, name="Shared Test Collection") shared_collection.save() shared_collection.contributors.add(self.user) # Re-fetch the data response = self.client.get('/api/my_collections/', follow=True) self.assertEqual(len(response.data['results']), 2) user_collections_ids = sorted([self.coll.id, shared_collection.id]) result_collection_ids = sorted(x['id'] for x in response.data['results']) self.assertListEqual(user_collections_ids, result_collection_ids)
def setUp(self): base_username = '******' password = '******' test_path = os.path.abspath(os.path.dirname(__file__)) self.user = User.objects.create_user( "%s_%s" % (base_username, self.uniqid()), None, password ) self.user.save() self.client = Client() self.client.login(username=self.user.username, password=password) self.coll = Collection(owner=self.user, name="Test %s" % self.uniqid()) self.coll.save() def test_data_path(filename): return os.path.join(test_path, 'test_data/statmaps/%s' % filename) self.image1 = save_statmap_form( image_path=test_data_path('motor_lips.nii.gz'), collection=self.coll ) self.image2 = save_statmap_form( image_path=test_data_path('beta_0001.nii.gz'), collection=self.coll )
def add_image_for_neurosynth(request): temp_collection_name = "%s's temporary collection" % request.user.username #this is a hack we need to make sure this collection can be only #owned by the same user try: temp_collection = Collection.objects.get(name=temp_collection_name) except Collection.DoesNotExist: priv_token = generate_url_token() temp_collection = Collection(name=temp_collection_name, owner=request.user, private=False, private_token=priv_token) temp_collection.save() image = StatisticMap(collection=temp_collection) if request.method == "POST": form = SimplifiedStatisticMapForm(request.POST, request.FILES, instance=image, user=request.user) if form.is_valid(): image = form.save() return HttpResponseRedirect( "http://neurosynth.org/decode/?neurovault=%s-%s" % (temp_collection.private_token, image.id)) else: form = SimplifiedStatisticMapForm(user=request.user, instance=image) context = {"form": form} return render(request, "statmaps/add_image_for_neurosynth.html.haml", context)
def setUp(self): self.user = User.objects.create_user('NeuroGuy', password="******") self.user.save() self.client = Client() self.client.login(username=self.user, password="******") self.coll = Collection(owner=self.user, name="Test Collection") self.coll.save()
def setUp(self): self.user_password = '******' self.user = User.objects.create_user('NeuroGuy') self.user.save() self.coll = Collection(owner=self.user, name="Test Collection") self.coll.save() self.item_url = '/api/collections/%s/' % self.coll.id
def setUp(self): testpath = os.path.join(os.path.abspath(os.path.dirname(__file__)),'test_data','feat') testdata_repo = 'https://github.com/NeuroVault/neurovault_data/blob/master/FEAT_testdata/' self.testfiles = { 'ds105.feat.zip': { 'fileuri':'ds105.feat.zip?raw=true', 'num_statmaps':2, 'export_dir':'ds105.feat/cope1.feat/nidm', 'ttl_fsize': 30000, 'map_types': ['T','Z'], 'names':['Statistic Map: group mean', 'Z-Statistic Map: group mean'], }, 'ds017A.zip': { 'fileuri':'ds017A.zip?raw=true', 'num_statmaps':2, 'export_dir': 'ds017A/group/model001/task001/cope001.gfeat/cope1.feat/nidm', 'ttl_fsize': 68026, 'map_types': ['T','Z'], 'names':['Statistic Map: group mean', 'Z-Statistic Map: group mean'], }, } self.tmpdir = tempfile.mkdtemp() self.user = User.objects.create_user('NeuroGuy') self.user.save() self.client = Client() self.client.login(username=self.user) self.coll = Collection(owner=self.user, name="Test Collection") self.coll.save() # FEAT test data is large so it lives in the external data repo for fname, info in self.testfiles.items(): self.testfiles[fname]['file'] = os.path.join(testpath,fname) if not os.path.exists(self.testfiles[fname]['file']): print '\ndownloading test data {}'.format(fname) furl = '{0}{1}'.format(testdata_repo, info['fileuri']) try: urllib.urlretrieve(furl, self.testfiles[fname]['file']) except: os.remove(os.path.join(testpath,fname)) raise self.testfiles[fname]['sourcedir'] = self.testfiles[fname]['file'][:-4] self.testfiles[fname]['dir'] = os.path.join(self.tmpdir,fname[:-4]) if not os.path.exists(self.testfiles[fname]['sourcedir']): fh = open(os.path.join(testpath,fname), 'rb') z = zipfile.ZipFile(fh) for name in [v for v in z.namelist() if not v.startswith('.') and '/.files' not in v]: outpath = self.testfiles[fname]['sourcedir'] z.extract(name, outpath) fh.close() shutil.copytree(self.testfiles[fname]['sourcedir'], self.testfiles[fname]['dir'])
def setUp(self): testpath = os.path.abspath(os.path.dirname(__file__)) self.files = { 'fsl_nidm': { 'file': os.path.join(testpath, 'test_data/nidm/fsl.nidm.zip'), 'output_row': { 'type': u'TStatistic', 'name': u'Statistic Map: Generation', }, 'num_statmaps': 2, }, 'two_contrasts': { 'file': os.path.join(testpath, 'test_data/nidm/two_contrasts.nidm.zip'), 'output_row': { 'type': u'FStatistic', 'name': 'Statistic Map: Generation FStatistic', }, 'num_statmaps': 6, }, 'spm_example': { 'file': os.path.join(testpath, 'test_data/nidm/spm_example.nidm.zip'), 'output_row': { 'type': u'TStatistic', 'name': u'Statistic Map: passive listening > rest', }, 'num_statmaps': 1, }, # case for a zip with no enclosed directory 'spm_nosubdir': { 'file': os.path.join(testpath, 'test_data/nidm/spm_nosubdir.nidm.zip'), 'output_row': { 'type': u'FStatistic', 'name': u'Statistic Map: Generation FStatistic', }, 'num_statmaps': 6, }, } self.failing_files = { 'spm_bad_ttl': os.path.join(testpath, 'test_data/nidm/spm_bad_ttl.nidm.zip'), } self.tmpdir = tempfile.mkdtemp() self.user = User.objects.create_user('NeuroGuy') self.user.save() self.client = Client() self.client.login(username=self.user) self.coll = Collection(owner=self.user, name="Test Collection") self.coll.save()
def setUp(self): self.user = User.objects.create_user('NeuroGuy') self.user.save() self.collection = Collection(owner=self.user, name="Test Collection") self.collection.save() zip_file = self.abs_data_path('nidm/spm_example.nidm.zip') self.nidm = save_nidm_form(zip_file=zip_file, collection=self.collection)
def edit_collection(request, cid=None): page_header = "Add new collection" if cid: collection = get_collection(cid, request) is_owner = True if collection.owner == request.user else False page_header = 'Edit collection' if not owner_or_contrib(request, collection): return HttpResponseForbidden() else: is_owner = True collection = Collection(owner=request.user) if request.method == "POST": if is_owner: form = OwnerCollectionForm(request.POST, request.FILES, instance=collection) else: form = CollectionForm(request.POST, request.FILES, instance=collection) if form.is_valid(): previous_contribs = set() if form.instance.pk is not None: previous_contribs = set(form.instance.contributors.all()) collection = form.save(commit=False) if collection.private and collection.private_token is None: collection.private_token = generate_url_token() collection.save() if is_owner: form.save_m2m() # save contributors current_contribs = set(collection.contributors.all()) new_contribs = list( current_contribs.difference(previous_contribs)) context = { 'owner': collection.owner.username, 'collection': collection.name, 'url': get_server_url(request) + collection.get_absolute_url(), } subj = '%s has added you to a NeuroVault collection' % context[ 'owner'] send_email_notification('new_contributor', subj, new_contribs, context) return HttpResponseRedirect(collection.get_absolute_url()) else: if is_owner: form = OwnerCollectionForm(instance=collection) else: form = CollectionForm(instance=collection) context = {"form": form, "page_header": page_header, "is_owner": is_owner} return render(request, "statmaps/edit_collection.html.haml", context)
def setUp(self): self.test_path = os.path.abspath(os.path.dirname(__file__)) self.user = User.objects.create(username='******') self.client = Client() self.client.login(username=self.user) self.Collection1 = Collection(name='Collection1', owner=self.user) self.Collection1.save() self.unorderedAtlas = Atlas(name='unorderedAtlas', description='', collection=self.Collection1) # Save new atlas object, unordered print "Adding unordered and ordered atlas..." nii_path = os.path.join( self.test_path, 'test_data/api/VentralFrontal_thr75_summaryimage_2mm.nii.gz') xml_path = os.path.join( self.test_path, 'test_data/api/unordered_VentralFrontal_thr75_summaryimage_2mm.xml' ) self.unorderedAtlas = save_atlas_form(nii_path=nii_path, xml_path=xml_path, collection=self.Collection1, name="unorderedAtlas") # Ordered nii_path = os.path.join( self.test_path, 'test_data/api/VentralFrontal_thr75_summaryimage_2mm.nii.gz') xml_path = os.path.join( self.test_path, 'test_data/api/VentralFrontal_thr75_summaryimage_2mm.xml') self.orderedAtlas = save_atlas_form(nii_path=nii_path, xml_path=xml_path, collection=self.Collection1, name="orderedAtlas") # Statistical Map 1 and 2 print "Adding statistical maps..." nii_path = os.path.join(self.test_path, 'test_data/statmaps/motor_lips.nii.gz') self.Image1 = save_statmap_form(image_path=nii_path, collection=self.Collection1) nii_path = os.path.join(self.test_path, 'test_data/statmaps/beta_0001.nii.gz') self.Image2 = save_statmap_form(image_path=nii_path, collection=self.Collection1) # Zip file with nidm results print "Adding nidm results..." zip_file = os.path.join(self.test_path, 'test_data/nidm/spm_example.nidm.zip') self.nidm = save_nidm_form(zip_file=zip_file, collection=self.Collection1)
def test_private_to_public_switch(self): private_collection1 = Collection(name='privateCollection1', owner=self.u1, private=True, DOI='10.3389/fninf.2015.00099') private_collection1.save() private_collection2 = Collection(name='privateCollection2', owner=self.u1, private=True, DOI='10.3389/fninf.2015.00089') private_collection2.save() app_path = os.path.abspath(os.path.dirname(__file__)) private_image1 = save_statmap_form(image_path=os.path.join( app_path, 'test_data/statmaps/all.nii.gz'), collection=private_collection1, image_name="image1") private_image2 = save_statmap_form(image_path=os.path.join( app_path, 'test_data/statmaps/motor_lips.nii.gz'), collection=private_collection2, image_name="image2") comparison = Comparison.objects.filter(image1=private_image1, image2=private_image2) self.assertEqual(len(comparison), 0) print "before private: %s" % Comparison.objects.all().count() private_collection1 = Collection.objects.get(pk=private_collection1.pk) private_collection1.private = False private_collection1.save() private_collection2 = Collection.objects.get(pk=private_collection2.pk) private_collection2.private = False private_collection2.save() print "after private: %s" % Comparison.objects.all().count() print private_collection1.basecollectionitem_set.instance_of( Image).all() comparison = Comparison.objects.filter(image1=private_image1, image2=private_image2) self.assertEqual(len(comparison), 1)
def setUp(self): self.user = {} self.client = {} for role in ['owner', 'contrib', 'someguy']: self.user[role] = User.objects.create_user( '%s_%s' % (role, self.uniqid()), None, 'pwd') self.user[role].save() self.client[role] = Client() self.client[role].login(username=self.user[role].username, password='******') self.coll = Collection(owner=self.user['owner'], name="Test %s" % self.uniqid()) self.coll.save() self.coll.contributors.add(self.user['contrib']) self.coll.save()
def setUpClass(cls): cls.test_path = os.path.abspath(os.path.dirname(__file__)) cls.user, _ = User.objects.get_or_create(username='******') cls.client = Client() cls.client.login(username=cls.user) cls.Collection1 = Collection(name='Collection1', owner=cls.user) cls.Collection1.save() nii_path = os.path.join(cls.test_path, cls._map) map = save_statmap_form(image_path=nii_path, collection=cls.Collection1) save_resampled_transformation_single(map.pk) response = json.loads( cls.client.get("/images/%d/gene_expression/json" % map.pk, follow=True).content) cls.df = pd.DataFrame(response["data"], columns=response["columns"])
def setUp(self): self.files = NIDM_TEST_FILES self.failing_files = { 'spm_bad_ttl': os.path.join(TEST_PATH, 'test_data/nidm/spm_bad_ttl.nidm.zip') } self.tmpdir = tempfile.mkdtemp() self.user = User.objects.create_user('NeuroGuy') self.user.save() self.client = Client() self.client.login(username=self.user) # we us private collection to avoid running the comparisons self.coll = Collection(owner=self.user, name="Test Collection", private=True, private_token="XBOLFOFU") self.coll.save()
def testDownloadCollection_NIDM_results(self): collection = Collection(owner=self.user, name="Collection2") collection.save() # Upload NIMDResult zip file zip_file = open( os.path.join(TEST_PATH, 'test_data/nidm/auditory.nidm.zip'), 'rb') post_dict = { 'name': 'auditory', 'description': '{0} upload test'.format('spm_auditory_v1.2.0'), 'collection': collection.pk, } fname = os.path.basename( os.path.join(TEST_PATH, 'test_data/nidm/auditory.nidm.zip')) file_dict = {'zip_file': SimpleUploadedFile(fname, zip_file.read())} form = NIDMResultsForm(post_dict, file_dict) form.save() # Upload Statistic Map image = save_statmap_form(image_path=os.path.join( TEST_PATH, 'test_data/statmaps/all.nii.gz'), collection=collection, image_name="all.nii.gz") factory = RequestFactory() self.client.login(username=self.user) request = factory.get('/collections/%s/download' % collection.pk, {'format': 'img.zip'}) request.user = self.user response = download_collection(request, str(collection.pk)) self.assertTrue(response.streaming_content) self.assertEqual(response.status_code, 200) self.assertEqual(response.get('Content-Disposition'), "attachment; filename=" + collection.name + ".zip") zf = zipfile.ZipFile(io.BytesIO(''.join(response.streaming_content))) self.assertEqual(len(zf.filelist), 2) # 1 NIDMResult, 1 Statmap self.assertIsNone(zf.testzip()) self.assertIn("Collection2/all.nii.gz", zf.namelist()) self.assertIn("Collection2/auditory.nidm.zip", zf.namelist())
def test_missing_required_permissions(self): self.client.force_authenticate(user=self.user) other_user = User.objects.create_user('OtherGuy') other_user.save() other_collection = Collection(owner=other_user, name="Another Test Collection") other_collection.save() url = '/api/collections/%s/' % other_collection.pk put_dict = {'name': "renamed %s" % uuid.uuid4()} response = self.client.put(url, put_dict) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual( response.data, {'detail': 'You do not have permission to perform this action.'})
def setUp(self): print "Preparing to test image comparison..." self.tmpdir = tempfile.mkdtemp() app_path = os.path.abspath(os.path.dirname(__file__)) self.u1 = User.objects.create(username='******') self.comparisonCollection = Collection(name='comparisonCollection',owner=self.u1) self.comparisonCollection.save() image1 = save_statmap_form(image_path=os.path.join(app_path,'test_data/api/VentralFrontal_thr75_summaryimage_2mm.nii.gz'), collection=self.comparisonCollection, image_name = "image1", ignore_file_warning=True) self.pk1 = image1.id # Image 2 is equivalent to 1, so pearson should be 1.0 image2 = save_statmap_form(image_path=os.path.join(app_path,'test_data/api/VentralFrontal_thr75_summaryimage_2mm.nii.gz'), collection=self.comparisonCollection, image_name = "image1_copy", ignore_file_warning=True) self.pk1_copy = image2.id # "Bricks" images bricks = split_afni4D_to_3D(nibabel.load(os.path.join(app_path,'test_data/TTatlas.nii.gz')),tmp_dir=self.tmpdir) image3 = save_statmap_form(image_path=bricks[0][1],collection=self.comparisonCollection,image_name="image2",ignore_file_warning=True) self.pk2 = image3.id image4 = save_statmap_form(image_path=bricks[1][1],collection=self.comparisonCollection,image_name="image3",ignore_file_warning=True) self.pk3 = image4.id # This last image is a statmap with NaNs to test that transformation doesn't eliminate them image_nan = save_statmap_form(image_path=os.path.join(app_path,'test_data/statmaps/motor_lips_nan.nii.gz'), collection=self.comparisonCollection, image_name = "image_nan", ignore_file_warning=True) self.pknan = image_nan.id Similarity.objects.update_or_create(similarity_metric="pearson product-moment correlation coefficient", transformation="voxelwise", metric_ontology_iri="http://webprotege.stanford.edu/RCS8W76v1MfdvskPLiOdPaA", transformation_ontology_iri="http://webprotege.stanford.edu/R87C6eFjEftkceScn1GblDL") self.pearson_metric = Similarity.objects.filter(similarity_metric="pearson product-moment correlation coefficient", transformation="voxelwise", metric_ontology_iri="http://webprotege.stanford.edu/RCS8W76v1MfdvskPLiOdPaA", transformation_ontology_iri="http://webprotege.stanford.edu/R87C6eFjEftkceScn1GblDL")
def setUp(self): super(UploadFolderTestCase, self).setUp() self.tmpdir = tempfile.mkdtemp() test_path = os.path.abspath(os.path.dirname(__file__)) with ZipFile(os.path.join(self.tmpdir, 'example.zip'), 'w') as myzip: myzip.write(os.path.join(test_path, 'test_data/statmaps/all.nii.gz')) myzip.write(os.path.join(test_path, 'test_data/statmaps/beta_0001.nii.gz')) myzip.write(os.path.join(test_path, 'test_data/statmaps/motor_lips.nii.gz')) myzip.write(os.path.join(test_path, 'test_data/statmaps/WA3.nii.gz')) with tarfile.open(os.path.join(self.tmpdir, 'example.tar.gz'), "w:gz") as tar: tar.add(os.path.join(test_path, 'test_data/statmaps/all.nii.gz')) tar.add(os.path.join(test_path, 'test_data/statmaps/beta_0001.nii.gz')) tar.add(os.path.join(test_path, 'test_data/statmaps/motor_lips.nii.gz')) tar.add(os.path.join(test_path, 'test_data/statmaps/WA3.nii.gz')) self.user = User.objects.create_user('NeuroGuy', password="******") self.user.save() self.client = Client() login_successful = self.client.login(username=self.user.username, password="******") self.assertTrue(login_successful) self.coll = Collection(owner=self.user, name="Test Collection") self.coll.save()
def setUp(self): print "\n#### TESTING THRESHOLDED IMAGES IN COMPARISON\n" self.tmpdir = tempfile.mkdtemp() self.app_path = os.path.abspath(os.path.dirname(__file__)) self.u1 = User.objects.create(username='******') self.comparisonCollection = Collection(name='comparisonCollection',owner=self.u1) self.comparisonCollection.save() # Image 1 is an atlas print "Adding atlas image..." nii_path = os.path.join(self.app_path,"test_data/api/VentralFrontal_thr75_summaryimage_2mm.nii.gz") xml_path = os.path.join(self.app_path,"test_data/api/VentralFrontal_thr75_summaryimage_2mm.xml") image1 = save_atlas_form(nii_path=nii_path,xml_path=xml_path,collection = self.comparisonCollection) self.pk1 = image1.id # Image 2 is a statistical map print "Adding statistical map..." image_path = os.path.join(self.app_path,'test_data/statmaps/beta_0001.nii.gz') image2 = save_statmap_form(image_path=image_path,collection = self.comparisonCollection) self.pk2 = image2.id # Image 3 is a thresholded statistical map print "Adding thresholded statistical map..." image_paths = [os.path.join(self.app_path,'test_data/statmaps/box_0b_vs_1b.img'), os.path.join(self.app_path,'test_data/statmaps/box_0b_vs_1b.hdr')] image3 = save_statmap_form(image_path=image_paths, collection = self.comparisonCollection,ignore_file_warning=True) self.pk3 = image3.id # Create similarity object Similarity.objects.update_or_create(similarity_metric="pearson product-moment correlation coefficient", transformation="voxelwise", metric_ontology_iri="http://webprotege.stanford.edu/RCS8W76v1MfdvskPLiOdPaA", transformation_ontology_iri="http://webprotege.stanford.edu/R87C6eFjEftkceScn1GblDL") self.pearson_metric = Similarity.objects.filter(similarity_metric="pearson product-moment correlation coefficient", transformation="voxelwise", metric_ontology_iri="http://webprotege.stanford.edu/RCS8W76v1MfdvskPLiOdPaA", transformation_ontology_iri="http://webprotege.stanford.edu/R87C6eFjEftkceScn1GblDL")
post_dict['DOI'] = parsed['records'][0]['doi'] try: col = Collection.objects.get(DOI=post_dict['DOI']) except Collection.DoesNotExist: col = None if col and not col.description.endswith(version): col.DOI = None old_version = re.search(r"Version: (?P<version>\w)", col.description).group("version") col.name = study_name + " (version %s - deprecated)" % old_version col.save() if not col or not col.description.endswith(version): collection = Collection(owner=anima_user) form = CollectionForm(post_dict, instance=collection) form.is_valid() print form.errors collection = form.save() arch_response = requests.get( url.replace("library", "library/archives").replace(".study", ".tar.gz")) arch_results = tarfile.open(mode="r:gz", fileobj=StringIO(arch_response.content)) for study_element in xml_obj.findall( ".//StudyElement[@type='VolumeFile']"): image_name = study_element.attrib['name'].strip() image_filename = study_element.attrib['file']
def setUp(self): self.user = User.objects.create_user('NeuroGuy') self.user.save() self.coll = Collection(owner=self.user, name="Test Collection") self.coll.save()