pynetstim/coordinates.py
def create_surf_roi(self, extents, surface='white', map_surface='white', map_to_annot=None, wf_base_dir=None,
      wf_name='surf_roi', add_vertex_to_name=True):
        
        """ creates surface ROIs for each coordinate point
        
        Parameters
        ----------
        extents: float or numpy array
            specifies the raidus of the growing ROI. Either one single number for all the points or a numpy array containing 
            radius for each point
            
        surface: str
            specifies which surface to use for growing the ROIs ( white or pial)
            
        map_to_annot: str
            specifies which annotation to use to assign name and color to use for ROI labeling
      
        wf_base_dir: str
              workflow base dir
      
        wf_name: str
              workflow name , the results will be saved under <wf_base_dir>/<wf_name>
        
        add_vertex_to_name: boolean
              if True, adds the projected vertex number to the ROI name ( in case the ROIs might have similar naming, adding vertex number can help get rid of this issue)
      
        Returns
        -------
        
        rois: instances of class of Label 
      
        rois_paths: path to the saved labels
      
        """
        ## wf_base_dir
        if wf_base_dir is None and self.working_dir is not None:
            wf_base_dir = self.working_dir
        
        elif wf_base_dir is None and self.working_dir is None:
            print('Working dir has not been specified, results will be stored in:  ', os.path.abspath('.'))             
            wf_base_dir = os.path.abspath('.')
            
        if len(self.hemi_not_determined)>0:
            raise ValueError('Use set_hemi_manually to assign hemiphere to these points: %s'%(','.join(self.hemi_not_determined)))
            

        results = self.map_to_surface(map_surface)
        mapped_vertices, mapped_coords_ras_tkr, mapped_coords_ras = results['vertices'], results['ras_coord'], results['ras_tkr_coord']
             
        ### extents can be one number or an array, make it an array if it is a number
        if type(extents)==list or type(extents)==np.ndarray:
            assert(len(extents)==self.npoints,'extents can be either one number or a list where len(extents) is equal to number of points')
        else:
            extents = [extents]*self.npoints
        
        hemi = [0 if hemi=='lh' else 1 for hemi in self.hemi]
        rois = grow_labels(self.subject, mapped_vertices, extents, hemi, self.freesurfer_dir, surface=surface)
        
       
        ### get structures and color for labels according to annotation
        if map_to_annot:
            structures, colors = self.map_to_annot(annot, map_surface=map_surface)
            for i in range(self.npoints):
                rois[i].color = colors[i]
                vertex = mapped_vertices[i]
                if add_vertex_to_name:
                    rois[i].name = structures[i]+'_{r}mm_{surf}_{vertex}'.format(r=extents[i],surf=surface,vertex=vertex)
                else:
                    rois[i].name = structures[i]+'_{r}mm_{surf}'.format(r=extents[i],surf=surface)
                
        elif hasattr(self,'name') or hasattr(self,'color'):
            for i in range(self.npoints):
                if hasattr(self,'name'):
                    vertex = mapped_vertices[i]
                    if add_vertex_to_name:
                        rois[i].name = self.name[i]+'_{r}mm_{surf}_{vertex}'.format(r=extents[i],surf=surface,vertex=vertex)
                    else:
                        rois[i].name = self.name[i]+'_{r}mm_{surf}'.format(r=extents[i],surf=surface,vertex=vertex)
                if hasattr(self,'color'):
                    rois[i].color = self.color[i]

        else:
            for i in range(self.npoints):
                vertex = mapped_vertices[i]
                if add_vertex_to_name:
                    rois[i].name = 'coor_id_{i}_{r}mm_{surf}_{vertex}'.format(r=extents[i],surf=surface,vertex=vertex,i=i)
                else:
                    rois[i].name = 'coor_id_{i}_{r}mm_{surf}_{vertex}'.format(r=extents[i],surf=surface,vertex=vertex,i=i)
            

        #### saving ROI labels

        rois_path = []
        if not os.path.exists(os.path.join(wf_base_dir,wf_name)):
            os.makedirs(os.path.join(wf_base_dir,wf_name))
            
    
        for i,roi in enumerate(rois):
            os.environ['SUBJECTS_DIR'] = self.freesurfer_dir
            
            ### saving ROI label
            roi_path = '{wf_base_dir}/{wf_name}/{roi_name}-{hemi}.label'.format(wf_base_dir=wf_base_dir, wf_name=wf_name, roi_name=roi.name, hemi=roi.hemi)
            rois_path.append(roi_path)
            roi.save(roi_path)
            
        ### converting list to arrays
        self.add_trait('roi', np.array(rois))
        return self.roi,rois_path
 creates surface ROIs for each coordinate point
        
        Parameters
        ----------
        extents: float or numpy array
            specifies the raidus of the growing ROI. Either one single number for all the points or a numpy array containing 
            radius for each point
            
        surface: str
            specifies which surface to use for growing the ROIs ( white or pial)
            
        map_to_annot: str
            specifies which annotation to use to assign name and color to use for ROI labeling
      
        wf_base_dir: str
              workflow base dir
      
        wf_name: str
              workflow name , the results will be saved under <wf_base_dir>/<wf_name>
        
        add_vertex_to_name: boolean
              if True, adds the projected vertex number to the ROI name ( in case the ROIs might have similar naming, adding vertex number can help get rid of this issue)
      
        Returns
        -------
        
        rois: instances of class of Label 
      
        rois_paths: path to the saved labels
      
        
