From 3732dbc63c82f1d7d170174f1ae8f31ce23f5038 Mon Sep 17 00:00:00 2001 From: Robert Smith Date: Mon, 29 Jan 2024 15:33:08 +1100 Subject: [PATCH] dwifslpreproc: Fix for PE direction, but not readout time, in header If the phase encoding information present in the header is only the phase encoding direction, but not readout time is present, then the constructed phase encoding matrix will possess only three columns, not four. If this happens, but an attempt is then made to cross-reference the readout time in the phase encoding table generated from header content against what the user has specified at the command-line, then an unhandled exception will occur. This change prevents specifically the comparison of readout times from being made if no such information is present. Replacement for erroneous commit faf0788a21c80498d431ed017661c0c179de2437. Also includes additional test that results in an unhandled exception on 3.0.4 but executes successfully with this change. --- bin/dwifslpreproc | 4 ++-- testing/scripts/tests/dwifslpreproc | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/dwifslpreproc b/bin/dwifslpreproc index 4e804e5554..a8b1012aa6 100755 --- a/bin/dwifslpreproc +++ b/bin/dwifslpreproc @@ -476,7 +476,7 @@ def execute(): #pylint: disable=unused-variable overwrite_dwi_pe_scheme = True if manual_trt: # Compare manual specification to that read from the header - if not scheme_times_match(dwi_pe_scheme, dwi_manual_pe_scheme): + if len(dwi_pe_scheme[0]) == 4 and app.ARGS.readout_time is not None and not scheme_times_match(dwi_pe_scheme, dwi_manual_pe_scheme): app.warn('User-defined total readout time does not match what is stored in DWI image header; proceeding with user specification') overwrite_dwi_pe_scheme = True if overwrite_dwi_pe_scheme: @@ -549,7 +549,7 @@ def execute(): #pylint: disable=unused-variable app.warn('User-defined phase-encoding direction design does not match what is stored in SE EPI image header; proceeding with user specification') overwrite_se_epi_pe_scheme = True if manual_trt: - if not scheme_times_match(se_epi_pe_scheme, se_epi_manual_pe_scheme): + if len(se_epi_pe_scheme[0]) == 4 and not scheme_times_match(se_epi_pe_scheme, se_epi_manual_pe_scheme): app.warn('User-defined total readout time does not match what is stored in SE EPI image header; proceeding with user specification') overwrite_se_epi_pe_scheme = True if overwrite_se_epi_pe_scheme: diff --git a/testing/scripts/tests/dwifslpreproc b/testing/scripts/tests/dwifslpreproc index fa3a742d3c..dbc9f3cf58 100644 --- a/testing/scripts/tests/dwifslpreproc +++ b/testing/scripts/tests/dwifslpreproc @@ -1,4 +1,5 @@ mkdir -p ../tmp/dwifslpreproc && mrconvert BIDS/sub-04/dwi/sub-04_dwi.nii.gz -fslgrad BIDS/sub-04/dwi/sub-04_dwi.bvec BIDS/sub-04/dwi/sub-04_dwi.bval -json_import BIDS/sub-04/dwi/sub-04_dwi.json tmp-sub-04_dwi.mif -export_grad_mrtrix tmp-sub-04_dwi.b -strides 0,0,0,1 && dwifslpreproc tmp-sub-04_dwi.mif ../tmp/dwifslpreproc/rpenone_default.mif -pe_dir ap -readout_time 0.1 -rpe_none -force && testing_diff_header ../tmp/dwifslpreproc/rpenone_default.mif dwifslpreproc/rpenone_default.mif.gz +mrconvert tmp-sub-04_dwi.mif -clear_property TotalReadoutTime tmp-sub-04_trt-none_dwi.mif && dwifslpreproc tmp-sub-04_trt-none ../tmp/dwifslpreproc/no_trt_header.mif -pe_dir ap -readout_time 0.1 -force dwifslpreproc BIDS/sub-04/dwi/sub-04_dwi.nii.gz -fslgrad BIDS/sub-04/dwi/sub-04_dwi.bvec BIDS/sub-04/dwi/sub-04_dwi.bval ../tmp/dwifslpreproc/fslgrad.mif -export_grad_fsl ../tmp/dwifslpreproc/fslgrad.bvec ../tmp/dwifslpreproc/fslgrad.bval -pe_dir ap -readout_time 0.1 -rpe_none -force && testing_diff_header ../tmp/dwifslpreproc/fslgrad.mif dwifslpreproc/rpenone_default.mif.gz && testing_diff_matrix ../tmp/dwifslpreproc/fslgrad.bvec dwifslpreproc/rpenone_default.bvec -abs 1e-2 && testing_diff_matrix ../tmp/dwifslpreproc/fslgrad.bval dwifslpreproc/rpenone_default.bval dwifslpreproc BIDS/sub-04/dwi/sub-04_dwi.nii.gz -grad tmp-sub-04_dwi.b ../tmp/dwifslpreproc/grad.mif -export_grad_mrtrix ../tmp/dwifslpreproc/grad.b -pe_dir ap -readout_time 0.1 -rpe_none -force && testing_diff_header ../tmp/dwifslpreproc/grad.mif dwifslpreproc/rpenone_default.mif.gz && testing_diff_matrix ../tmp/dwifslpreproc/grad.b dwifslpreproc/rpenone_default.b -abs 1e-2 mrconvert BIDS/sub-04/fmap/sub-04_dir-1_epi.nii.gz -json_import BIDS/sub-04/fmap/sub-04_dir-1_epi.json tmp-sub-04_dir-1_epi.mif -force && mrconvert BIDS/sub-04/fmap/sub-04_dir-2_epi.nii.gz -json_import BIDS/sub-04/fmap/sub-04_dir-2_epi.json tmp-sub-04_dir-2_epi.mif -force && mrcat tmp-sub-04_dir-1_epi.mif tmp-sub-04_dir-2_epi.mif tmp-sub-04_dir-all_epi.mif -axis 3 -force && dwifslpreproc tmp-sub-04_dwi.mif ../tmp/dwifslpreproc/rpepair_default.mif -pe_dir ap -readout_time 0.1 -rpe_pair -se_epi tmp-sub-04_dir-all_epi.mif -force && testing_diff_header ../tmp/dwifslpreproc/rpepair_default.mif dwifslpreproc/rpepair_default.mif.gz