Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename reorder_dwi #835

Merged
merged 7 commits into from
Dec 7, 2023
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
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()
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.')

arnaudbore marked this conversation as resolved.
Show resolved Hide resolved
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