bids-standard / legacy-validator

Validator for the Brain Imaging Data Structure
https://bids-standard.github.io/legacy-validator/
MIT License
185 stars 110 forks source link

[Code 26] NIFTI_HEADER_UNREADABLE #1537

Closed jagruti8 closed 2 years ago

jagruti8 commented 2 years ago

@chrisgorgo Hi, so when I uploaded my dataset in the bids-validator, I got the above error, with more details as "We were unable to parse header data from this NIfTI file. Please ensure it is not corrupted or mislabeled".

The nifti file is saved as this "_HCP_DATA/sub-103818/dwi/sub-103818_acq-multishelldwi.nii.gz"

However, when I ran this using the command line version, it didn't show me this error.

Also, there was a dataset which has been made BIDS-compatible by my senior and I had replicated the same structure. However for her case, it didn't show this error either in the web-version or the command line version. Is there any error in my data?

julfou81 commented 2 years ago

It seems to be a bug or an over-interpretation of the new release of BIDS validator, I got the same error on my data even though the nifty files are perfectly readable by FSL for instance. I moved on to try with an earlier version of the BIDS validator (v1.9.3) and didn't get this error.

effigies commented 2 years ago

Could you share the raw header of a files that is failing? You could copy and paste the results of:

FILE="/path/to/file.nii.gz"
python -c "import sys; print(open(sys.argv[1], 'rb').read(352))" $FILE
jagruti8 commented 2 years ago

@effigies Thanks for the reply. Here it is, python -c "import sys; print(open(sys.argv[1], 'rb').read(352))" sub-103818_acq-multishell_dwi.nii.gz

