def __init__( self, data, radius=10, color="salmon", alpha=1, show_injection=True, name=None, ): """ Turns streamlines data to a mesh. :param data: pd.DataFrame with streamlines points data :param radius: float. Radius of the Tube mesh used to render streamlines :param color: str, name of the color to be used :param alpha: float, transparancy :param name: str, name of the actor. :param show_injection: bool. If true spheres mark the injection sites """ logger.debug(f"Creating a streamlines actor") if isinstance(data, (str, Path)): data = pd.read_json(data) elif not isinstance(data, pd.DataFrame): raise TypeError("Input data should be a dataframe") self.radius = radius mesh = ( self._make_mesh(data, show_injection=show_injection) .c(color) .alpha(alpha) .clean() ) name = name or "Streamlines" Actor.__init__(self, mesh, name=name, br_class="Streamliness")
def __init__(self, data, name=None, colors="salmon", alpha=1, radius=20): """ Creates an actor representing multiple points (more efficient than creating many Point instances). :param data: np.ndarray, Nx3 array or path to .npy file with coords data :param radius: float :param color: str, or list of str with color names or hex codes :param alpha: float :param name: str, actor name """ PointsBase.__init__(self) self.radius = radius self.colors = colors self.alpha = alpha self.name = name if isinstance(data, np.ndarray): mesh = self._from_numpy(data) elif isinstance(data, (str, Path)): mesh = self._from_file(data) else: # pragma: no cover raise TypeError( # pragma: no cover f"Input data should be either a numpy array or a file path, not: {_class_name(data)}" # pragma: no cover ) # pragma: no cover Actor.__init__(self, mesh, name=self.name, br_class="Points")
def __init__(self, pos, root, color="powderblue", alpha=1, radius=350): """ Cylinder class creates a cylinder mesh between a given point and the brain's surface. :param pos: list, np.array of ap, dv, ml coordinates. If an actor is passed, get's the center of mass instead :param root: brain root Actor or mesh object :param color: str, color :param alpha: float :param radius: float """ # Get pos if isinstance(pos, Mesh): pos = pos.points().mean(axis=0) elif isinstance(pos, Actor): pos = pos.center logger.debug(f"Creating Cylinder actor at: {pos}") # Get point at top of cylinder top = pos.copy() top[1] = root.bounds()[2] - 500 # Create mesh and Actor mesh = shapes.Cylinder(pos=[top, pos], c=color, r=radius, alpha=alpha) Actor.__init__(self, mesh, name="Cylinder", br_class="Cylinder")
def __init__(self, *args, ROIs=None, **kwargs): self.ROIs = ROIs or [ (0, self.length), ] ProbeGeometry.__init__(self, *args, **kwargs) Actor.__init__(self, self.get_mesh(), name="Probe", br_class="Probe")
def __init__(self, data, name=None, dims=(40, 40, 40), radius=None, **kwargs): """ Creates a Volume actor showing the 3d density of a set of points. :param data: np.ndarray, Nx3 array with cell coordinates from vedo: Generate a density field from a point cloud. Input can also be a set of 3D coordinates. Output is a ``Volume``. The local neighborhood is specified as the `radius` around each sample position (each voxel). The density is expressed as the number of counts in the radius search. :param int,list dims: numer of voxels in x, y and z of the output Volume. """ volume = vPoints(data).density(dims=dims, radius=radius, **kwargs) # returns a vedo Volume Actor.__init__(self, volume, name=name, br_class="density")
def __init__(self, data, name=None, dims=(40, 40, 40), radius=None, **kwargs): """ Creates a Volume actor showing the 3d density of a set of points. :param data: np.ndarray, Nx3 array with cell coordinates from vedo: Generate a density field from a point cloud. Input can also be a set of 3D coordinates. Output is a ``Volume``. The local neighborhood is specified as the `radius` around each sample position (each voxel). The density is expressed as the number of counts in the radius search. :param int,list dims: numer of voxels in x, y and z of the output Volume. """ logger.debug("Creating a PointsDensity actor") # flip coordinates on XY axis to match brainrender coordinates system # data[:, 2] = -data[:, 2] # create volume and then actor volume = (vPoints(data).density(dims=dims, radius=radius, **kwargs).c("Dark2").alpha([0, 0.9 ]).mode(1) ) # returns a vedo Volume volume.mirror("z") Actor.__init__(self, volume, name=name, br_class="density")
def __init__( self, griddata, voxel_size=1, cmap="bwr", min_quantile=None, min_value=None, name=None, br_class=None, as_surface=True, **volume_kwargs, ): """ Takes a 3d numpy array with volumetric data and returns an Actor with mesh: vedo.Volume.isosurface or a vedo.Volume. BY default the volume is represented as a surface To extract the surface: The isosurface needs a lower bound threshold, this can be either a user defined hard value (min_value) or the value corresponding to some percentile of the grid data. :param griddata: np.ndarray, 3d array with grid data :param voxel_size: int, size of each voxel in microns :param min_quantile: float, percentile for threshold :param min_value: float, value for threshold :param cmap: str, name of colormap to use :param as_surface, bool. default True. If True a surface mesh is returned instead of the whole volume :param volume_kwargs: keyword arguments for vedo's Volume class """ # Create mesh color = volume_kwargs.pop("c", "viridis") if isinstance(griddata, np.ndarray): # create volume from data mesh = VedoVolume( griddata, spacing=[voxel_size, voxel_size, voxel_size], c=color, **volume_kwargs, ) else: mesh = griddata # assume a vedo Volume was passed if as_surface: # Get threshold if min_quantile is None and min_value is None: th = 0 elif min_value is not None: th = min_value else: th = np.percentile(griddata.ravel(), min_quantile) mesh = mesh.legosurface(vmin=th, cmap=cmap) Actor.__init__(self, mesh, name=name or "Volume", br_class=br_class or "Volume")
def __init__(self, data, radius=10, color="salmon", alpha=1, name=None): """ Turns streamlines data to a mesh. :param data: pd.DataFrame with streamlines points data :param radius: float. Radius of the Tube mesh used to render streamlines :param color: str, name of the color to be used :param alpha: float, transparancy :param name: str, name of the actor. """ if not isinstance(data, pd.DataFrame): raise TypeError("Input data should be a dataframe") self.radius = radius mesh = self._make_mesh(data).c(color).alpha(alpha) name = name or "Streamlines" Actor.__init__(self, mesh, name=name, br_class="Streamliness")
def __init__(self, pos, radius=100, color="blackboard", alpha=1, res=25, name=None): """ Creates an actor representing a single point :param pos: list or np.ndarray with coordinates :param radius: float :param color: str, :param alpha: float :param res: int, resolution of mesh :param name: str, actor name """ mesh = Sphere(pos=pos, r=radius, c=color, alpha=alpha, res=res) name = name or "Point" Actor.__init__(self, mesh, name=name, br_class="Point")
def __init__( self, neuron, color=None, alpha=1, neurite_radius=8, soma_radius=15, name=None, ): """ Creates an Actor representing a single neuron's morphology :param neuron: path to .swc file, Mesh, Actor or Neuron from morphapi.morphology :param alpha: float :param color: str, :param neuron_radius: float, radius of axon/dendrites :param soma_radius: float, radius of soma :param name: str, actor name """ logger.debug(f"Creating a Neuron actor") if color is None: color = "blackboard" alpha = alpha self.neurite_radius = neurite_radius self.soma_radius = soma_radius self.name = None if isinstance(neuron, (str, Path)): mesh = self._from_file(neuron) elif isinstance(neuron, (Mesh)): mesh = neuron elif isinstance(neuron, Actor): mesh = neuron.mesh elif isinstance(neuron, MorphoNeuron): mesh = self._from_morphapi_neuron(neuron) else: raise ValueError( f'Argument "neuron" is not in a recognized format: {_class_name(neuron)}' ) Actor.__init__(self, mesh, name=self.name, br_class="Neuron") self.mesh.c(color).alpha(alpha)