def testaddAFNI(self):

            post_dict = {
                'name': "test map",
                'cognitive_paradigm_cogatlas': 'trm_4f24126c22011',
                'modality':'fMRI-BOLD',
                'map_type': 'T',
                'collection':self.coll.pk,
            }
            testpath = os.path.abspath(os.path.dirname(__file__))
            fname = os.path.join(testpath,'test_data/statmaps/saccade.I_C.MNI.nii.gz')

            nii = nb.load(fname)

            self.assertTrue(detect_4D(nii))
            self.assertTrue(len(split_4D_to_3D(nii)) > 0)

            file_dict = {'file': SimpleUploadedFile(fname, open(fname).read())}
            form = StatisticMapForm(post_dict, file_dict)

            self.assertTrue(form.is_valid())

            form.save()

            self.assertEqual(StatisticMap.objects.filter(collection=self.coll.pk).count(), 2)
Exemplo n.º 2
0
    def testaddAFNI(self):

        post_dict = {
            'name': "test map",
            'cognitive_paradigm_cogatlas': 'trm_4f24126c22011',
            'modality': 'fMRI-BOLD',
            'map_type': 'T',
            'number_of_subjects': 10,
            'analysis_level': 'G',
            'collection': self.coll.pk,
            'target_template_image': 'GenericMNI',
        }
        testpath = os.path.abspath(os.path.dirname(__file__))
        fname = os.path.join(testpath,
                             'test_data/statmaps/saccade.I_C.MNI.nii.gz')

        nii = nb.load(fname)

        self.assertTrue(detect_4D(nii))
        self.assertTrue(len(split_4D_to_3D(nii)) > 0)

        file_dict = {'file': SimpleUploadedFile(fname, open(fname).read())}
        form = StatisticMapForm(post_dict, file_dict)

        self.assertTrue(form.is_valid())

        form.save()

        self.assertEqual(
            StatisticMap.objects.filter(collection=self.coll.pk).count(), 2)
Exemplo n.º 3
0
    def testaddImgHdr(self):

        post_dict = {
            'name': "test map",
            'cognitive_paradigm_cogatlas': 'trm_4f24126c22011',
            'modality': 'fMRI-BOLD',
            'map_type': 'T',
            'number_of_subjects': 10,
            'analysis_level': 'G',
            'collection': self.coll.pk,
            'target_template_image': 'GenericMNI',
        }
        testpath = os.path.abspath(os.path.dirname(__file__))
        fname_img = os.path.join(testpath,
                                 'test_data/statmaps/box_0b_vs_1b.img')
        fname_hdr = os.path.join(testpath,
                                 'test_data/statmaps/box_0b_vs_1b.hdr')
        file_dict = {
            'file': SimpleUploadedFile(fname_img,
                                       open(fname_img).read()),
            'hdr_file': SimpleUploadedFile(fname_hdr,
                                           open(fname_hdr).read())
        }
        form = StatisticMapForm(post_dict, file_dict)
        self.assertFalse(form.is_valid())
        self.assertTrue("thresholded" in form.errors["file"][0])

        post_dict = {
            'name': "test map",
            'cognitive_paradigm_cogatlas': 'trm_4f24126c22011',
            'modality': 'fMRI-BOLD',
            'map_type': 'T',
            'number_of_subjects': 10,
            'analysis_level': 'G',
            'collection': self.coll.pk,
            'ignore_file_warning': True,
            'target_template_image': 'GenericMNI',
        }
        testpath = os.path.abspath(os.path.dirname(__file__))
        fname_img = os.path.join(testpath,
                                 'test_data/statmaps/box_0b_vs_1b.img')
        fname_hdr = os.path.join(testpath,
                                 'test_data/statmaps/box_0b_vs_1b.hdr')
        file_dict = {
            'file': SimpleUploadedFile(fname_img,
                                       open(fname_img).read()),
            'hdr_file': SimpleUploadedFile(fname_hdr,
                                           open(fname_hdr).read())
        }
        form = StatisticMapForm(post_dict, file_dict)
        self.assertTrue(form.is_valid())

        form.save()

        self.assertEqual(
            StatisticMap.objects.filter(collection=self.coll.pk)[0].name,
            "test map")
Exemplo n.º 4
0
def save_statmap_form(image_path,collection,ignore_file_warning=False,image_name=None):

    if image_name == None:
        if isinstance(image_path,list):
            image_name = image_path[0]
        else:
            image_name = image_path
    
    post_dict = {
        'name': image_name,
        'cognitive_paradigm_cogatlas': 'trm_4f24126c22011',
        'modality': 'fMRI-BOLD',
        'map_type': 'T',
        'collection': collection.pk,
        'ignore_file_warning': ignore_file_warning
    }
    # If image path is a list, we have img/hdr
    if isinstance(image_path,list):
        file_dict = {'file': SimpleUploadedFile(image_path[0], open(image_path[0]).read()),
                     'hdr_file': SimpleUploadedFile(image_path[1], open(image_path[1]).read())}
    else:
        file_dict = {'file': SimpleUploadedFile(image_path, open(image_path).read())}
    form = StatisticMapForm(post_dict, file_dict)
    # this is necessary to split 4D volumes
    form.is_valid()
    return form.save()
