Skip to content

Commit

Permalink
fixed up mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Sep 12, 2024
1 parent 2e01d2d commit 95fe74d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions extras/fileformats/extras/medimage/diffusion.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import typing as ty
import numpy as np
import numpy.typing
from fileformats.core import extra_implementation
from fileformats.medimage import DwiEncoding, Bval, Bvec


@extra_implementation(Bval.read_array)
def bval_read_array(bval: Bval) -> numpy.typing.NDArray[np.floating]: # noqa
def bval_read_array(bval: Bval) -> numpy.typing.NDArray[np.floating[ty.Any]]: # noqa
return np.asarray([float(ln) for ln in bval.read_contents().split()])


@extra_implementation(DwiEncoding.read_array)
def bvec_read_array(bvec: Bvec) -> numpy.typing.NDArray[np.floating]: # noqa
def bvec_read_array(bvec: Bvec) -> numpy.typing.NDArray[np.floating[ty.Any]]: # noqa
bvals = bvec.b_values_file.read_array()
directions = np.asarray(
[[float(x) for x in ln.split()] for ln in bvec.read_contents().splitlines()]
Expand Down
6 changes: 3 additions & 3 deletions extras/fileformats/extras/medimage/nifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
def nifti_read_metadata(
nifti: Nifti, selected_keys: ty.Optional[ty.Collection[str]] = None
) -> ty.Mapping[str, ty.Any]:
metadata = dict(nibabel.load(nifti.fspath).header) # type: ignore[attr-defined]
metadata = dict(nibabel.load(nifti.fspath).header)
if selected_keys:
metadata = {k: v for k, v in metadata.items() if k in selected_keys}
return metadata


@extra_implementation(MedicalImage.read_array)
def nifti_data_array(nifti: Nifti) -> numpy.typing.NDArray[np.floating]: # noqa
return nibabel.load(nifti.fspath).get_data() # type: ignore[attr-defined, no-any-return]
def nifti_data_array(nifti: Nifti) -> numpy.typing.NDArray[np.floating[ty.Any]]: # noqa
return nibabel.load(nifti.fspath).get_data() # type: ignore[no-any-return]


@extra_implementation(MedicalImage.vox_sizes)
Expand Down
4 changes: 2 additions & 2 deletions fileformats/medimage/dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def from_paths(
fspaths : ty.Iterable[Path]
the fspaths pointing to the DICOM files
common_ok : bool, optional
included to match the signature of the overriden method, but ignored as each
included to match the signature of the overridden method, but ignored as each
dicom should belong to only one series.
selected_keys : ty.Optional[ty.Collection[str]], optional
metadata keys to load from the DICOM files, typically used for performance
Expand Down Expand Up @@ -101,7 +101,7 @@ def dicom_collection_read_metadata(
base_class: ty.Union[ty.Type[TypedSet], ty.Type[Directory]] = (
TypedSet if isinstance(collection, DicomSeries) else Directory
)
for dicom in base_class.contents.__get__(collection): # type: ignore[union-attr, arg-type]
for dicom in base_class.contents.__get__(collection): # type: ignore[arg-type]
if selected_keys is not None:
dicom = Dicom(dicom, metadata_keys=selected_keys)
for key, val in dicom.metadata.items():
Expand Down

0 comments on commit 95fe74d

Please sign in to comment.