IndexError: index -1 is out of bounds for axis 0 with size 0

I’m encountering this strange error while using version 21.0.2

Node Name: fmriprep_wf.single_subject_C501_wf.func_preproc_ses_1post_task_VerbNback_run_1_wf.unwarp_wf.brainextraction_wf.clipper_pre

File: /N/project/Kawata_TBI_1/R01_HighSchool_BIDS/derivatives/fmriprep-21.0.2/sub-C501/log/20220705-181654_396a0ce4-6943-4879-816a-91cff124252a/crash-20220706-123925-dlevitas-clipper_pre-a2dcd77e-9c6f-4088-bc63-273854dde356.txt
Working Directory: /N/scratch/dlevitas/fmriprep-21.0.2_temp/sub-C501/fmriprep_wf/single_subject_C501_wf/func_preproc_ses_1post_task_VerbNback_run_1_wf/unwarp_wf/brainextraction_wf/clipper_pre
Inputs:

    dtype: int16
    in_file:
    invert: False
    nonnegative: True
    p_max: 99.98
    p_min: 35.0

Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/nipype/pipeline/plugins/legacymultiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/opt/conda/lib/python3.8/site-packages/nipype/pipeline/engine/nodes.py", line 516, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/lib/python3.8/site-packages/nipype/pipeline/engine/nodes.py", line 635, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/lib/python3.8/site-packages/nipype/pipeline/engine/nodes.py", line 741, in _run_command
    result = self._interface.run(cwd=outdir)
  File "/opt/conda/lib/python3.8/site-packages/nipype/interfaces/base/core.py", line 428, in run
    runtime = self._run_interface(runtime)
  File "/opt/conda/lib/python3.8/site-packages/niworkflows/interfaces/nibabel.py", line 409, in _run_interface
    self._results["out_file"] = _advanced_clip(
  File "/opt/conda/lib/python3.8/site-packages/niworkflows/interfaces/nibabel.py", line 543, in _advanced_clip
    a_min = np.percentile(
  File "<__array_function__ internals>", line 5, in percentile
  File "/opt/conda/lib/python3.8/site-packages/numpy/lib/function_base.py", line 3818, in percentile
    return _quantile_unchecked(
  File "/opt/conda/lib/python3.8/site-packages/numpy/lib/function_base.py", line 3937, in _quantile_unchecked
    r, k = _ureduce(a, func=_quantile_ureduce_func, q=q, axis=axis, out=out,
  File "/opt/conda/lib/python3.8/site-packages/numpy/lib/function_base.py", line 3515, in _ureduce
    r = func(a, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/numpy/lib/function_base.py", line 4050, in _quantile_ureduce_func
    n = np.isnan(ap[-1])
IndexError: index -1 is out of bounds for axis 0 with size 0

My fmriprep command is:

        unset PYTHONPATH; singularity run \
		-B ${bids_root_dir}:${bids_root_dir} \
		-B /N/dcwan/projects/irf/templateflow:/opt/templateflow
		-B ${work_dir}:${work_dir} \
		-B ${output_dir}:${output_dir} \
		/N/dcwan/projects/irf/containers/fmriprep-${fmriprep_version}.simg 			\
		$bids_root_dir $output_dir													\
			participant																\
			--participant-label $s 													\
			--task-id $task_id 														\
			--skip-bids-validation 													\
			--md-only-boilerplate													\
			--fs-license-file $FREESURFER_HOME/license.txt							\
			--fs-subjects-dir $output_dir/sourcedata/freesurfer/sub-${s}			\
			--output-spaces MNI152NLin6Asym:res-2									\
			--nthreads $cores														\
			--stop-on-first-crash 													\
			--resource-monitor 														\
			--low-mem 																\
			--mem_mb $reduced_mem 													\
			--use-plugin $bids_root_dir/fmriprep_plugin_${s}.yml 					\
			--use-aroma 															\
			--use-syn-sdc															\
			--verbose 																\
			--output-layout bids 													\
			-w $work_dir/sub-${s}

This dataset is different from previous datasets I’ve worked with, in that this contains 2 sessions (each session has a T1w image) and doesn’t contain field maps, so I’m using the --use-syn-sdc parameter. I haven’t been able to find this error message online, so I was wondering what might be causing this issue?

My best guess without seeing the working directory would be that a mask turned out to be empty. Is this a consistent issue, or does clearing the working directory and retrying help?

Ah yes, one of the masks was indeed empty, I’ll try re-running after clearing the work directory

This seems to have solved the issue, thanks again.

1 Like

Whew. While non-determinism is a pain, a bug that reliably produces empty masks in the middle of a workflow would be a nightmare to fix.