generated from ArcanaFramework/fileformats-extension-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ArcanaFramework/brainhack2023
Started to add in radlex classifiers and fixed up extras hooks
- Loading branch information
Showing
15 changed files
with
333 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ __pycache__ | |
~* | ||
*.venv | ||
/fileformats/medimage/_version.py | ||
/extras/fileformats/extras/medimage/_version.py |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,65 @@ | ||
from pathlib import Path | ||
import typing as ty | ||
from random import Random | ||
import nibabel | ||
import numpy as np | ||
from fileformats.core import FileSet | ||
from fileformats.core.utils import gen_filename | ||
from fileformats.medimage import MedicalImage, Nifti, NiftiGz, Nifti1, NiftiGzX, NiftiX | ||
import medimages4tests.dummy.nifti | ||
|
||
|
||
@FileSet.read_metadata.register | ||
def nifti_read_metadata(nifti: Nifti): | ||
def nifti_read_metadata(nifti: Nifti) -> ty.Mapping[str, ty.Any]: | ||
return dict(nibabel.load(nifti.fspath).header) | ||
|
||
|
||
@MedicalImage.read_array.register | ||
def nifti_data_array(nifti: Nifti): | ||
def nifti_data_array(nifti: Nifti) -> np.ndarray: # noqa | ||
return nibabel.load(nifti.fspath).get_data() | ||
|
||
|
||
@MedicalImage.vox_sizes.register | ||
def nifti_vox_sizes(nifti: Nifti): | ||
def nifti_vox_sizes(nifti: Nifti) -> ty.Tuple[float, float, float]: | ||
# FIXME: This won't work for 4-D files | ||
return nifti.metadata["pixdim"][1:4] | ||
return tuple(float(d) for d in nifti.metadata["pixdim"][1:4]) | ||
|
||
|
||
@MedicalImage.dims.register | ||
def nifti_dims(nifti: Nifti): | ||
def nifti_dims(nifti: Nifti) -> ty.Tuple[int, int, int]: | ||
# FIXME: This won't work for 4-D files | ||
return nifti.metadata["dim"][1:4] | ||
return tuple(int(d) for d in nifti.metadata["dim"][1:4]) | ||
|
||
|
||
@FileSet.generate_sample_data.register | ||
def nifti_generate_sample_data(nifti: Nifti1, dest_dir: Path, seed: int, stem: ty.Optional[str]): | ||
return medimages4tests.dummy.nifti.get_image(out_file=dest_dir / "nifti.nii") | ||
def nifti_generate_sample_data( | ||
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) | ||
) | ||
|
||
|
||
@FileSet.generate_sample_data.register | ||
def nifti_gz_generate_sample_data(nifti: NiftiGz, dest_dir: Path, seed: int, stem: ty.Optional[str]): | ||
def nifti_gz_generate_sample_data( | ||
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 / "nifti.nii.gz", compressed=True | ||
out_file=dest_dir / gen_filename(seed, file_type=NiftiGz, stem=stem), | ||
compressed=True, | ||
) | ||
|
||
|
||
@FileSet.generate_sample_data.register | ||
def nifti_gz_x_generate_sample_data(nifti: NiftiGzX, dest_dir: Path, seed: int, stem: ty.Optional[str]): | ||
def nifti_gz_x_generate_sample_data( | ||
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]): | ||
def nifti_x_generate_sample_data( | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from fileformats.core import ClassifierCategory | ||
|
||
|
||
class AnatomicalEntity(ClassifierCategory): | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from fileformats.core import ClassifierCategory | ||
|
||
|
||
class AnatomicalEntity(ClassifierCategory): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from fileformats.core import ClassifierCategory | ||
|
||
|
||
class ImagingSpecialty(ClassifierCategory): | ||
pass |
Oops, something went wrong.