diff --git a/darwin/exporter/formats/nifti.py b/darwin/exporter/formats/nifti.py index c6c4e5168..c23aaac48 100644 --- a/darwin/exporter/formats/nifti.py +++ b/darwin/exporter/formats/nifti.py @@ -83,7 +83,9 @@ def export( medical_metadata = video_annotation.slots[0].metadata legacy = not medical_metadata.get("handler") == "MONAI" # type: ignore plane_map = medical_metadata.get("plane_map", {slot_name: "AXIAL"}) - primary_plane = plane_map.get(slot_name, "AXIAL") + primary_plane = medical_metadata.get( + "primary_plane", plane_map.get(slot_name, "AXIAL") + ) except (KeyError, AttributeError): legacy = True primary_plane = "AXIAL" diff --git a/tests/darwin/exporter/formats/export_nifti_test.py b/tests/darwin/exporter/formats/export_nifti_test.py index 5641b883a..cec352648 100644 --- a/tests/darwin/exporter/formats/export_nifti_test.py +++ b/tests/darwin/exporter/formats/export_nifti_test.py @@ -1,6 +1,6 @@ import tempfile from pathlib import Path -from unittest.mock import patch, MagicMock +from unittest.mock import patch, MagicMock, ANY from zipfile import ZipFile import nibabel as nib @@ -129,12 +129,19 @@ def test_export_calls_populate_output_volumes_from_raster_layer( / team_slug_darwin_json_v2 / "nifti/releases/latest/annotations" ) - video_annotation_filepaths = [annotations_dir / "mask_only.json"] + video_annotation_filepaths = [annotations_dir / "non_axial_mask_only.json"] video_annotations = list( darwin_to_dt_gen(video_annotation_filepaths, False) ) nifti.export(video_annotations, output_dir=Path(tmpdir)) mock.assert_called() + mock.assert_called_with( + annotation=ANY, + mask_id_to_classname=ANY, + slot_map=ANY, + output_volumes=ANY, + primary_plane="CORONAL", + ) def test_export_creates_file_for_polygons_and_masks( diff --git a/tests/data.zip b/tests/data.zip index cd5a2f149..e1f414e8e 100644 Binary files a/tests/data.zip and b/tests/data.zip differ