3dMean template space

AFNI version info (afni -ver): Precompiled binary linux_ubuntu_16_64: Apr 13 2025 (Version AFNI_25.1.03 'Maximinus')

Dear AFNI experts, thanks for your work on AFNI.

I used 3dMean to estimate fMRI signal levels by averaging beta values obtained from a GLM. Recently, I noticed that the output dataset's template space was set to ORIG, whereas in the past, it was recorded as TLRC. This led to unexpected behavior in the AFNI GUI, such as automatic changes in the underlay setting.

I understand that 3dMean inherits template space information from the first input dataset. However, all my input files were NIFTI files with consistent dimensions and identical header information. I wonder whether this change was caused by an overlooked difference in the input files, a change in 3dMean works, or possibly an issue with my AFNI settings.

Thanks!
yonghyun

3dinfo sub_01_post_Cineol_beta_new.nii                                              
++ 3dinfo: AFNI version=AFNI_25.1.03 (Apr 13 2025) [64-bit]

Dataset File:    /mnt/ext3/aroma/stats/betamap/mean_beta/sub_01_post_Cineol_beta_new.nii
Identifier Code: XYZ_g9raP2kfd1E7QHKf8FpZkw  Creation Date: Thu Apr 17 17:20:36 2025
Template Space:  ORIG
Dataset Type:    Anat Bucket (-abuc)
Byte Order:      LSB_FIRST {assumed} [this CPU native = LSB_FIRST]
Storage Mode:    NIFTI
Storage Space:   4,202,496 (4.2 million) bytes
Geometry String: "MATRIX(-2,0,0,95,0,-2,0,131,0,0,2,-77):96,114,96"
Data Axes Tilt:  Plumb
Data Axes Orientation:
  first  (x) = Left-to-Right
  second (y) = Posterior-to-Anterior
  third  (z) = Inferior-to-Superior   [-orient LPI]
R-to-L extent:   -95.000 [R] -to-    95.000 [L] -step-     2.000 mm [ 96 voxels]
A-to-P extent:   -95.000 [A] -to-   131.000 [P] -step-     2.000 mm [114 voxels]
I-to-S extent:   -77.000 [I] -to-   113.000 [S] -step-     2.000 mm [ 96 voxels]
Number of values stored at each pixel = 1
  -- At sub-brick #0 '?' datum type is float:    -0.789868 to       1.21546

----- HISTORY -----
[yonghyun@user-TRX40-DESIGNARE: Thu Apr 17 17:20:35 2025] {AFNI_25.1.03:linux_ubuntu_16_64} 3dMean -prefix sub_01_post_Cineol_beta_new.nii ../sub_01_post/beta/sub_01_post_Cineol_beta_r01.nii ../sub_01_post/beta/sub_01_post_Cineol_beta_r02.nii ../sub_01_post/beta/sub_01_post_Cineol_beta_r03.nii


3dinfo sub_01_post_Cineol_beta.nii                                             
++ 3dinfo: AFNI version=AFNI_25.1.03 (Apr 13 2025) [64-bit]

Dataset File:    /mnt/ext3/aroma/stats/betamap/mean_beta/sub_01_post_Cineol_beta.nii
Identifier Code: XYZ_tr-SFnhgEpKDAsE5bZdeKw  Creation Date: Wed Apr  9 10:48:58 2025
Template Space:  TLRC
Dataset Type:    Anat Bucket (-abuc)
Byte Order:      LSB_FIRST {assumed} [this CPU native = LSB_FIRST]
Storage Mode:    NIFTI
Storage Space:   4,202,496 (4.2 million) bytes
Geometry String: "MATRIX(-2,0,0,95,0,-2,0,131,0,0,2,-77):96,114,96"
Data Axes Tilt:  Plumb
Data Axes Orientation:
  first  (x) = Left-to-Right
  second (y) = Posterior-to-Anterior
  third  (z) = Inferior-to-Superior   [-orient LPI]
R-to-L extent:   -95.000 [R] -to-    95.000 [L] -step-     2.000 mm [ 96 voxels]
A-to-P extent:   -95.000 [A] -to-   131.000 [P] -step-     2.000 mm [114 voxels]
I-to-S extent:   -77.000 [I] -to-   113.000 [S] -step-     2.000 mm [ 96 voxels]
Number of values stored at each pixel = 1
  -- At sub-brick #0 '?' datum type is float:    -0.789868 to       1.21546

----- HISTORY -----
[yonghyun@user-TRX40-DESIGNARE: Wed Apr  9 10:48:58 2025] {AFNI_24.0.17:linux_ubuntu_16_64} 3dMean -prefix sub_01_post_Cineol_beta.nii ../sub_01_post/beta/sub_01_post_Cineol_beta_r01.nii ../sub_01_post/beta/sub_01_post_Cineol_beta_r02.nii ../sub_01_post/beta/sub_01_post_Cineol_beta_r03.nii

Hi, yonghyun-

OK, I will hazard a guess that this relates to the NIFTI header items, sform_code and qform_code. I will summarize some points here that are described in more detail in this part of the AFNI docs.

Can you please run this on your dataset and copy+paste the output here, so we can see what those header field values are for your dataset?

nifti_tool \
    -infiles DSET \
    -disp_hdr -field sform_code -field qform_code

In AFNI format header, we have +orig and +tlrc strings to denote the space of the dataset, whether it is original or some general template, respectively. These are called the "view codes". For more detailed description about which space it is, there is a separately "space" name. All dsets with +orig view codes have a space name of ORIG, but for a +tlrc view code, you might have a space name of MNI, MNI_2009c_asym, TLRC, TT_N27 IBTv2, HaskinsPeds, NMT, MBMv3, etc.

In the NIFTI header, the sform_code and qform_code denote similar information, but using integer values.

  • 0 means unknown
  • 1 is "original space" and clearly/easily maps to the BRIK/HEAD +orig/ORIG info.
  • 3 is "Talairach Tournoux" space, and clearly maps to the BRIK/HEAD +tlrc/TLRC info
  • 4 is "MNI space" and clearly maps to the BRIK/HEAD +tlrc/MNI info
  • 5 is "other template space" and maps to at least BRIK/HEAD's +tlrc info, and can be given a more detailed descriptive space name, too.

Keen observers will see that the [qc]form_code value of 2 was left out. It is the dreaded ambiguous code that could be either template or original space. This was a design decision forced into the NIFTI standard to accommodate some software (AFNI doesn't produce these). But AFNI users have to make a choice when using data with the dreaded ambiguous code. You can do this by setting an environment variable in your ~/.afnirc settings file, or in a script-by-script way, using the AFNI environment variable AFNI_NIFTI_VIEW. The description of this env var is:

The default view extension used for output when creating AFNI format
datasets from NIFTI datasets. This variable is only applicable for
sform and qform codes that do not have clearly defined views
(sform/qform code = 2). Set to "tlrc" or "orig". See also
AFNI_DEFAULT_STD_SPACE and AFNI_NIFTI_PRIORITY. Note sform/qform code=5
can be used for spaces other than MNI or TLRC including MNI_ANAT or D99
spaces.
If unset, the default is 'orig'.

So, by default now, we treat [qs]form_code values as corresponding to +orig view, as you have noticed. This was a change a couple years ago, because of how some other software tools were populating their outputs with the dreaded ambiguous [qs]form_code=2. Basically, it seemed more appropriate to treat these as +orig dsets, so we do now by default.

So, you can can indeed control this on your system to make all ambiguous-coded NIFTIs be treated as +tlrc by setting this variable in your `~/.afnirc:

AFNI_NIFTI_PRIORITY = tlrc

However, I think it would be better to actively disambiguate the datasets, like using 3drefit like this, if you had an MNI template dset:

3drefit -view tlrc -space MNI <DSET>

Less ambiguity and more clarity seems like a good thing to me.

--pt