From 81e452b98573f2463351559ab5b88d29e16f6845 Mon Sep 17 00:00:00 2001 From: arnaudbore Date: Wed, 6 Dec 2023 14:45:05 -0500 Subject: [PATCH 1/6] fix pep8 --- scripts/legacy/scil_reorder_dwi_philips.py | 21 ++++++++++++++++++ ...philips.py => scil_dwi_reorder_philips.py} | 22 ++++++++++++++++++- ...philips.py => test_dwi_reorder_philips.py} | 2 +- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100755 scripts/legacy/scil_reorder_dwi_philips.py rename scripts/{scil_reorder_dwi_philips.py => scil_dwi_reorder_philips.py} (73%) rename scripts/tests/{test_reorder_dwi_philips.py => test_dwi_reorder_philips.py} (64%) diff --git a/scripts/legacy/scil_reorder_dwi_philips.py b/scripts/legacy/scil_reorder_dwi_philips.py new file mode 100755 index 000000000..cc68ec12a --- /dev/null +++ b/scripts/legacy/scil_reorder_dwi_philips.py @@ -0,0 +1,21 @@ +#!/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/scil_reorder_dwi_philips.py b/scripts/scil_dwi_reorder_philips.py similarity index 73% rename from scripts/scil_reorder_dwi_philips.py rename to scripts/scil_dwi_reorder_philips.py index d5ded2e97..a11404f25 100755 --- a/scripts/scil_reorder_dwi_philips.py +++ b/scripts/scil_dwi_reorder_philips.py @@ -6,7 +6,9 @@ """ import argparse +import json import logging +from packaging import version from dipy.io.gradients import read_bvals_bvecs import nibabel as nib @@ -19,6 +21,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 +39,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 +63,21 @@ 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 args.force: + 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('_', ' ') + if version.parse(SOFTWARE_VERSION_MIN) <= version.parse(curr_version): + logging.error('There is no need for reording since your' + ' dwi comes from a philips machine ' + 'version {}'.format(curr_version)) + 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_reorder_dwi_philips.py b/scripts/tests/test_dwi_reorder_philips.py similarity index 64% rename from scripts/tests/test_reorder_dwi_philips.py rename to scripts/tests/test_dwi_reorder_philips.py index b88f98872..3a3a2df42 100644 --- a/scripts/tests/test_reorder_dwi_philips.py +++ b/scripts/tests/test_dwi_reorder_philips.py @@ -3,5 +3,5 @@ def test_help_option(script_runner): - ret = script_runner.run('scil_reorder_dwi_philips.py', '--help') + ret = script_runner.run('scil_dwi_reorder_philips.py', '--help') assert ret.success From cd49e00b3e7dfd2c8e71950a1059df00ccb1d751 Mon Sep 17 00:00:00 2001 From: arnaudbore Date: Wed, 6 Dec 2023 14:46:57 -0500 Subject: [PATCH 2/6] fix legacy --- scripts/legacy/scil_reorder_dwi_philips.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/legacy/scil_reorder_dwi_philips.py b/scripts/legacy/scil_reorder_dwi_philips.py index cc68ec12a..d7247cf70 100755 --- a/scripts/legacy/scil_reorder_dwi_philips.py +++ b/scripts/legacy/scil_reorder_dwi_philips.py @@ -11,8 +11,7 @@ """ -@deprecate_script("scil_reorder_dwi_philips.py", - DEPRECATION_MSG, '1.7.0') +@deprecate_script("scil_reorder_dwi_philips.py", DEPRECATION_MSG, '1.7.0') def main(): new_main() From 41eea9ef8bda54e5ba5be51106e1fbf02b1a2888 Mon Sep 17 00:00:00 2001 From: arnaudbore Date: Wed, 6 Dec 2023 15:04:05 -0500 Subject: [PATCH 3/6] fix overwrite --- scripts/scil_dwi_reorder_philips.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/scil_dwi_reorder_philips.py b/scripts/scil_dwi_reorder_philips.py index a11404f25..3c3942f21 100755 --- a/scripts/scil_dwi_reorder_philips.py +++ b/scripts/scil_dwi_reorder_philips.py @@ -66,7 +66,7 @@ def main(): assert_inputs_exist(parser, required_args, args.json) assert_outputs_exist(parser, args, output_filenames) - if args.json and args.force: + 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(): From 3fcc90c6a2eb368e60d02f69722d38babf96e48d Mon Sep 17 00:00:00 2001 From: arnaudbore Date: Wed, 6 Dec 2023 16:38:25 -0500 Subject: [PATCH 4/6] fix pk comments --- scripts/scil_dwi_reorder_philips.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/scil_dwi_reorder_philips.py b/scripts/scil_dwi_reorder_philips.py index 3c3942f21..d38f5bfa0 100755 --- a/scripts/scil_dwi_reorder_philips.py +++ b/scripts/scil_dwi_reorder_philips.py @@ -2,13 +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 @@ -70,13 +72,16 @@ def main(): 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('_', ' ') + curr_version = curr_version.replace('\\', + ' ').replace('_', + ' ').split()[0] if version.parse(SOFTWARE_VERSION_MIN) <= version.parse(curr_version): - logging.error('There is no need for reording since your' - ' dwi comes from a philips machine ' - 'version {}'.format(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) From 10814b15fbb83b4d8568755f23a014e3c1f2e7f0 Mon Sep 17 00:00:00 2001 From: arnaudbore Date: Wed, 6 Dec 2023 16:41:14 -0500 Subject: [PATCH 5/6] add legacy test --- scripts/legacy/tests/test_reorder_dwi_philips.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 scripts/legacy/tests/test_reorder_dwi_philips.py diff --git a/scripts/legacy/tests/test_reorder_dwi_philips.py b/scripts/legacy/tests/test_reorder_dwi_philips.py new file mode 100644 index 000000000..b88f98872 --- /dev/null +++ b/scripts/legacy/tests/test_reorder_dwi_philips.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + + +def test_help_option(script_runner): + ret = script_runner.run('scil_reorder_dwi_philips.py', '--help') + assert ret.success From 5430d771e901c8e6c2178abd9501fc75166ff60c Mon Sep 17 00:00:00 2001 From: arnaudbore Date: Thu, 7 Dec 2023 08:58:57 -0500 Subject: [PATCH 6/6] capital P --- scripts/scil_dwi_reorder_philips.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/scil_dwi_reorder_philips.py b/scripts/scil_dwi_reorder_philips.py index d38f5bfa0..0af2fe01e 100755 --- a/scripts/scil_dwi_reorder_philips.py +++ b/scripts/scil_dwi_reorder_philips.py @@ -43,7 +43,7 @@ def _build_arg_parser(): p.add_argument('--json', help='If you json file, it will check if you need' - ' to reorder your philips dwi.') + ' to reorder your Philips dwi.') add_overwrite_arg(p) add_verbose_arg(p) @@ -78,7 +78,7 @@ def main(): ' ').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 ' + 'dwi comes from a Philips machine with ' 'version {}. '.format(curr_version) + 'No file will be created. \n' 'Use -f to force overwriting.')