christianbrodbeck / Eelbrain

eelbrain.readthedocs.io
Other
65 stars 26 forks source link

Eelbrain not rendering Brain objects #55

Closed dustinchacon closed 1 year ago

dustinchacon commented 1 year ago

Hi,

I'm trying to plot a cluster from a spatiotemporal cluster-based permutation test. Everything's working fine, until I try to use eelbrian.plot.brain.cluster, in which case I get an error saying that init() takes exactly one argument. I get this error if I just try to plot a brain using eelbrain.plot.brain.brain('fsaverage'), traceback below. I've had this issue with eelbrain 0.38.4 and 0.38.6, and I'm running this on Python 3.10 on Mac OS Monterey.

I've also tried to (re)install pysurfer. My MNE environment is able to render Brain objects fine in an ipython environment, and also in an eelbrain environment. So there's something happening specifically with eelbrain functions. Any ideas what's going on?

2023-05-04 19:27:13.917 python[27564:826284] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/mr/79qm2pcs3f76pkqdnd_pwfzml0x6yh/T/com.continuum.python.savedState
Installed eelbrain event loop hook.
<frozen importlib._bootstrap>:241: RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 96 from PyObject
/Users/dac49596/anaconda3/envs/eelbrain0386/lib/python3.10/site-packages/eelbrain/plot/_brain_object.py:49: UserWarning: Error importing PySurfer: cannot import name 'Sequence' from 'collections' (/Users/dac49596/anaconda3/envs/eelbrain0386/lib/python3.10/collections/__init__.py)
  warn(f"Error importing PySurfer: {exception}")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 eelbrain.plot.brain.brain('fsaverage')

File ~/anaconda3/envs/eelbrain0386/lib/python3.10/site-packages/eelbrain/plot/_brain.py:562, in brain(src, cmap, vmin, vmax, surf, views, hemi, colorbar, time_label, w, h, axw, axh, foreground, background, parallel, cortex, title, smoothing_steps, mask, subjects_dir, name, pos)
    559 if subjects_dir is None:
    560     subjects_dir = source.subjects_dir
--> 562 brain = Brain(subject, hemi, surf, title, cortex, views=views, w=w, h=h, axw=axw, axh=axh, foreground=foreground, background=background, subjects_dir=subjects_dir, name=name, pos=pos, source_space=source)
    564 if ndvar is not None:
    565     if ndvar.x.dtype.kind in 'ui':

File ~/anaconda3/envs/eelbrain0386/lib/python3.10/site-packages/eelbrain/plot/_brain_object.py:240, in Brain.__init__(self, subject, hemi, surf, title, cortex, alpha, background, foreground, subjects_dir, views, offset, show_toolbar, offscreen, interaction, w, h, axw, axh, name, pos, source_space, show, run)
    238 if subjects_dir is not None:
    239     subjects_dir = os.path.expanduser(subjects_dir)
--> 240 surfer.Brain.__init__(self, subject, hemi, surf, '', cortex, alpha, (w, h), background, foreground, figure, subjects_dir, views, offset, show_toolbar, offscreen, interaction)
    241 TimeSlicer.__init__(self)
    243 if self._frame and CONFIG['show'] and show:

TypeError: object.__init__() takes exactly one argument (the instance to initialize)
christianbrodbeck commented 1 year ago

The real issue is a problem occurs earlier, see the following line:

/Users/dac49596/anaconda3/envs/eelbrain0386/lib/python3.10/site-packages/eelbrain/plot/_brain_object.py:49: UserWarning: Error importing PySurfer: cannot import name 'Sequence' from 'collections' (/Users/dac49596/anaconda3/envs/eelbrain0386/lib/python3.10/collections/__init__.py)

This (admittedly vague) warning is issued when the following initialization fails:

    from traits.trait_base import ETSConfig
    if use_inline_backend() or not CONFIG['eelbrain']:
        ETSConfig.toolkit = 'qt'
        INLINE_DISPLAY = True
        from mayavi import mlab
        mlab.options.offscreen = True
    else:
        ETSConfig.toolkit = 'wx'
    import surfer

What's strange is the actual error (cannot import name 'Sequence' from 'collections').

Can you try to run the following in your environment?

from traits.trait_base import ETSConfig
ETSConfig.toolkit = 'wx'
import surfer
dustinchacon commented 1 year ago

Hi Christian,

Yes, I tried 'from surfer import Brain' and got the same error; I should have mentioned that as well.

I tried the code that you gave me. Unfortunately, I'm seeing the same thing:

(Thanks for the really fast response!!)



In [1]: from traits.trait_base import ETSConfig

In [2]: ETSConfig.toolkit = 'wx'

In [3]: import surfer
2023-05-04 20:01:05.067 python[30876:852374] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/mr/79qm2pcs3f76pkqdnd_pwfzml0x6yh/T/com.continuum.python.savedState
<frozen importlib._bootstrap>:241: RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 96 from PyObject
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[3], line 1
----> 1 import surfer

File ~/anaconda3/envs/eelbrain0.38.4/lib/python3.10/site-packages/surfer/__init__.py:1
----> 1 from .viz import Brain, TimeViewer  # noqa
      2 from .utils import Surface, verbose, set_log_level, set_log_file  # noqa
      3 from .io import project_volume_data  # noqa

File ~/anaconda3/envs/eelbrain0.38.4/lib/python3.10/site-packages/surfer/viz.py:25
     22 from pyface.api import GUI
     23 from traitsui.api import View, Item, Group, VGroup, HGroup, VSplit, HSplit
---> 25 from . import utils, io
     26 from .utils import (Surface, verbose, create_color_lut, _get_subjects_dir,
     27                     string_types, threshold_filter, _check_units)
     30 logger = logging.getLogger('surfer')

File ~/anaconda3/envs/eelbrain0.38.4/lib/python3.10/site-packages/surfer/utils.py:1
----> 1 from collections import Sequence
      2 from distutils.version import LooseVersion
      3 import logging

ImportError: cannot import name 'Sequence' from 'collections' (/Users/dac49596/anaconda3/envs/eelbrain0.38.4/lib/python3.10/collections/__init__.py)```
christianbrodbeck commented 1 year ago

Looks like pysurfer is overdue for an update

This is from Python 3.9:

>>> from collections import Sequence
<ipython-input-6-8844d1891ca7>:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
  from collections import Sequence

For now, if you create an environment with Python 3.9 you should be able to proceed.

dustinchacon commented 1 year ago

Ahhh, it didn't even occur to me to try other python versions.

Thanks so much for your help! I'll try it with python3.9 and report back

christianbrodbeck commented 1 year ago

PySurfer PR (and branch) on which this should be fixed, in case you want to try: https://github.com/nipy/PySurfer/pull/320

christianbrodbeck commented 1 year ago

PySurfer is now updated to 0.11.1 which should fix this.