Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_streamlines(self, *args, **kwargs):
"""
Render streamline data.
Check the function definition in ABA for more details
"""
actors = self.atlas.get_streamlines(*args, **kwargs)
self.actors.extend(actors)
return return_list_smart(actors)
each item is the color of the brain region each point is in
"""
if isinstance(p0[0], (float, int)):
p0 = [p0]
resolution = int(self.metadata["resolution"][0])
colors = []
for point in p0:
point = np.round(np.array(point) / resolution).astype(int)
try:
struct = self.structure_from_coords(point, as_acronym=True)
except KeyError: # couldn't find any region
struct = "root"
colors.append(self._get_from_structure(struct, "rgb_triplet"))
return return_list_smart(colors)
def add_from_file(self, *filepaths, **kwargs):
"""
Add data to the scene by loading them from a file. Should handle .obj, .vtk and .nii files.
:param filepaths: path to the file. Can pass as many arguments as needed
:param **kwargs:
"""
actors = []
for filepath in filepaths:
actor = load_mesh_from_file(filepath, **kwargs)
actor.name = Path(filepath).name
self.actors.append(actor)
actors.append(actor)
return return_list_smart(actors)
def add_tractography(self, *args, **kwargs):
"""
Renders tractography data and adds it to the scene.
Check the function definition in ABA for more details
"""
actors = self.atlas.get_tractography(*args, **kwargs)
self.actors.extend(actors)
return return_list_smart(actors)
if not display_dendrites:
neuron_actors["dendrites"] = None
_neurons_actors.append(neuron_actors)
# Color actors
colors = parse_neurons_colors(neurons, color)
for n, neuron in enumerate(_neurons_actors):
if neuron["axon"] is not None:
neuron["axon"].c(colors["axon"][n])
if neuron["soma"] is not None:
neuron["soma"].c(colors["soma"][n])
if neuron["dendrites"] is not None:
neuron["dendrites"].c(colors["dendrites"][n])
# Return
return return_list_smart(_neurons_actors), None
def add_actor(self, *actors, store=None):
"""
Add a vtk actor to the scene
:param actor:
:param store: a list to store added actors
"""
for actor in actors:
if store is None:
self.actors.append(actor)
else:
store.append(actor)
return return_list_smart(actors)
planes = [plane]
actors = []
for plane in planes:
if isinstance(plane, str):
plane = self.atlas.get_plane_at_point(plane=plane, **kwargs)
else:
if not isinstance(plane, Plane):
raise ValueError(
"The plane arguments should either be a Plane actor or"
+ "a string with the name of predefined planes."
+ f" Not: {plane.__type__}"
)
actors.append(plane)
self.add_actor(*actors)
return return_list_smart(actors)
each item is the color of the brain region each point is in
"""
if isinstance(p0[0], (float, int)):
p0 = [p0]
resolution = int(self.metadata["resolution"][0])
colors = []
for point in p0:
point = np.round(np.array(point) / resolution).astype(int)
try:
struct = self.structure_from_coords(point, as_acronym=True)
except KeyError: # couldn't find any region
struct = "root"
colors.append(self._get_from_structure(struct, "rgb_triplet"))
return return_list_smart(colors)
if not display_dendrites:
neuron_actors["dendrites"] = None
_neurons_actors.append(neuron_actors)
# Color actors
for n, neuron in enumerate(_neurons_actors):
if neuron["axon"] is not None:
neuron["axon"].c(colors["axon"][n])
neuron["soma"].c(colors["soma"][n])
if neuron["dendrites"] is not None:
neuron["dendrites"].c(colors["dendrites"][n])
# Add to actors storage
self.actors.extend(_neurons_actors)
return return_list_smart(_neurons_actors)