Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAR-4299][External] Allow import of NifTI annotations to dataset items with >1 slot #940

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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