Skip to content

Commit

Permalink
[DAR-4299][External] Allow import of NifTI annotations to dataset ite…
Browse files Browse the repository at this point in the history
…ms with >1 slot (#940)

* Skip item-properties import for non-Darwin JSON formats

* Allow import of NifTI annotations to dataset items with >1 slot
  • Loading branch information
JBWilkie authored Oct 11, 2024
1 parent 0bb7e13 commit 11fb90b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
7 changes: 4 additions & 3 deletions darwin/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2115,12 +2115,13 @@ def _display_slot_warnings_and_errors(
Raises
------
TypeError
If there are any warnings generated and the annotation format is not Darwin JSON 2.0
If there are any warnings generated and the annotation format is not Darwin JSON 2.0 or NifTI
"""

# 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 11fb90b

Please sign in to comment.