Exemple #1
0
    def save_unmasked_coefs(self,
                            unmasked,
                            nifti_filename,
                            affine=None,
                            talairach_template_path='./TT_N27+tlrc.'):
        '''
        Simple function to save the unmasked coefficients to a specified nifti.
        Affine is usually self.mask_affine, but can be specified.
        '''

        if affine is None:
            affine = self.mask_affine

        if self.verbose:
            print 'erasing old files with prefix:', nifti_filename  #[:-4]

        glob_remove(nifti_filename)  #[:-4])

        self.nifti.save_nifti(unmasked, affine, nifti_filename)

        time.sleep(0.25)

        self.nifti.convert_to_afni(nifti_filename, nifti_filename)  #[:-4])

        time.sleep(0.25)

        subprocess.call(
            ['3drefit', '-view', 'tlrc', nifti_filename + '+orig.'])
Exemple #2
0
 def adwarp_to_subject_talairach(self, dataset_in, dataset_out, anatomical,
                                 dxyz):
     glob_remove(dataset_out)
     subprocess.call([
         'adwarp', '-apar', anatomical, '-dpar', dataset_in, '-dxyz',
         str(dxyz), '-prefix', dataset_out
     ])
Exemple #3
0
 def convert_to_afni(self, nifti_in, dataset_out):
     try:
         glob_remove(dataset_out+'+orig')
     except:
         pass
     try:
         glob_remove(dataset_out+'+tlrc')
     except:
         pass
     subprocess.call(['3dcopy', nifti_in, dataset_out])
Exemple #4
0
 def convert_to_afni(self, nifti_in, dataset_out):
     try:
         glob_remove(dataset_out + '+orig')
     except:
         pass
     try:
         glob_remove(dataset_out + '+tlrc')
     except:
         pass
     subprocess.call(['3dcopy', nifti_in, dataset_out])
Exemple #5
0
    def create_talairach_niftis(self,
                                subject_dirs,
                                functional_name,
                                anatomical_name,
                                dxyz,
                                talairach_path,
                                output_name,
                                within_subject_warp=True,
                                to_template_warp=True):

        if not output_name.endswith('.nii'):
            output_name = output_name + '.nii'

        # iterate subject directories:
        for s in subject_dirs:

            functional = os.path.join(s, functional_name)
            anatomical = os.path.join(s, anatomical_name)

            # refit the functional to the anatomical:
            self.afni.refit_apar(anatomical + '+tlrc', functional + '+orig')
            #self.refit(functional, anatomical)

            # adwarp the functional to the anatomical
            if within_subject_warp:
                adwarp_temp = os.path.join(s, 'temp_adwarp_func')
                self.afni.adwarp(anatomical + '+tlrc',
                                 functional + '+orig',
                                 adwarp_temp,
                                 dxyz=dxyz)
            else:
                adwarp_temp = functional

            # warp the warped functional to the talairach template:
            if to_template_warp:
                template_temp = os.path.join(s, 'temp_template_func')
                self.afni.adwarp(talairach_path,
                                 adwarp_temp + '+tlrc',
                                 template_temp,
                                 dxyz=dxyz,
                                 force=True)
            else:
                template_temp = adwarp_temp

            # make the nifti files
            nifti_path = os.path.join(s, output_name)
            try:
                glob_remove(nifti_path)
            except:
                pass
            self.convert_to_nifti(template_temp + '+tlrc', nifti_path)

            if within_subject_warp:
                glob_remove(adwarp_temp)
            if to_template_warp:
                glob_remove(template_temp)

        return [os.path.join(s, output_name) for s in subject_dirs]
Exemple #6
0
 def save_unmasked_coefs(self, unmasked, nifti_filename, affine=None,
                         talairach_template_path='./TT_N27+tlrc.'):
     '''
     Simple function to save the unmasked coefficients to a specified nifti.
     Affine is usually self.mask_affine, but can be specified.
     '''
     
     if affine is None:
         affine = self.mask_affine
         
     if self.verbose:
         print 'erasing old files with prefix:', nifti_filename#[:-4]
         
     glob_remove(nifti_filename)#[:-4])
         
     self.nifti.save_nifti(unmasked, affine, nifti_filename)
     
     time.sleep(0.25)
     
     self.nifti.convert_to_afni(nifti_filename, nifti_filename)#[:-4])
     
     time.sleep(0.25)
     
     subprocess.call(['3drefit','-view','tlrc',nifti_filename+'+orig.'])
Exemple #7
0
 def create_talairach_niftis(self, subject_dirs, functional_name, anatomical_name,
                             dxyz, talairach_path, output_name, within_subject_warp=True,
                             to_template_warp=True):
     
     if not output_name.endswith('.nii'):
         output_name = output_name+'.nii'
     
     # iterate subject directories:
     for s in subject_dirs:
         
         functional = os.path.join(s, functional_name)
         anatomical = os.path.join(s, anatomical_name)
         
         # refit the functional to the anatomical:
         self.afni.refit_apar(anatomical+'+tlrc', functional+'+orig')
         #self.refit(functional, anatomical)
                     
         # adwarp the functional to the anatomical
         if within_subject_warp:
             adwarp_temp = os.path.join(s, 'temp_adwarp_func')
             self.afni.adwarp(anatomical+'+tlrc', functional+'+orig', adwarp_temp, dxyz=dxyz)
         else:
             adwarp_temp = functional
         
         # warp the warped functional to the talairach template:
         if to_template_warp:
             template_temp = os.path.join(s, 'temp_template_func')
             self.afni.adwarp(talairach_path, adwarp_temp+'+tlrc', template_temp, dxyz=dxyz,
                              force=True)
         else:
             template_temp = adwarp_temp
             
         # make the nifti files
         nifti_path = os.path.join(s, output_name)
         try:
             glob_remove(nifti_path)
         except:
             pass
         self.convert_to_nifti(template_temp+'+tlrc', nifti_path)
         
         if within_subject_warp:
             glob_remove(adwarp_temp)
         if to_template_warp:
             glob_remove(template_temp)
             
     return [os.path.join(s, output_name) for s in subject_dirs]
Exemple #8
0
 def adwarp_to_subject_talairach(self, dataset_in, dataset_out, anatomical, dxyz):
     glob_remove(dataset_out)
     subprocess.call(['adwarp', '-apar', anatomical, '-dpar', dataset_in,
                      '-dxyz', str(dxyz), '-prefix', dataset_out])
Exemple #9
0
 def convert_to_nifti(self, dataset_in, dataset_out):
     glob_remove(dataset_out)
     subprocess.call(['3dAFNItoNIFTI', '-prefix', dataset_out, dataset_in])
Exemple #10
0
 def save_nifti(self, data, affine, filepath):
     if not filepath.endswith('.nii'):
         filepath = filepath+'.nii'
     glob_remove(filepath)
     nii = nib.Nifti1Image(data, affine)
     nii.to_filename(filepath)
Exemple #11
0
 def convert_to_nifti(self, dataset_in, dataset_out):
     glob_remove(dataset_out)
     subprocess.call(['3dAFNItoNIFTI', '-prefix', dataset_out, dataset_in])
Exemple #12
0
 def save_nifti(self, data, affine, filepath):
     if not filepath.endswith('.nii'):
         filepath = filepath + '.nii'
     glob_remove(filepath)
     nii = nib.Nifti1Image(data, affine)
     nii.to_filename(filepath)