Skip to content

Commit 92866a8

Browse files
committed
fix nib type hinting for mypy
1 parent 4daa1d0 commit 92866a8

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/rbc/core/functional/motion.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""RBC motion reference & correction."""
22

33
from pathlib import Path
4-
from typing import NamedTuple
4+
from typing import NamedTuple, cast
55

66
import nibabel as nib
77
from niwrap import afni, fsl
@@ -17,7 +17,8 @@ def generate_motion_reference(in_file: Path, output_fname: str) -> afni.V3dcalcO
1717
Returns:
1818
AFNI 3dcalc output object.
1919
"""
20-
total_vols = nib.load(in_file).shape[3]
20+
img = cast("nib.Nifti1Image", nib.load(in_file))
21+
total_vols = img.shape[3]
2122

2223
mid_vol = total_vols // 2
2324

tests/integration/test_functional.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Integration tests for functional workflow."""
22

33
from types import SimpleNamespace
4+
from typing import cast
45

56
import nibabel as nib
67
import pytest
@@ -16,7 +17,7 @@
1617

1718
def test_truncate_trs(test_subject: SimpleNamespace) -> None:
1819
"""Test truncating initial TRs from BOLD timeseries."""
19-
original_count = nib.load(test_subject.bold).shape[3]
20+
original_count = cast("nib.Nifti1Image", nib.load(test_subject.bold)).shape[3]
2021

2122
start_tr = 4
2223
reoriented = reorient(
@@ -29,13 +30,13 @@ def test_truncate_trs(test_subject: SimpleNamespace) -> None:
2930
)
3031
# Test truncated BOLD file exists & volume count is reduced
3132
assert truncated_bold.output_file.exists()
32-
new_shape = nib.load(truncated_bold.output_file).shape
33+
new_shape = cast("nib.Nifti1Image", nib.load(truncated_bold.output_file)).shape
3334
assert new_shape[3] == original_count - start_tr
3435

3536

3637
def test_truncate_to_min_volume(test_subject: SimpleNamespace) -> None:
3738
"""Test truncating to minimum volume count of 1."""
38-
original_count = nib.load(test_subject.bold).shape[3]
39+
original_count = cast("nib.Nifti1Image", nib.load(test_subject.bold)).shape[3]
3940

4041
start_tr = original_count - 1
4142
truncated_bold = truncate_trs(
@@ -44,7 +45,7 @@ def test_truncate_to_min_volume(test_subject: SimpleNamespace) -> None:
4445
start_tr=start_tr,
4546
)
4647
# Test truncated BOLD file volume count is 1
47-
new_shape = nib.load(truncated_bold.output_file).shape
48+
new_shape = cast("nib.Nifti1Image", nib.load(truncated_bold.output_file)).shape
4849
nvols = new_shape[3] if len(new_shape) > 3 else 1
4950
assert nvols == 1
5051

@@ -55,7 +56,7 @@ def test_motion_reference_volume_count(test_subject: SimpleNamespace) -> None:
5556
in_file=test_subject.bold, output_fname="test_motion_ref.nii.gz"
5657
)
5758
# Test motion reference file has 1 volume
58-
ref_shape = nib.load(reference.output_file).shape
59+
ref_shape = cast("nib.Nifti1Image", nib.load(reference.output_file)).shape
5960
nvols = ref_shape[3] if len(ref_shape) > 3 else 1
6061
assert nvols == 1
6162

@@ -82,7 +83,9 @@ def test_motion_correction_10vols(test_subject: SimpleNamespace) -> None:
8283
output_prefix="test_mc_10v",
8384
)
8485
assert motion_corrected.bold.with_suffix(".nii.gz").exists()
85-
mc_shape = nib.load(motion_corrected.bold.with_suffix(".nii.gz")).shape
86+
mc_shape = cast(
87+
"nib.Nifti1Image", nib.load(motion_corrected.bold.with_suffix(".nii.gz"))
88+
).shape
8689
assert mc_shape[3] == 10
8790

8891
assert motion_corrected.par.exists()

0 commit comments

Comments
 (0)