nifreeze.utils.iterators module¶
Iterators to traverse the volumes in a 4D image.
- nifreeze.utils.iterators.bvalue_iterator(*_, **kwargs) Iterator[int] [source]¶
Traverse the volumes in a DWI dataset by growing b-value.
- Parameters:
bvals (
list
) – List of b-values corresponding to all orientations of the dataset. Please note thatbvals
is a keyword argument and MUST be provided to generate the volume sequence.- Yields:
int
– The next index.
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]
- nifreeze.utils.iterators.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
orNone
, optional) – Number of volumes in the dataset. IfNone
,size
will be inferred from thebvals
keyword argument.bvals (
list
, optional (keyword argument)) – List of b-values corresponding to all orientations of the dataset. Ifsize
is provided, this argument will be ignored. Otherwise,size
will be inferred from the length ofbvals
.
- Yields:
int
– The next index.
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]
- nifreeze.utils.iterators.linear_iterator(size: int | None = None, **kwargs) Iterator[int] [source]¶
Traverse the dataset volumes in ascending order.
- Parameters:
size (
int
orNone
, optional) – Number of volumes in the dataset. IfNone
,size
will be inferred from thebvals
keyword argument.bvals (
list
, optional (keyword argument)) – List of b-values corresponding to all orientations of a DWI dataset. Ifsize
is provided, this argument will be ignored. Otherwise,size
will be inferred from the length ofbvals
.
- Yields:
int
– The next index.
Examples
>>> list(linear_iterator(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
- nifreeze.utils.iterators.random_iterator(size: int | None = None, **kwargs) Iterator[int] [source]¶
Traverse the dataset volumes randomly.
If the
seed
key is present in the keyword arguments, initializes the seed of Python’srandom
pseudo-random number generator library with the given value. Specifically, ifFalse
,None
is used as the seed; ifTrue
, a default seed value is used.- Parameters:
size (
int
orNone
, optional) – Number of volumes in the dataset. IfNone
,size
will be inferred from thebvals
keyword argument.bvals (
list
, optional (keyword argument)) – List of b-values corresponding to all orientations of a DWI dataset. Ifsize
is provided, this argument will be ignored. Otherwise,size
will be inferred from the length ofbvals
.seed (
int
,bool
,str
, orNone
, optional (keyword argument)) – Ifint
orstr
orNone
, initializes the seed of Python’s random generator with the given value. IfFalse
, the random generator is passedNone
. IfTrue
, a default seed value is set.
- Yields:
int
– The next index.
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]