From cdbe8bb7f612872846f5ea930420170eebef619e Mon Sep 17 00:00:00 2001 From: Tom Close Date: Wed, 6 Dec 2023 14:50:57 +1100 Subject: [PATCH] fixed up extras hooks signatures --- extras/fileformats/extras/medimage/dicom.py | 10 +++++----- extras/fileformats/extras/medimage/nifti.py | 9 +++++---- fileformats/medimage/base.py | 4 ++-- fileformats/medimage/dicom.py | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/extras/fileformats/extras/medimage/dicom.py b/extras/fileformats/extras/medimage/dicom.py index 484e42d..2996735 100644 --- a/extras/fileformats/extras/medimage/dicom.py +++ b/extras/fileformats/extras/medimage/dicom.py @@ -19,14 +19,14 @@ def dicom_read_array(collection: DicomCollection): @MedicalImage.vox_sizes.register -def dicom_vox_sizes(collection: DicomCollection): +def dicom_vox_sizes(collection: DicomCollection) -> ty.Tuple[float, float, float]: return tuple( collection.metadata["PixelSpacing"] + [collection.metadata["SliceThickness"]] ) @MedicalImage.dims.register -def dicom_dims(collection: DicomCollection): +def dicom_dims(collection: DicomCollection) -> ty.Tuple[int, int, int]: return tuple( ( collection.metadata["Rows"], @@ -37,12 +37,12 @@ def dicom_dims(collection: DicomCollection): @DicomCollection.series_number.register -def dicom_series_number(collection: DicomCollection): +def dicom_series_number(collection: DicomCollection) -> str: return str(collection.metadata["SeriesNumber"]) @FileSet.generate_sample_data.register -def dicom_dir_generate_sample_data(dcmdir: DicomDir, dest_dir: Path, seed: ty.Union[int, Random], stem: ty.Optional[str]) -> ty.Iterable[Path]: +def dicom_dir_generate_sample_data(dcmdir: DicomDir, dest_dir: Path, seed: ty.Union[int, Random] = 0, stem: ty.Optional[str] = None) -> ty.Iterable[Path]: dcm_dir = medimages4tests.dummy.dicom.mri.t1w.siemens.skyra.syngo_d13c.get_image() # Set series number to random value to make it different if isinstance(seed, Random): @@ -60,7 +60,7 @@ def dicom_dir_generate_sample_data(dcmdir: DicomDir, dest_dir: Path, seed: ty.Un @FileSet.generate_sample_data.register -def dicom_set_generate_sample_data(dcm_series: DicomSeries, dest_dir: Path, seed: int, stem: ty.Optional[str]) -> ty.Iterable[Path]: +def dicom_set_generate_sample_data(dcm_series: DicomSeries, dest_dir: Path, seed: ty.Union[int, Random] = 0, stem: ty.Optional[str] = None) -> ty.Iterable[Path]: rng = Random(seed) dicom_dir = dicom_dir_generate_sample_data(dcm_series, dest_dir=mkdtemp(), seed=rng, stem=None)[0] stem = gen_filename(rng, stem=stem) diff --git a/extras/fileformats/extras/medimage/nifti.py b/extras/fileformats/extras/medimage/nifti.py index 5aaff4a..cf43b68 100644 --- a/extras/fileformats/extras/medimage/nifti.py +++ b/extras/fileformats/extras/medimage/nifti.py @@ -1,5 +1,6 @@ from pathlib import Path import typing as ty +from random import Random import nibabel from fileformats.core import FileSet from fileformats.core.utils import gen_filename @@ -31,7 +32,7 @@ def nifti_dims(nifti: Nifti): @FileSet.generate_sample_data.register def nifti_generate_sample_data( - nifti: Nifti1, dest_dir: Path, seed: int, stem: ty.Optional[str] + nifti: Nifti1, dest_dir: Path, seed: ty.Union[int, Random] = 0, stem: ty.Optional[str] = None ) -> ty.Iterable[Path]: return medimages4tests.dummy.nifti.get_image( out_file=dest_dir / gen_filename(seed, file_type=Nifti1, stem=stem) @@ -40,7 +41,7 @@ def nifti_generate_sample_data( @FileSet.generate_sample_data.register def nifti_gz_generate_sample_data( - nifti: NiftiGz, dest_dir: Path, seed: int, stem: ty.Optional[str] + nifti: NiftiGz, dest_dir: Path, seed: ty.Union[int, Random] = 0, stem: ty.Optional[str] = None ) -> ty.Iterable[Path]: return medimages4tests.dummy.nifti.get_image( out_file=dest_dir / gen_filename(seed, file_type=NiftiGz, stem=stem), @@ -50,14 +51,14 @@ def nifti_gz_generate_sample_data( @FileSet.generate_sample_data.register def nifti_gz_x_generate_sample_data( - nifti: NiftiGzX, dest_dir: Path, seed: int, stem: ty.Optional[str] + nifti: NiftiGzX, dest_dir: Path, seed: ty.Union[int, Random] = 0, stem: ty.Optional[str] = None ) -> ty.Iterable[Path]: return medimages4tests.mri.neuro.t1w.get_image() @FileSet.generate_sample_data.register def nifti_x_generate_sample_data( - nifti: NiftiX, dest_dir: Path, seed: int, stem: ty.Optional[str] + nifti: NiftiX, dest_dir: Path, seed: ty.Union[int, Random] = 0, stem: ty.Optional[str] = None ) -> ty.Iterable[Path]: nifti_gz_x = NiftiGzX(medimages4tests.mri.neuro.t1w.get_image()) return NiftiX.convert(nifti_gz_x) diff --git a/fileformats/medimage/base.py b/fileformats/medimage/base.py index b72869e..bc620ec 100644 --- a/fileformats/medimage/base.py +++ b/fileformats/medimage/base.py @@ -26,11 +26,11 @@ def read_array(self): raise NotImplementedError @hook.extra - def vox_sizes(self) -> ty.Tuple[float]: + def vox_sizes(self) -> ty.Tuple[float, float, float]: """The length of the voxels along each dimension""" raise NotImplementedError @hook.extra - def dims(self) -> ty.Tuple[int]: + def dims(self) -> ty.Tuple[int, int, int]: """The dimensions of the image""" raise NotImplementedError diff --git a/fileformats/medimage/dicom.py b/fileformats/medimage/dicom.py index 7ba930f..70bf677 100644 --- a/fileformats/medimage/dicom.py +++ b/fileformats/medimage/dicom.py @@ -26,7 +26,7 @@ def __len__(self): return len(self.contents) @hook.extra - def series_number(self): + def series_number(self) -> str: raise NotImplementedError @cached_property