navis-org/navis

Error in navis.plot3d when radius = True

kuanawanda opened this issue · 3 comments

I'm having trouble getting plot3d to work with radius=True.
When I run the following:
nl = navis.example_neurons()
nl.plot3d(backend='plotly', radius=True)

I get the error below. With radius=False, it's fine. 'k3d' backend gives the same error. I'm running a jupyter notebook on Visual Studio on mac.

Thanks!

ValueError Traceback (most recent call last)
in
1 nl = navis.example_neurons()
----> 2 nl.plot3d(backend='plotly', radius=True)

~/ppc_env/lib/python3.7/site-packages/navis/core/neuronlist.py in plot3d(self, **kwargs)
672 from ..plotting import plot3d
673
--> 674 return plot3d(self, **kwargs)
675
676 def plot2d(self, **kwargs):

~/ppc_env/lib/python3.7/site-packages/navis/plotting/ddd.py in plot3d(x, **kwargs)
258 return plot3d_k3d(x, **kwargs)
259 elif backend == 'plotly':
--> 260 return plot3d_plotly(x, **kwargs)
261 else:
262 raise ValueError(f'Unknown backend "{backend}". '

~/ppc_env/lib/python3.7/site-packages/navis/plotting/ddd.py in plot3d_plotly(x, **kwargs)
369 data = []
370 if neurons:
--> 371 data += neuron2plotly(neurons, neuron_cmap, **kwargs)
372 if volumes:
373 data += volume2plotly(volumes, volumes_cmap, **kwargs)

~/ppc_env/lib/python3.7/site-packages/navis/plotting/plotly/graph_objs.py in neuron2plotly(x, colormap, **kwargs)
122 # Convert and carry connectors with us
123 if isinstance(neuron, core.TreeNeuron):
--> 124 _neuron = conversion.tree2meshneuron(neuron)
125 _neuron.connectors = neuron.connectors
126 neuron = _neuron

~/ppc_env/lib/python3.7/site-packages/navis/utils/misc.py in wrapper(*args, **kwargs)
249 else:
250 # If single neuron just pass through
--> 251 return function(*args, **kwargs)
252
253 # Update the docstring

~/ppc_env/lib/python3.7/site-packages/navis/conversion/converters.py in tree2meshneuron(x, tube_points, use_normals)
476 radii=radii,
477 tube_points=tube_points,
--> 478 use_normals=use_normals)
479
480 return core.MeshNeuron({'vertices': vertices, 'faces': faces},

~/ppc_env/lib/python3.7/site-packages/navis/plotting/plot_utils.py in make_tube(segments, radii, tube_points, use_normals)
190
191 if use_normals:
--> 192 tangents, normals, binormals = _frenet_frames(points)
193 else:
194 tangents = normals = binormals = np.ones((len(points), 3))

~/ppc_env/lib/python3.7/site-packages/navis/plotting/plot_utils.py in _frenet_frames(points)
304 if vec_norm > epsilon:
305 normals[i] = rotate(-np.degrees(th[i-1]),
--> 306 vec)[:3, :3].dot(normals[i])
307
308 binormals = np.cross(tangents, normals)

ValueError: could not broadcast input array from shape (0,) into shape (3,)

Hmm strange. If I run exactly this:

import navis
nl = navis.example_neurons()
nl.plot3d(backend='plotly', radius=True)

it works just fine. Can I just confirm that you haven't edited the example neurons in your code?

Hi Phillip - Thanks for your reply. Yes, I've been unable to reproduce the error on my ubuntu machine (ie, it works fine on ubuntu). Strangely enough when I copy the exact environment to my mac with pip freeze, I still get the same error. I'll try to dig a bit into where the error is coming from specifically and let you know if anything becomes more clear.

The good news is that it runs fine on my ubuntu machine so it's not currently an urgent issue for me. Thanks!

Hi Phillip - I think I tracked down the issue. I have been using MagicMock to work around issues installing Vispy on Big Sur (from #17).

In plot_utils.py, vispy.util.transforms.rotate is used even if a different backend is used. (

normals[i] = rotate(-np.degrees(th[i-1]),
). So in my case the rotate function was getting mocked and caused the error.

I was able to install vispy (MacOs BigSur 11.2.3) and then it works fine. I don't know when/how the issue with Big Sur and vispy got resolved but it seems fixed. It might make sense to use a rotate function that doesn't require vispy, but since vispy is installed with navis and the Mac compatibility issue seems resolved maybe this isn't necessary.

Thanks!