creates surface ROIs for each coordinate point
Parameters

float or numpy array
specifies the raidus of the growing ROI. Either one single number for all the points or a numpy array containing
radius for each point

str
specifies which surface to use for growing the ROIs ( white or pial)

str
specifies which annotation to use to assign name and color to use for ROI labeling

str
workflow base dir

str
workflow name , the results will be saved under /

boolean
if True, adds the projected vertex number to the ROI name ( in case the ROIs might have similar naming, adding vertex number can help get rid of this issue)

Returns

instances of class of Label

path to the saved labels
creates surface ROIs for each coordinate point Parameters float or numpy array specifies the raidus of the growing ROI . Either one single number for all the points or a numpy array containing radius for each point str specifies which surface to use for growing the ROIs ( white or pial ) str specifies which annotation to use to assign name and color to use for ROI labeling str workflow base dir str workflow name the results will be saved under / boolean if True adds the projected vertex number to the ROI name ( in case the ROIs might have similar naming adding vertex number can help get rid of this issue ) Returns instances of class of Label path to the saved labels
def create_surf_roi(self, extents, surface='white', map_surface='white', map_to_annot=None, wf_base_dir=None,
      wf_name='surf_roi', add_vertex_to_name=True):
        if wf_base_dir is None and self.working_dir is not None:
            wf_base_dir = self.working_dir
        elif wf_base_dir is None and self.working_dir is None:
            print('Working dir has not been specified, results will be stored in:  ', os.path.abspath('.'))             
            wf_base_dir = os.path.abspath('.')
        if len(self.hemi_not_determined)>0:
            raise ValueError('Use set_hemi_manually to assign hemiphere to these points: %s'%(','.join(self.hemi_not_determined)))
        results = self.map_to_surface(map_surface)
        mapped_vertices, mapped_coords_ras_tkr, mapped_coords_ras = results['vertices'], results['ras_coord'], results['ras_tkr_coord']
        if type(extents)==list or type(extents)==np.ndarray:
            assert(len(extents)==self.npoints,'extents can be either one number or a list where len(extents) is equal to number of points')
        else:
            extents = [extents]*self.npoints
        hemi = [0 if hemi=='lh' else 1 for hemi in self.hemi]
        rois = grow_labels(self.subject, mapped_vertices, extents, hemi, self.freesurfer_dir, surface=surface)
        if map_to_annot:
            structures, colors = self.map_to_annot(annot, map_surface=map_surface)
            for i in range(self.npoints):
                rois[i].color = colors[i]
                vertex = mapped_vertices[i]
                if add_vertex_to_name:
                    rois[i].name = structures[i]+'_{r}mm_{surf}_{vertex}'.format(r=extents[i],surf=surface,vertex=vertex)
                else:
                    rois[i].name = structures[i]+'_{r}mm_{surf}'.format(r=extents[i],surf=surface)
        elif hasattr(self,'name') or hasattr(self,'color'):
            for i in range(self.npoints):
                if hasattr(self,'name'):
                    vertex = mapped_vertices[i]
                    if add_vertex_to_name:
                        rois[i].name = self.name[i]+'_{r}mm_{surf}_{vertex}'.format(r=extents[i],surf=surface,vertex=vertex)
                    else:
                        rois[i].name = self.name[i]+'_{r}mm_{surf}'.format(r=extents[i],surf=surface,vertex=vertex)
                if hasattr(self,'color'):
                    rois[i].color = self.color[i]
        else:
            for i in range(self.npoints):
                vertex = mapped_vertices[i]
                if add_vertex_to_name:
                    rois[i].name = 'coor_id_{i}_{r}mm_{surf}_{vertex}'.format(r=extents[i],surf=surface,vertex=vertex,i=i)
                else:
                    rois[i].name = 'coor_id_{i}_{r}mm_{surf}_{vertex}'.format(r=extents[i],surf=surface,vertex=vertex,i=i)
        rois_path = []
        if not os.path.exists(os.path.join(wf_base_dir,wf_name)):
            os.makedirs(os.path.join(wf_base_dir,wf_name))
        for i,roi in enumerate(rois):
            os.environ['SUBJECTS_DIR'] = self.freesurfer_dir
            roi_path = '{wf_base_dir}/{wf_name}/{roi_name}-{hemi}.label'.format(wf_base_dir=wf_base_dir, wf_name=wf_name, roi_name=roi.name, hemi=roi.hemi)
            rois_path.append(roi_path)
            roi.save(roi_path)
        self.add_trait('roi', np.array(rois))
        return self.roi,rois_path
