noahbenson / neuropythy

A neuroscience library for Python, intended to complement the existing nibabel library.
GNU Affero General Public License v3.0
115 stars 21 forks source link

pint version >=0.21 breaks neuropythy #32

Open dlinhardt opened 1 year ago

dlinhardt commented 1 year ago

Hey Noah! When compiling my docker I ran into problems running neuropythy that I traced back to the version of pint. When the version is increased to 0.21 I have the following output/error message:

  * Using FreeSurfer subject: sub-002
  * Using Atlas subject: fsaverage
  * Preparing Hemispheres...
  * Preparing Atlases...
      * Atlas: benson14, Version: (4, 0)
      * Atlas: wang15, Version: (1, 0)
  * Preparing Images...
  * Preparing Filemap...
  * Extracting Files...
      * sub-002/surf/rh.wang15_fplbl.mgz
      * sub-002/surf/rh.wang15_mplbl.mgz
      * sub-002/surf/lh.wang15_fplbl.mgz
      * sub-002/surf/lh.wang15_mplbl.mgz
      * sub-002/surf/rh.benson14_eccen.mgz
      * sub-002/surf/rh.benson14_varea.mgz
      * sub-002/surf/rh.benson14_sigma.mgz
      * sub-002/surf/rh.benson14_angle.mgz
      * sub-002/surf/lh.benson14_eccen.mgz
      * sub-002/surf/lh.benson14_sigma.mgz
      * sub-002/surf/lh.benson14_varea.mgz
      * sub-002/surf/lh.benson14_angle.mgz
      * sub-002/mri/wang15_fplbl.mgz
Traceback (most recent call last):
  File "/flywheel/v0/run.py", line 269, in <module>
    atlas.main(f'sub-{sub}', '-v', '-S')
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/commands/atlas.py", line 487, in main
    try: imap['export_all_fn']()
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/commands/atlas.py", line 411, in export_all
    filenames.append(nyio.save(flnm, filemap[flnm]))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 856, in __getitem__
    return self._examine_val(k, ps.PMap.__getitem__(self, k))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 852, in _examine_val
    val = val()
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 756, in curried_f
    return f(*(args0 + args), **merge(kwargs0, kwargs))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/commands/atlas.py", line 387, in <lambda>
    fm[flnm] = curry(lambda ims,m: ims[m], ims, m)
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 856, in __getitem__
    return self._examine_val(k, ps.PMap.__getitem__(self, k))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 852, in _examine_val
    val = val()
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 756, in curried_f
    return f(*(args0 + args), **merge(kwargs0, kwargs))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/commands/atlas.py", line 299, in _make_images
    im = subject.cortex_to_image(idat, image_template, hemi=(lk, rk), address=aa,
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/mri/core.py", line 381, in cortex_to_image
    hemi = self.to_hemi(hemi)
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/mri/core.py", line 176, in to_hemi
    elif h.startswith('lr_'): return self.to_hemi(('lh'+h[2:], 'rh'+h[2:]))
AttributeError: 'tuple' object has no attribute 'startswith'

my call in python: neuropythy.commands.atlas.main(f'sub-{sub}', '-v', '-S')

working conda env:

name: scientific
channels:
  - conda-forge
dependencies:
  - python=3.10.11
  - numpy=1.25.0
  - scipy=1.10.1
  - nilearn=0.10.1
  - nibabel=5.1.0
  - jupyter=1.0.0
  - pip
  - pip:
    - pybids==0.16.1
    - neuropythy==0.12.11
    - pint==0.20.1

Quick and dirty fix would be specify pint<0.21 in the requirements.txt, right?

noahbenson commented 1 year ago

Hey! Thanks for catching this—the issue is actually coming from the pimms library, and I have a fix, but I'm having trouble with my testing environments at the moment (numpy's changes in 1.24 have really broken a lot of packages recently). I'll push this to a new version of pimms and will update the neuropythy requirements soon.

dlinhardt commented 1 year ago

Great thanks!

noahbenson commented 1 year ago

