diff --git a/scripts/legacy/scil_reorder_dwi_philips.py b/scripts/legacy/scil_reorder_dwi_philips.py new file mode 100755 index 000000000..d7247cf70 --- /dev/null +++ b/scripts/legacy/scil_reorder_dwi_philips.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +from scilpy.io.deprecator import deprecate_script +from scripts.scil_dwi_reorder_philips import main as new_main + + +DEPRECATION_MSG = """ +This script has been renamed scil_dwi_reorder_philips.py. +Please change your existing pipelines accordingly. +""" + + +@deprecate_script("scil_reorder_dwi_philips.py", DEPRECATION_MSG, '1.7.0') +def main(): + new_main() + + +if __name__ == "__main__": + main() diff --git a/scripts/tests/test_reorder_dwi_philips.py b/scripts/legacy/tests/test_reorder_dwi_philips.py similarity index 100% rename from scripts/tests/test_reorder_dwi_philips.py rename to scripts/legacy/tests/test_reorder_dwi_philips.py diff --git a/scripts/scil_reorder_dwi_philips.py b/scripts/scil_dwi_reorder_philips.py similarity index 65% rename from scripts/scil_reorder_dwi_philips.py rename to scripts/scil_dwi_reorder_philips.py index d5ded2e97..0af2fe01e 100755 --- a/scripts/scil_reorder_dwi_philips.py +++ b/scripts/scil_dwi_reorder_philips.py @@ -2,11 +2,15 @@ # -*- coding: utf-8 -*- """ -Re-order gradient according to original table +Re-order gradient according to original table (Philips) +This script is not needed for version 5.6 and higher """ import argparse +import json import logging +from packaging import version +import sys from dipy.io.gradients import read_bvals_bvecs import nibabel as nib @@ -19,6 +23,8 @@ assert_outputs_exist) from scilpy.utils.filenames import split_name_with_nii +SOFTWARE_VERSION_MIN = '5.6' + def _build_arg_parser(): p = argparse.ArgumentParser(description=__doc__, @@ -35,6 +41,10 @@ def _build_arg_parser(): p.add_argument('out_basename', help='Basename output file.') + p.add_argument('--json', + help='If you json file, it will check if you need' + ' to reorder your Philips dwi.') + add_overwrite_arg(p) add_verbose_arg(p) @@ -55,9 +65,24 @@ def main(): args.out_basename + '.bval', args.out_basename + '.bvec'] - assert_inputs_exist(parser, required_args) + assert_inputs_exist(parser, required_args, args.json) assert_outputs_exist(parser, args, output_filenames) + if args.json and not args.overwrite: + with open(args.json) as curr_json: + dwi_json = json.load(curr_json) + if 'SoftwareVersions' in dwi_json.keys(): + curr_version = dwi_json['SoftwareVersions'] + curr_version = curr_version.replace('\\', + ' ').replace('_', + ' ').split()[0] + if version.parse(SOFTWARE_VERSION_MIN) <= version.parse(curr_version): + sys.exit('ERROR: There is no need for reording since your ' + 'dwi comes from a Philips machine with ' + 'version {}. '.format(curr_version) + + 'No file will be created. \n' + 'Use -f to force overwriting.') + philips_table = np.loadtxt(args.in_table, skiprows=1) bvals, bvecs = read_bvals_bvecs(args.in_bval, args.in_bvec) dwi = nib.load(args.in_dwi) diff --git a/scripts/tests/test_dwi_reorder_philips.py b/scripts/tests/test_dwi_reorder_philips.py new file mode 100644 index 000000000..3a3a2df42 --- /dev/null +++ b/scripts/tests/test_dwi_reorder_philips.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + + +def test_help_option(script_runner): + ret = script_runner.run('scil_dwi_reorder_philips.py', '--help') + assert ret.success