Skip to content

Commit

Permalink
Merge pull request #1011 from arnaudbore/add_script_normalise_bvec
Browse files Browse the repository at this point in the history
[ENH] Add script normalize bvec
  • Loading branch information
arnaudbore authored Jul 25, 2024
2 parents 3626114 + f0a2084 commit 20903a8
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
47 changes: 47 additions & 0 deletions scripts/scil_gradients_normalize_bvecs.py
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 modified scripts/scil_labels_from_mask.py
100644 → 100755
Empty file.
Empty file modified scripts/scil_surface_create.py
100644 → 100755
Empty file.
Empty file modified scripts/scil_tractogram_add_dps.py
100644 → 100755
Empty file.
27 changes: 27 additions & 0 deletions scripts/tests/test_gradients_normalize_bvecs.py
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

0 comments on commit 20903a8

Please sign in to comment.