def save_afni_slices(self, commit):
        try:
            orig_img = self.instance

            for n, (label, brick) in enumerate(self.afni_subbricks):
                brick_fname = os.path.split(brick)[-1]
                mfile = memory_uploadfile(brick, brick_fname, orig_img.file)
                brick_img = StatisticMap(name='%s - %s' % (orig_img.name, label), collection=orig_img.collection,
                                         file=mfile)
                for field in set(self.Meta.fields) - set(['file', 'hdr_file', 'name', 'collection']):
                    if field in self.cleaned_data:
                        setattr(brick_img, field, self.cleaned_data[field])

                brick_img.save()
            return orig_img.collection

        finally:
            try:
                shutil.rmtree(self.afni_tmp)
            except __HOLE__ as exc:
                if exc.errno != 2:
                    raise
dataset/ETHPy150Open NeuroVault/NeuroVault/neurovault/apps/statmaps/forms.py/StatisticMapForm.save_afni_slices