-
Notifications
You must be signed in to change notification settings - Fork 63
Description
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
base_path = os.path.dirname(os.getcwd())
dk_fsaverage_164k = (base_path + '/parcellations/atlas-desikankilliany_space-fsaverage_den-164k_hemi-L.aparc-1.annot',
base_path + '/parcellations/atlas-desikankilliany_space-fsaverage_den-164k_hemi-R.aparc-1.annot')
dk_fsaverage_164k = annot_to_gifti(dk_fsaverage_164k)
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
>>>dk_fsaverage_164k = (base_path + '/parcellations/atlas-desikankilliany_space-fsaverage_den-164k_hemi-L.aparc-1.annot', base_path + '/parcellations/atlas-desikankilliany_space-fsaverage_den-164k_hemi-R.aparc-1.annot')
>>>dk_fsaverage_164k = annot_to_gifti(dk_fsaverage_164k)Software version
0.0.4+41.g899aae1
What operating system were you using when you encountered this issue?
- macOS
- Windows
- Linux
Code of Conduct
- I agree to follow the
neuromapsCode of Conduct