eddymotion.utils module

Iterators to traverse the volumes in a 4D image.

eddymotion.utils.bvalue_iterator(size: int | None = None, **kwargs) Iterator[int][source]

Traverse the volumes in a DWI dataset by growing b-value.

Parameters:

bvalues (list) – List of b-values corresponding to all orientations of the dataset.

Returns:

The sorted index order.

Return type:

Iterator

Examples

>>> list(bvalue_iterator(bvals=[0.0, 0.0, 1000.0, 1000.0, 700.0, 700.0, 2000.0, 2000.0, 0.0]))
[0, 1, 8, 4, 5, 2, 3, 6, 7]
eddymotion.utils.centralsym_iterator(size: int | None = None, **kwargs) Iterator[int][source]

Traverse the dataset starting from the center and alternatingly progressing to the sides.

Parameters:

size (int) – Number of volumes in the dataset (for instance, the number of orientations in a DWI)

Returns:

The sorted index order.

Return type:

Iterator

Examples

>>> list(centralsym_iterator(10))
[5, 4, 6, 3, 7, 2, 8, 1, 9, 0]
>>> list(centralsym_iterator(11))
[5, 4, 6, 3, 7, 2, 8, 1, 9, 0, 10]
eddymotion.utils.linear_iterator(size: int | None = None, **kwargs) Iterator[int][source]

Traverse the dataset volumes in ascending order.

Parameters:

size (int) – Number of volumes in the dataset (for instance, the number of orientations in a DWI)

Returns:

The sorted index order.

Return type:

Iterator

Examples

>>> list(linear_iterator(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
eddymotion.utils.random_iterator(size: int | None = None, **kwargs) Iterator[int][source]

Traverse the dataset volumes randomly.

Parameters:
  • size (int) – Number of volumes in the dataset (for instance, the number of orientations in a DWI)

  • seed (int or bool or bool or None) – If int or str or None, initializes the seed of Python’s random generator with the given value. If False, the random generator is passed None. If True, a default seed value is set.

Returns:

The sorted index order.

Return type:

Iterator

Examples

>>> list(random_iterator(15, seed=0))  # seed is 0
[1, 10, 9, 5, 11, 2, 3, 7, 8, 4, 0, 14, 12, 6, 13]
>>>  # seed is True -> the default value 20210324 is set
>>> list(random_iterator(15, seed=True))
[1, 12, 14, 5, 0, 11, 10, 9, 7, 8, 3, 13, 2, 6, 4]
>>> list(random_iterator(15, seed=20210324))
[1, 12, 14, 5, 0, 11, 10, 9, 7, 8, 3, 13, 2, 6, 4]
>>> list(random_iterator(15, seed=42))  # seed is 42
[8, 13, 7, 6, 14, 12, 5, 2, 9, 3, 4, 11, 0, 1, 10]