Skip to content

Commit

Permalink
Answer Philip's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaRenauld committed Feb 20, 2024
1 parent 333ec84 commit 2181190
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions scilpy/gradients/tests/test_gradients_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from scilpy.gradients.bvec_bval_tools import is_normalized_bvecs
from scilpy.gradients.utils import random_uniform_on_sphere, \
get_new_order_table
get_new_gtab_order


def test_random_uniform_on_sphere():
Expand All @@ -25,7 +25,7 @@ def test_random_uniform_on_sphere():
assert np.all(np.asarray(smallests) > min_expected_angle)


def test_get_new_order_table():
def test_get_new_gtab_order():
# Using N=4 vectors
philips_table = np.asarray([[1, 1, 1, 1],
[2, 2, 2, 2],
Expand All @@ -38,7 +38,7 @@ def test_get_new_order_table():
[1, 1, 1]])
bvals = np.asarray([3, 4, 2, 1])

order = get_new_order_table(philips_table, dwi, bvals, bvecs)
order = get_new_gtab_order(philips_table, dwi, bvals, bvecs)

assert np.array_equal(bvecs[order, :], philips_table[:, 0:3])
assert np.array_equal(bvals[order], philips_table[:, 3])
12 changes: 6 additions & 6 deletions scilpy/gradients/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def random_uniform_on_sphere(nb_vectors):
return bvecs


def get_new_order_table(ref_gradients_table, dwi, bvals, bvecs):
def get_new_gtab_order(ref_gradient_table, dwi, bvals, bvecs):
"""
Find the sorting order that could be applied to the bval and bvec files to
obtain the same order as in the reference gradient table.
Expand All @@ -52,7 +52,7 @@ def get_new_order_table(ref_gradients_table, dwi, bvals, bvecs):
Parameters
----------
ref_gradients_table: nd.array
ref_gradient_table: nd.array
Gradient table, of shape (N, 4). It will use as reference for the
ordering of b-vectors.
Ex: Could be the result of scil_gradients_generate_sampling.py
Expand All @@ -61,19 +61,19 @@ def get_new_order_table(ref_gradients_table, dwi, bvals, bvecs):
bvals : array, (N,)
bvals that need to be reordered.
bvecs : array, (N, 3)
bvecs that need to be reorered.
bvecs that need to be reordered.
Returns
-------
new_index: nd.array
New index to reorder bvals/bvec
"""
if not (len(bvecs) == dwi.shape[3] == len(bvals) ==
len(ref_gradients_table)):
len(ref_gradient_table)):
raise ValueError('bvec/bval/dwi and reference table do not contain '
'the same number of gradients.')

ref_bval = np.unique(ref_gradients_table[:, 3])
ref_bval = np.unique(ref_gradient_table[:, 3])
ref_dwi_shells = ref_bval[ref_bval > 1]
ref_b0s = ref_bval[ref_bval < 1]

Expand All @@ -89,7 +89,7 @@ def get_new_order_table(ref_gradients_table, dwi, bvals, bvecs):

for nbval in ref_bval:
curr_bval = np.where(bvals == nbval)[0]
curr_bval_table = np.where(ref_gradients_table[:, 3] == nbval)[0]
curr_bval_table = np.where(ref_gradient_table[:, 3] == nbval)[0]

if len(curr_bval) != len(curr_bval_table):
raise ValueError('bval/bvec and orginal table do not contain '
Expand Down
4 changes: 2 additions & 2 deletions scripts/scil_dwi_reorder_philips.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import nibabel as nib
import numpy as np

from scilpy.gradients.utils import get_new_order_table
from scilpy.gradients.utils import get_new_gtab_order
from scilpy.io.utils import (add_overwrite_arg,
add_verbose_arg,
assert_inputs_exist,
Expand Down Expand Up @@ -90,7 +90,7 @@ def main():
bvals, bvecs = read_bvals_bvecs(args.in_bval, args.in_bvec)
dwi = nib.load(args.in_dwi)

new_index = get_new_order_table(philips_table, dwi, bvals, bvecs)
new_index = get_new_gtab_order(philips_table, dwi, bvals, bvecs)
bvecs = bvecs[new_index]
bvals = bvals[new_index]

Expand Down

0 comments on commit 2181190

Please sign in to comment.