Esempio n. 1
0
    def display(self):
        """ Display Electrode in Mayavi """
        f = mlab.figure(figure=mlab.gcf(),
                        bgcolor=(0,0,0),
                        size=(800,600))

        # Call Super Class
        Electrode.display(self)

        # Build electrode contacts
        c0 = find_new_point(self.sphere_center, self.direction, self.contact_height * 3 / 2)
        c1 = find_new_point(self.sphere_center, self.direction, self.contact_height * 7 / 2)
        c2 = find_new_point(self.sphere_center, self.direction, self.contact_height * 11 / 2)
        c3 = find_new_point(self.sphere_center, self.direction, self.contact_height * 15 / 2)

        contactCenters = array([c0, c1, c2, c3])
        contact = []
        for ii in xrange(4):
            topContact = find_new_point(contactCenters[ii,:], self.direction, self.contact_height / 2)
            bottomContact = find_new_point(contactCenters[ii,:], [-1 * ii for ii in self.direction], self.contact_height / 2)
            contact.append([bottomContact, topContact])

        contact_array = array(contact)
        x, y, z = contact_array.T

        activity_array = array([
            [self.contact0, self.contact0],
            [self.contact1, self.contact1],
            [self.contact2, self.contact2],
            [self.contact3, self.contact3]])
        src = pipeline.scalar_scatter(x.T, y.T, z.T, activity_array)
        src.mlab_source.dataset.lines = array([[0, 1], [2, 3], [4, 5], [6, 7]])
        src.name = 'Contacts'

        self.mlab_contacts = pipeline.tube(src,
                                                tube_radius=self.diameter * 1.03 / 2,
                                                tube_sides=40,
                                                name='DBS Contacts',)
        stripper = pipeline.stripper(self.mlab_contacts)
        surface = pipeline.surface(stripper)
        self.mlab_contacts.filter.capping = True
        surface.module_manager.scalar_lut_manager.lut_mode = 'RdBu'
        surface.module_manager.scalar_lut_manager.reverse_lut = True
        #surface.module_manager.scalar_lut_manager.use_default_range = False
        surface.module_manager.scalar_lut_manager.use_default_range = True
        surface.module_manager.scalar_lut_manager.data_range = array([-1., 1.])
    def display(self,
                func,
                segfunc=False,
                scaling=1,
                replace=True,
                clim=None,
                colormap='jet'):
        ''' Display current cell in mayavi
        '''
        #from neuron import h
        from numpy import array, vstack, float_
        from enthought.mayavi import mlab
        from enthought.mayavi.mlab import pipeline
        if replace:
            try:
                self.mlab_cell.parent.parent.parent.parent.parent.parent.remove(
                )
            except AttributeError:
                pass
        ### Turn off vtk warnings # # # # # # # # # # # # # # # # # # # # # # #
        from vtk import vtkObject
        o = vtkObject
        o.GetGlobalWarningDisplay()
        o.SetGlobalWarningDisplay(0)  # Turn it off.

        f = mlab.figure(figure=mlab.gcf(), bgcolor=(1, 1, 1), size=(800, 600))

        self.build_tree(func, segfunc)
        ##        xs = self.xyzdv[:,0]
        ##        ys = self.xyzdv[:,1]
        ##        zs = self.xyzdv[:,2]
        xs = float_(self.xyzdv[:, 0])
        ys = float_(self.xyzdv[:, 1])
        zs = float_(self.xyzdv[:, 2])

        # don't want scaling for soma segments
        ##        diams = self.xyzdv[:,3]
        diams = float_(self.xyzdv[:, 3])
        #nonsoma = (diams < 15) # non-somatic
        nonsoma = ones(shape(diams))
        diams += diams * nonsoma * (scaling - 1)
        #diams = self.xyzdv[:,3] * scaling # larger scaling makes neurons more visible
        ##        data = self.xyzdv[:,4]
        data = float_(self.xyzdv[:, 4])
        edges = self.connections

        # Display in mayavi
        pts = pipeline.scalar_scatter(xs, ys, zs, diams / 2.0, name=str(self))
        dataset = pts.mlab_source.dataset
        dataset.point_data.get_array(0).name = 'diameter'
        dataset.lines = vstack(edges)

        array_id = dataset.point_data.add_array(data.T.ravel())
        dataset.point_data.get_array(array_id).name = 'data'
        dataset.point_data.update()

        #### Create tube with diameter data
        src = pipeline.set_active_attribute(pts, point_scalars='diameter')
        stripper = pipeline.stripper(src)
        tube = pipeline.tube(stripper, tube_sides=8, tube_radius=1)
        tube.filter.capping = True
        tube.filter.use_default_normal = False
        tube.filter.vary_radius = 'vary_radius_by_absolute_scalar'
        #tube.filter.radius_factor = 90.0 # just for making movies
        src2 = pipeline.set_active_attribute(tube, point_scalars='data')

        lines = pipeline.surface(src2, colormap=colormap)
        if clim:
            from numpy import array
            lines.parent.scalar_lut_manager.use_default_range = False
            lines.parent.scalar_lut_manager.data_range = array(clim)
        self.mlab_cell = lines
