Closed
Description
Hi,
I needed the TCK streamline format so I installed the latest master branch with:
pip install -e git+https://github.com/nipy/nibabel.git#egg=nibabel
I can now load TCK streamlines:
nib.streamlines.FORMATS
Out[2]:
{'.tck': nibabel.streamlines.tck.TckFile,
'.trk': nibabel.streamlines.trk.TrkFile}
But I cannot load gzipped nifti files any more. If I gunzip the nifti, then it works fine.
The error I get:
AttributeError Traceback (most recent call last)
<ipython-input-4-6e9570ba8f5d> in <module>()
----> 1 nib.load('Diffusion_brain_mask.nii.gz')
.../Softwares/nibabel/src/nibabel2/nibabel/loadsave.py in load(filename, **kwargs)
41 sniff = None
42 for image_klass in all_image_classes:
---> 43 is_valid, sniff = image_klass.path_maybe_image(filename, sniff)
44 if is_valid:
45 img = image_klass.from_filename(filename, **kwargs)
.../Softwares/nibabel/src/nibabel2/nibabel/filebasedimages.py in path_maybe_image(klass, filename, sniff, sniff_max)
508 sniff = klass._sniff_meta_for(filename,
509 max(klass._meta_sniff_len, sniff_max),
--> 510 sniff)
511 if sniff is None or len(sniff[0]) < klass._meta_sniff_len:
512 return False, sniff
.../Softwares/nibabel/src/nibabel2/nibabel/filebasedimages.py in _sniff_meta_for(klass, filename, sniff_nbytes, sniff)
455 # Attempt to sniff from metadata location
456 try:
--> 457 with ImageOpener(meta_fname, 'rb') as fobj:
458 binaryblock = fobj.read(sniff_nbytes)
459 except IOError:
.../Softwares/nibabel/src/nibabel2/nibabel/openers.py in __init__(self, fileish, *args, **kwargs)
135 if 'compresslevel' in arg_names and 'compresslevel' not in kwargs:
136 kwargs['compresslevel'] = self.default_compresslevel
--> 137 self.fobj = opener(fileish, *args, **kwargs)
138 self._name = fileish
139 self.me_opened = True
.../Softwares/nibabel/src/nibabel2/nibabel/openers.py in _gzip_open(filename, mode, compresslevel)
72 # use indexed_gzip if possible for faster read access
73 if mode == 'rb' and HAVE_INDEXED_GZIP:
---> 74 gzip_file = SafeIndexedGzipFile(filename)
75
76 # Fall-back to built-in GzipFile (wrapped with the BufferedGzipFile class
indexed_gzip.pyx in indexed_gzip.IndexedGzipFile.__cinit__ (indexed_gzip.c:1404)()
AttributeError: 'str' object has no attribute 'mode'
I'm using python 2.7.12 with conda on a mac.
Many thanks for this excellent work.
Best,
-Auro