Skip to content

Commit

Permalink
WIP no soma rendering (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov authored May 2, 2024
1 parent a3cab4d commit a3b1f4b
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions morphapi/morphology/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,30 @@ def load_from_swc(self):
self.neuron_name = self.data_file.name

nrn = nm.load_morphology(self.data_file)

# Get position and radius of some
soma_pos = nrn.soma.points[0, :3]
soma_radius = nrn.soma.points[0, -1]

# Get the rest of the data and store it
self.morphology = nrn
self.points = dict(
soma=component(
soma_pos[0],
soma_pos[1],
soma_pos[2],
soma_pos,
soma_radius,
nrn.soma,
),
)

try:
# Get position and radius of soma
soma_pos = nrn.soma.points[0, :3]
soma_radius = nrn.soma.points[0, -1]

# Get the rest of the data and store it
self.points = dict(
soma=component(
soma_pos[0],
soma_pos[1],
soma_pos[2],
soma_pos,
soma_radius,
nrn.soma,
),
)
except IndexError:
logger.warning(
f"Neuron {self.neuron_name} has no soma, "
"only neurites will be loaded"
)
self.points = dict(soma=None)

for ntype, nclass in self._neurite_types.items():
self.points[ntype] = [
Expand Down Expand Up @@ -207,16 +214,17 @@ def create_mesh(
else:
# Create soma actor
neurites = {}
coords = self.points["soma"].coords
if self.invert_dims:
coords = coords[[2, 1, 0]]

soma = Sphere(
pos=coords,
r=self.points["soma"].radius * soma_radius,
c=soma_color,
).compute_normals()
neurites["soma"] = soma.clone().c(soma_color)
if self.points["soma"] is not None:
coords = self.points["soma"].coords
if self.invert_dims:
coords = coords[[2, 1, 0]]

soma = Sphere(
pos=coords,
r=self.points["soma"].radius * soma_radius,
c=soma_color,
).compute_normals()
neurites["soma"] = soma.clone().c(soma_color)

# Create neurites actors
for ntype in self._neurite_types:
Expand Down

0 comments on commit a3b1f4b

Please sign in to comment.