Esempio n. 3
0
    def display(self, var='v', scaling=1):
        ''' Display current cell in mayavi'''
        from neuron import h
        from numpy import array, vstack
        from enthought.mayavi import mlab
        from enthought.mayavi.mlab import pipeline
        try:
            self.mlab_cell.parent.parent.parent.parent.parent.parent.remove()
        except:
            pass
        f = mlab.figure(figure=mlab.gcf(),
                        bgcolor=(0,0,0),
                        size=(800,600))

        ### Turn off vtk warnings # # # # # # # # # # # # # # # # # # # # # # #
        from vtk import vtkObject
        o = vtkObject
        o.GetGlobalWarningDisplay()
        o.SetGlobalWarningDisplay(0) # Turn it off.

        self.var = var
        self.build_tree()
        xs = self.xyzdv[:,0]
        ys = self.xyzdv[:,1]
        zs = self.xyzdv[:,2]
        diams = self.xyzdv[:,3] * scaling # larger scaling makes neurons more visible
        data = self.xyzdv[:,4]
        edges = self.connections

        # Display in mayavi
        #Create Scalar scatter with diameter data and edges
        #pts = pipeline.scalar_scatter(xs, ys, zs, diams)

        # Display in mayavi
        pts = pipeline.scalar_scatter(xs, ys, zs, diams/2.0,
                                      name=self.name)
        dataset = pts.mlab_source.dataset
        dataset.point_data.get_array(0).name = 'diameter'
        dataset.lines = vstack(edges)

        array_id = dataset.point_data.add_array(data.T.ravel())
        dataset.point_data.get_array(array_id).name = 'data'
        dataset.point_data.update()

        #### Create tube with diameter data
        src = pipeline.set_active_attribute(pts,
                                            point_scalars='diameter')
        stripper = pipeline.stripper(src)
        tube = pipeline.tube(stripper,
                             tube_sides = 8,
                             tube_radius = 1)
        tube.filter.capping = True
        tube.filter.use_default_normal = False
        tube.filter.vary_radius = 'vary_radius_by_absolute_scalar'
        #tube.filter.radius_factor = 90.0 # just for making movies
        src2 = pipeline.set_active_attribute(tube, point_scalars='data')

        lines = pipeline.surface(src2)
        self.mlab_cell = lines

        if self.var is 'v':
            self.mlab_cell.module_manager.scalar_lut_manager.use_default_range=False
            self.mlab_cell.module_manager.scalar_lut_manager.data_range = array([-70, 0])
        mlab.view(azimuth = 133.48567814586244,
                  elevation = 72.824281412546014,
                  distance = 409.81131636077509,
                  focalpoint = array([-4502.1515611 ,  5031.21983918, -2293.53156414]))