Skip to content

Gzip file load error on latest master #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
solitaryangler opened this issue Sep 28, 2017 · 6 comments
Closed

Gzip file load error on latest master #557

solitaryangler opened this issue Sep 28, 2017 · 6 comments

Comments

@solitaryangler
Copy link

solitaryangler commented Sep 28, 2017

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

@effigies
Copy link
Member

Hi, thanks for the report. We'll look into this ASAP.

@solitaryangler
Copy link
Author

Thanks for the quick response. I'll keep my eyes open for an update/solution.

@pauldmccarthy
Copy link
Contributor

pauldmccarthy commented Oct 2, 2017

Hi @solitaryangler, could you update your version of indexed_gzip to the latest available? Versions of indexed_gzip prior to 0.4.0 (released about a month ago) expect the filename to be passed as a keyword argument, whereas the code in nibabel has been written against indexed_gzip>=0.4.0

@solitaryangler
Copy link
Author

Hi @pauldmccarthy many thanks. This is to confirm that upgrading indexed_gzip:
pip install indexed_gzip -U
resolved my problem.

@effigies
Copy link
Member

effigies commented Oct 2, 2017

@pauldmccarthy We shouldn't try to use indexed_gzip older than 0.4.0, then. Maybe print a warning and set HAVE_INDEXED_GZIP=False if the version is too old?

@pauldmccarthy
Copy link
Contributor

@effigies sure, I can add this to PR #562

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants