Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"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(
# 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
)
# Deal with other inputs
else:
raise ValueError(
f"Passed neuron {neuron} is not a valid input"
)
actors = []
for branch in data["branches"]:
coords = [data["coordinates"][str(p)] for p in branch]
# Just like for synapses we need to adjust the coordinates to match the .obj files
# coords are x z -y
adjusted_coords = [(c[0], c[2], -c[1]) for c in coords]
actors.append(
Tube(
adjusted_coords,
r=cs.skeleton_radius,
res=NEURON_RESOLUTION,
)
)
return merge(*actors)