Fmriprep issue with validate node / qform

Hello,

I am running fmriprep on a sample of 80 subjects (singularity container), but I have an issue with two of them: preprocessing seems to work fine for anatomical data but it stop before the bold processing. On the html report, there are the anatomical preprocessed images (segmentation and normalisation) but no bold images.
The error is about the _validate node which “failed to run on host” and it seems to be related to qform…

I checked my data for bids validity and the anatomical and functional images of these subjects look fine. I am using the last version of fmriprep (20.0.0). The qform_code of the bold.nii is 1 (the same as for the others subjects).

My command line is:
fmriprep /netapp/vol7_u923/COSIMAGE/cosimage_ml/repos/fmriprep/dataset /netapp/vol7_u923/COSIMAGE/cosimage_ml/repos/fmriprep/derivative participant --fs-license-file /netapp/vol7_u923/COSIMAGE/cosimage_ml/repos/fmriprep/ --use-aroma --fs-no-reconall --participant_label sub-07

Here is the copy of the crash file:
Node: fmriprep_wf.single_subject_07_wf.func_preproc_task_rest_wf.bold_reference_wf.validate
Working directory: /netapp/vol7_u923/COSIMAGE/cosimage_ml/repos/fmriprep/work/fmriprep_wf/single_subject_07_wf/func_preproc_task_rest_wf/bold_reference_wf/validate

Node inputs:

in_file = /netapp/vol7_u923/COSIMAGE/cosimage_ml/repos/fmriprep/dataset/sub-07/func/sub-07_task-rest_bold.nii

Traceback (most recent call last):
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/plugins/multiproc.py”, line 69, in run_node
result[‘result’] = node.run(updatehash=updatehash)
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py”, line 479, in run
result = self._run_interface(execute=True)
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py”, line 585, in _run_interface
return self._run_command(execute)
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py”, line 678, in _run_command
result = self._interface.run(cwd=outdir)
File “/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/base/core.py”, line 382, in run
runtime = self._run_interface(runtime)
File “/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/interfaces/images.py”, line 423, in _run_interface
if np.allclose(new_qform, qform) and qform_code > 0:
UnboundLocalError: local variable ‘qform’ referenced before assignment

Any held would be appreciated,
Thanks

Marine LP

Yup, looks like a bug. Thanks for the report. We’ll have this fixed in fMRIPrep 20.0.1.

Bug reported: https://github.com/poldracklab/niworkflows/issues/465

Hi Marine, is there any chance that you’re able to share an example file for testing? Just the first 352 bytes should be fine:

head -c 352 /netapp/vol7_u923/COSIMAGE/cosimage_ml/repos/fmriprep/dataset/sub-07/func/sub-07_task-rest_bold.nii > img.hdr

I send you the link for img.hdr in my google drive:

Let me know if this help,

Marine

Thanks! This should be enough to reproduce the issue reliably.

If you're curious...
In [1]: import nibabel as nb                                                                                                                                  

In [2]: with open('img.hdr', 'rb') as fobj: 
   ...:     hdr = nb.Nifti1Header(fobj.read()[:348]) 
   ...:                                                                                                                                                       

In [3]: print(hdr)                                                                                                                                            
<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  80  80  42 280   1   1   1]
intent_p1       : 0.0
intent_p2       : 0.0
intent_p3       : 0.0
intent_code     : none
datatype        : int16
bitpix          : 16
slice_start     : 0
pixdim          : [-1.     2.8    2.8    2.8    2.382  1.     1.     1.   ]
vox_offset      : 352.0
scl_slope       : 0.04215814
scl_inter       : 1381.438
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'FSL4.0'
aux_file        : b''
qform_code      : scanner
sform_code      : scanner
quatern_b       : 0.0
quatern_c       : 0.998322
quatern_d       : -0.0579125
qoffset_x       : 107.954
qoffset_y       : -113.837
qoffset_z       : -11.965
srow_x          : [ -2.8     0.      0.    107.954]
srow_y          : [   0.          2.78122     0.323765 -113.837   ]
srow_z          : [  0.        -0.323765   2.78122  -11.965   ]
intent_name     : b''
magic           : b'n+1'

In [4]: hdr.get_qform()                                                                                                                                       
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-e5f0ff010fda> in <module>
----> 1 hdr.get_qform()

~/anaconda3/lib/python3.7/site-packages/nibabel/nifti1.py in get_qform(self, coded)
    918         if code == 0 and coded:
    919             return None, 0
--> 920         quat = self.get_qform_quaternion()
    921         R = quat2mat(quat)
    922         vox = hdr['pixdim'][1:4].copy()

~/anaconda3/lib/python3.7/site-packages/nibabel/nifti1.py in get_qform_quaternion(self)
    893         bcd = [hdr['quatern_b'], hdr['quatern_c'], hdr['quatern_d']]
    894         # Adjust threshold to precision of stored values in header
--> 895         return fillpositive(bcd, self.quaternion_threshold)
    896 
    897     def get_qform(self, coded=False):

~/anaconda3/lib/python3.7/site-packages/nibabel/quaternions.py in fillpositive(xyz, w2_thresh)
     98     if w2 < 0:
     99         if w2 < w2_thresh:
--> 100             raise ValueError('w2 should be positive, but is %e' % w2)
    101         w = 0
    102     else:

ValueError: w2 should be positive, but is -6.932380e-07