From 8ded8db7acfb19785f4573732a6bd5e95b26f151 Mon Sep 17 00:00:00 2001 From: Christoffer Date: Tue, 14 Nov 2023 18:10:39 +0100 Subject: [PATCH] black reformat --- darwin/exporter/formats/darwin.py | 93 ++++++++++++++++--------------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/darwin/exporter/formats/darwin.py b/darwin/exporter/formats/darwin.py index fbc1f31a4..be3ad7df7 100644 --- a/darwin/exporter/formats/darwin.py +++ b/darwin/exporter/formats/darwin.py @@ -14,7 +14,6 @@ """ - def build_image_annotation(annotation_file: dt.AnnotationFile) -> Dict[str, Any]: """ Builds and returns a dictionary with the annotations present in the given file in Darwin v2 format. @@ -36,52 +35,19 @@ def build_image_annotation(annotation_file: dt.AnnotationFile) -> Dict[str, Any] annotations_list.append(annotation_data) slots_data = _build_slots_data(annotation_file.slots) - item =_build_item_data(annotation_file) - item['slots'] = slots_data + item = _build_item_data(annotation_file) + item["slots"] = slots_data return { "version": "2.0", "schema_ref": "https://darwin-public.s3.eu-west-1.amazonaws.com/darwin_json/2.0/schema.json", "item": item, - "annotations": annotations_list + "annotations": annotations_list, } -@deprecation.deprecated( - deprecated_in="0.7.8", - removed_in="0.8.0", - current_version=__version__, - details=DEPRECATION_MESSAGE, -) -def build_annotation_data(annotation: dt.Annotation) -> Dict[str, Any]: - if annotation.annotation_class.annotation_type == "complex_polygon": - return {"path": annotation.data["paths"]} - - if annotation.annotation_class.annotation_type == "polygon": - return dict( - filter(lambda item: item[0] != "bounding_box", annotation.data.items()) - ) - - return dict(annotation.data) - - -def _build_annotation_data(annotation: dt.Annotation) -> Dict[str, Any]: - if annotation.annotation_class.annotation_type == "complex_polygon": - return {"path": annotation.data["paths"]} - - if annotation.annotation_class.annotation_type == "polygon": - return dict( - filter(lambda item: item[0] != "bounding_box", annotation.data.items()) - ) - - return dict(annotation.data) - - def _build_v2_annotation_data(annotation: dt.Annotation) -> Dict[str, Any]: - annotation_data = { - "id": annotation.id, - "name": annotation.annotation_class.name - } + annotation_data = {"id": annotation.id, "name": annotation.annotation_class.name} if annotation.annotation_class.annotation_type == "bounding_box": annotation_data["bounding_box"] = _build_bounding_box_data(annotation.data) @@ -92,16 +58,19 @@ def _build_v2_annotation_data(annotation: dt.Annotation) -> Dict[str, Any]: return annotation_data + def _build_bounding_box_data(data: Dict[str, Any]) -> Dict[str, Any]: return { "h": data.get("h"), "w": data.get("w"), "x": data.get("x"), - "y": data.get("y") + "y": data.get("y"), } -def _build_polygon_data(data: Dict[str, Any]) -> Dict[str, List[List[Dict[str, float]]]]: +def _build_polygon_data( + data: Dict[str, Any] +) -> Dict[str, List[List[Dict[str, float]]]]: """ Builds the polygon data for Darwin v2 format. @@ -150,15 +119,17 @@ def _build_item_data(annotation_file: dt.AnnotationFile) -> Dict[str, Any]: "source_info": { "dataset": { "name": annotation_file.dataset_name, - "slug": annotation_file.dataset_name.lower().replace(" ", "-") if annotation_file.dataset_name else None + "slug": annotation_file.dataset_name.lower().replace(" ", "-") + if annotation_file.dataset_name + else None, }, "item_id": annotation_file.item_id or "unknown-item-id", "team": { - "name": None, # TODO Replace with actual team name - "slug": None # TODO Replace with actual team slug + "name": None, # TODO Replace with actual team name + "slug": None, # TODO Replace with actual team slug }, - "workview_url": annotation_file.workview_url - } + "workview_url": annotation_file.workview_url, + }, } @@ -184,8 +155,38 @@ def _build_slots_data(slots: List[dt.Slot]) -> List[Dict[str, Any]]: "width": slot.width, "height": slot.height, "thumbnail_url": slot.thumbnail_url, - "source_files": slot.source_files + "source_files": slot.source_files, } slots_data.append(slot_data) return slots_data + + +@deprecation.deprecated( + deprecated_in="0.7.8", + removed_in="0.8.0", + current_version=__version__, + details=DEPRECATION_MESSAGE, +) +def build_annotation_data(annotation: dt.Annotation) -> Dict[str, Any]: + if annotation.annotation_class.annotation_type == "complex_polygon": + return {"path": annotation.data["paths"]} + + if annotation.annotation_class.annotation_type == "polygon": + return dict( + filter(lambda item: item[0] != "bounding_box", annotation.data.items()) + ) + + return dict(annotation.data) + + +def _build_annotation_data(annotation: dt.Annotation) -> Dict[str, Any]: + if annotation.annotation_class.annotation_type == "complex_polygon": + return {"path": annotation.data["paths"]} + + if annotation.annotation_class.annotation_type == "polygon": + return dict( + filter(lambda item: item[0] != "bounding_box", annotation.data.items()) + ) + + return dict(annotation.data)