Can't input affine matrix to auto_warp.py

Hi there,

In one of my subjects auto_warp.py failed to do the affine step by itself. Therefore I tried to calculate before the affine transform with 3dAllineate:
3dAllineate -base ${TEMPLATEDIR}/${TEMPLATE}‘[0]’ -input ${SUBJ}_T1_ns_bc.nii.gz -1Dmatrix_save extra.1D -prefix prueba.nii.gz

I checked and the images are aligned successfully. I tried to give the extra.1D matrix to auto_warp.py to skip the automatic affine step:

auto_warp.py -overwrite -base ${TEMPLATEDIR}/${TEMPLATE}‘[0]’ -input prueba.nii.gz -skull_strip_input no -affine_input_xmat ‘extra.1D’

However, it gave me this error:
#++ auto_warp.py version: 0.04

Output directory /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/

#Script is running:
mkdir /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/
mkdir: cannot create directory `/bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/': File exists
cd /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/
#Script is running:
rm /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/anat.nii
#Script is running (command trimmed):
3dcopy /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/prueba.nii.gz ./anat.nii
++ 3dcopy: AFNI version=AFNI_18.2.06 (Jul 31 2018) [64-bit]
#Script is running:
rm /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/anat.un.nii
#Script is running (command trimmed):
3dUnifize -GM -input ./anat.nii -prefix ./anat.un.nii
++ 3dUnifize: AFNI version=AFNI_18.2.06 (Jul 31 2018) [64-bit]

  • Pre-processing: ADV…UWG
    ++ Output dataset ./anat.un.nii
    ++ ===== Elapsed = 7.9 sec
    #Script is running:
    rm /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/base.nii
    #Script is running (command trimmed):
    3dcopy /export/home/vferrer/public/PARK_VFERRER/TEMPLATES_ATLAS/MNI152_2009_template_FSL.nii.gz ./base.nii
    ++ 3dcopy: AFNI version=AFNI_18.2.06 (Jul 31 2018) [64-bit]
    ** AFNI converts NIFTI_datatype=64 (FLOAT64) in file /export/home/vferrer/public/PARK_VFERRER/TEMPLATES_ATLAS/MNI152_2009_template_FSL.nii.gz to FLOAT32
    Warnings of this type will be muted for this session.
    Set AFNI_NIFTI_TYPE_WARN to YES to see them all, NO to see none.
    #++ Aligning /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/base.nii data to /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/anat.un.nii data
    #Script is running (command trimmed):
    3dWarp -matvec_out2in extra.1D -prefix ./anat.un.aff.nii ./anat.un.nii
    ++ 3dWarp: AFNI version=AFNI_18.2.06 (Jul 31 2018) [64-bit]
    ++ Authored by: RW Cox
    ** FATAL ERROR: Can’t read -matvec file extra.1D
    ** Program compile date = Jul 31 2018
    #**ERROR Failed in affine step
    ** ERROR - script failed
    I have checked and the extra.1D file looks like this with cat_vect:
    0.960819 0.0413537 -0.101087 -1.88474
    0.0722554 0.78104 0.443372 -19.1824
    0.0627243 -0.520414 0.699751 -16.6196

and like this with cat:

3dAllineate matrices (DICOM-to-DICOM, row-by-row):

  0.960819     0.0413537     -0.101087      -1.88474     0.0722554       0.78104      0.443372      -19.1824     0.0627243     -0.520414      0.699751      -16.6196

Could you tell me what have i been doing wrong?

Cheers,
Vicente

Hi Vicente,

I have not done what you are doing, but it seems unsafe to
rely on the script deleting or overwriting old results. To be
sure, delete the anat/awpy directory and run it again.

Also, it is worth noting how well the source and base datasets
overlap before registration begins. If they barely touch each
other, one of them probably does not have correct coordinate
information. Use @Align_Centers to shift the source to match
the base before beginning.

  • rick

Hi I have tried what you say and it doesn’t work, after applying @Align_centers the auto_warp.py stops in the affine registration:
@Align_Centers -overwrite -base ${TEMPLATEDIR}/${TEMPLATE} -dset ${SUBJ}_T1_ns_bc.nii.gz -prefix prueba.nii.gz -1Dmat_only
++ 3dcopy: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
++ 3drefit: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
++ Authored by: RW Cox
++ Processing AFNI dataset ./prueba.nii.gz

  • deoblique
  • loading and re-writing dataset ./prueba.nii.gz (./prueba.nii.gz in NIFTI storage)
    ++ 3drefit processed 1 datasets
    auto_warp.py -overwrite -base ${TEMPLATEDIR}/${TEMPLATE}‘[0]’ -input prueba.nii.gz -skull_strip_input no
    #++ auto_warp.py version: 0.04

Output directory /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/

#Script is running:
mkdir /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/
cd /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/
#Script is running (command trimmed):
3dcopy /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/prueba.nii.gz ./anat.nii
++ 3dcopy: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
#Script is running (command trimmed):
3dUnifize -GM -input ./anat.nii -prefix ./anat.un.nii
++ 3dUnifize: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]

  • Pre-processing: ADV…UWGm
    ++ Output dataset ./anat.un.nii
    ++ ===== Elapsed = 35.7 sec
    #Script is running (command trimmed):
    3dcopy /export/home/vferrer/public/PARK_VFERRER/TEMPLATES_ATLAS/MNI152_2009_template_flip.nii.gz ./base.nii
    ++ 3dcopy: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    #++ Aligning /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/base.nii data to /bcbl/home/public/PARK_VFERRER/PREPROC/sub-029ParkEglPb/anat/awpy/anat.un.nii data
    #Script is running (command trimmed):
    @auto_tlrc -base ./base.nii -input ./anat.un.nii -suffix .aff -no_ss -no_pre -init_xform CENTER
    Copying NIFTI volume to ./anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA
    ++ 3dcopy: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]

Performing center alignment with @Align_Centers

++ 3dcopy: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
++ 3drefit: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
++ Authored by: RW Cox
++ Processing AFNI dataset ./anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA_shft+orig

  • deoblique
    ++ 3drefit processed 1 datasets
    ++ 3drename: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    ++ THD_rename_dataset_files: rename anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA_shft+orig.HEAD → __ats_tmp__anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA_shft+orig.HEAD
    ++ THD_rename_dataset_files: rename anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA_shft+orig.BRIK → __ats_tmp__anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA_shft+orig.BRIK
    ** THD_rename_dataset_files: old header anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA_shft+acpc.HEAD doesn’t exist!
    ** THD_rename_dataset_files: old header anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA_shft+tlrc.HEAD doesn’t exist!
    ++ 3dWarp: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    ++ Authored by: RW Cox
    Center distance of 0.000000 mm
    Padding …
    ++ 3dZeropad: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    ++ output dataset: ./__ats_tmp__ref_base.nii_40pad+orig.BRIK
    Resampling …
    ++ 3dcalc: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    ++ Authored by: A cast of thousands
    ++ Output dataset ././__ats_tmp__resamp_step+orig.BRIK
    ++ 3dcalc: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    ++ Authored by: A cast of thousands
    ++ Output dataset ././__ats_tmp__resamp+orig.BRIK
    Clipping -0.000100 3185.330100 …
    ++ 3dcalc: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    ++ Authored by: A cast of thousands
    ++ Output dataset ./__ats_tmp___rs_pre.anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA+orig.BRIK
    ++ 3drefit: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    ++ Authored by: RW Cox
    ++ Processing AFNI dataset __ats_tmp___rs_pre.anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA+orig.HEAD
  • Didn’t make any changes for dataset __ats_tmp___rs_pre.anat.un_XYZ_OYmeqfZ3JqF7n9LNC7gDAA+orig.HEAD !
    ++ 3drefit processed 1 datasets
    ++ 3drefit: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    ++ Authored by: RW Cox
    ++ Processing AFNI dataset __ats_tmp__resamp_NN+orig.HEAD
  • Didn’t make any changes for dataset __ats_tmp__resamp_NN+orig.HEAD !
    ++ 3drefit processed 1 datasets
    ++ 3drefit: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    ++ Authored by: RW Cox
    ++ Processing AFNI dataset __ats_tmp__resamp_edge_art+orig.HEAD
  • Didn’t make any changes for dataset __ats_tmp__resamp_edge_art+orig.HEAD !
    ++ 3drefit processed 1 datasets
    Registration (linear final interpolation) …
    ++ 3dWarpDrive: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
    ++ Authored by: RW Cox
    RMS[0] = 501.667 415.306 ITER = 137/137
    501.667

Warping used up maximum iterations of 137
Convergence might not have
been reached.
Doubling number of iterations

++ 3drename: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
++ THD_rename_dataset_files: rename __ats_tmp__reg_warpdriveout+orig.HEAD → __ats_tmp__reg_warpdriveout_maxed_iters+orig.HEAD
++ THD_rename_dataset_files: rename __ats_tmp__reg_warpdriveout+orig.BRIK → __ats_tmp__reg_warpdriveout_maxed_iters+orig.BRIK
++ 3dWarpDrive: AFNI version=AFNI_18.2.16 (Sep 12 2018) [64-bit]
++ Authored by: RW Cox
RMS[0] = 501.667 415.306 ITER = 274/274
501.667

Warping used up maximum iterations
even after doubling number of iterations to 274.
Convergence might not have been reached.

If you find the alignment poor, try
rerunning the script with a transform
type of fewer parameters (-xform) or by using
an even higher number of iterations (-maxite).
You can also choose to continue with the
current result (dset: __ats_tmp__reg_warpdriveout+orig
by using the option: -OK_maxite

Script will stop …

#**ERROR Failed in affine step
** ERROR - script failed

I have checked and the images are touching each other after the Align_centers (obviusly) and if you notice, this was already incorporated in the auto_warp.py pipeline. Is there any alternative i can use in this subject for the wrapping?. Thanks in adavance,

Vicente

Hi Vicente,

For affine alignment to fail, there is probably something peculiar
about the data. Would it be possible to upload those 2 datasets
(both the base and input)?

Why does the base have ‘flip’ in the name? What sort of flip
operation was applied?

If you are able to do that, I will send you a PM (private message)
with instructions.

  • rick

auto_warp.py, with builds after this posting, will have the option “-at_opts” to pass options on to @auto_tlrc. In this case, consider “-OK_maxite -maxite 50”.