Skip to content

Commit

Permalink
plotting: warn about missing radii only once
Browse files Browse the repository at this point in the history
  • Loading branch information
schlegelp committed Sep 15, 2024
1 parent 655b658 commit f5160bb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
16 changes: 13 additions & 3 deletions navis/plotting/dd.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,17 @@ def plot2d(
settings.radius = False

if isinstance(neuron, core.TreeNeuron) and settings.radius:
_neuron = conversion.tree2meshneuron(neuron)
# Warn once if more than 5% of nodes have missing radii
if not getattr(fig, '_radius_warned', False):
if ((neuron.nodes.radius.fillna(0).values <= 0).sum() / neuron.n_nodes) > 0.05:
logger.warning(
"Some skeleton nodes have radius <= 0. This may lead to "
"rendering artifacts. Set `radius=False` to plot skeletons "
"as single-width lines instead."
)
fig._radius_warned = True

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

Expand Down Expand Up @@ -883,7 +893,7 @@ def _plot_connectors(neuron, color, ax, settings):
inner_dict["color"] = settings.cn_colors

if settings.method == "2d":
for c, this_cn in connectors.groupby('type'):
for c, this_cn in connectors.groupby("type"):
x, y = _parse_view2d(this_cn[["x", "y", "z"]].values, settings.view)

ax.scatter(
Expand All @@ -892,7 +902,7 @@ def _plot_connectors(neuron, color, ax, settings):
color=cn_layout[c]["color"],
edgecolor="none",
s=settings.cn_size if settings.cn_size else cn_layout["size"],
zorder=1000
zorder=1000,
)
ax.get_children()[-1].set_gid(f"CN_{neuron.id}")
elif settings.method in ["3d", "3d_complex"]:
Expand Down
13 changes: 12 additions & 1 deletion navis/plotting/k3d/k3d_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def neuron2k3d(x, colormap, settings):
cn_lay.update(settings.cn_layout)

trace_data = []
_radius_warned = False
for i, neuron in enumerate(x):
name = str(getattr(neuron, "name", neuron.id))
color = colormap[i]
Expand Down Expand Up @@ -106,7 +107,17 @@ def neuron2k3d(x, colormap, settings):
settings.radius = False

if isinstance(neuron, core.TreeNeuron) and settings.radius:
_neuron = conversion.tree2meshneuron(neuron)
# Warn once if more than 5% of nodes have missing radii
if not _radius_warned:
if ((neuron.nodes.radius.fillna(0).values <= 0).sum() / neuron.n_nodes) > 0.05:
logger.warning(
"Some skeleton nodes have radius <= 0. This may lead to "
"rendering artifacts. Set `radius=False` to plot skeletons "
"as single-width lines instead."
)
_radius_warned = True

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

Expand Down
13 changes: 12 additions & 1 deletion navis/plotting/plotly/graph_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def neuron2plotly(x, colormap, settings):
cn_lay.update(settings.cn_layout)

trace_data = []
_radius_warned = False
for i, neuron in enumerate(x):
name = str(getattr(neuron, "name", neuron.id))
color = colormap[i]
Expand Down Expand Up @@ -135,7 +136,17 @@ def neuron2plotly(x, colormap, settings):
settings.radius = False

if isinstance(neuron, core.TreeNeuron) and settings.radius:
_neuron = conversion.tree2meshneuron(neuron)
# Warn once if more than 5% of nodes have missing radii
if not _radius_warned:
if ((neuron.nodes.radius.fillna(0).values <= 0).sum() / neuron.n_nodes) > 0.05:
logger.warning(
"Some skeleton nodes have radius <= 0. This may lead to "
"rendering artifacts. Set `radius=False` to plot skeletons "
"as single-width lines instead."
)
_radius_warned = True

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

Expand Down
13 changes: 12 additions & 1 deletion navis/plotting/vispy/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def neuron2vispy(x, settings):

# List to fill with vispy visuals
visuals = []
_radius_warned = False
for i, neuron in enumerate(x):
# Generate random ID -> we need this in case we have duplicate IDs
object_id = uuid.uuid4()
Expand All @@ -263,7 +264,17 @@ def neuron2vispy(x, settings):
settings.radius = False

if isinstance(neuron, core.TreeNeuron) and settings.radius:
_neuron = conversion.tree2meshneuron(neuron)
# Warn once if more than 5% of nodes have missing radii
if not _radius_warned:
if ((neuron.nodes.radius.fillna(0).values <= 0).sum() / neuron.n_nodes) > 0.05:
logger.warning(
"Some skeleton nodes have radius <= 0. This may lead to "
"rendering artifacts. Set `radius=False` to plot skeletons "
"as single-width lines instead."
)
_radius_warned = True

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

Expand Down

0 comments on commit f5160bb

Please sign in to comment.