Skip to content

Commit

Permalink
Merge pull request #418 from arnaudbore/fix_todos
Browse files Browse the repository at this point in the history
Fix todos
  • Loading branch information
arnaudbore authored Feb 25, 2021
2 parents c620b82 + fa664f0 commit c8d2927
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 48 deletions.
8 changes: 4 additions & 4 deletions scripts/scil_concatenate_dwi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ def _build_arg_parser():
p.add_argument('out_dwi',
help='The name of the output DWI file.')
p.add_argument('out_bval',
help='The name of the output b-values.')
help='The name of the output b-values file (.bval).')
p.add_argument('out_bvec',
help='The name of the output b-vectors.')
help='The name of the output b-vectors file (.bvec).')

p.add_argument('--in_dwis', nargs='+',
help='The DWI file (.nii) to concatenate.')
p.add_argument('--in_bvals', nargs='+',
help='The b-values in FSL format.')
help='The b-values files in FSL format (.bval).')
p.add_argument('--in_bvecs', nargs='+',
help='The b-vectors in FSL format.')
help='The b-vectors files in FSL format (.bvec).')

p.add_argument('--data_type',
help='Data type of the output image. Use the format: '
Expand Down
85 changes: 41 additions & 44 deletions scripts/scil_extract_dwi_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,49 @@
assert_inputs_exist, assert_outputs_exist)
from scilpy.utils.bvec_bval_tools import extract_dwi_shell

# TODO switch from parser to p
# TODO switch to in_*
# TODO switch to out_*

def _build_arg_parser():
parser = argparse.ArgumentParser(
p = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawTextHelpFormatter)

parser.add_argument('dwi',
help='The DW image file to split.')
p.add_argument('in_dwi',
help='The DW image file to split.')

parser.add_argument('bvals',
help='The b-values in FSL format.')
p.add_argument('in_bval',
help='The b-values file in FSL format (.bval).')

parser.add_argument('bvecs',
help='The b-vectors in FSL format.')
p.add_argument('in_bvec',
help='The b-vectors file in FSL format (.bvec).')

parser.add_argument('bvals_to_extract', nargs='+',
metavar='bvals-to-extract', type=int,
help='The list of b-values to extract. For example '
'0 2000.')
p.add_argument('in_bvals_to_extract', nargs='+',
type=int,
help='The list of b-values to extract. For example 0 2000.')

parser.add_argument('output_dwi',
help='The name of the output DWI file.')
p.add_argument('out_dwi',
help='The name of the output DWI file.')

parser.add_argument('output_bvals',
help='The name of the output b-values.')
p.add_argument('out_bval',
help='The name of the output b-value file (.bval).')

parser.add_argument('output_bvecs',
help='The name of the output b-vectors')
p.add_argument('out_bvec',
help='The name of the output b-vector file (.bvec).')

parser.add_argument('--block-size', '-s',
metavar='INT', type=int,
help='Loads the data using this block size. '
'Useful\nwhen the data is too large to be '
'loaded in memory.')
p.add_argument('--block-size', '-s',
metavar='INT', type=int,
help='Loads the data using this block size. '
'Useful\nwhen the data is too large to be '
'loaded in memory.')

parser.add_argument('--tolerance', '-t',
metavar='INT', type=int, default=20,
help='The tolerated gap between the b-values to '
'extract\nand the actual b-values.')
p.add_argument('--tolerance', '-t',
metavar='INT', type=int, default=20,
help='The tolerated gap between the b-values to '
'extract\nand the actual b-values.')

add_verbose_arg(parser)
add_overwrite_arg(parser)
add_verbose_arg(p)
add_overwrite_arg(p)

return parser
return p


def main():
Expand All @@ -83,28 +80,28 @@ def main():
if args.verbose:
logging.basicConfig(level=logging.INFO)

assert_inputs_exist(parser, [args.dwi, args.bvals, args.bvecs])
assert_outputs_exist(parser, args, [args.output_dwi, args.output_bvals,
args.output_bvecs])
assert_inputs_exist(parser, [args.in_dwi, args.in_bval, args.in_bvec])
assert_outputs_exist(parser, args, [args.out_dwi, args.out_bval,
args.out_bvec])

bvals, bvecs = read_bvals_bvecs(args.bvals, args.bvecs)
bvals, bvecs = read_bvals_bvecs(args.in_bval, args.in_bvec)

# Find the volume indices that correspond to the shells to extract.
tol = args.tolerance

img = nib.load(args.dwi)
img = nib.load(args.in_dwi)

outputs = extract_dwi_shell(img, bvals, bvecs, args.in_bvals_to_extract,
tol, args.block_size)

outputs = extract_dwi_shell(img, bvals, bvecs, args.bvals_to_extract, tol,
args.block_size)
indices, shell_data, new_bvals, new_bvecs = outputs

logging.info("Selected indices: {}".format(indices))

np.savetxt(args.output_bvals, new_bvals, '%d')
np.savetxt(args.output_bvecs, new_bvecs.T, '%0.15f')
# use named argument header=
nib.save(nib.Nifti1Image(shell_data, img.affine, img.header),
args.output_dwi)
np.savetxt(args.out_bval, new_bvals, '%d')
np.savetxt(args.out_bvec, new_bvecs.T, '%0.15f')
nib.save(nib.Nifti1Image(shell_data, img.affine, header=img.header),
args.out_dwi)


if __name__ == "__main__":
Expand Down

0 comments on commit c8d2927

Please sign in to comment.