-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1011 from arnaudbore/add_script_normalise_bvec
[ENH] Add script normalize bvec
- Loading branch information
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Script to normalize gradients bvecs. | ||
""" | ||
|
||
import argparse | ||
import logging | ||
|
||
import numpy as np | ||
|
||
from scilpy.io.utils import (assert_inputs_exist, assert_outputs_exist, | ||
add_overwrite_arg, add_verbose_arg) | ||
from scilpy.gradients.bvec_bval_tools import normalize_bvecs | ||
|
||
|
||
def _build_arg_parser(): | ||
p = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, | ||
description=__doc__) | ||
|
||
p.add_argument('in_bvec', | ||
help='Path to the gradient file (.bvec).') | ||
|
||
p.add_argument('out_bvec', | ||
help='Output bvec file.') | ||
|
||
add_overwrite_arg(p) | ||
add_verbose_arg(p) | ||
|
||
return p | ||
|
||
|
||
def main(): | ||
parser = _build_arg_parser() | ||
args = parser.parse_args() | ||
logging.getLogger().setLevel(logging.getLevelName(args.verbose)) | ||
|
||
assert_inputs_exist(parser, args.in_bvec) | ||
assert_outputs_exist(parser, args, args.out_bvec) | ||
|
||
bvecs = np.loadtxt(args.in_bvec) | ||
np.savetxt(args.out_bvec, normalize_bvecs(bvecs)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import tempfile | ||
|
||
from scilpy import SCILPY_HOME | ||
from scilpy.io.fetcher import fetch_data, get_testing_files_dict | ||
|
||
# If they already exist, this only takes 5 seconds (check md5sum) | ||
fetch_data(get_testing_files_dict(), keys=['processing.zip']) | ||
tmp_dir = tempfile.TemporaryDirectory() | ||
|
||
|
||
def test_help_option(script_runner): | ||
ret = script_runner.run('scil_gradients_normalize_bvecs.py', | ||
'--help') | ||
assert ret.success | ||
|
||
|
||
def test_execution_processing_fsl(script_runner, monkeypatch): | ||
monkeypatch.chdir(os.path.expanduser(tmp_dir.name)) | ||
in_bvec = os.path.join(SCILPY_HOME, 'processing', | ||
'1000.bvec') | ||
ret = script_runner.run('scil_gradients_normalize_bvecs.py', | ||
in_bvec, '1000_norm.bvec') | ||
assert ret.success |