Closed ltuominen closed 11 months ago
Hi @ltuominen. This appears to be caused by a recent PR in nibabel. We're currently fixing this. We even have the PR ready. I was actually working on this at this exact moment. We'll merge it in a couple of minutes max. I'll let you know when the PR is merged :smile:
Wow! This is the speed I like to see things happening.
The PR is merged @ltuominen. Let us know if the bug is fixed with the new version :smile:
Works perfectly! Thanks again
Awesome!
I am having the same issue, even if I am using the latest versions of neuromaps (0.0.4) and nibabel (5.2.0). Would you have any tips on how to solve it? @VinceBaz
Hi @Turius, we should have fixed the issue on the main branch, but we have not released an official new version on pypi yet. Could you please update the package to install from the latest github version?
To confirm, if you run the following code, the output should be something like 0.0.4+51.gefef838
instead of just 0.0.4
.
python -c 'import sys,neuromaps; print(sys.version); print(neuromaps.__version__)'
Issue summary
Hi there, I am rerunning my code and since last update annot_to_gifti stopped working. Something about unable to read giftis even if I give it annot's. Appreciate your help! Thanks again Lauri
Detailed issue description
TypeError Traceback (most recent call last) Cell In[4], line 4 1 base_path = os.path.dirname(os.getcwd()) 2 dk_fsaverage_164k = (base_path + '/parcellations/atlas-desikankilliany_space-fsaverage_den-164k_hemi-L.aparc-1.annot', 3 base_path + '/parcellations/atlas-desikankilliany_space-fsaverage_den-164k_hemi-R.aparc-1.annot') ----> 4 dk_fsaverage_164k = annot_to_gifti(dk_fsaverage_164k)
File ~/anaconda3/envs/neuromaps_py3.8/lib/python3.8/site-packages/neuromaps/images.py:529, in annot_to_gifti(parcellation, background) 525 labeltable.labels.append(glabel) 527 gifti += (nib.GiftiImage(darrays=[darr], labeltable=labeltable),) --> 529 return relabel_gifti(gifti, background=background)
File ~/anaconda3/envs/neuromaps_py3.8/lib/python3.8/site-packages/neuromaps/images.py:456, in relabel_gifti(parcellation, background, offset) 452 background = PARCIGNORE.copy() 454 for hemi in parcellation: 455 # get necessary info from file --> 456 img = load_gifti(hemi) 457 data = img.agg_data().copy() 458 labels = img.labeltable.labels
File ~/anaconda3/envs/neuromaps_py3.8/lib/python3.8/site-packages/neuromaps/images.py:170, in load_gifti(img) 166 # it's not a pre-loaded GiftiImage so error out 167 elif (isinstance(err, TypeError) 168 and not str(err) == 'stat: path should be string, bytes, os.' 169 'PathLike or integer, not GiftiImage'): --> 170 raise err 172 return img
File ~/anaconda3/envs/neuromaps_py3.8/lib/python3.8/site-packages/neuromaps/images.py:160, in load_gifti(img) 143 """ 144 Load gifti file
img
. 145 (...) 157 Loaded GIFTI images 158 """ 159 try: --> 160 img = nib.load(img) 161 except (ImageFileError, TypeError) as err: 162 # it's gzipped, so read the gzip and pipe it in 163 if isinstance(err, ImageFileError) and str(err).endswith('.gii.gz"'):File ~/anaconda3/envs/neuromaps_py3.8/lib/python3.8/site-packages/nibabel/loadsave.py:96, in load(filename, kwargs) 81 def load(filename: FileSpec, kwargs) -> FileBasedImage: 82 r"""Load file given filename, guessing at file type 83 84 Parameters (...) 94 Image of guessed type 95 """ ---> 96 filename = _stringify_path(filename) 98 # Check file exists and is not empty 99 try:
File ~/anaconda3/envs/neuromaps_py3.8/lib/python3.8/site-packages/nibabel/filename_parser.py:41, in _stringify_path(filepath_or_buffer) 25 def _stringify_path(filepath_or_buffer: FileSpec) -> str: 26 """Attempt to convert a path-like object to a string. 27 28 Parameters (...) 39 https://github.com/pandas-dev/pandas/blob/325dd68/pandas/io/common.py#L131-L160 40 """ ---> 41 return pathlib.Path(filepath_or_buffer).expanduser().as_posix()
File ~/anaconda3/envs/neuromaps_py3.8/lib/python3.8/pathlib.py:1042, in Path.new(cls, *args, **kwargs) 1040 if cls is Path: 1041 cls = WindowsPath if os.name == 'nt' else PosixPath -> 1042 self = cls._from_parts(args, init=False) 1043 if not self._flavour.is_supported: 1044 raise NotImplementedError("cannot instantiate %r on your system" 1045 % (cls.name,))
File ~/anaconda3/envs/neuromaps_py3.8/lib/python3.8/pathlib.py:683, in PurePath._from_parts(cls, args, init) 678 @classmethod 679 def _from_parts(cls, args, init=True): 680 # We need to call _parse_args on the instance, so as to get the 681 # right flavour. 682 self = object.new(cls) --> 683 drv, root, parts = self._parse_args(args) 684 self._drv = drv 685 self._root = root
File ~/anaconda3/envs/neuromaps_py3.8/lib/python3.8/pathlib.py:667, in PurePath._parse_args(cls, args) 665 parts += a._parts 666 else: --> 667 a = os.fspath(a) 668 if isinstance(a, str): 669 # Force-cast str subclasses to str (issue #21127) 670 parts.append(str(a))
TypeError: expected str, bytes or os.PathLike object, not GiftiImage
Steps to reproduce issue
Software version
0.0.4+41.g899aae1
What operating system were you using when you encountered this issue?
Code of Conduct
neuromaps
Code of Conduct