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

ENH: Add number of volumes per *b*-value to QC report #129

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions dmriprep/interfaces/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class _CheckGradientTableOutputSpec(TraitedSpec):
out_bvec = File(exists=True)
full_sphere = traits.Bool()
pole = traits.Tuple(traits.Float, traits.Float, traits.Float)
num_shells = traits.Dict()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
num_shells = traits.Dict()
num_shells = traits.Int
shells_dist = traits.Dict

b0_ixs = traits.List(traits.Int)


Expand All @@ -47,6 +48,8 @@ class CheckGradientTable(SimpleInterface):
(0.0, 0.0, 0.0)
>>> check.outputs.full_sphere
True
>>> check.outputs.num_shells
{0.0: 12, 1200.0: 32, 2500.0: 61}
Comment on lines +51 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
>>> check.outputs.num_shells
{0.0: 12, 1200.0: 32, 2500.0: 61}
>>> check.outputs.num_shells
3
>>> check.outputs.shells_dist
{0.0: 12, 1200.0: 32, 2500.0: 61}


>>> check = CheckGradientTable(
... dwi_file=str(data_dir / 'dwi.nii.gz'),
Expand All @@ -56,6 +59,8 @@ class CheckGradientTable(SimpleInterface):
(0.0, 0.0, 0.0)
>>> check.outputs.full_sphere
True
>>> check.outputs.num_shells
{0: 12, 1200: 32, 2500: 61}
Comment on lines +62 to +63
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
>>> check.outputs.num_shells
{0: 12, 1200: 32, 2500: 61}
>>> check.outputs.num_shells
3
>>> check.outputs.shells_dist
{0: 12, 1200: 32, 2500: 61}

>>> newrasb = np.loadtxt(check.outputs.out_rasb, skiprows=1)
>>> oldrasb = np.loadtxt(str(data_dir / 'dwi.tsv'), skiprows=1)
>>> np.allclose(newrasb, oldrasb, rtol=1.e-3)
Expand All @@ -81,6 +86,7 @@ def _run_interface(self, runtime):
pole = table.pole
self._results["pole"] = tuple(pole)
self._results["full_sphere"] = np.all(pole == 0.0)
self._results["num_shells"] = table.count_shells
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._results["num_shells"] = table.count_shells
self._results["num_shells"] = len(table.count_shells)
self._results["shells_dist"] = table.count_shells

self._results["b0_ixs"] = np.where(table.b0mask)[0].tolist()

cwd = Path(runtime.cwd).absolute()
Expand Down
6 changes: 6 additions & 0 deletions dmriprep/utils/vectors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Utilities to operate on diffusion gradients."""
from .. import config
from collections import Counter
from pathlib import Path
from itertools import permutations
import nibabel as nb
Expand Down Expand Up @@ -174,6 +175,11 @@ def bvals(self, value):
raise ValueError("The number of b-vectors and b-values do not match")
self._bvals = np.array(value)

@property
def count_shells(self):
"""Count the number of volumes per b-value."""
return Counter(sorted(self._bvals))

@property
def b0mask(self):
"""Get a mask of low-b frames."""
Expand Down