** FATAL ERROR: Can't open dataset run-1_blur8.nii.gz


I'm using AFNI with BASH. I'm getting the following error and am not sure how to troubleshoot. I'm new to AFNI.

** FATAL ERROR: Can't open dataset run-1_blur8.nii.gz



Could you please provide the command that you ran, which produced that error?

Also, what does the following produce, run from the same terminal location:

ls run-1_blur8.nii.gz



Thank you! Here's the command:

        if [ ! -f ${scanRuns[$i]}_blur8.nii.gz ]; then
            3dmerge -1blur_fwhm 8.0 -doall -prefix ${scanRuns[$i]}_blur8.nii.gz func*${scanRuns[$i]}.space*/bold.nii.gz
        #scale to have a mean of 100, no negatives, subject to a range of [0,200]
        if [ ! -f ${scanRuns[$i]}_blur8_scale.nii.gz ]; then
            3dTstat -mean -prefix ${scanRuns[$i]}_blur8_mean.nii.gz ${scanRuns[$i]}_blur8.nii.gz
            3dcalc -a ${scanRuns[$i]}_blur8.nii.gz -b ${scanRuns[$i]}_blur8_mean.nii.gz \
                -prefix ${scanRuns[$i]}_blur8_scale.nii.gz \
                -expr "min(200, a/b*100)*step(a)*step(b)"

Here's what your command produced:
ls: cannot access 'run-1_blur8.nii.gz': No such file or directory

Sorry, here's a screen shot:

OK, thanks. Because the ls FILE is failing to show the file, that means it wasn't created, either from a previous run or in line 3 of your code. So, maybe perhaps a filename is a bit off or something earlier in the code failing so that a program's input doesn't actually exist?

It is still a bit hard to see what exactly is failing without the full output; I could guess from testing that either 3dTstat or 3dcalc is failing, but I'm not sure which. Could you please copy+paste the full set of output messages when those lines run? It would help to know what is successful and what is not, specifically.

Separately, I guess that is a bash translation of what an afni_proc.py-generated script would do for blurring. If this is part of an FMRI processing pipeline, is there a reason to not just use afni_proc.py itself? I'd also be a little curious about what processing would use an 8mm blur, perhaps? That seems quite large for most FMRI voxel sizes, but there certainly might be some special considerations/goals/type of data.


Thanks for your help! Here is the output with 3dTstat and 3dcalc:

working on subject: sub-008pre ----------
working on datatype: run-1 ------------
Program 3dmerge
++ 3dmerge: AFNI version=AFNI_23.1.00 (Apr 7 2023) [64-bit]
3dmerge: edit and combine 3D datasets, by RW Cox
*** cannot open dataset funcrun-1.space/bold.nii.gz
++ 3dTstat: AFNI version=AFNI_23.1.00 (Apr 7 2023) [64-bit]
++ Authored by: KR Hammett & RW Cox
** FATAL ERROR: Can't open dataset run-1_blur8.nii.gz
** Program compile date = Apr 7 2023
++ 3dcalc: AFNI version=AFNI_23.1.00 (Apr 7 2023) [64-bit]
++ Authored by: A cast of thousands

Thanks for your patience! I'm very new to afni and don't know what afni_proc.py is or why it would be preferred to bash. If this whole thing is a waste of your time, I understand! I'll keep doing self-study to figure it all out.

Ok, the first error that appears there is when 3dmerge starts running:

*** cannot open dataset func*run-1.space*/bold.nii.gz

That means that the input dataset to 3dmerge, which is specified as func*${scanRuns[$i]}.space*/bold.nii.gz, does not appear to exist. So, you should check about the name of the actual directory and/or file for the dataset to be input, and make sure that you code that correctly.

There is nothing wrong with using bash, which is the shell environment for specifying your commands here. In Linux, there are different shells for interpreting commands. In all of them, things like ls, cd, mv, cp, etc. work the same; but differences exist in the syntax for defining a variable, an "if" condition, a "for" loop, etc. Your bash shell syntax looks fine here. And shell choice is independent of using AFNI (or any other software suite).

The program in AFNI called afni_proc.py is one that helps you build your full FMRI processing script for a single subject's data, including both regression modeling and building a quality control HTML page to help review steps.

Something that might be useful is we have the AFNI Academy online tutorials from our "AFNI Bootcamps". The specific playlist about afni_proc.py is here.

A recent paper about processing and quality control is here:

A draft about processing and setting up a pipeline both generally and specifically with afni_proc.py is also here:

  • Taylor PA, Chen G, Glen DR, Rajendra JK, Reynolds RC, Cox RW (2018). FMRI processing with AFNI: Some comments and corrections on ‘Exploring the Impact of Analysis Software on Task fMRI Results’. bioRxiv 308643; doi:10.1101/308643


I would have to guess that the '/' in func*run-1.space*/bold.nii.gz might be inappropriate. What is the output from:

ls func*bold.nii.gz
  • rick

Yes you're right. I'm trying to figure out how to correct the error so it can find the directory. The output from your command is:

ls: cannot access 'func*bold.nii.gz': No such file or directory

Well, if it's BIDSy, then func might be the directory, and the files something like:
func/*bold.nii.gz. In any case, use ls and possibly tab-completion for file names to sort this out.

  • rick