Skip to content

Commit 5ab1730

Browse files
authored
Merge pull request #304 from jhlegarreta/sty/annotate-opt-data-params
STY: Annotate DWI optional data class parameters as such
2 parents 270a84c + 698b6b4 commit 5ab1730

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/nifreeze/data/dmri.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
class DWI(BaseDataset[np.ndarray]):
6969
"""Data representation structure for dMRI data."""
7070

71-
bzero: np.ndarray = attrs.field(default=None, repr=_data_repr, eq=attrs.cmp_using(eq=_cmp))
71+
bzero: np.ndarray | None = attrs.field(
72+
default=None, repr=_data_repr, eq=attrs.cmp_using(eq=_cmp)
73+
)
7274
"""A *b=0* reference map, preferably obtained by some smart averaging."""
7375
gradients: np.ndarray = attrs.field(default=None, repr=_data_repr, eq=attrs.cmp_using(eq=_cmp))
7476
"""A 2D numpy array of the gradient table (``N`` orientations x ``C`` components)."""
@@ -284,7 +286,7 @@ def to_nifti(
284286
stacklevel=2,
285287
)
286288
else:
287-
data = np.concatenate((self.bzero[..., np.newaxis], self.dataobj), axis=-1)
289+
data = np.concatenate((self.bzero[..., np.newaxis], self.dataobj), axis=-1) # type: ignore
288290
nii = nb.Nifti1Image(data, nii.affine, nii.header)
289291

290292
if filename is not None:

test/test_data_dmri.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ def test_load(datadir, tmp_path, insert_b0, rotate_bvecs): # noqa: C901
122122
)
123123

124124
if insert_b0:
125+
assert dwi_h5.bzero is not None
126+
assert dwi_from_nifti1.bzero is not None
125127
assert np.allclose(dwi_h5.bzero, dwi_from_nifti1.bzero)
126128

127129
assert np.allclose(dwi_h5.bvals, dwi_from_nifti1.bvals, atol=1e-3)
@@ -146,6 +148,8 @@ def test_load(datadir, tmp_path, insert_b0, rotate_bvecs): # noqa: C901
146148
if not rotate_bvecs: # If we set motion_affines, data WILL change
147149
assert np.allclose(dwi_h5.dataobj, dwi_from_nifti2.dataobj)
148150
if insert_b0:
151+
assert dwi_h5.bzero is not None
152+
assert dwi_from_nifti2.bzero is not None
149153
assert np.allclose(dwi_h5.bzero, dwi_from_nifti2.bzero)
150154

151155
assert np.allclose(dwi_h5.gradients, dwi_from_nifti2.gradients)
@@ -173,6 +177,8 @@ def test_load(datadir, tmp_path, insert_b0, rotate_bvecs): # noqa: C901
173177
if not rotate_bvecs: # If we set motion_affines, data WILL change
174178
assert np.allclose(dwi_h5.dataobj, dwi_from_nifti3.dataobj)
175179

180+
assert dwi_h5.bzero is not None
181+
assert dwi_from_nifti3.bzero is not None
176182
assert np.allclose(dwi_h5.bzero, dwi_from_nifti3.bzero)
177183
assert np.allclose(dwi_h5.gradients, dwi_from_nifti3.gradients, atol=1e-6)
178184
assert np.allclose(dwi_h5.bvals, dwi_from_nifti3.bvals, atol=1e-6)
@@ -184,6 +190,7 @@ def test_load(datadir, tmp_path, insert_b0, rotate_bvecs): # noqa: C901
184190
if not rotate_bvecs: # If we set motion_affines, data WILL change
185191
assert np.allclose(dwi_h5.dataobj, dwi_from_nifti4.dataobj)
186192

193+
assert dwi_from_nifti4.bzero is not None
187194
assert np.allclose(dwi_h5.bzero, dwi_from_nifti4.bzero)
188195
assert np.allclose(dwi_h5.gradients, dwi_from_nifti4.gradients)
189196
assert np.allclose(dwi_h5.bvals, dwi_from_nifti4.bvals, atol=1e-6)

0 commit comments

Comments
 (0)