fMRIPrep raising OSError

Hi all,

I am trying to run fMRIPrep v20.2.5 (via singularity) and getting the following exception for any subject I tried:

Node: fmriprep_wf.single_subject_144_wf.anat_preproc_wf.brain_extraction_wf.res_tmpl
Working directory: /home/zvi/Projects/labbing/work/fmriprep_wf/single_subject_144_wf/anat_preproc_wf/brain_extraction_wf/res_tmpl

Node inputs:

clip = True
in_file = /home/zvi/.cache/templateflow/tpl-OASIS30ANTs/tpl-OASIS30ANTs_res-01_T1w.nii.gz
order = 3
smooth = True
zooms = (4.0, 4.0, 4.0)

Traceback (most recent call last):
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 516, in run
    result = self._run_interface(execute=True)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 635, in _run_interface
    return self._run_command(execute)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/nodes.py", line 741, in _run_command
    result = self._interface.run(cwd=outdir)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/base/core.py", line 428, in run
    runtime = self._run_interface(runtime)
  File "/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/interfaces/images.py", line 75, in _run_interface
    smooth=self.inputs.smooth,
  File "/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/utils/images.py", line 205, in resample_by_spacing
    data = gaussian_filter(in_file.get_fdata(), smooth)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nibabel/dataobj_images.py", line 355, in get_fdata
    data = np.asanyarray(self._dataobj, dtype=dtype)
  File "/usr/local/miniconda/lib/python3.7/site-packages/numpy/core/numeric.py", line 553, in asanyarray
    return array(a, dtype, copy=False, order=order, subok=True)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nibabel/arrayproxy.py", line 391, in __array__
    arr = self._get_scaled(dtype=dtype, slicer=())
  File "/usr/local/miniconda/lib/python3.7/site-packages/nibabel/arrayproxy.py", line 358, in _get_scaled
    scaled = apply_read_scaling(self._get_unscaled(slicer=slicer), scl_slope, scl_inter)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nibabel/arrayproxy.py", line 337, in _get_unscaled
    mmap=self._mmap)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nibabel/volumeutils.py", line 529, in array_from_file
    raise IOError(f"Expected {n_bytes} bytes, got {n_read} bytes from "
OSError: Expected 64364544 bytes, got 38797506 bytes from object
 - could the file be damaged?

Prior posts I found here concerning this exception had to do with either disk space, which should not be the issue (over 12TB available) or a problem with TemplateFlow when running multiple subjects. I tried running a number of subjects independently and am still getting this error. Same thing happens with v20.2.4 (I can check more version if that might be helpful).

Any help figuring this out will be greatly appreciated!

Thank you all and best wishes,
Zvi

Hi Zvi, can you post your fMRIPrep command? Also, is this dataset BIDS valid?

1 Like

Looks like a probable cause. TemplateFlow works with lazy loading (i.e., templates are downloaded just once, the first time you need them), however, unless you use datalad (which is not the default), two processes are likely to request one template at the same time, trigger the download and the result is likely a corrupted file.

Once the file seems to contain data, TemplateFlow does not check the hash, so it remains there. I would suggest deleting the TEMPLATEFLOW_HOME directory altogether, and using the download script (https://github.com/nipreps/fmriprep/blob/a4fd718918c95c79fe8ec56bbc233caa0b3f445e/scripts/fetch_templates.py) to pull down the necessary templates before you run you job array.

1 Like

It worked perfectly! :fireworks:
Thank you so much!

@Steven thanks for your comment in any case, it did lead me to finding an issue with DWI scans that weren’t converted properly (but had nothing to do with the fMRIPrep issue).

1 Like

MANAGED BY INCF