Thanks Peter ! It takes me some time to figure it out. The method I used below is generally robust and I have tested it for several sessions.
I feel it is helpful to put it here as a reference.
# Before the nudging, two issues here
# 1. If the epi data is too far away from its target position, you might want to use the command below to move its origin (the nudge data plugin seems to clip data...)
# 3drefit -dxorigin 20 -prefix epi_shft.nii.gz epi.nii.gz
# 2. it is generally a good idea to pad the data
# !3dZeropad -I 20 -P 30 -A 30 -overwrite -prefix epi_pad.nii.gz epi_shft.nii.gz
# Then you can nudge the data manually, Once you are happy, click 'print' button. NudgeDataset prints out something as below in your terminal.
3drotate -NN -rotate 0.44I -33.99R 3.73A -ashift 1.82S 0.00L 20.30P \
-prefix tmp.epi.rotated.nii.gz -overwrite epi_pad.nii.gz
# Extract the transform of manual nudge
cat_matvec tmp.epi.rotated.nii.gz::ROTATE_MATVEC_000000 -ONELINE > tmp.init.aff12.1D
# Align the anat to the rotated epi
align_epi_anat.py -anat2epi -anat T1.nii.gz -epi tmp.epi.rotated.nii.gz \
-epi_base 0 -epi_strip 3dAutomask -tshift off -volreg off -deoblique off \
-anat_has_skull no -suffix _al -overwrite
# Combine the two transforms and invert
cat_matvec tmp.init.aff12.1D T1_al_mat.aff12.1D -ONELINE > mat.anat2epi.aff12.1D
cat_matvec mat.anat2epi.aff12.1D -I -ONELINE > mat.epi2anat.aff12.1D
# Apply the combined transform, warp epi to anat
3dAllineate -final wsinc5 -base T1.nii.gz \
-1Dmatrix_apply mat.epi2anat.aff12.1D -input epi_shft.nii.gz \
-prefix epi_al.nii.gz -overwrite
# Clean up
!rm tmp.* T1_al*
Edited 2 time(s). Last edit at 07/10/2019 11:25PM by ruyuanzhang.