Hi AFNI team,
I’m having Anat_EPI alignment issues with most of our subjects. For troubleshooting purposes, I’ve focused on subjects that have the best initial alignment between anat and EPI. For these subjects, when running align_epi_anat.py independently, the output alignment looks excellent regardless of using lpc+ZZ or lpa+ZZ. But, the overlap between anat_final and final_epi_base_min_outlier is still noticeably off. Which leads me to believe something may be going awry during the 3dVolreg command? I thought the non-linear warp output of SSwarper looked good for the most part, but in case that could be contributing to this I’ll include one of those QC images too. AFNI ver is 23.0.01, Commodus, Jan 18 2023. Happy to provide anything else upon request! Attached is the output (APQC, etc) for one of our subjects for you to take a look at (I was going to include the whole thing but for upload size I took a screenshot of just the first half). Thank you for your continued help.
Sincerely,
Ian
# ================================= align ==================================
# for e2a: compute anat alignment transformation to EPI registration base
# (new anat will be current anatSS.${subj}+orig)
# run (localized) uniformity correction on EPI base
3dLocalUnifize -input vr_base_min_outlier+orig -prefix \
vr_base_min_outlier_unif
align_epi_anat.py -anat2epi -anat anatSS.${subj}+orig \
-suffix _al_junk \
-epi vr_base_min_outlier_unif+orig -epi_base 0 \
-epi_strip 3dAutomask \
-anat_has_skull no \
-cost lpc+ZZ -check_flip \
-volreg off -tshift off
# ================================== tlrc ==================================
# nothing to do: have external -tlrc_NL_warped_dsets
# warped anat : anatQQ.${subj}+tlrc
# affine xform : anatQQ.${subj}.aff12.1D
# non-linear warp : anatQQ.${subj}_WARP.nii
# ================================= volreg =================================
# align each dset to base volume, to anat, warp to tlrc space
# verify that we have a +tlrc warp dataset
if ( ! -f anatQQ.${subj}+tlrc.HEAD ) then
echo "** missing +tlrc warp dataset: anatQQ.${subj}+tlrc.HEAD"
exit
endif
# register and warp
foreach run ( $runs )
# register each volume to the base image
3dvolreg -verbose -zpad 1 -base vr_base_min_outlier+orig \
-1Dfile dfile.r$run.1D -prefix rm.epi.volreg.r$run \
-cubic \
-1Dmatrix_save mat.r$run.vr.aff12.1D \
pb01.$subj.r$run.tshift+orig
# create an all-1 dataset to mask the extents of the warp
3dcalc -overwrite -a pb01.$subj.r$run.tshift+orig -expr 1 \
-prefix rm.epi.all1
# catenate volreg/epi2anat/tlrc xforms
cat_matvec -ONELINE \
anatQQ.${subj}.aff12.1D \
anatSS.${subj}_al_junk_mat.aff12.1D -I \
mat.r$run.vr.aff12.1D > mat.r$run.warp.aff12.1D
# apply catenated xform: volreg/epi2anat/tlrc/NLtlrc
# then apply non-linear standard-space warp
3dNwarpApply -master anatQQ.${subj}+tlrc -dxyz 3 \
-source pb01.$subj.r$run.tshift+orig \
-nwarp "anatQQ.${subj}_WARP.nii mat.r$run.warp.aff12.1D" \
-prefix rm.epi.nomask.r$run
# warp the all-1 dataset for extents masking
3dNwarpApply -master anatQQ.${subj}+tlrc -dxyz 3 \
-source rm.epi.all1+orig \
-nwarp "anatQQ.${subj}_WARP.nii mat.r$run.warp.aff12.1D" \
-interp cubic \
-ainterp NN -quiet \
-prefix rm.epi.1.r$run
# make an extents intersection mask of this run
3dTstat -min -prefix rm.epi.min.r$run rm.epi.1.r$run+tlrc
end
# make a single file of registration params
cat dfile.r*.1D > dfile_rall.1D
# ----------------------------------------
# create the extents mask: mask_epi_extents+tlrc
# (this is a mask of voxels that have valid data at every TR)
3dMean -datum short -prefix rm.epi.mean rm.epi.min.r*.HEAD
3dcalc -a rm.epi.mean+tlrc -expr 'step(a-0.999)' -prefix mask_epi_extents
# and apply the extents mask to the EPI data
# (delete any time series with missing data)
foreach run ( $runs )
3dcalc -a rm.epi.nomask.r$run+tlrc -b mask_epi_extents+tlrc \
-expr 'a*b' -prefix pb02.$subj.r$run.volreg
end
# warp the volreg base EPI dataset to make a final version
cat_matvec -ONELINE \
anatQQ.${subj}.aff12.1D \
anatSS.${subj}_al_junk_mat.aff12.1D -I > mat.basewarp.aff12.1D
3dNwarpApply -master anatQQ.${subj}+tlrc -dxyz 3 \
-source vr_base_min_outlier+orig \
-nwarp "anatQQ.${subj}_WARP.nii mat.basewarp.aff12.1D" \
-prefix final_epi_vr_base_min_outlier
# create an anat_final dataset, aligned with stats
3dcopy anatQQ.${subj}+tlrc anat_final.$subj
# record final registration costs
3dAllineate -base final_epi_vr_base_min_outlier+tlrc -allcostX \
-input anat_final.$subj+tlrc |& tee out.allcostX.txt
# --------------------------------------
# create a TSNR dataset, just from run 1
3dTstat -mean -prefix rm.signal.vreg.r01 pb02.$subj.r01.volreg+tlrc
3dDetrend -polort 2 -prefix rm.noise.det -overwrite pb02.$subj.r01.volreg+tlrc
3dTstat -stdev -prefix rm.noise.vreg.r01 rm.noise.det+tlrc
3dcalc -a rm.signal.vreg.r01+tlrc \
-b rm.noise.vreg.r01+tlrc \
-c mask_epi_extents+tlrc \
-expr 'c*a/b' -prefix TSNR.vreg.r01.$subj
# -----------------------------------------
# warp anat follower datasets (non-linear)
# warp follower dataset copy_af_anat_orig+orig
3dNwarpApply -source copy_af_anat_orig+orig \
-master anat_final.$subj+tlrc \
-ainterp wsinc5 -nwarp anatQQ.${subj}_WARP.nii \
anatQQ.${subj}.aff12.1D \
-prefix follow_anat_anat_orig