예제 #1
0
파일: dataview.py 프로젝트: mick-d/cvu
	def draw_surfs(self): 	
		from parsing_utils import demangle_hemi

		srf_scalar=self.ds.scalar_display_settings.surf_color
		
		if (self.ds.display_mode=='scalar' and srf_scalar):
			colors_lh=np.zeros((len(self.ds.srf.lh_verts)),)
			colors_rh=np.zeros((len(self.ds.srf.rh_verts)),)
			for i,l in enumerate(self.ds.labnam):
				#assumes that lh labels start with L and so on
				vertices=self.ds.labv[demangle_hemi(l)]
				if l[0]=='l':
					colors_lh[vertices]=self.ds.node_scalars[srf_scalar][i]
				elif l[0]=='r':
					colors_rh[vertices]=self.ds.node_scalars[srf_scalar][i]
			self.syrf_lh.mlab_source.scalars=colors_lh
			self.syrf_rh.mlab_source.scalars=colors_rh
			
			for syrf in (self.syrf_lh,self.syrf_rh):
				set_lut(syrf,self.ds.opts.scalar_map)
				syrf.actor.mapper.scalar_visibility=True

		else:
			for syrf in (self.syrf_lh,self.syrf_rh):
				syrf.actor.mapper.scalar_visibility=False
예제 #2
0
def loadannot_gifti(parcname,
                    subject,
                    subjects_dir,
                    labnam=None,
                    surf_type='pial',
                    surf_struct=None,
                    quiet=False):

    import numpy as np
    from nibabel import gifti

    fname = os.path.join(subjects_dir, subject, 'label',
                         'lh.%s.%sgii' % (parcname, '%s'))
    fname = match_gifti_intent(fname, 'label')

    annot_lh = gifti.read(parse.hemineutral(fname) % 'lh')
    annot_rh = gifti.read(parse.hemineutral(fname) % 'rh')

    #unpack the annotation data
    labdict_lh = parse.appendhemis(annot_lh.labeltable.get_labels_as_dict(),
                                   "lh_")
    labv_lh = map(labdict_lh.get, annot_lh.darrays[0].data)

    labdict_rh = parse.appendhemis(annot_rh.labeltable.get_labels_as_dict(),
                                   "rh_")
    labv_rh = map(labdict_rh.get, annot_rh.darrays[0].data)

    labv = labv_lh + labv_rh

    #return labv
    #The objective is now to create MNE label files for these on the fly

    vertices = np.vstack((surf_struct.lh_verts, surf_struct.rh_verts))
    mne_labels = []

    for lab in labnam:
        cur_lab_verts = np.flatnonzero(np.array(labv) == lab)
        cur_lab_pos = vertices[cur_lab_verts]

        cur_lab = mne.Label(cur_lab_verts,
                            pos=cur_lab_pos / 1000,
                            hemi=lab[:2],
                            name=parse.demangle_hemi(lab))
        mne_labels.append(cur_lab)

    return mne_labels
예제 #3
0
    def cracked_surfs_gen(self):
        from parsing_utils import demangle_hemi
        tri_inds_l, tri_inds_r = [], []
        #all lh nodes are assumed to start with l
        for l in self.ds.labnam:
            if l[0] == 'l':
                tris = self.ds.srf.lh_tris
                tri_inds = tri_inds_l
            elif l[0] == 'r':
                tris = self.ds.srf.rh_tris
                tri_inds = tri_inds_r
            else:
                self.error_dialog('Bad label name %s' % l)
                return

            #get the triangles entirely contained in this set of vertices
            v_as_set = set(self.ds.labv[demangle_hemi(l)])
            ts, = np.where([v_as_set.issuperset(tri) for tri in tris])
            tri_inds.extend(ts)

        self.syrf_lh = mlab.triangular_mesh(
            self.ds.srf.lh_verts[:, 0],
            self.ds.srf.lh_verts[:, 1],
            self.ds.srf.lh_verts[:, 2],
            self.ds.srf.lh_tris[tri_inds_l],
            opacity=self.ds.opts.surface_visibility,
            color=self.ds.default_glass_brain_color,
            figure=self.scene.mayavi_scene)
        self.syrf_rh = mlab.triangular_mesh(
            self.ds.srf.rh_verts[:, 0],
            self.ds.srf.rh_verts[:, 1],
            self.ds.srf.rh_verts[:, 2],
            self.ds.srf.rh_tris[tri_inds_r],
            opacity=self.ds.opts.surface_visibility,
            color=self.ds.default_glass_brain_color,
            figure=self.scene.mayavi_scene)

        self.surfs_cracked = True

        for syrf in (self.syrf_lh, self.syrf_rh):
            syrf.actor.actor.pickable = 0
            set_lut(syrf, self.ds.opts.scalar_map)

        self.ds.chg_lh_surfmask()
        self.ds.chg_rh_surfmask()