def create_surf_roi ( self , extents , surface = 'white' , map_surface = 'white' , map_to_annot = None , wf_base_dir = None , wf_name = 'surf_roi' , add_vertex_to_name = True ) : if wf_base_dir is None and self . working_dir is not None : wf_base_dir = self . working_dir elif wf_base_dir is None and self . working_dir is None : print ( 'Working dir has not been specified, results will be stored in:  ' , os . path . abspath ( '.' ) ) wf_base_dir = os . path . abspath ( '.' ) if len ( self . hemi_not_determined ) > 0 : raise ValueError ( 'Use set_hemi_manually to assign hemiphere to these points: %s' % ( ',' . join ( self . hemi_not_determined ) ) ) results = self . map_to_surface ( map_surface ) mapped_vertices , mapped_coords_ras_tkr , mapped_coords_ras = results [ 'vertices' ] , results [ 'ras_coord' ] , results [ 'ras_tkr_coord' ] if type ( extents ) == list or type ( extents ) == np . ndarray : assert ( len ( extents ) == self . npoints , 'extents can be either one number or a list where len(extents) is equal to number of points' ) else : extents = [ extents ] * self . npoints hemi = [ 0 if hemi == 'lh' else 1 for hemi in self . hemi ] rois = grow_labels ( self . subject , mapped_vertices , extents , hemi , self . freesurfer_dir , surface = surface ) if map_to_annot : structures , colors = self . map_to_annot ( annot , map_surface = map_surface ) for i in range ( self . npoints ) : rois [ i ] . color = colors [ i ] vertex = mapped_vertices [ i ] if add_vertex_to_name : rois [ i ] . name = structures [ i ] + '_{r}mm_{surf}_{vertex}' . format ( r = extents [ i ] , surf = surface , vertex = vertex ) else : rois [ i ] . name = structures [ i ] + '_{r}mm_{surf}' . format ( r = extents [ i ] , surf = surface ) elif hasattr ( self , 'name' ) or hasattr ( self , 'color' ) : for i in range ( self . npoints ) : if hasattr ( self , 'name' ) : vertex = mapped_vertices [ i ] if add_vertex_to_name : rois [ i ] . name = self . name [ i ] + '_{r}mm_{surf}_{vertex}' . format ( r = extents [ i ] , surf = surface , vertex = vertex ) else : rois [ i ] . name = self . name [ i ] + '_{r}mm_{surf}' . format ( r = extents [ i ] , surf = surface , vertex = vertex ) if hasattr ( self , 'color' ) : rois [ i ] . color = self . color [ i ] else : for i in range ( self . npoints ) : vertex = mapped_vertices [ i ] if add_vertex_to_name : rois [ i ] . name = 'coor_id_{i}_{r}mm_{surf}_{vertex}' . format ( r = extents [ i ] , surf = surface , vertex = vertex , i = i ) else : rois [ i ] . name = 'coor_id_{i}_{r}mm_{surf}_{vertex}' . format ( r = extents [ i ] , surf = surface , vertex = vertex , i = i ) rois_path = [ ] if not os . path . exists ( os . path . join ( wf_base_dir , wf_name ) ) : os . makedirs ( os . path . join ( wf_base_dir , wf_name ) ) for i , roi in enumerate ( rois ) : os . environ [ 'SUBJECTS_DIR' ] = self . freesurfer_dir roi_path = '{wf_base_dir}/{wf_name}/{roi_name}-{hemi}.label' . format ( wf_base_dir = wf_base_dir , wf_name = wf_name , roi_name = roi . name , hemi = roi . hemi ) rois_path . append ( roi_path ) roi . save ( roi_path ) self . add_trait ( 'roi' , np . array ( rois ) ) return self . roi , rois_path
creates surface ROIs for each coordinate point
Parameters
creates surface ROIs for each coordinate point Parameters
""" creates surface ROIs for each coordinate point
        
        Parameters
        ----------
        extents: float or numpy array
            specifies the raidus of the growing ROI. Either one single number for all the points or a numpy array containing 
            radius for each point
            
        surface: str
            specifies which surface to use for growing the ROIs ( white or pial)
            
        map_to_annot: str
            specifies which annotation to use to assign name and color to use for ROI labeling
      
        wf_base_dir: str
              workflow base dir
      
        wf_name: str
              workflow name , the results will be saved under <wf_base_dir>/<wf_name>
        
        add_vertex_to_name: boolean
              if True, adds the projected vertex number to the ROI name ( in case the ROIs might have similar naming, adding vertex number can help get rid of this issue)
      
        Returns
        -------
        
        rois: instances of class of Label 
      
        rois_paths: path to the saved labels
      
        """ ## wf_base_dir ### extents can be one number or an array, make it an array if it is a number ### get structures and color for labels according to annotation #### saving ROI labels ### saving ROI label ### converting list to arrays
self
extents
surface
map_surface
map_to_annot
wf_base_dir
wf_name
add_vertex_to_name