-
Notifications
You must be signed in to change notification settings - Fork 34
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
ENH: add initial streamline widget #4
Conversation
needs: widgetti/ipyvolume#72 |
any chance you could make a .trk file available to try this out? |
Thanks. For some reason I can't get it to work - it doesn't work with ipyvolume from pypi but even if I install from your repo with the fix it's throwing errors. I'll wait until your fix is merged and try it out then! |
unzip and cd to the ipyvolume folder
note these last steps set up ipyvolume in dev mode and requires nodejs. and any jupyter instance needs to be restarted for this to take effect. |
I tried following this and am getting:
Any ideas? |
@arokem - hold on based on a conversion on ipyvolume i sent some updates that i didn't test. perhaps those are inappropriate. give me a minute to check. |
@arokem - try now - you will have to wget the zip file again. |
Yep - installing/enabling seems to work now! Thanks! |
using Mesh for efficient streamline plotting
@janfreyberg, @arokem - this does require ipyvolume master, but it works well now at scale. once this branch is installed together with ipyvolume master, you can test with: https://www.dropbox.com/s/oukfh9agca5k9im/streamlines.ipynb?dl=0 https://www.dropbox.com/s/dbexuhk7fsawvox/streamlines.trk?dl=0 |
@arokem - with this new mechanism, it would not take much work to refactor to draw bundles. |
Thanks, will test this ASAP. Any idea yet when the required changes will be released by ipyvolume? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of small comments from my end.
def color(x): | ||
"""Returns an approximation for color of line based on its endpoints""" | ||
dirvec = (x[0, :] - x[-1, :]) | ||
return (dirvec/(np.sqrt(np.sum(dirvec*dirvec, axis=-1)))).dot(np.eye(3)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this do the same thing as this?
https://github.com/nipy/dipy/blob/master/dipy/viz/colormap.py#L211-L240
I'm not sure it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this line, https://github.com/nipy/dipy/blob/master/dipy/viz/colormap.py#L257, i think they are doing exactly the same thing. line 19 can be simplified because i'm not really using anything other than rgb extremes. but instead of eye, one could use three different colors in the colorspace, and a non-linearity on the normalized direction vector.
niwidgets/streamlines.py
Outdated
|
||
Args | ||
---- | ||
skip : int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explanation of this parameter could be understood as the number of streamlines to omit from the beginning of the collection, or something of that sort.
Might be easier if it is formulated as proportion_to_display
, from which the skip is calculated.
BTW: the default here and in the _default_plotter
method is different. Is that intentional?
Also, what would a None
input do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
would use all streamlines. i will change this to proportion_to_display
.
the defaults were not updated since the efficiency boost. initially we couldn't display more than 5k lines, but now it can handle much more.
@janfreyberg - thanks for the review. those suggestions are great. whenever i get some time next, i'll add those in together with @arokem's suggestions. |
* upstream/master: Update path to repos for direct pip install from git niwidget_volume- delete os import Added flipping to the left for sagittal view version number change Some formatting changes allow taking in nifti file Use the scaled rather than the unscaled data stored in nifti file change default for background masking Backwards compatibility to 3.5 Revert from using Path's `strict` kwarg to using explicit file check, since `strict` was only added in 3.6.
@arokem and @janfreyberg - finally got to this. should have all the pieces in place now.
|
@arokem and @janfreyberg - any chance this can be reviewed soon. |
Did your changes make it upstream to current ipyvolume? |
yes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, and works well. I had a couple of small comments, and found one error that should be easy to work around. +1 from my end for the merge, once these small things are resolved.
@@ -25,3 +25,5 @@ | |||
surface_dir / f | |||
for f in ('lh.area', 'lh.curv', 'lh.thickness', 'lh.aparc.annot') | |||
] | |||
|
|||
streamlines = root_dir / 'streamlines.trk' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this returns a PosixPath object, the example in the index file raises an error, unless I pass sw = StreamlineWidget(filename=streamlines.as_posix())
---- | ||
filename : str | ||
The path to your ``.trk`` file. Can be a string, or a | ||
``PosixPath`` from python3's pathlib. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PosixPath doesn't work for me. Raises:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-9-09a88a08f323> in <module>()
----> 1 sw = StreamlineWidget(filename=streamlines)
2
3 style = {'axes': {'color': 'red',
4 'label': {'color': 'white'},
5 'ticklabel': {'color': 'white'},
~/source/niwidgets/niwidgets/streamlines.py in __init__(self, filename, streamlines)
41
42 if filename:
---> 43 if not os.path.isfile(filename):
44 # for Python3 should have FileNotFoundError here
45 raise IOError('file {} not found'.format(filename))
~/anaconda3/lib/python3.5/genericpath.py in isfile(path)
28 """Test whether a path is a regular file"""
29 try:
---> 30 st = os.stat(path)
31 except OSError:
32 return False
TypeError: argument should be string, bytes or integer, not PosixPath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm curious as to your environment:
on my osx with py36 i get this:
In [1]: from niwidgets.exampledata import streamlines
In [2]: streamlines
Out[2]: PosixPath('/software/nipy-repo/niwidgets/niwidgets/data/streamlines.trk')
In [3]: from niwidgets.streamlines import StreamlineWidget
In [4]: sw = StreamlineWidget(filename=streamlines)
niwidgets/streamlines.py
Outdated
|
||
class StreamlineWidget: | ||
""" | ||
Turns mrtrix track or trackvis files into interactive plots using ipyvolume. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The safest here would be to say that this can use any file type that nibabel knows how to read. This will be true even for future versions that implement reading of any other streamline file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
roger.
added a streamline widget. usage example here: https://nbviewer.jupyter.org/urls/dl.dropbox.com/s/oukfh9agca5k9im/streamlines.ipynb
this requires a few changes to ipyvolume that i will be submitting as a PR shortly.
additional things to consider: