Ejemplo n.º 1
0
 def set_node_colors(self):
     #set node_colors
     if self.display_mode == 'normal':
         self.node_colors = list(self.node_colors_default)
     elif self.display_mode == 'scalar':
         #node colors are not used here, instead the scalar value is set directly
         self.node_colors = list(self.node_colors_default)
     elif self.display_mode == 'module_single':
         new_colors = np.tile(.3, self.nr_labels)
         new_colors[self.get_module()] = .8
         self.node_colors = list(self.opts.default_map._pl(new_colors))
     elif self.display_mode == 'module_multi':
         while self.nr_modules > len(self.module_colors):
             i, j = np.random.randint(18, size=(2, ))
             col = (np.array(self.module_colors[i]) +
                    self.module_colors[j]) / 2
             col = np.array(col, dtype=int)
             self.module_colors.append(col.tolist())
         #perm=np.random.permutation(len(self.module_colors))
         #mayavi scalars depend on saving the module colors
         #self.module_colors=np.array(self.module_colors)[perm].tolist()
         cols = self.module_colors[:self.nr_modules]
         import bct
         ci = bct.ls2ci(self.modules, zeroindexed=True)
         self.node_colors = ((np.array(self.module_colors)[ci]) /
                             255).tolist()
Ejemplo n.º 2
0
	def draw_nodes(self): 
		nc=self.ds.scalar_display_settings.node_color
		ns=self.ds.scalar_display_settings.node_size

		lhn=self.nodes_lh; lhn_ix=self.ds.lhnodes
		rhn=self.nodes_rh; rhn_ix=self.ds.rhnodes

		for nodes,ixes in ((lhn,lhn_ix),(rhn,rhn_ix)):
			nr=len(ixes)
			#set node size
			if self.ds.display_mode=='scalar' and ns:
				nodes.glyph.scale_mode='scale_by_vector'
				nodes.glyph.glyph.scale_factor=8
				nodes.mlab_source.dataset.point_data.vectors=(
					np.tile(self.ds.node_scalars[ns][ixes],(3,1)).T)
			else:
				nodes.glyph.scale_mode='data_scaling_off'
				nodes.glyph.glyph.scale_factor=3

		#set node color -- we dont care about ds.node_colors for mayavi
			if (self.ds.display_mode=='normal' or
					(self.ds.display_mode=='scalar' and not nc)):
				set_lut(nodes,self.ds.opts.default_map)
				nodes.mlab_source.dataset.point_data.scalars=np.tile(.3,nr)

			elif self.ds.display_mode=='scalar': #and nc must be true
				set_lut(nodes,self.ds.opts.scalar_map)
				nodes.mlab_source.dataset.point_data.scalars=(
					self.ds.node_scalars[nc][ixes])

			elif self.ds.display_mode=='module_single':
				set_lut(nodes,self.ds.opts.default_map)
				new_colors=np.tile(.3,self.ds.nr_labels)
				new_colors[self.ds.get_module()]=.8
				nodes.mlab_source.dataset.point_data.scalars=new_colors[ixes]

			elif self.ds.display_mode=='module_multi':
				new_colors=np.array(self.ds.module_colors[:self.ds.nr_modules])
				manager=nodes.module_manager.scalar_lut_manager
				#set the mayavi object to the dummy cmap that we hide from user
				#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	

				#set the mayavi scalars to be fractions between 0 and 1
				import bct
				nodes.mlab_source.dataset.point_data.scalars=(bct.ls2ci(
					self.ds.modules,zeroindexed=True)/self.ds.nr_modules)[ixes]

		mlab.draw()
Ejemplo n.º 3
0
	def calculate_graph_stats(self,thres):
		import graph,bct
		thres_adj = self.adj.copy()
		thres_adj[thres_adj < thres] = 0
		self.verbose_msg('Threshold for graph calculations: %s'%str(thres))
		try:
			self.graph_stats=graph.do_summary(thres_adj,bct.ls2ci(self.modules),
				self.opts.intermediate_graphopts_list)

			for name,arr in self.graph_stats.iteritems():
				self.save_scalar(name,arr,passive=True)
		except CVUError:
			self.error_dialog("Community structure required for some of "
				"the calculations specified.  Try calculating modules first.")
Ejemplo n.º 4
0
    def calculate_graph_stats(self, thres):
        import graph, bct
        thres_adj = self.adj.copy()
        thres_adj[thres_adj < thres] = 0
        self.verbose_msg('Threshold for graph calculations: %s' % str(thres))
        try:
            self.graph_stats = graph.do_summary(
                thres_adj, bct.ls2ci(self.modules),
                self.opts.intermediate_graphopts_list)

            for name, arr in self.graph_stats.iteritems():
                self.save_scalar(name, arr, passive=True)
        except CVUError:
            self.error_dialog(
                "Community structure required for some of "
                "the calculations specified.  Try calculating modules first.")
Ejemplo n.º 5
0
	def set_node_colors(self):
		#set node_colors
		if self.display_mode=='normal':
			self.node_colors=list(self.node_colors_default)
		elif self.display_mode=='scalar':
		#node colors are not used here, instead the scalar value is set directly
			self.node_colors=list(self.node_colors_default)
		elif self.display_mode=='module_single':
			new_colors=np.tile(.3,self.nr_labels)
			new_colors[self.get_module()]=.8
			self.node_colors=list(self.opts.default_map._pl(new_colors))
		elif self.display_mode=='module_multi':
			while self.nr_modules > len(self.module_colors):
				i,j=np.random.randint(18,size=(2,))
				col=(np.array(self.module_colors[i])+self.module_colors[j])/2
				col=np.array(col,dtype=int)
				self.module_colors.append(col.tolist())
			perm=np.random.permutation(len(self.module_colors))
			#mayavi scalars depend on saving the module colors
			self.module_colors=np.array(self.module_colors)[perm].tolist()
			cols=self.module_colors[:self.nr_modules]
			import bct
			ci=bct.ls2ci(self.modules,zeroindexed=True)
			self.node_colors=((np.array(self.module_colors)[ci])/255).tolist()
Ejemplo n.º 6
0
    def draw_nodes(self):
        nc = self.ds.scalar_display_settings.node_color
        ns = self.ds.scalar_display_settings.node_size

        lhn = self.nodes_lh
        lhn_ix = self.ds.lhnodes
        rhn = self.nodes_rh
        rhn_ix = self.ds.rhnodes

        for nodes, ixes in ((lhn, lhn_ix), (rhn, rhn_ix)):
            nr = len(ixes)
            #set node size
            if self.ds.display_mode == 'scalar' and ns:
                scalars = self.ds.node_scalars[ns]
                #for node size, the scalars need to be scaled to 0-1
                scalars = (scalars - np.min(scalars)) / (np.max(scalars) -
                                                         np.min(scalars))
                #logarithmic scaling does a better job of differentiating large nodes
                scalars = (np.exp(scalars * np.log(2)) - 1) / (np.e - 1)
                #scalars=(4**(scalars*np.log(3)/np.log(4))-1)/3
                #scalars=(4**scalars-1)/3
                #scalars**=2

                nodes.glyph.scale_mode = 'scale_by_vector'
                nodes.glyph.glyph.scale_factor = 12
                nodes.mlab_source.dataset.point_data.vectors = (np.tile(
                    scalars[ixes], (3, 1)).T)
            else:
                nodes.glyph.scale_mode = 'data_scaling_off'
                nodes.glyph.glyph.scale_factor = 3

        #set node color -- we dont care about ds.node_colors for mayavi
            if (self.ds.display_mode == 'normal'
                    or (self.ds.display_mode == 'scalar' and not nc) or
                (self.ds.display_mode in ['module_single', 'module_multi']
                 and self.ds.opts.modules_on_surface)):
                scalars = np.tile(.3, nr)
                set_lut(nodes, self.ds.opts.default_map)
                set_color_range(nodes, (0., 1.))
                nodes.mlab_source.dataset.point_data.scalars = scalars

            elif self.ds.display_mode == 'scalar':  #and nc must be true
                scalars = self.ds.node_scalars[nc]
                set_lut(nodes, self.ds.opts.scalar_map)
                set_color_range(nodes, scalars)
                nodes.mlab_source.dataset.point_data.scalars = scalars[ixes]

            elif self.ds.display_mode == 'module_single':
                scalars = np.tile(.3, self.ds.nr_labels)
                scalars[self.ds.get_module()] = .8
                set_lut(nodes, self.ds.opts.default_map)
                set_color_range(nodes, (0., 1.))
                nodes.mlab_source.dataset.point_data.scalars = scalars[ixes]

            elif self.ds.display_mode == 'module_multi':
                new_colors = np.array(
                    self.ds.module_colors[:self.ds.nr_modules + 1])
                manager = nodes.module_manager.scalar_lut_manager
                #set the mayavi object to the dummy cmap that we hide from user
                #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

                #set the mayavi scalars to be fractions between 0 and 1
                import bct
                nodes.mlab_source.dataset.point_data.scalars = (bct.ls2ci(
                    self.ds.modules, zeroindexed=True))[ixes] + 1
                set_color_range(nodes, (0., self.ds.nr_modules + 1))

        mlab.draw()
