Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions python/mrtrix3/commands/dwifslpreproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@



import glob, itertools, json, math, os, shlex, shutil, sys
import argparse, glob, itertools, json, math, os, shlex, shutil, sys



Expand Down Expand Up @@ -389,19 +389,23 @@ def find_fieldcoef(fieldcoef_prefix):

if os.path.isfile(topup_file_userpath):
if topup_file_userpath.endswith('_movpar.txt'):
topup_input_movpar = app.Parser.FileIn(topup_file_userpath)
topup_input_fieldcoef = app.Parser.ImageIn(find_fieldcoef(topup_file_userpath[:-len('_movpar.txt')]))
topup_input_movpar = app.Parser.FileIn()(topup_file_userpath)
topup_input_fieldcoef = app.Parser.ImageIn()(find_fieldcoef(topup_file_userpath[:-len('_movpar.txt')]))
elif any(str(topup_file_userpath).endswith(postfix) for postfix in ('_fieldcoef.nii', '_fieldcoef.nii.gz')):
topup_input_fieldcoef = app.Parser.ImageIn(topup_file_userpath)
topup_input_fieldcoef = app.Parser.ImageIn()(topup_file_userpath)
topup_input_movpar = topup_file_userpath[:-len('.gz')] if topup_file_userpath.endswith('.gz') else topup_file_userpath
topup_input_movpar = app.Parser.FileIn(topup_input_movpar[:-len('_fieldcoef.nii')] + '_movpar.txt')
topup_input_movpar = app.Parser.FileIn()(topup_input_movpar[:-len('_fieldcoef.nii')] + '_movpar.txt')
else:
raise MRtrixError(f'Unrecognised file "{topup_file_userpath}" specified as pre-calculated topup susceptibility field')
else:
if topup_file_userpath[-1] == '_':
topup_file_userpath = topup_file_userpath[:-1]
topup_input_movpar = app.Parser.FileIn(f'{topup_file_userpath}_movpar.txt')
topup_input_fieldcoef = app.Parser.ImageIn(find_fieldcoef(topup_file_userpath))
try:
topup_input_movpar = app.Parser.FileIn()(f'{topup_file_userpath}_movpar.txt')
topup_input_fieldcoef = app.Parser.ImageIn()(find_fieldcoef(topup_file_userpath))
except argparse.ArgumentTypeError as exc:
raise argparse.ArgumentTypeError(f'Unable to find topup files from user specification "{topup_file_userpath}"') from exc



# Convert all input images into MRtrix format and store in scratch directory first
Expand Down
1 change: 1 addition & 0 deletions testing/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ add_bash_script_test(dwifslpreproc/rpeheader_rpepair)
add_bash_script_test(dwifslpreproc/rpenone_default)
add_bash_script_test(dwifslpreproc/rpepair_alignseepi)
add_bash_script_test(dwifslpreproc/rpepair_default)
add_bash_script_test(dwifslpreproc/topup_files)
add_bash_script_test(dwifslpreproc/whitespace)

add_bash_script_test(dwigradcheck/default)
Expand Down
46 changes: 46 additions & 0 deletions testing/scripts/tests/dwifslpreproc/topup_files
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Ensure that the -topup_files for dwifslpreproc works for all intended use cases

mrconvert BIDS/sub-04/dwi/sub-04_dwi.nii.gz tmp-sub-04_dwi.mif -force \
-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 \
-strides 0,0,0,1

mrcat \
BIDS/sub-04/fmap/sub-04_dir-1_epi.nii.gz \
BIDS/sub-04/fmap/sub-04_dir-2_epi.nii.gz \
-axis 3 - | \
mrconvert - tmp-sub-04_epi.nii \
-strides -1,+2,+3,+4 -force

echo $'0 -1 0 0.1\n0 1 0 0.1\n' | \
tee tmp-sub-04_epi.txt

topupcmd="topup --imain=tmp-sub-04_epi.nii --datain=tmp-sub-04_epi.txt --config=${FSLDIR}/etc/flirtsch/b02b0_2.cnf --out=tmp-out"
echo $topupcmd
$topupcmd

#topup \
# --imain=tmp-sub-04_epi.nii \
# --datain=tmp-sub-04_epi.txt \
# --config=${FSLDIR}/etc/flirtsch/b02b0_2.cnf \
# --out=tmp-out

# Different strings that could possibly be provided by the user at the command-line
dwifslpreproc tmp-sub-04_dwi.mif tmp.mif -rpe_header -force \
-topup_files tmp-out -debug
testing_diff_header tmp.mif dwifslpreproc/rpepair_default.mif.gz

dwifslpreproc tmp-sub-04_dwi.mif tmp.mif -rpe_header -force \
-topup_files tmp-out_ -debug
testing_diff_header tmp.mif dwifslpreproc/rpepair_default.mif.gz

dwifslpreproc tmp-sub-04_dwi.mif tmp.mif -rpe_header -force \
-topup_files tmp-out_fieldcoef.nii.gz -debug
testing_diff_header tmp.mif dwifslpreproc/rpepair_default.mif.gz

dwifslpreproc tmp-sub-04_dwi.mif tmp.mif -rpe_header -force \
-topup_files tmp-out_movpar.txt -debug
testing_diff_header tmp.mif dwifslpreproc/rpepair_default.mif.gz


Loading