Skip to content

Commit

Permalink
Update tests/darwin/importer/formats/import_nifti_test.py
Browse files Browse the repository at this point in the history
Co-authored-by: dorfmanrobert <[email protected]>
  • Loading branch information
JBWilkie and dorfmanrobert committed Nov 8, 2024
1 parent da844d4 commit f6b6312
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions tests/darwin/importer/formats/import_nifti_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,15 @@ def test_get_new_axial_size_with_isotropic():
assert new_size == (20, 10)


def test_process_nifti_orinetation(team_slug_darwin_json_v2):
def test_process_nifti_orientation_ras_to_lpi(team_slug_darwin_json_v2):
"""
Test that an input NifTI annotation file in the RAS orientation is correctly
transformed to the LPI orientation.
Do this by emulating the `process_nifti` function, which:
- 1: Transforms the input file into the RAS orientation
- 2: Transforms the transformed RAS file into the LPI orientation
"""
with tempfile.TemporaryDirectory() as tmpdir:
with ZipFile("tests/data.zip") as zfile:
zfile.extractall(tmpdir)
Expand All @@ -254,14 +262,47 @@ def test_process_nifti_orinetation(team_slug_darwin_json_v2):
)
lpi_ornt = [[0.0, -1.0], [1.0, -1.0], [2.0, -1.0]]
ras_file = nib.load(filepath)
ras_transformed_file = nib.funcs.as_closest_canonical(ras_file)
lpi_transformed_file = nib.orientations.apply_orientation(
ras_file.get_fdata(), lpi_ornt
ras_transformed_file.get_fdata(), lpi_ornt
)
processed_file, _ = process_nifti(input_data=ras_file)
assert not np.array_equal(processed_file, ras_file._dataobj)
assert np.array_equal(processed_file, lpi_transformed_file)


def test_process_nifti_orientation_las_to_lpi(team_slug_darwin_json_v2):
"""
Test that an input NifTI annotation file in the LAS orientation is correctly
transformed to the LPI orientation.
Do this by emulating the `process_nifti` function, which:
- 1: Transforms the input file into the RAS orientation
- 2: Transforms the transformed RAS file into the LPI orientation
"""
with tempfile.TemporaryDirectory() as tmpdir:
with ZipFile("tests/data.zip") as zfile:
zfile.extractall(tmpdir)
filepath = (
Path(tmpdir)
/ team_slug_darwin_json_v2
/ "nifti"
/ "releases"
/ "latest"
/ "annotations"
/ "BRAINIX_NIFTI_ROI.nii.gz"
)
lpi_ornt = [[0.0, -1.0], [1.0, -1.0], [2.0, -1.0]]
las_file = nib.load(filepath)
ras_transformed_file = nib.funcs.as_closest_canonical(las_file)
lpi_transformed_file = nib.orientations.apply_orientation(
ras_transformed_file.get_fdata(), lpi_ornt
)
processed_file, _ = process_nifti(input_data=las_file)
assert not np.array_equal(processed_file, las_file._dataobj)
assert np.array_equal(processed_file, lpi_transformed_file)


def serialise_annotation_file(
annotation_file: AnnotationFile, as_dict
) -> Union[str, dict]:
Expand Down
Binary file modified tests/data.zip
Binary file not shown.

0 comments on commit f6b6312

Please sign in to comment.