Skip to content

Commit

Permalink
Merge pull request #835 from arnaudbore/update_philips_reorder
Browse files Browse the repository at this point in the history
Rename reorder_dwi
  • Loading branch information
arnaudbore authored Dec 7, 2023
2 parents 45ee3ff + 5430d77 commit 259d3e9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
20 changes: 20 additions & 0 deletions scripts/legacy/scil_reorder_dwi_philips.py
Original file line number Diff line number Diff line change
@@ -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()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__,
Expand All @@ -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)

Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions scripts/tests/test_dwi_reorder_philips.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 259d3e9

Please sign in to comment.