Beispiel #1
0
    def save(self, *args, **kwargs):
        if self.DOI is not None and self.DOI.strip() == "":
            self.DOI = None
        if self.private_token is not None and self.private_token.strip() == "":
            self.private_token = None

        if self.DOI and not self.private and not self.doi_add_date:
            self.doi_add_date = datetime.now()

        # run calculations when collection turns public
        privacy_changed = False
        DOI_changed = False
        if self.pk is not None:
            old_object = Collection.objects.get(pk=self.pk)
            old_is_private = old_object.private
            old_has_DOI = old_object.DOI is not None
            privacy_changed = old_is_private != self.private
            DOI_changed = old_has_DOI != (self.DOI is not None)

        super(Collection, self).save(*args, **kwargs)

        if (privacy_changed
                and not self.private) or (DOI_changed
                                          and self.DOI is not None):
            for image in self.basecollectionitem_set.instance_of(Image).all():
                if image.pk:
                    generate_glassbrain_image.apply_async([image.pk])
                    run_voxelwise_pearson_similarity.apply_async([image.pk])
Beispiel #2
0
    def save(self):
        file_changed = False
        collection_changed = False
        if self.pk is not None:
            old_pk = Image.objects.get(pk=self.pk)
            if old_pk.file != self.file:
                file_changed = True
            if old_pk.collection != self.collection:
                collection_changed = True

        do_update = True if file_changed else False
        new_image = True if self.pk is None else False
        super(Image, self).save()

        if (do_update or new_image) and self.collection and self.collection.private == False:
            # Generate glass brain image
            generate_glassbrain_image.apply_async([self.pk])

        if collection_changed:
            for field_name in self._meta.get_all_field_names():
                field_instance = getattr(self, field_name)
                if field_instance and isinstance(field_instance, FieldFile):
                    old_path = field_instance.path
                    new_name = upload_img_to(self, field_instance.name.split("/")[-1])
                    new_name = field_instance.storage.get_available_name(new_name)
                    new_path = field_instance.storage.path(new_name)
                    if not os.path.exists(os.path.dirname(new_path)):
                        os.mkdir(os.path.dirname(new_path))
                    shutil.copy(old_path, new_path)
                    field_instance.name = new_name
                    assert(old_path != new_path)
                    os.remove(old_path)
            super(Image, self).save()
Beispiel #3
0
    def save(self, *args, **kwargs):
        if self.DOI is not None and self.DOI.strip() == "":
            self.DOI = None
        if self.private_token is not None and self.private_token.strip() == "":
            self.private_token = None

        if self.DOI and not self.private and not self.doi_add_date:
            self.doi_add_date = datetime.now()

        # run calculations when collection turns public
        privacy_changed = False
        DOI_changed = False
        if self.pk is not None:
            old_object = Collection.objects.get(pk=self.pk)
            old_is_private = old_object.private
            old_has_DOI = old_object.DOI is not None
            privacy_changed = old_is_private != self.private
            DOI_changed = old_has_DOI != (self.DOI is not None)

        super(Collection, self).save(*args, **kwargs)

        if (privacy_changed and not self.private) or (DOI_changed and self.DOI is not None):
            for image in self.basecollectionitem_set.instance_of(Image).all():
                if image.pk:
                    generate_glassbrain_image.apply_async([image.pk])
                    run_voxelwise_pearson_similarity.apply_async([image.pk])