예제 #4
0
파일: dataview.py 프로젝트: aestrivex/cvu
    def cracked_surfs_gen(self): 
        from parsing_utils import demangle_hemi
        tri_inds_l,tri_inds_r=[],[]
        #all lh nodes are assumed to start with l
        for l in self.ds.labnam:
            if l[0]=='l':
                tris=self.ds.srf.lh_tris; tri_inds=tri_inds_l
            elif l[0]=='r':
                tris=self.ds.srf.rh_tris; tri_inds=tri_inds_r
            else:
                self.error_dialog('Bad label name %s'%l)
                return

            #get the triangles entirely contained in this set of vertices
            v_as_set=set(self.ds.labv[demangle_hemi(l)])
            ts,=np.where([v_as_set.issuperset(tri) for tri in tris])
            tri_inds.extend(ts)

        self.syrf_lh=mlab.triangular_mesh(
            self.ds.srf.lh_verts[:,0],self.ds.srf.lh_verts[:,1],
            self.ds.srf.lh_verts[:,2],self.ds.srf.lh_tris[tri_inds_l],
            opacity=self.ds.opts.surface_visibility,
            color=self.ds.default_glass_brain_color,
            figure=self.scene.mayavi_scene)
        self.syrf_rh=mlab.triangular_mesh(
            self.ds.srf.rh_verts[:,0],self.ds.srf.rh_verts[:,1],
            self.ds.srf.rh_verts[:,2],self.ds.srf.rh_tris[tri_inds_r],
            opacity=self.ds.opts.surface_visibility,
            color=self.ds.default_glass_brain_color,
            figure=self.scene.mayavi_scene)

        self.surfs_cracked=True

        for syrf in (self.syrf_lh,self.syrf_rh):
            syrf.actor.actor.pickable=0
            set_lut(syrf,self.ds.opts.scalar_map)

        self.ds.chg_lh_surfmask(); self.ds.chg_rh_surfmask()
예제 #5
0
def loadannot_gifti(parcname, subject, subjects_dir, labnam=None, surf_type='pial',
        surf_struct=None, quiet=False):

    import numpy as np
    from nibabel import gifti

    fname = os.path.join(subjects_dir, subject, 'label', 'lh.%s.%sgii'%(parcname,'%s'))
    fname = match_gifti_intent(fname, 'label')

    annot_lh = gifti.read(parse.hemineutral(fname)%'lh')
    annot_rh = gifti.read(parse.hemineutral(fname)%'rh')
    
    #unpack the annotation data
    labdict_lh=parse.appendhemis(annot_lh.labeltable.get_labels_as_dict(),"lh_")
    labv_lh=map(labdict_lh.get,annot_lh.darrays[0].data)

    labdict_rh=parse.appendhemis(annot_rh.labeltable.get_labels_as_dict(),"rh_")
    labv_rh=map(labdict_rh.get,annot_rh.darrays[0].data)

    labv=labv_lh+labv_rh

    #return labv
    #The objective is now to create MNE label files for these on the fly

    vertices = np.vstack((surf_struct.lh_verts, surf_struct.rh_verts))
    mne_labels = []

    for lab in labnam:
        cur_lab_verts = np.flatnonzero(np.array(labv)==lab)
        cur_lab_pos = vertices[cur_lab_verts]

        cur_lab = mne.Label(cur_lab_verts, pos=cur_lab_pos/1000, hemi=lab[:2],
            name = parse.demangle_hemi(lab))
        mne_labels.append(cur_lab)
        
    return mne_labels	
예제 #6
0
    def draw_surfs(self):
        from parsing_utils import demangle_hemi

        srf_scalar = self.ds.scalar_display_settings.surf_color
        nc = self.ds.scalar_display_settings.node_color

        if (self.ds.display_mode == 'scalar' and srf_scalar):

            scalars = self.ds.node_scalars[srf_scalar]
            colors_lh = np.zeros((len(self.ds.srf.lh_verts)), )
            colors_rh = np.zeros((len(self.ds.srf.rh_verts)), )
            for i, l in enumerate(self.ds.labnam):
                #assumes that lh labels start with L and so on
                vertices = self.ds.labv[demangle_hemi(l)]
                if l[0] == 'l':
                    colors_lh[vertices] = scalars[i]
                elif l[0] == 'r':
                    colors_rh[vertices] = scalars[i]
            self.syrf_lh.mlab_source.scalars = colors_lh
            self.syrf_rh.mlab_source.scalars = colors_rh

            for syrf in (self.syrf_lh, self.syrf_rh):
                set_lut(syrf, self.ds.opts.scalar_map)
                set_color_range(syrf, scalars)
                syrf.actor.mapper.scalar_visibility = True

        #we don't need to set the scalars properly, but lets set the scalar range
        #of the surface properly so that a colorbar will capture it
        elif (self.ds.display_mode == 'scalar' and nc):
            scalars = self.ds.node_scalars[nc]
            #the scalar colorbar refers to syrf_lh only
            min_scale, max_scale = np.min(scalars), np.max(scalars)
            colors = np.tile(min_scale, (len(self.ds.srf.lh_verts), ))
            colors[0] = max_scale
            self.syrf_lh.mlab_source.scalars = colors

            for syrf in (self.syrf_lh, self.syrf_rh):
                syrf.actor.mapper.scalar_visibility = False

        elif (self.ds.display_mode == 'module_multi'
              and self.ds.opts.modules_on_surface):

            new_colors = np.array(self.ds.module_colors[:self.ds.nr_modules +
                                                        1])

            for syrf, nodes, letter, verts in ((self.syrf_lh, self.ds.lhnodes,
                                                'l', self.ds.srf.lh_verts),
                                               (self.syrf_rh, self.ds.rhnodes,
                                                'r', self.ds.srf.rh_verts)):

                colors = np.zeros((len(verts)), )

                manager = syrf.module_manager.scalar_lut_manager
                #set the mayavi object to the dummy cmap
                #so that when changed notifications will work correctly
                manager.lut_mode = 'black-white'
                #now adjust its LUT manually
                manager.number_of_colors = self.ds.nr_modules
                manager.lut.table = new_colors

                import bct
                ci = bct.ls2ci(self.ds.modules, zeroindexed=True)[nodes]

                i = 0
                for l in self.ds.labnam:
                    #assumes that lh labels start with L and so on
                    if not l[0] == letter:
                        continue
                    vertices = self.ds.labv[demangle_hemi(l)]
                    colors[vertices] = ci[i] + 1
                    i += 1

                syrf.mlab_source.scalars = colors

                set_color_range(syrf, (0., self.ds.nr_modules + 1))
                syrf.actor.mapper.scalar_visibility = True

        else:
            for syrf in (self.syrf_lh, self.syrf_rh):
                syrf.actor.mapper.scalar_visibility = False