Okay, try neuropythy version 0.12.12 and see if that fixes this for you (or send me the error message if not)!

dlinhardt commented 1 year ago

Hey I fixex neuropythy==0.12.12 and removed pint from the env.yml, new error:

  * Using FreeSurfer subject: sub-002
  * Using Atlas subject: fsaverage
  * Preparing Hemispheres...
  * Preparing Atlases...
      * Atlas: benson14, Version: (4, 0)
      * Atlas: wang15, Version: (1, 0)
  * Preparing Images...
  * Preparing Filemap...
  * Extracting Files...
      * sub-002/surf/lh.wang15_mplbl.mgz
      * sub-002/surf/lh.wang15_fplbl.mgz
      * sub-002/surf/rh.wang15_mplbl.mgz
      * sub-002/surf/rh.wang15_fplbl.mgz
      * sub-002/surf/lh.benson14_sigma.mgz
      * sub-002/surf/lh.benson14_varea.mgz
      * sub-002/surf/lh.benson14_eccen.mgz
      * sub-002/surf/lh.benson14_angle.mgz
      * sub-002/surf/rh.benson14_sigma.mgz
      * sub-002/surf/rh.benson14_varea.mgz
      * sub-002/surf/rh.benson14_eccen.mgz
      * sub-002/surf/rh.benson14_angle.mgz
      * sub-002/mri/wang15_mplbl.mgz
Traceback (most recent call last):
  File "/flywheel/v0/run.py", line 269, in <module>
    atlas.main(f'sub-{sub}', '-v', '-S')
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/commands/atlas.py", line 487, in main
    try: imap['export_all_fn']()
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/commands/atlas.py", line 411, in export_all
    filenames.append(nyio.save(flnm, filemap[flnm]))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 874, in __getitem__
    return self._examine_val(k, ps.PMap.__getitem__(self, k))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 870, in _examine_val
    val = val()
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 774, in curried_f
    return f(*(args0 + args), **merge(kwargs0, kwargs))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/commands/atlas.py", line 387, in <lambda>
    fm[flnm] = curry(lambda ims,m: ims[m], ims, m)
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 874, in __getitem__
    return self._examine_val(k, ps.PMap.__getitem__(self, k))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 870, in _examine_val
    val = val()
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/pimms/util.py", line 774, in curried_f
    return f(*(args0 + args), **merge(kwargs0, kwargs))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/commands/atlas.py", line 299, in _make_images
    im = subject.cortex_to_image(idat, image_template, hemi=(lk, rk), address=aa,
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/mri/core.py", line 381, in cortex_to_image
    hemi = self.to_hemi(hemi)
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/mri/core.py", line 190, in to_hemi
    return self.to_hemi(to_hemi_str(h))
  File "/opt/conda/envs/scientific/lib/python3.10/site-packages/neuropythy/util/core.py", line 41, in to_hemi_str
    if not pimms.is_str(s): raise ValueError('to_hemi_str(%s): not a string or ... or None' % s)
TypeError: not all arguments converted during string formatting
noahbenson commented 1 year ago

Ahh, okay, I think I know what is causing this also, but just to make sure that we don't keep ping-ponging errors back and forth, can you point me to your env.yml file?

noahbenson commented 1 year ago

I've pushed a new version of pimms (0.3.23) that should fix this issue; you'll need to add that explicitly for now because neuropythy currently only requires version 0.3.22 (that will change next time I update it). Just FYI there may be more issues that have to do with specific library versions and their interactions around the recent numpy changes. Finger's crossed that this is it, though!

dlinhardt commented 1 year ago

Thank you! I'll test asap and report the outcome.

dlinhardt commented 1 year ago

This worked, thanks a lot!

name: scientific channels:

  • conda-forge dependencies:
  • python=3.10.11
  • numpy=1.25.0
  • scipy=1.10.1
  • nilearn=0.10.1
  • nibabel=5.1.0
  • jupyter=1.0.0
  • pip
  • pip:
    • pybids==0.16.1
    • neuropythy==0.12.12
    • pimms==0.3.23