Skip to content
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

embed_nb for plot_cortical #24

Open
araikes opened this issue Feb 17, 2023 · 4 comments
Open

embed_nb for plot_cortical #24

araikes opened this issue Feb 17, 2023 · 4 comments

Comments

@araikes
Copy link

araikes commented Feb 17, 2023

Hi @saratheriver,

I'm attempting to do some fairly simple visualization (for testing purposes) using my own data. I've attempted to use plot_cortical inside of Jupyter notebook but receive an error (see below). I have no problem with exporting to a file.

Call:

plot_cortical(array_name=CT_schaefer_fsa5, surface_name="fsa5", cmap = 'viridis', embed_nb = True)

Error:

TypeError                                 Traceback (most recent call last)
Cell In[19], line 8
      5 CT_schaefer_fsa5 = parcel_to_surface(CT_schaefer_200, 'schaefer_200_fsa5')
      7 # Project the results on the surface brain
----> 8 plot_cortical(array_name=CT_schaefer_fsa5, surface_name="fsa5", cmap = 'viridis', embed_nb = True)

File ~\.conda\envs\brainstat\lib\site-packages\enigmatoolbox\vtk_interface\decorators.py:41, in wrap_input.<locals>._wrapper_decorator.<locals>._wrapper_wrap(*args, **kwds)
     38 @functools.wraps(func)
     39 def _wrapper_wrap(*args, **kwds):
     40     args, kwds = _wrap_input_data(args, kwds, *xargs, skip=skip)
---> 41     data = func(*args, **kwds)
     42     return data

File ~\.conda\envs\brainstat\lib\site-packages\enigmatoolbox\plotting\surface_plotting.py:528, in plot_cortical(array_name, surface_name, color_bar, color_range, label_text, cmap, nan_color, zoom, background, size, interactive, embed_nb, screenshot, filename, scale, transparent_bg, **kwargs)
    526 kwds = {'view': view, 'share': 'r'}
    527 kwds.update(kwargs)
--> 528 return plot_surf(surfs, layout, array_name=array_name, color_bar=color_bar,
    529                  color_range=color_range, label_text=label_text, cmap=cmap,
    530                  nan_color=nan_color, zoom=zoom, background=background,
    531                  size=size, interactive=interactive, embed_nb=embed_nb,
    532                  screenshot=screenshot, filename=filename, scale=scale,
    533                  transparent_bg=transparent_bg, **kwds)

File ~\.conda\envs\brainstat\lib\site-packages\enigmatoolbox\plotting\surface_plotting.py:419, in plot_surf(surfs, layout, array_name, view, color_bar, color_range, share, label_text, cmap, nan_color, zoom, background, size, embed_nb, interactive, scale, transparent_bg, screenshot, filename, return_plotter, **kwargs)
    415 if screenshot:
    416     return p.screenshot(filename, transparent_bg=transparent_bg,
    417                         scale=scale)
--> 419 return p.show(embed_nb=embed_nb, interactive=interactive, scale=scale,
    420               transparent_bg=transparent_bg)

File ~\.conda\envs\brainstat\lib\site-packages\enigmatoolbox\plotting\base.py:308, in Plotter.show(self, embed_nb, interactive, transparent_bg, scale)
    306     if interactive:
    307         return self.to_panel(scale)
--> 308     return self.to_notebook(transparent_bg, scale)
    310 else:
    312     self._check_closed()

File ~\.conda\envs\brainstat\lib\site-packages\enigmatoolbox\plotting\base.py:413, in Plotter.to_notebook(self, transparent_bg, scale)
    411 writer = BSPNGWriter(writeToMemory=True)
    412 result = serial_connect(wimg, writer, as_data=False).result
--> 413 data = memoryview(result).tobytes()
    414 from IPython.display import Image
    415 return Image(data)

TypeError: memoryview: a bytes-like object is required, not 'BSVTKObjectWrapper'

What am I missing about the use of the embed_nb flag?

@saratheriver
Copy link
Collaborator

Hello -

I can't seem to reproduce your error. Would you mind providing me with more information, please? Eg python version, enigmaa toolbox version, etc

@Dominic-Arold
Copy link

Dominic-Arold commented Jun 14, 2023