b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xec\xda\x05|\x14g\xd7\xf7\xf1\x85\xe0\x04\x08\x0e\xc5\x8b\x14w\r\x90\xbd\xe6:\xc1\x1d\x8a\xbb\x15)\xee\xce\x84\x00\x81 \t\x12\x82[p\x87\xe0N\xd0\xe2N\x91\xe2Z\xb4\xb8\xf3\xd2\xfby\xfa>\xdc\x14\x89\xecF\xe0\xf7\xe5\xf3\xff\xecf3s\xce\x99\x99\x8b\xd9\xdd\xd2z\x91,\x81\xd0\xc9\x12\xc52\xca\xb2\xe4}\xd2F\x8ad\xf9\xfb\xcf\x7fs\xb2\xa4\xfd\xcf\xa3\xb9\xc5b\x99n\xfd\xbf\x98\xd6\xff\xden\x99|\xf0Z\xac\xcfu+Y\xad|\x81\x9c\xb9\x033W\xc8Dy\xff\xe7\x7f\xfc3\xd3Jm\xb1\xbc\x0e\xb0X\xbc\xdfg\xfa\x96\xff\xdb\xf2\xef\xd7\xff6\xfd\x7f\xb7\xfb{\x9b\x7f\xfc\xfd\x9a\xf7\x07?\xff\x8fv\xd9\xf2\xd8ab\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

jagruti8 commented 2 years ago

@julfou81 Thanks for the reply. Can you please share the link of the BIDS-Validator v1.9.3?

effigies commented 2 years ago

Definitely a readable header:

>>> import io, gzip, nibabel as nb
>>> bio = io.BytesIO(b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xec\xda\x05|\x14g\xd7\xf7\xf1\x85\xe0\x04\x08\x0e\xc5\x8b\x14w\r\x90\xbd\xe6:\xc1\x1d\x8a\xbb\x15)\xee\xce\x84\x00\x81 \t\x12\x82[p\x87\xe0N\xd0\xe2N\x91\xe2Z\xb4\xb8\xf3\xd2\xfby\xfa>\xdc\x14\x89\xecF\xe0\xf7\xe5\xf3\xff\xecf3s\xce\x99\x99\x8b\xd9\xdd\xd2z\x91,\x81\xd0\xc9\x12\xc52\xca\xb2\xe4}\xd2F\x8ad\xf9\xfb\xcf\x7fs\xb2\xa4\xfd\xcf\xa3\xb9\xc5b\x99n\xfd\xbf\x98\xd6\xff\xden\x99|\xf0Z\xac\xcfu+Y\xad|\x81\x9c\xb9\x033W\xc8Dy\xff\xe7\x7f\xfc3\xd3Jm\xb1\xbc\x0e\xb0X\xbc\xdfg\xfa\x96\xff\xdb\xf2\xef\xd7\xff6\xfd\x7f\xb7\xfb{\x9b\x7f\xfc\xfd\x9a\xf7\x07?\xff\x8fv\xd9\xf2\xd8ab\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
>>> fobj = gzip.GzipFile(fileobj=bio)
>>> raw = fobj.read(352)
>>> img = nb.Nifti1Image.from_bytes(raw)
>>> print(img)
<class 'nibabel.nifti1.Nifti1Image'>
data shape (145, 174, 145, 288)
affine: 
[[  -1.25    0.      0.     90.  ]
 [   0.      1.25    0.   -126.  ]
 [   0.      0.      1.25  -72.  ]
 [   0.      0.      0.      1.  ]]
metadata:
<class 'nibabel.nifti1.Nifti1Header'> object, endian='<'
sizeof_hdr      : 348
data_type       : b''
db_name         : b''
extents         : 0
session_error   : 0
regular         : b'r'
dim_info        : 0
dim             : [  4 145 174 145 288   1   1   1]
intent_p1       : 0.0
intent_p2       : 0.0
intent_p3       : 0.0
intent_code     : none
datatype        : float32
bitpix          : 32
slice_start     : 0
pixdim          : [-1.    1.25  1.25  1.25  1.    0.    0.    0.  ]
vox_offset      : 0.0
scl_slope       : nan
scl_inter       : nan
slice_end       : 0
slice_code      : unknown
xyzt_units      : 10
cal_max         : 0.0
cal_min         : 0.0
slice_duration  : 0.0
toffset         : 0.0
glmax           : 0
glmin           : 0
descrip         : b'FSL5.0'
aux_file        : b''
qform_code      : mni
sform_code      : mni
quatern_b       : 0.0
quatern_c       : 1.0
quatern_d       : 0.0
qoffset_x       : 90.0
qoffset_y       : -126.0
qoffset_z       : -72.0
srow_x          : [-1.25  0.    0.   90.  ]
srow_y          : [   0.      1.25    0.   -126.  ]
srow_z          : [  0.     0.     1.25 -72.  ]
intent_name     : b''
magic           : b'n+1'

@rwblair Have we changed the Nifti I/O recently?

jagruti8 commented 2 years ago

@effigies Thanks for the reply. So, I hope everything is correct on my side and proceed forward with this data?

sappelhoff commented 2 years ago

Can you please share the link of the BIDS-Validator v1.9.3?

there is no web version available for previous releases of the bids-validator, only for the stable version (currently 1.9.8). However, you can install it as a command line tool using nodejs and npm: https://www.npmjs.com/package/bids-validator/v/1.9.3

julfou81 commented 2 years ago

@julfou81 Thanks for the reply. Can you please share the link of the BIDS-Validator v1.9.3?

For completeness:

https://neurostars.org/t/nifti-header-unreadable/23602/4?u=jsein

effigies commented 2 years ago

For anybody trying to debug this, you can generate a file of zeros that should fail in the same way:

import gzip
import io

import nibabel as nb
import numpy as np

bio = io.BytesIO(
    b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xec\xda\x05|\x14g\xd7\xf7\xf1\x85'
    b'\xe0\x04\x08\x0e\xc5\x8b\x14w\r\x90\xbd\xe6:\xc1\x1d\x8a\xbb\x15)\xee\xce'
    b'\x84\x00\x81 \t\x12\x82[p\x87\xe0N\xd0\xe2N\x91\xe2Z\xb4\xb8\xf3\xd2\xfby'
    b'\xfa>\xdc\x14\x89\xecF\xe0\xf7\xe5\xf3\xff\xecf3s\xce\x99\x99\x8b\xd9\xdd'
    b'\xd2z\x91,\x81\xd0\xc9\x12\xc52\xca\xb2\xe4}\xd2F\x8ad\xf9\xfb\xcf\x7fs'
    b'\xb2\xa4\xfd\xcf\xa3\xb9\xc5b\x99n\xfd\xbf\x98\xd6\xff\xden\x99|\xf0Z\xac'
    b'\xcfu+Y\xad|\x81\x9c\xb9\x033W\xc8Dy\xff\xe7\x7f\xfc3\xd3Jm\xb1\xbc\x0e'
    b'\xb0X\xbc\xdfg\xfa\x96\xff\xdb\xf2\xef\xd7\xff6\xfd\x7f\xb7\xfb{\x9b\x7f'
    b'\xfc\xfd\x9a\xf7\x07?\xff\x8fv\xd9\xf2\xd8ab\x00\x00\x00\x00\x00\x00\x00'
)

hdr = nb.Nifti1Header.from_fileobj(gzip.GzipFile(fileobj=bio))

fake_img = nb.Nifti1Image(
    np.zeros(hdr.get_data_shape(), dtype=hdr.get_data_dtype()),
    affine=None,
    header=hdr
)
fake_img.to_filename('fake_img.nii.gz')
jagruti8 commented 2 years ago

@effigies I am sorry to ask again, so is there any problem with the nifti image I am having that it shows me the "NIFTI_HEADER_UNREADABLE" error?

effigies commented 2 years ago

Not necessarily. In this case, it's probably an out of memory error. But I would validate the dataset on an older version of the validator, as suggested on the neutostars thread.

jagruti8 commented 2 years ago

@effigies Thanks a lot for the reply.

Screenshot 2022-09-29 at 02 26 08

The above is the result when I ran bids-validator current version in the command line. Do I still need to redo it for an older version?

effigies commented 2 years ago

No, that looks like a successful run.

jagruti8 commented 2 years ago

@effigies Thanks a lot for all the help.