Ejemplo n.º 7
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
Ejemplo n.º 8
0
    def draw_nodes(self): 
        nc=self.ds.scalar_display_settings.node_color
        ns=self.ds.scalar_display_settings.node_size

        lhn=self.nodes_lh; lhn_ix=self.ds.lhnodes
        rhn=self.nodes_rh; rhn_ix=self.ds.rhnodes

        for nodes,ixes in ((lhn,lhn_ix),(rhn,rhn_ix)):
            nr=len(ixes)
            #set node size
            if self.ds.display_mode=='scalar' and ns:
                scalars = self.ds.node_scalars[ns]
                #for node size, the scalars need to be scaled to 0-1
                scalars = (scalars-np.min(scalars)) / (np.max(scalars)-np.min(scalars))
                #logarithmic scaling does a better job of differentiating large nodes
                scalars = (np.exp(scalars*np.log(2))-1)/(np.e-1)	
                #scalars=(4**(scalars*np.log(3)/np.log(4))-1)/3
                #scalars=(4**scalars-1)/3
                #scalars**=2

                nodes.glyph.scale_mode='scale_by_vector'
                nodes.glyph.glyph.scale_factor=12
                nodes.mlab_source.dataset.point_data.vectors=(
                    np.tile(scalars[ixes],(3,1)).T)
            else:
                nodes.glyph.scale_mode='data_scaling_off'
                nodes.glyph.glyph.scale_factor=3

        #set node color -- we dont care about ds.node_colors for mayavi
            if (self.ds.display_mode=='normal' or
                    (self.ds.display_mode=='scalar' and not nc) or
                    (self.ds.display_mode in ['module_single', 
                        'module_multi'] and self.ds.opts.modules_on_surface)):
                scalars = np.tile(.3, nr)
                set_lut(nodes, self.ds.opts.default_map)
                set_color_range(nodes, (0.,1.))
                nodes.mlab_source.dataset.point_data.scalars = scalars

            elif self.ds.display_mode=='scalar': #and nc must be true
                scalars = self.ds.node_scalars[nc]
                set_lut(nodes, self.ds.opts.scalar_map)
                set_color_range(nodes, scalars)
                nodes.mlab_source.dataset.point_data.scalars = scalars[ixes]

            elif self.ds.display_mode=='module_single':
                scalars = np.tile(.3, self.ds.nr_labels)
                scalars[self.ds.get_module()]=.8
                set_lut(nodes, self.ds.opts.default_map)
                set_color_range(nodes, (0.,1.))
                nodes.mlab_source.dataset.point_data.scalars = scalars[ixes]

            elif self.ds.display_mode=='module_multi':
                new_colors=np.array(self.ds.module_colors[
                    :self.ds.nr_modules+1])
                manager=nodes.module_manager.scalar_lut_manager
                #set the mayavi object to the dummy cmap that we hide from user
                #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

                #set the mayavi scalars to be fractions between 0 and 1
                import bct
                nodes.mlab_source.dataset.point_data.scalars=(bct.ls2ci(
                    self.ds.modules,zeroindexed=True))[ixes]+1
                set_color_range(nodes, (0., self.ds.nr_modules+1))

        mlab.draw()
Ejemplo n.º 9
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