Skip to content

Commit

Permalink
fixed up extras hooks signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Dec 6, 2023
1 parent 33795f8 commit cdbe8bb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions extras/fileformats/extras/medimage/dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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):
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions extras/fileformats/extras/medimage/nifti.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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),
Expand All @@ -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)
4 changes: 2 additions & 2 deletions fileformats/medimage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion fileformats/medimage/dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cdbe8bb

Please sign in to comment.