Skip to content

Commit

Permalink
fix logic for radius='auto'
Browse files Browse the repository at this point in the history
  • Loading branch information
schlegelp committed Sep 21, 2024
1 parent 6314074 commit 89f1ad2
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions octarine_navis_plugin/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,22 @@ def neuron2gfx(x, color=None, random_ids=False, **kwargs):
else:
object_id = neuron.id # this may also be a random ID

if isinstance(neuron, navis.TreeNeuron) and kwargs.get('radius', False) == "auto":
# Number of nodes with radii
n_radii = (neuron.nodes.get("radius", pd.Series([])).fillna(0) > 0).sum()
# If less than 30% of nodes have a radius, we will fall back to lines
if n_radii / neuron.nodes.shape[0] < 0.3:
kwargs['radius'] = False

_neuron = navis.conversion.tree2meshneuron(neuron, warn_missing_radii=False)
_neuron.connectors = neuron.connectors
neuron = _neuron

# See if we need to map colors to vertices
if isinstance(colormap[i], np.ndarray) and colormap[i].ndim == 2:
colormap[i] = colormap[i][neuron.vertex_map]
if isinstance(neuron, navis.TreeNeuron):
if kwargs.get('radius', False) == "auto":
# Number of nodes with radii
n_radii = (neuron.nodes.get("radius", pd.Series([])).fillna(0) > 0).sum()
# If less than 30% of nodes have a radius, we will fall back to lines
if n_radii / neuron.nodes.shape[0] < 0.3:
kwargs['radius'] = False

if kwargs.get('radius', False):
_neuron = navis.conversion.tree2meshneuron(neuron, warn_missing_radii=False)
_neuron.connectors = neuron.connectors
neuron = _neuron

# See if we need to map colors to vertices
if isinstance(colormap[i], np.ndarray) and colormap[i].ndim == 2:
colormap[i] = colormap[i][neuron.vertex_map]

neuron_color = colormap[i]
if not kwargs.get("connectors_only", False):
Expand Down

0 comments on commit 89f1ad2

Please sign in to comment.