Hi all,
I get the same error message with embed_nb=True. I work in Jupyterlab 3.6.2. The used python kernel has Python 3.8.10 and enigmatoolbox 2.0.3.

Call:

from enigmatoolbox.plotting import plot_cortical
from enigmatoolbox.utils.parcellation import parcel_to_surface
plot_cortical(array_name = parcel_to_surface(CT_values, 'aparc_fsa5'), surface_name='fsa5', interactive=False, embed_nb=True)

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[84], line 8
      5 df_th, df_area, df_vol, dropped = ukb_to_enigmatoolbox_feature_set(df_p)
      6 CT_values = df_th.values.reshape(-1)
----> 8 plot_cortical(array_name = parcel_to_surface(CT_values, 'aparc_fsa5'), surface_name='fsa5', interactive=False, embed_nb=True)

File ~/.cache/pypoetry/virtualenvs/nafld-xc7jJsTU-py3.8/lib/python3.8/site-packages/enigmatoolbox/vtk_interface/decorators.py:41, in wrap_input.<locals>._wrapper_decorator.<locals>._wrapper_wrap(*args, **kwds)
     38 @functools.wraps(func)
     39 def _wrapper_wrap(*args, **kwds):
     40     args, kwds = _wrap_input_data(args, kwds, *xargs, skip=skip)
---> 41     data = func(*args, **kwds)
     42     return data

File ~/.cache/pypoetry/virtualenvs/nafld-xc7jJsTU-py3.8/lib/python3.8/site-packages/enigmatoolbox/plotting/surface_plotting.py:528, in plot_cortical(array_name, surface_name, color_bar, color_range, label_text, cmap, nan_color, zoom, background, size, interactive, embed_nb, screenshot, filename, scale, transparent_bg, **kwargs)
    526 kwds = {'view': view, 'share': 'r'}
    527 kwds.update(kwargs)
--> 528 return plot_surf(surfs, layout, array_name=array_name, color_bar=color_bar,
    529                  color_range=color_range, label_text=label_text, cmap=cmap,
    530                  nan_color=nan_color, zoom=zoom, background=background,
    531                  size=size, interactive=interactive, embed_nb=embed_nb,
    532                  screenshot=screenshot, filename=filename, scale=scale,
    533                  transparent_bg=transparent_bg, **kwds)

File ~/.cache/pypoetry/virtualenvs/nafld-xc7jJsTU-py3.8/lib/python3.8/site-packages/enigmatoolbox/plotting/surface_plotting.py:419, in plot_surf(surfs, layout, array_name, view, color_bar, color_range, share, label_text, cmap, nan_color, zoom, background, size, embed_nb, interactive, scale, transparent_bg, screenshot, filename, return_plotter, **kwargs)
    415 if screenshot:
    416     return p.screenshot(filename, transparent_bg=transparent_bg,
    417                         scale=scale)
--> 419 return p.show(embed_nb=embed_nb, interactive=interactive, scale=scale,
    420               transparent_bg=transparent_bg)

File ~/.cache/pypoetry/virtualenvs/nafld-xc7jJsTU-py3.8/lib/python3.8/site-packages/enigmatoolbox/plotting/base.py:308, in Plotter.show(self, embed_nb, interactive, transparent_bg, scale)
    306     if interactive:
    307         return self.to_panel(scale)
--> 308     return self.to_notebook(transparent_bg, scale)
    310 else:
    312     self._check_closed()

File ~/.cache/pypoetry/virtualenvs/nafld-xc7jJsTU-py3.8/lib/python3.8/site-packages/enigmatoolbox/plotting/base.py:413, in Plotter.to_notebook(self, transparent_bg, scale)
    411 writer = BSPNGWriter(writeToMemory=True)
    412 result = serial_connect(wimg, writer, as_data=False).result
--> 413 data = memoryview(result).tobytes()
    414 from IPython.display import Image
    415 return Image(data)

TypeError: memoryview: a bytes-like object is required, not 'BSVTKObjectWrapper'

@teanijarv
Copy link

teanijarv commented Nov 2, 2023

Same error for me. Has anyone managed to fix it?

1 similar comment
@chenfei-ye
Copy link

Same error for me. Has anyone managed to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants