New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dipy.viz.colormap crash on single fibers #928

Closed
samuelstjean opened this Issue Feb 18, 2016 · 4 comments

Comments

Projects
5 participants
@samuelstjean
Copy link
Contributor

samuelstjean commented Feb 18, 2016

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-740-27f8ba00858a> in <module>()
     17 stream_actor2 = actor.line(bundle_native2, meth, linewidth=0.1,
     18                            lookup_colormap=lut_cmap)
---> 19 mean_bund_actor = actor.streamtube(mean_fiber_aligned, lookup_colormap=lut_cmap)
     20 
     21 ax_actor = actor.slicer(meth, np.eye(4))

/home/samuel/python/dipy/viz/actor.pyc in streamtube(lines, colors, opacity, linewidth, tube_sides, lod, lod_points, lod_points_size, spline_subdiv, lookup_colormap)
    280     """
    281     # Poly data with lines and colors
--> 282     poly_data, is_colormap = lines_to_vtk_polydata(lines, colors)
    283     next_input = poly_data
    284 

/home/samuel/python/dipy/viz/utils.pyc in lines_to_vtk_polydata(lines, colors)
    258     #           - if/else tested and work in normal simple case
    259     if colors is None:  # set automatic rgb colors
--> 260         cols_arr = line_colors(lines)
    261         colors_mapper = np.repeat(lines_range, points_per_line, axis=0)
    262         vtk_colors = numpy_to_vtk_colors(255 * cols_arr[colors_mapper])

/home/samuel/python/dipy/viz/colormap.pyc in line_colors(streamlines, cmap)
    249     if cmap == 'rgb_standard':
    250         col_list = [orient2rgb(streamline[-1] - streamline[0])
--> 251                     for streamline in streamlines]
    252 
    253     if cmap == 'boys_standard':

/home/samuel/python/dipy/viz/colormap.pyc in orient2rgb(v)
    231         orient = np.abs(v / orientn)
    232 
--> 233     return orient
    234 
    235 

UnboundLocalError: local variable 'orient' referenced before assignment

Granted, that is my fault as I was giving it an array instead of a (single element) list, but it only checks for input of dimension 1 or 2, and crash weirdly if that is not the case as seen above.

@samuelstjean samuelstjean changed the title dipy.vix.colormap crash on single fibers dipy.viz.colormap crash on single fibers Feb 18, 2016

@sahmed95

This comment has been minimized.

Copy link
Contributor

sahmed95 commented Mar 17, 2016

The orient variable is not initialized to anything at the start of the function.

    if v.ndim == 1:
        orient = v
        orient = np.abs(orient / np.linalg.norm(orient))

    if v.ndim == 2:
        orientn = np.sqrt(v[:, 0] ** 2 + v[:, 1] ** 2 + v[:, 2] ** 2)
        orientn.shape = orientn.shape + (1,)
        orient = np.abs(v / orientn)

    return orient

If the argument to colormap.orient2rgb is not a valid numpy array both 'if' conditions are not satisfied and hence it may be throwing the "referenced before assignment error"

What should be the type for the variable v? Can a check on argument v fix this?

@samuelstjean Does this reproduce all cases?

>>> colormap.orient2rgb([2,3,4])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dipy/viz/colormap.py", line 224, in orient2rgb
    if v.ndim == 1:
AttributeError: 'list' object has no attribute 'ndim'
>>> colormap.orient2rgb(np.array([2,3,4]))
array([ 0.37139068,  0.55708601,  0.74278135])
>>> colormap.orient2rgb(np.array(1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dipy/viz/colormap.py", line 233, in orient2rgb
    return orient
UnboundLocalError: local variable 'orient' referenced before assignment
>>> colormap.orient2rgb(np.array([1]))
array([ 1.])
@theaverageguy

This comment has been minimized.

Copy link
Contributor

theaverageguy commented Mar 22, 2016

@samuelstjean @sahmed95
I would like to fix this. A little help please.

@arokem

This comment has been minimized.

Copy link
Member

arokem commented Mar 22, 2016

I would try to implement a check for the number of streamlines and special-case the single fiber case.

@skoudoro

This comment has been minimized.

Copy link
Member

skoudoro commented Sep 20, 2018

This issue was moved to fury-gl/fury#8

@skoudoro skoudoro closed this Sep 20, 2018

@skoudoro skoudoro moved this from Issues to PR needs a review in Viz Module Oct 31, 2018

@skoudoro skoudoro moved this from PR needs a review to Done in Viz Module Oct 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment