Skip to content

Commit

Permalink
Allow import of NifTI annotations to dataset items with >1 slot
Browse files Browse the repository at this point in the history
  • Loading branch information
JBWilkie committed Oct 10, 2024
1 parent cb3ea0d commit 525476c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
5 changes: 3 additions & 2 deletions darwin/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2118,9 +2118,10 @@ def _display_slot_warnings_and_errors(
If there are any warnings generated and the annotation format is not Darwin JSON 2.0
"""

# Warnings can only be generated by referring to slots, which is only supported by Darwin JSON
# Warnings can only be generated by referring to slots, which is only supported by the Darwin JSON & NiFTI formats
# Therefore, stop imports of all other formats if there are any warnings
if (slot_errors or slot_warnings) and annotation_format != "darwin":
supported_formats = ["darwin", "nifti"]
if (slot_errors or slot_warnings) and annotation_format not in supported_formats:
raise TypeError(
"You are attempting to import annotations to multi-slotted or multi-channeled items using an annotation format that doesn't support them. To import annotations to multi-slotted or multi-channeled items, please use the Darwin JSON 2.0 format: https://docs.v7labs.com/reference/darwin-json"
)
Expand Down
43 changes: 43 additions & 0 deletions tests/darwin/importer/importer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,49 @@ def test_does_not_raise_error_for_darwin_format_with_warnings():
assert not slot_errors


def test_does_not_raise_error_for_nifti_format_with_warnings():
bounding_box_class = dt.AnnotationClass(
name="class1", annotation_type="bounding_box"
)
local_files = [
dt.AnnotationFile(
path=Path("file1"),
remote_path="/",
filename="file1",
annotation_classes={bounding_box_class},
annotations=[
dt.Annotation(
annotation_class=bounding_box_class,
data={"x": 5, "y": 10, "w": 5, "h": 10},
slot_names=[],
),
dt.Annotation(
annotation_class=bounding_box_class,
data={"x": 15, "y": 20, "w": 15, "h": 20},
slot_names=[],
),
],
),
]
remote_files = {
"/file1": {
"item_id": "123",
"slot_names": ["0", "1"],
"layout": {"type": "grid", "version": 1, "slots": ["0", "1"]},
},
}

local_files, slot_errors, slot_warnings = _verify_slot_annotation_alignment(
local_files,
remote_files,
)

console = MagicMock()
_display_slot_warnings_and_errors(slot_errors, slot_warnings, "nifti", console)

assert not slot_errors


@patch("darwin.importer.importer._get_team_properties_annotation_lookup")
@pytest.mark.parametrize("setup_data", ["section"], indirect=True)
def test_import_existing_section_level_property_values_without_manifest(
Expand Down

0 comments on commit 525476c

Please sign in to comment.