mindboggle icon indicating copy to clipboard operation
mindboggle copied to clipboard

plotting surfaces in jupyter notebook tutorial broken

Open binarybottle opened this issue 6 years ago • 14 comments

Screen Shot 2019-06-10 at 8 19 16 AM

binarybottle avatar Jun 10 '19 12:06 binarybottle

TO DO -- use nilearn's plot_surf:

https://nilearn.github.io/modules/generated/nilearn.plotting.plot_surf.html#nilearn.plotting.plot_surf

binarybottle avatar Jun 10 '19 13:06 binarybottle

I tried nilearn's plot_surf (https://nilearn.github.io/modules/generated/nilearn.plotting.plot_surf.html#nilearn.plotting.plot_surf) on mindboggle data:

import numpy as np
depths_array = np.asarray(depths)
fs_surf_mesh = subject_path + 'surf/lh.pial'
nilearn.plotting.plot_surf(surf_mesh=fs_surf_mesh, surf_map=depths_array, bg_map=None, 
                           hemi='left', view='lateral', 
                           cmap=None, colorbar=True, 
                           avg_method='mean', threshold=None, 
                           alpha='auto', bg_on_data=False, darkness=1, 
                           vmin=None, vmax=None, cbar_vmin=None, cbar_vmax=None, 
                           title=None, output_file=None, axes=None, figure=None)

but got the following error:


NotImplementedError Traceback (most recent call last) in 8 alpha='auto', bg_on_data=False, darkness=1, 9 vmin=None, vmax=None, cbar_vmin=None, cbar_vmax=None, ---> 10 title=None, output_file=None, axes=None, figure=None)

/opt/miniconda-latest/envs/mb/lib/python3.6/site-packages/nilearn/plotting/surf_plotting.py in plot_surf(surf_mesh, surf_map, bg_map, hemi, view, cmap, colorbar, avg_method, threshold, alpha, bg_on_data, darkness, vmin, vmax, cbar_vmin, cbar_vmax, title, output_file, axes, figure, **kwargs) 188 axes.set_xlim(*limits) 189 axes.set_ylim(*limits) --> 190 axes.set_aspect(.74) 191 axes.view_init(elev=elev, azim=azim) 192 axes.set_axis_off()

/opt/miniconda-latest/envs/mb/lib/python3.6/site-packages/matplotlib/axes/_base.py in set_aspect(self, aspect, adjustable, anchor, share) 1279 if (not cbook._str_equal(aspect, 'auto')) and self.name == '3d': 1280 raise NotImplementedError( -> 1281 'It is not currently possible to manually set the aspect ' 1282 'on 3D axes') 1283

NotImplementedError: It is not currently possible to manually set the aspect on 3D axes

binarybottle avatar Jun 10 '19 22:06 binarybottle

That might be a matplotlib thingy. I had the same problem recently and solved it by downgrading matplotlib to 3.0.3 I think.

PeerHerholz avatar Aug 16 '19 02:08 PeerHerholz

pinging @binarybottle to ask about current status: should I try to implement a corresponding fix?

PeerHerholz avatar Oct 04 '19 11:10 PeerHerholz

@PeerHerholz - that would be great. perhaps a quick look to see if niwidgets can be used may also be helpful.

satra avatar Oct 04 '19 13:10 satra

@satra, on it! I'll try both (nilearn-matplotlib and niwidgets) here.

PeerHerholz avatar Oct 04 '19 14:10 PeerHerholz

quick update re nilearn: there will be a fix in the next release of nilearn and nistats as mentioned by this neurostars post. As the problem is not related to nilearn but matplotlib (starting at version 3.1) we could either install nilearn from source or downgrade the matplotlib version. Otherwise, we would've to wait for the next release which should happen soon. Let me know what you think (I would vote for waiting for the next release). Re niwidgets: currently checking it.

PeerHerholz avatar Oct 16 '19 13:10 PeerHerholz

Downgrading matplotlib to 3.0.3 solves it and both, the static (plot_surf) and interactive plot (view_surf) are working:

Screen Shot 2019-10-16 at 10 41 20 AM Screen Shot 2019-10-16 at 10 44 53 AM

Although the interactive plot needs some more tweaking.

PeerHerholz avatar Oct 16 '19 14:10 PeerHerholz

Re niwidgets: not sure about it, that is if what I did makes sense. I had to put the extracted values (e.g. depths) into a .gii as niwidgets requires that. To do so, I converted the FreeSurfer surface to .gii, loaded it using nibabel, exchanged the values in the first dimension with the depth values and saved it. When trying to plot it as an overlay in niwidgets nothing is visible, but when I plot it directly it looks like this: Screen Shot 2019-10-16 at 5 20 06 PM

PeerHerholz avatar Oct 16 '19 21:10 PeerHerholz

Wow, nice workaround, @PeerHerholz!

binarybottle avatar Nov 04 '19 20:11 binarybottle

@binarybottle should we go with the nilearn version first, till I figure out the niwidgets part completely?

PeerHerholz avatar Nov 05 '19 14:11 PeerHerholz

Sounds good!

Cheers, @rno

Arno Klein, PhD MATTER Lab Director Joseph Healey Scholar Senior Research Scientist Child Mind Institute 101 E 56 St, NY, NY matter.childmind.org 347-577-2091


From: Peer Herholz [email protected] Sent: Tuesday, November 5, 2019 9:45:26 AM To: nipy/mindboggle [email protected] Cc: Arno Klein [email protected]; Mention [email protected] Subject: Re: [nipy/mindboggle] plotting surfaces in jupyter notebook tutorial broken (#177)

@binarybottlehttps://github.com/binarybottle should we go with the nilearn version first, till I figure out the niwidgets part completely?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/nipy/mindboggle/issues/177?email_source=notifications&email_token=AABZX5EWEIVIWEJIIKU4YKLQSGBINA5CNFSM4HWTAJMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDC52YI#issuecomment-549838177, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AABZX5F6E7ELK5OHIBGIH7TQSGBINANCNFSM4HWTAJMA.

binarybottle avatar Nov 05 '19 14:11 binarybottle

@PeerHerholz - while nilearn can plot surfaces, i'm not sure it can plot the shape features. hence it may limit what you can do.

in addition to niwidgets, you may want to take a look at vtk.js, which i know has been used in jupyter notebooks.

satra avatar Nov 05 '19 15:11 satra

@satra, yes. That's related to the examples and question I posted a bit further up. The example is based on depth values and the plotting seems to work (higher depth values further inside the cortex). The point I raised back then was how to tweak the plot to make it clearer and more interpretable. Was this your point? That although plots might work, they are not very comprehensive? In general, I like the nilearn version as it's rather light-weighted and (maybe) easier to use, especially for new users. That being said, if certain plotting (functions that would allow users to create plots for publications, posters, talks, etc.) would be included in the images, this should also be fine.

I'll check out vtk.js. There's also itkwidgets, but going from vtk to itk might create another hurdle we want to avoid.

PeerHerholz avatar Nov 05 '19 16:11 PeerHerholz