actually my wild guess is that may be those files somehow managed to be
not compressed at all (e.g. just renamed into .nii.gz from original
.nii). If there would be such a cross-platform problem -- we would have
heard about this issue long before. Do you still have access to those
files? what would be output of running 'file' command on them?
yeap -- here is my protocol and sample of errors you would get if you
try to open non-gzipped .nii.gz (your case) and actual gzipped .nii
% python -c 'import nibabel as nib; print nib.load("1.nii.gz")' | head
<class 'nibabel.nifti1.Nifti1Image'>
data shape (91, 109, 91)
affine:
[[ -2. 0. 0. 90.]
[ 0. 2. 0. -126.]
[ 0. 0. 2. -72.]
[ 0. 0. 0. 1.]]
metadata:
<class 'nibabel.nifti1.Nifti1Header'> object, endian='<'
sizeof_hdr : 348
% mv 1.nii.gz 1.nii
% python -c 'import nibabel as nib; print nib.load("1.nii")' | head
sizeof_hdr should be 348; set sizeof_hdr to 348
data code -4149 not recognized; not attempting fix
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/nibabel/loadsave.py", line 54, in load
return klass.from_filename(filename)
File "/usr/lib/pymodules/python2.7/nibabel/spatialimages.py", line 411, in from_filename
return klass.from_file_map(file_map)
File "/usr/lib/pymodules/python2.7/nibabel/analyze.py", line 870, in from_file_map
header = klass.header_class.from_fileobj(hdrf)
File "/usr/lib/pymodules/python2.7/nibabel/nifti1.py", line 569, in from_fileobj
hdr = klass(raw_str, endianness, check)
File "/usr/lib/pymodules/python2.7/nibabel/nifti1.py", line 552, in __init__
check)
File "/usr/lib/pymodules/python2.7/nibabel/analyze.py", line 248, in __init__
super(AnalyzeHeader, self).__init__(binaryblock, endianness, check)
File "/usr/lib/pymodules/python2.7/nibabel/wrapstruct.py", line 172, in __init__
self.check_fix()
File "/usr/lib/pymodules/python2.7/nibabel/wrapstruct.py", line 357, in check_fix
report.log_raise(logger, error_level)
File "/usr/lib/pymodules/python2.7/nibabel/batteryrunners.py", line 275, in log_raise
raise self.error(self.problem_msg)
nibabel.spatialimages.HeaderDataError: data code -4149 not recognized
% zcat 1.nii > 1_unzipped.nii
% python -c 'import nibabel as nib; print nib.load("1_unzipped.nii")' | head
<class 'nibabel.nifti1.Nifti1Image'>
data shape (91, 109, 91)
affine:
[[ -2. 0. 0. 90.]
[ 0. 2. 0. -126.]
[ 0. 0. 2. -72.]
[ 0. 0. 0. 1.]]
metadata:
<class 'nibabel.nifti1.Nifti1Header'> object, endian='<'
sizeof_hdr : 348
% mv 1_unzipped.nii 1_unzipped.nii.gz
% python -c 'import nibabel as nib; print nib.load("1_unzipped.nii.gz")' | head
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/nibabel/loadsave.py", line 54, in load
return klass.from_filename(filename)
File "/usr/lib/pymodules/python2.7/nibabel/spatialimages.py", line 411, in from_filename
return klass.from_file_map(file_map)
File "/usr/lib/pymodules/python2.7/nibabel/analyze.py", line 870, in from_file_map
header = klass.header_class.from_fileobj(hdrf)
File "/usr/lib/pymodules/python2.7/nibabel/nifti1.py", line 568, in from_fileobj
raw_str = fileobj.read(klass.template_dtype.itemsize)
File "/usr/lib/python2.7/gzip.py", line 261, in read
self._read(readsize)
File "/usr/lib/python2.7/gzip.py", line 296, in _read
self._read_gzip_header()
File "/usr/lib/python2.7/gzip.py", line 190, in _read_gzip_header
raise IOError, 'Not a gzipped file'
IOError: Not a gzipped file
% file 1_unzipped.nii.gz 1.nii
1_unzipped.nii.gz: data
1.nii: gzip compressed data, from Unix
Yaroslav O. Halchenko, Ph.D.
http://neuro.debian.net http://www.pymvpa.org http://www.fail2ban.org
Research Scientist, Psychological and Brain Sciences Dept.
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone:
+1 (603) 646-9834 Fax:
+1 (603) 646-1419
WWW:
http://www.linkedin.com/in/yarik