AFNI version info (afni -ver): linux_ubuntu_16_64: Jun 29 2023 (Version AFNI_23.1.10 'Publius Helvius Pertinax'')

hello AFNI experts,
When I used to preprocess the Monkey fMRI data, the following error came up:

Then I used @Align Centers : -base {ref_base} -dset {sdir_anat2} -child ${ddets_epi}
But the problem is not solved, there is no change in the image after and before alignment, why is that?


Can you please copy+paste the full command you are using? It will help diagnose things.

Could you also please trying running the following:

@djunct_overlap_check \
    -ulay DSET_ANAT \
    -olay DSET_REF \
    -prefix IMG_OLAP

... where DSET_ANAT is your input anatomical volume (probably a T1w anatomical) and DSET_REF is the reference/template volume you are using? This command will make an image that shows the initial overlap of those---I wonder if part of the problem here is that they are very far away to start, like if the anatomical has not-well-centered coordinates, and that is creating a memory issue.

So, please post the image (or images) that are output by that command, as well as the command, and hopefully those will suggest what is happening.


Similarly, the EPI could be far off from the anat (sometimes the volume origins are not correct). It might be good to see how the +orig space vr_base dataset overlaps with the +orig space anat.

  • rick

export dir_root=/media/monster/HDisk/PWL/test_57 # define your root directory
export dir_basic=${dir_root} # define directory path of the raw data
export dir_ap=${dir_root}/PreprocessedASD # define directory path of the preprocessed data
mkdir -p $dir_ap

# Redirecting output to log directory
exec > >(tee -a $dir_ap/output_prepro.log) 2>&1

# Print the current date and time to the log
echo "Script executed on: $(date)"

# Print the content of the script to the log
echo "Script content:"
echo "---------------------------------------------------------------------"

# define a preprocessing program
process_subject() {
    con=$1 # first input 
    subj=$2 # second input
    echo "%%%%%%%%%%%%%% Processing $subj $con %%%%%%%%%%%%%%%%%%%"
    sdir_basic=$dir_basic/$con/$subj # define data path for individual subject
    3dcopy $sdir_anat1 $sdir_anat2
    3drefit -view orig -space ORIG $sdir_anat2

    #3dUnifize -prefix $subj_indir/anat_uni.nii.gz -input $subj_indir/anat.nii.gz
    mkdir -p "$sdir_ap"
    cd ${sdir_ap}
    # input file
    dsets_epi=${sdir_epi}/session_1/rest_1/rest.nii.gz # define path to fmri images
    anat_cp=${sdir_basic}/session_1/anat_1 # define path to anatomical image
    #cjg add
    3dcopy $dsets_epi $ddsets_epi
    3drefit -view orig -space ORIG $ddsets_epi

    ## Preprocessing for epi in individual space
    # control variables in


    @Align_Centers -overwrite -base ${ref_base} -dset ${sdir_anat2} -child ${ddsets_epi} 

cat > run.afni_proc << EOF

# ----------------------------------------------------------------- -subj_id $subj                                    \
          -dsets ${ddsets_epi}                           \
          -copy_anat ${sdir_anat2}                     \
          -blocks despike tshift align tlrc volreg blur mask regress \
          -tcat_remove_first_trs $nt_rm                                   \
          -align_opts_aea -cost ${cost_a2e} -ginormous_move              \
          -tlrc_base MNI152_T1_2009c+tlrc                            \
          -tlrc_NL_warp                                              \
          -volreg_tlrc_warp \
          -volreg_align_to MIN_OUTLIER                               \
          -volreg_align_e2a                                          \
     	  -volreg_warp_dxyz ${final_dxyz}                            \
          -blur_size ${blur_size}                                             \
          -mask_epi_anat yes                                         \
          -mask_segment_anat yes                                     \
          -mask_segment_erode yes                                    \
          -regress_censor_motion ${cen_motion}                                 \
          -regress_censor_outliers ${cen_outliers}                               \
          -regress_bandpass 0.01 0.1                                 \
	      -regress_ROI_PC CSFe 5                                     \
	      -regress_ROI_PC WMe 5                                      \
          -regress_apply_mot_types demean deriv                      \
          -regress_est_blur_epits                                    \
          -regress_est_blur_errts                                    \
          -html_review_style        pythonic                         \
    tcsh run.afni_proc

# Export the function for parallel
export -f process_subject

for con in ASD ; do
    # get the list of subjects    
    #subj=$(find $dir_basic/$con -maxdepth 1 -mindepth 1 -name 5* -type d -exec basename {} \;)
    # echo "************************************* $subj **************************"
    # replace the line 87 if you want to process several specific subjects, such as sub001 sub003 sub014
    echo "************************************* $subj **************************"
    # Run with GNU parallel. -j indicate the number of CPU. 
    parallel -j 5 process_subject ::: $con ::: $subj

here is the full code,thanks again!

Thanks, can you please also run the @djunct_overlap_check command above that I had provided? That will be quite helpful to see what is happening.


Oh, and I suspect that this might be part of the issue:

3dcopy $dsets_epi $ddsets_epi
3drefit -view orig -space ORIG $ddsets_epi

While deobliquing the anatomical before any processing can be useful, you should not need to deoblique the EPI. And deobliquing it in this way can actually change its apparent location quite a lot, possibly moving it far away from overlapping with its partner anatomical dataset. Even for deobliquing the anatomical, this is probably not the best way to go. We have recently written a new wrapper script to manage this, called adjunct_deob_around_origin. It essentially provides a way to deoblique while preserving the coordinate origin:

# and note that this has to copy to a BRIK/HEAD file,
# but the final DSET_NEW can be NIFTI again, fine
3dcopy   DSET       __tmp
3drefit  -oblique_recenter __tmp+orig
3drefit  -deoblique        __tmp+orig
3dcopy __tmp+orig DSET_NEW

Another issue is that I notice to you also refitting the headers for your EPI and anatomical to have ORIG space. Your inputs should be in native/original space already. One reason they might not be is because of the ambiguous qform_code and sform_code values that some (other) software produce for NIFTI files (seeing the dreaded "2" appear there). Is that the case in what you have? What is the output of this for your EPI and anatomical:

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

That can be reset with 3drefit, sure. That is a separate consideration, but it would be good to know the root of the issue.

... and all of this is prior to considering anything about Such is life with data, that much work+understanding happens before the actual processing.