diff --git a/dmriprep/interfaces/vectors.py b/dmriprep/interfaces/vectors.py index 1329bd62..7d3763ec 100644 --- a/dmriprep/interfaces/vectors.py +++ b/dmriprep/interfaces/vectors.py @@ -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() b0_ixs = traits.List(traits.Int) @@ -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} >>> check = CheckGradientTable( ... dwi_file=str(data_dir / 'dwi.nii.gz'), @@ -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} >>> 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) @@ -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 self._results["b0_ixs"] = np.where(table.b0mask)[0].tolist() cwd = Path(runtime.cwd).absolute() diff --git a/dmriprep/utils/vectors.py b/dmriprep/utils/vectors.py index c29bf239..cfc7744e 100644 --- a/dmriprep/utils/vectors.py +++ b/dmriprep/utils/vectors.py @@ -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 @@ -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."""