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/", line 67, in run_node
    result["result"] =
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/", line 516, in run
    result = self._run_interface(execute=True)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/", line 635, in _run_interface
    return self._run_command(execute)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/pipeline/engine/", line 741, in _run_command
    result =
  File "/usr/local/miniconda/lib/python3.7/site-packages/nipype/interfaces/base/", line 428, in run
    runtime = self._run_interface(runtime)
  File "/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/interfaces/", line 75, in _run_interface
  File "/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/utils/", line 205, in resample_by_spacing
    data = gaussian_filter(in_file.get_fdata(), smooth)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nibabel/", line 355, in get_fdata
    data = np.asanyarray(self._dataobj, dtype=dtype)
  File "/usr/local/miniconda/lib/python3.7/site-packages/numpy/core/", line 553, in asanyarray
    return array(a, dtype, copy=False, order=order, subok=True)
  File "/usr/local/miniconda/lib/python3.7/site-packages/nibabel/", line 391, in __array__
    arr = self._get_scaled(dtype=dtype, slicer=())
  File "/usr/local/miniconda/lib/python3.7/site-packages/nibabel/", 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/", line 337, in _get_unscaled
  File "/usr/local/miniconda/lib/python3.7/site-packages/nibabel/", 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,

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 ( 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