Exemplo n.º 5
0
def save_statmap_form(image_path,collection,ignore_file_warning=False,image_name=None):

    if image_name == None:
        if isinstance(image_path,list):
            image_name = image_path[0]
        else:
            image_name = image_path
    
    post_dict = {
        'name': image_name,
        'cognitive_paradigm_cogatlas': 'trm_4f24126c22011',
        'modality': 'fMRI-BOLD',
        'map_type': 'T',
        'target_template_image': 'GenericMNI',
        'collection': collection.pk,
        'ignore_file_warning': ignore_file_warning
    }
    # If image path is a list, we have img/hdr
    if isinstance(image_path,list):
        file_dict = {'file': SimpleUploadedFile(image_path[0], open(image_path[0]).read()),
                     'hdr_file': SimpleUploadedFile(image_path[1], open(image_path[1]).read())}
    else:
        file_dict = {'file': SimpleUploadedFile(image_path, open(image_path).read())}
    form = StatisticMapForm(post_dict, file_dict)
    # this is necessary to split 4D volumes
    form.is_valid()
    return form.save()
Exemplo n.º 6
0
def save_statmap_form(image_path, collection, ignore_file_warning=False, image_name=None):

    if image_name == None:
        if isinstance(image_path, list):
            image_name = image_path[0]
        else:
            image_name = image_path

    post_dict = {
        "name": image_name,
        "cognitive_paradigm_cogatlas": "trm_4f24126c22011",
        "modality": "fMRI-BOLD",
        "map_type": "T",
        "collection": collection.pk,
        "ignore_file_warning": ignore_file_warning,
    }
    # If image path is a list, we have img/hdr
    if isinstance(image_path, list):
        file_dict = {
            "file": SimpleUploadedFile(image_path[0], open(image_path[0]).read()),
            "hdr_file": SimpleUploadedFile(image_path[1], open(image_path[1]).read()),
        }
    else:
        file_dict = {"file": SimpleUploadedFile(image_path, open(image_path).read())}
    form = StatisticMapForm(post_dict, file_dict)
    return form.save()
    def testaddNiiGz(self):

            post_dict = {
                'name': "test map",
                'cognitive_paradigm_cogatlas': 'trm_4f24126c22011',
                'modality':'fMRI-BOLD',
                'map_type': 'T',
                'collection':self.coll.pk,
            }
            testpath = os.path.abspath(os.path.dirname(__file__))
            fname = os.path.join(testpath,'test_data/statmaps/motor_lips.nii.gz')
            file_dict = {'file': SimpleUploadedFile(fname, open(fname).read())}
            form = StatisticMapForm(post_dict, file_dict)

            self.assertTrue(form.is_valid())

            form.save()
            
            self.assertEqual(StatisticMap.objects.filter(collection=self.coll.pk)[0].name, "test map")
    def testaddImgHdr(self):

            post_dict = {
                'name': "test map",
                'cognitive_paradigm_cogatlas': 'trm_4f24126c22011',
                'modality':'fMRI-BOLD',
                'map_type': 'T',
                'number_of_subjects': 10,
                'analysis_level': 'G',
                'collection':self.coll.pk,
                'target_template_image': 'GenericMNI',
            }
            testpath = os.path.abspath(os.path.dirname(__file__))
            fname_img = os.path.join(testpath,'test_data/statmaps/box_0b_vs_1b.img')
            fname_hdr = os.path.join(testpath,'test_data/statmaps/box_0b_vs_1b.hdr')
            file_dict = {'file': SimpleUploadedFile(fname_img, open(fname_img).read()),
                         'hdr_file': SimpleUploadedFile(fname_hdr, open(fname_hdr).read())}
            form = StatisticMapForm(post_dict, file_dict)
            self.assertFalse(form.is_valid())
            self.assertTrue("thresholded" in form.errors["file"][0])
            
            post_dict = {
                'name': "test map",
                'cognitive_paradigm_cogatlas': 'trm_4f24126c22011',
                'modality':'fMRI-BOLD',
                'map_type': 'T',
                'number_of_subjects': 10,
                'analysis_level': 'G',
                'collection':self.coll.pk,
                'ignore_file_warning': True,
                'target_template_image': 'GenericMNI',
            }
            testpath = os.path.abspath(os.path.dirname(__file__))
            fname_img = os.path.join(testpath,'test_data/statmaps/box_0b_vs_1b.img')
            fname_hdr = os.path.join(testpath,'test_data/statmaps/box_0b_vs_1b.hdr')
            file_dict = {'file': SimpleUploadedFile(fname_img, open(fname_img).read()),
                         'hdr_file': SimpleUploadedFile(fname_hdr, open(fname_hdr).read())}
            form = StatisticMapForm(post_dict, file_dict)
            self.assertTrue(form.is_valid())

            form.save()
            
            self.assertEqual(StatisticMap.objects.filter(collection=self.coll.pk)[0].name, "test map")
