Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (
not isinstance(data, np.ndarray)
or not isinstance(data2, np.ndarray)
or not isinstance(data3, np.ndarray)
):
raise ValueError
if not np.array_equal(data, data3):
raise ValueError
gene_actor = geapi.griddata_to_volume(
data, min_quantile=90, cmap="inferno"
)
gene_actor2 = geapi.griddata_to_volume(data2, min_value=0.2)
if not isinstance(gene_actor, Mesh) or not isinstance(gene_actor2, Mesh):
raise ValueError
def test_scene_creation_notebook():
settings.notebookBackend = "k3d"
Scene()
settings.notebookBackend = None
def test_scene_creation_notebook():
settings.notebookBackend = "k3d"
Scene()
settings.notebookBackend = None
# Text to add
s = "BRAINRENDER"
# Specify a color for each letter
colors = makePalette(len(s), "salmon", "powderblue")
x = 0 # use to specify the position of each letter
# Add letters one at the time to color them individually
for n, letter in enumerate("BRAINRENDER"):
if "I" == letter or "N" == letter and n < 5: # make the spacing right
x += 0.6
else:
x += 1
# Add letter and silhouette to the scne
act = Text(
letter, depth=0.5, c=colors[n], pos=(x, 0, 0), justify="centered"
)
sil = act.silhouette().lw(3).color("k")
scene.add_actor(act, sil)
scene.render(interactive=False)
scene.close()
def download_and_write_mesh(self, acronym, obj_path):
print(f"Downloading mesh data for {acronym}")
path = self.structures.loc[
self.structures.acronym == acronym
].obj_path.values[0]
url = f"{self._url_paths['data']}/{path}"
# download and write .obj
mesh_data = request(url).content.decode("utf-8").split("\n")
with open(obj_path, "w") as f:
for md in mesh_data:
f.write(f"{md}\n")
f.close()
# return the vtk actor
return load(obj_path)
"Create root method not supported yet, sorry"
)
print(f"Creating root mesh for atlas {self.atlas_name}")
temp_scene = Scene(
atlas=Celegans,
add_root=False,
display_inset=False,
atlas_kwargs=dict(data_folder=self.data_folder),
)
temp_scene.add_neurons(self.neurons_names)
temp_scene.render(interactive=False)
temp_scene.close()
root = merge(*temp_scene.actors["neurons"]).clean().cap()
# root = mesh2Volume(root, spacing=(0.02, 0.02, 0.02)).isosurface()
points = Points(root.points()).smoothMLS2D(f=0.8).clean(tol=0.005)
root = recoSurface(points, dims=100, radius=0.2)
# Save
write(root, rootpath)
del temp_scene
return root
def make_root_mesh(self):
if self.structures is None:
return
obj_path = os.path.join(self.meshes_folder, "root.vtk")
if os.path.isfile(obj_path):
return
# Get the mesh for each brain region to create root
meshes = [
self._get_structure_mesh(reg) for reg in self.region_acronyms
]
root = merge(meshes)
write(root, obj_path)
# Deal with neuron as dictionary of actor
elif isinstance(neuron, dict):
neuron_actors["soma"] = neuron.pop("soma", None)
neuron_actors["axon"] = neuron.pop("axon", None)
# Get dendrites actors
if (
"apical_dendrites" in neuron.keys()
or "basal_dendrites" in neuron.keys()
):
if "apical_dendrites" not in neuron.keys():
neuron_actors["dendrites"] = neuron["basal_dendrites"]
elif "basal_dendrites" not in neuron.keys():
neuron_actors["dendrites"] = neuron["apical_dendrites"]
else:
neuron_actors["dendrites"] = merge(
neuron["apical_dendrites"],
neuron["basal_dendrites"],
)
else:
neuron_actors["dendrites"] = neuron.pop("dendrites", None)
# Deal with neuron as instance of Neuron from morphapi
elif isinstance(neuron, Neuron):
neuron_actors, _ = get_neuron_actors_with_morphapi(
neuron=neuron,
neurite_radius=neurite_radius,
use_cache=use_cache,
)
# Deal with other inputs
else:
raise ValueError(
soma_radius = SOMA_RADIUS
actors = neuron.create_mesh(
neurite_radius=neurite_radius,
use_cache=use_cache,
soma_radius=soma_radius,
)
if actors is None:
raise ValueError(f"Failed to get neuron actors. {swcfile} - {neuron}")
else:
neurites, whole_neuron = actors
actors = dict(
soma=neurites["soma"],
axon=neurites["axon"],
dendrites=merge(
neurites["basal_dendrites"], neurites["apical_dendrites"]
),
)
return actors, whole_neuron
# Deal with neuron as dictionary of actor
elif isinstance(neuron, dict):
neuron_actors["soma"] = neuron.pop("soma", None)
neuron_actors["axon"] = neuron.pop("axon", None)
# Get dendrites actors
if (
"apical_dendrites" in neuron.keys()
or "basal_dendrites" in neuron.keys()
):
if "apical_dendrites" not in neuron.keys():
neuron_actors["dendrites"] = neuron["basal_dendrites"]
elif "basal_dendrites" not in neuron.keys():
neuron_actors["dendrites"] = neuron["apical_dendrites"]
else:
neuron_actors["dendrites"] = merge(
neuron["apical_dendrites"],
neuron["basal_dendrites"],
)
else:
neuron_actors["dendrites"] = neuron.pop("dendrites", None)
# Deal with neuron as instance of Neuron from morphapi
elif isinstance(neuron, Neuron):
neuron_actors, _ = get_neuron_actors_with_morphapi(
neuron=neuron,
neurite_radius=neurite_radius,
use_cache=use_cache,
)
# Deal with other inputs
else:
raise ValueError(