예제 #7
0
파일: dataview.py 프로젝트: aestrivex/cvu
    def draw_surfs(self): 	
        from parsing_utils import demangle_hemi

        srf_scalar=self.ds.scalar_display_settings.surf_color
        nc = self.ds.scalar_display_settings.node_color
        
        if (self.ds.display_mode=='scalar' and srf_scalar):

            scalars = self.ds.node_scalars[srf_scalar]
            colors_lh=np.zeros((len(self.ds.srf.lh_verts)),)
            colors_rh=np.zeros((len(self.ds.srf.rh_verts)),)
            for i,l in enumerate(self.ds.labnam):
                #assumes that lh labels start with L and so on
                vertices=self.ds.labv[demangle_hemi(l)]
                if l[0]=='l':
                    colors_lh[vertices] = scalars[i]
                elif l[0]=='r':
                    colors_rh[vertices] = scalars[i]
            self.syrf_lh.mlab_source.scalars=colors_lh
            self.syrf_rh.mlab_source.scalars=colors_rh
            
            for syrf in (self.syrf_lh,self.syrf_rh):
                set_lut(syrf,self.ds.opts.scalar_map)
                set_color_range(syrf, scalars)
                syrf.actor.mapper.scalar_visibility=True

        #we don't need to set the scalars properly, but lets set the scalar range
        #of the surface properly so that a colorbar will capture it
        elif (self.ds.display_mode=='scalar' and nc):
            scalars = self.ds.node_scalars[nc]
            #the scalar colorbar refers to syrf_lh only
            min_scale, max_scale = np.min(scalars), np.max(scalars)
            colors = np.tile(min_scale, (len(self.ds.srf.lh_verts),))
            colors[0] = max_scale
            self.syrf_lh.mlab_source.scalars = colors

            for syrf in (self.syrf_lh,self.syrf_rh):
                syrf.actor.mapper.scalar_visibility=False

        elif (self.ds.display_mode=='module_multi' and 
                self.ds.opts.modules_on_surface):
             
            new_colors=np.array(self.ds.module_colors[:self.ds.nr_modules+1])

            for syrf,nodes,letter,verts in (
                    (self.syrf_lh,self.ds.lhnodes,'l',self.ds.srf.lh_verts),
                    (self.syrf_rh,self.ds.rhnodes,'r',self.ds.srf.rh_verts)):

                colors=np.zeros((len(verts)),)

                manager=syrf.module_manager.scalar_lut_manager
                #set the mayavi object to the dummy cmap
                #so that when changed notifications will work correctly
                manager.lut_mode='black-white'
                #now adjust its LUT manually
                manager.number_of_colors=self.ds.nr_modules
                manager.lut.table=new_colors	

                import bct
                ci = bct.ls2ci(self.ds.modules,zeroindexed=True)[nodes]

                i = 0
                for l in self.ds.labnam:
                    #assumes that lh labels start with L and so on
                    if not l[0]==letter:
                        continue
                    vertices=self.ds.labv[demangle_hemi(l)]
                    colors[vertices] = ci[i]+1
                    i+=1

                syrf.mlab_source.scalars = colors

                set_color_range(syrf, (0., self.ds.nr_modules+1))
                syrf.actor.mapper.scalar_visibility=True

        else:
            for syrf in (self.syrf_lh,self.syrf_rh):
                syrf.actor.mapper.scalar_visibility=False