Exemplo n.º 9
0
    def testaddNiiGz(self):

        post_dict = {
            "name": "test map",
            "cognitive_paradigm_cogatlas": "trm_4f24126c22011",
            "modality": "fMRI-BOLD",
            "map_type": "T",
            "collection": self.coll.pk,
        }
        testpath = os.path.abspath(os.path.dirname(__file__))
        fname = os.path.join(testpath, "test_data/statmaps/motor_lips.nii.gz")
        file_dict = {"file": SimpleUploadedFile(fname, open(fname).read())}
        form = StatisticMapForm(post_dict, file_dict)

        self.assertTrue(form.is_valid())

        form.save()

        self.assertEqual(StatisticMap.objects.filter(collection=self.coll.pk)[0].name, "test map")
Exemplo n.º 10
0
    def testaddImgHdr(self):

        post_dict = {
            "name": "test map",
            "cognitive_paradigm_cogatlas": "trm_4f24126c22011",
            "modality": "fMRI-BOLD",
            "map_type": "T",
            "collection": self.coll.pk,
        }
        testpath = os.path.abspath(os.path.dirname(__file__))
        fname_img = os.path.join(testpath, "test_data/statmaps/box_0b_vs_1b.img")
        fname_hdr = os.path.join(testpath, "test_data/statmaps/box_0b_vs_1b.hdr")
        file_dict = {
            "file": SimpleUploadedFile(fname_img, open(fname_img).read()),
            "hdr_file": SimpleUploadedFile(fname_hdr, open(fname_hdr).read()),
        }
        form = StatisticMapForm(post_dict, file_dict)
        self.assertFalse(form.is_valid())
        self.assertTrue("thresholded" in form.errors["file"][0])

        post_dict = {
            "name": "test map",
            "cognitive_paradigm_cogatlas": "trm_4f24126c22011",
            "modality": "fMRI-BOLD",
            "map_type": "T",
            "collection": self.coll.pk,
            "ignore_file_warning": True,
        }
        testpath = os.path.abspath(os.path.dirname(__file__))
        fname_img = os.path.join(testpath, "test_data/statmaps/box_0b_vs_1b.img")
        fname_hdr = os.path.join(testpath, "test_data/statmaps/box_0b_vs_1b.hdr")
        file_dict = {
            "file": SimpleUploadedFile(fname_img, open(fname_img).read()),
            "hdr_file": SimpleUploadedFile(fname_hdr, open(fname_hdr).read()),
        }
        form = StatisticMapForm(post_dict, file_dict)
        self.assertTrue(form.is_valid())

        form.save()

        self.assertEqual(StatisticMap.objects.filter(collection=self.coll.pk)[0].name, "test map")
    def testaddNiiGz(self):

        post_dict = {
            'name': "test map",
            'cognitive_paradigm_cogatlas': 'trm_4f24126c22011',
            'modality': 'fMRI-BOLD',
            'map_type': 'T',
            'collection': self.coll.pk,
        }
        testpath = os.path.abspath(os.path.dirname(__file__))
        fname = os.path.join(testpath, 'test_data/statmaps/motor_lips.nii.gz')
        file_dict = {'file': SimpleUploadedFile(fname, open(fname).read())}
        form = StatisticMapForm(post_dict, file_dict)

        self.assertTrue(form.is_valid())

        form.save()

        self.assertEqual(
            StatisticMap.objects.filter(collection=self.coll.pk)[0].name,
            "test map")
Exemplo n.º 12
0
def add_image(request, collection_cid):
    collection = get_collection(collection_cid, request)
    image = StatisticMap(collection=collection)
    if request.method == "POST":
        form = StatisticMapForm(request.POST, request.FILES, instance=image)
        if form.is_valid():
            image = form.save()
            return HttpResponseRedirect(image.get_absolute_url())
    else:
        form = StatisticMapForm(instance=image)

    context = {"form": form}
    return render(request, "statmaps/add_image.html.haml", context)
Exemplo n.º 13
0
def add_image(request, collection_cid):
    collection = get_collection(collection_cid,request)
    image = StatisticMap(collection=collection)
    if request.method == "POST":
        form = StatisticMapForm(request.POST, request.FILES, instance=image)
        if form.is_valid():
            image = form.save()
            return HttpResponseRedirect(image.get_absolute_url())
    else:
        form = StatisticMapForm(instance=image)

    context = {"form": form}
    return render(request, "statmaps/add_image.html.haml", context)