def test_volume(): s = Scene(inset=False, root=True) data = np.load("examples/data/volume.npy") s.add(Volume(data, voxel_size=200, as_surface=False, c="Reds")) s.add(Volume(data, voxel_size=200, as_surface=True, c="Reds", mode=2)) del s
def test_volume(): scene = Scene(inset=False, root=True) data = np.load("examples/data/volume.npy") scene.add(Volume(data, voxel_size=200, as_surface=False, c="Reds")) scene.add(Volume(data, voxel_size=200, as_surface=True, c="Reds", mode=2)) scene.render(interactive=False)
def griddata_to_volume( self, griddata, min_quantile=None, min_value=None, cmap="bwr", ): """ Takes a 3d numpy array with volumetric gene expression and returns a vedo.Volume.isosurface actor. 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 gene expression data. :param griddata: np.ndarray, 3d array with gene expression data :param min_quantile: float, percentile for threshold :param min_value: float, value for threshold """ return Volume( griddata, min_quantile=min_quantile, voxel_size=self.voxel_size, min_value=min_value, cmap=cmap, name=self.gene_name, br_class="Gene Data", )
def add(self, *items, names=None, classes=None, **kwargs): """ General method to add Actors to the scene. :param items: vedo.Mesh, Actor, (str, Path). If str/path it should be a path to a .obj or .stl file. Whatever the input it's turned into an instance of Actor before adding it to the scne :param names: names to be assigned to the Actors :param classs: br_classes to be assigned to the Actors :param **kwargs: parameters to be passed to the individual loading functions (e.g. to load from file and specify the color) """ names = names or [None for a in items] classes = classes or [None for a in items] # turn items into Actors actors = [] for item, name, _class in zip(items, listify(names), listify(classes)): if item is None: continue if isinstance(item, (Mesh, Assembly)): actors.append(Actor(item, name=name, br_class=_class)) elif pi.utils._class_name(item) == "vtkCornerAnnotation": # Mark text actors differently because they don't behave like # other 3d actors actors.append( Actor( item, name=name, br_class=_class, is_text=True, **kwargs, )) elif pi.utils._class_name(item) == "Volume" and not isinstance( item, Volume): actors.append( Volume(item, name=name, br_class=_class, **kwargs)) elif isinstance(item, Actor): actors.append(item) elif isinstance(item, (str, Path)): mesh = load_mesh_from_file(item, **kwargs) name = name or Path(item).name _class = _class or "from file" actors.append(Actor(mesh, name=name, br_class=_class)) else: raise ValueError( f"Unrecognized argument: {item} [{pi.utils._class_name(item)}]" ) # Add to the lists actors self.actors.extend(actors) return return_list_smart(actors)
""" This example shows how to render volumetric (i.e. organized in voxel) data in brainrender. The data used are is the localized expression of 'Gpr161' from the Allen Atlas database, downloaded with brainrender and saved to a numpy file """ import numpy as np from brainrender import Scene from brainrender import settings from brainrender.actors import Volume settings.SHOW_AXES = False scene = Scene(inset=False) data = np.load("examples/data/volume.npy") # make a volume actor and add actor = Volume( data, voxel_size=200, # size of a voxel's edge in microns as_surface=False, # if true a surface mesh is rendered instead of a volume c="Reds", # use matplotlib colormaps to color the volume ) scene.add(actor) scene.render(zoom=1.6)
# create scene scene = Scene( atlas_name="mpin_zfish_1um", inset=INSET, screenshots_folder="paper/screenshots", ) scene.root.alpha(0.2) # add custom meshes from file, but don't show them (alpha=0) m = scene.add("paper/data/T_AVG_nk1688CGt_GFP.obj", color=gene1_color, alpha=0) m2 = scene.add("paper/data/T_AVG_brn3c_GFP.obj", color=gene2_color, alpha=0) # adjust meshes position for mesh in (m, m2): mesh.mesh.addPos(dp_x=SHIFT) # convert meshes to volumetric data showing gene expression density vol1 = Volume(m.density(), as_surface=True, min_value=20000, cmap="Reds") vol1.lw(1) scene.add(vol1) vol2 = Volume(m2.density(), as_surface=True, min_value=600, cmap="Blues") vol2.lw(1) scene.add(vol2) # render scene.render(camera=cam, zoom=2.5) scene.screenshot(name="zfish_gene_expression")