Beispiel #4
0
    def save(self, *args, **kwargs):
        if self.DOI is not None and self.DOI.strip() == "":
            self.DOI = None
        if self.private_token is not None and self.private_token.strip() == "":
            self.private_token = None
            
        if self.DOI and not self.private and not self.doi_add_date:
            self.doi_add_date = datetime.now()

        # run calculations when collection turns public
        privacy_changed = False
        if self.pk is not None:
            old_object = Collection.objects.get(pk=self.pk)
            old_is_private = old_object.private
            privacy_changed = old_is_private != self.private

        super(Collection, self).save(*args, **kwargs)

        assign_perm('delete_collection', self.owner, self)
        assign_perm('change_collection', self.owner, self)
        for image in self.image_set.all():
            assign_perm('change_image', self.owner, image)
            assign_perm('delete_image', self.owner, image)
        for nidmresult in self.nidmresults_set.all():
            assign_perm('change_nidmresults', self.owner, nidmresult)
            assign_perm('delete_nidmresults', self.owner, nidmresult)
        

        if privacy_changed and self.private == False:
            for image in self.image_set.all():
                if image.pk:
                    generate_glassbrain_image.apply_async([image.pk])
                    run_voxelwise_pearson_similarity.apply_async([image.pk])
Beispiel #5
0
    def save(self):
        file_changed = False
        if self.pk is not None:
            existing = Image.objects.get(pk=self.pk)
            if existing.file != self.file:
                file_changed = True
        do_update = True if file_changed else False
        new_image = True if self.pk is None else False
        super(Image, self).save()

        if (do_update or new_image) and self.collection and self.collection.private == False:

            # Generate glass brain image
            generate_glassbrain_image.apply_async([self.pk])
Beispiel #6
0
    def save(self):
        file_changed = False
        if self.pk is not None:
            existing = Image.objects.get(pk=self.pk)
            if existing.file != self.file:
                file_changed = True
        do_update = True if file_changed else False
        new_image = True if self.pk is None else False
        super(Image, self).save()

        if (do_update or new_image
            ) and self.collection and self.collection.private == False:

            # Generate glass brain image
            generate_glassbrain_image.apply_async([self.pk])
Beispiel #7
0
 def save(self):
     if self.DOI is not None and self.DOI.strip() == "":
         self.DOI = None
     if self.private_token is not None and self.private_token.strip() == "":
         self.private_token = None
     
     # run calculations when collection turns public
     privacy_changed = False
     if self.pk is not None:
         old_object = Collection.objects.get(pk=self.pk)
         old_is_private = old_object.private    
         privacy_changed = old_is_private != self.private        
             
     super(Collection, self).save()
     
     if privacy_changed and self.private == False:
         for image in self.image_set.all():
             if image.pk:
                 generate_glassbrain_image.apply_async([image.pk])
                 run_voxelwise_pearson_similarity.apply_async([image.pk])
Beispiel #8
0
    def save(self):
        file_changed = False
        collection_changed = False
        if self.pk is not None:
            old_pk = Image.objects.get(pk=self.pk)
            if old_pk.file != self.file:
                file_changed = True
            if old_pk.collection != self.collection:
                collection_changed = True

        do_update = True if file_changed else False
        new_image = True if self.pk is None else False
        super(Image, self).save()

        if (do_update or new_image
            ) and self.collection and self.collection.private == False:
            # Generate glass brain image
            generate_glassbrain_image.apply_async([self.pk])

        if collection_changed:
            for field_name in self._meta.get_all_field_names():
                field_instance = getattr(self, field_name)
                if field_instance and isinstance(field_instance, FieldFile):
                    old_path = field_instance.path
                    new_name = upload_img_to(
                        self,
                        field_instance.name.split("/")[-1])
                    new_name = field_instance.storage.get_available_name(
                        new_name)
                    new_path = field_instance.storage.path(new_name)
                    if not os.path.exists(os.path.dirname(new_path)):
                        os.mkdir(os.path.dirname(new_path))
                    shutil.copy(old_path, new_path)
                    field_instance.name = new_name
                    assert (old_path != new_path)
                    os.remove(old_path)
            super(Image, self).save()
import os
import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "neurovault.settings")
django.setup()

from neurovault.apps.statmaps.models import StatisticMap
from neurovault.apps.statmaps.tasks import generate_glassbrain_image,\
    save_resampled_transformation_single

for image in StatisticMap.objects.filter(collection__private=False).exclude(analysis_level = 'S').exclude(is_thresholded = True):
    print image.id
    generate_glassbrain_image.apply_async([image.id])
    save_resampled_transformation_single.apply_async([image.id])