Skip to content

Commit

Permalink
Merge pull request #1097 from karanphil/fix_viz_gradients_read
Browse files Browse the repository at this point in the history
Update script scil_viz_gradients_screenshot
  • Loading branch information
arnaudbore authored Dec 18, 2024
2 parents 0817790 + 92fbb64 commit c352faf
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions scripts/scil_viz_gradients_screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os

from dipy.data import get_sphere
from dipy.io.gradients import read_bvals_bvecs

from scilpy.gradients.bvec_bval_tools import identify_shells
from scilpy.io.utils import (add_overwrite_arg,
Expand Down Expand Up @@ -88,7 +89,7 @@ def main():

if len(args.in_gradient_scheme) == 2:
assert_gradients_filenames_valid(parser, args.in_gradient_scheme,
'fsl')
True)
elif len(args.in_gradient_scheme) == 1:
basename, ext = os.path.splitext(args.in_gradient_scheme[0])
if ext in ['.bvec', '.bvecs', '.bvals', '.bval']:
Expand All @@ -97,7 +98,7 @@ def main():
else:
assert_gradients_filenames_valid(parser,
args.in_gradient_scheme,
'mrtrix')
False)
else:
parser.error('Depending on the gradient format you should have '
'two files for FSL format and one file for MRtrix')
Expand All @@ -120,17 +121,14 @@ def main():
if len(args.in_gradient_scheme) == 2:
in_gradient_schemes = args.in_gradient_scheme
in_gradient_schemes.sort() # [bval, bvec]
# bvecs/bvals (FSL) format, X Y Z AND b (or transpose)
points = np.genfromtxt(in_gradient_schemes[1])
if points.shape[0] == 3:
points = points.T
bvals = np.genfromtxt(in_gradient_schemes[0])
bvals, bvecs = read_bvals_bvecs(in_gradient_schemes[0],
in_gradient_schemes[1])
centroids, shell_idx = identify_shells(bvals)
else:
# MRtrix format X, Y, Z, b
in_gradient_scheme = args.in_gradient_scheme[0]
tmp = np.genfromtxt(in_gradient_scheme, delimiter=' ')
points = tmp[:, :3]
bvecs = tmp[:, :3]
bvals = tmp[:, 3]
centroids, shell_idx = identify_shells(bvals)

Expand Down Expand Up @@ -161,7 +159,7 @@ def main():
for idx, val in enumerate(shell_idx):
if val != 0 and val != -1:
shell_idx[idx] -= len(np.where(indexes < val)[0])
ms = build_ms_from_shell_idx(points, shell_idx)
ms = build_ms_from_shell_idx(bvecs, shell_idx)

else:
ms = [get_sphere(args.dipy_sphere).vertices]
Expand Down

0 comments on commit c352faf

Please sign in to comment.