Skip to content

Commit 756b680

Browse files
surygengJinghui Geng
andauthored
feat: add GlobalCaption to db/api for text annotation (#625)
* add global caption to db * remove typo * update * use saber not json * Fix annotation metadata glob to exclude globalcaption files * remove empty autogenerated migration --------- Co-authored-by: Jinghui Geng <jgeng@CZIMACOS5722.local>
1 parent e2b3512 commit 756b680

File tree

9 files changed

+53
-8
lines changed

9 files changed

+53
-8
lines changed

apiv2/db_import/importers/annotation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ def get_filters(self) -> dict[str, Any]:
106106
def get_finder_args(self) -> dict[str, Any]:
107107
return {
108108
"path": os.path.join(self.tomogram_voxel_spacing.s3_prefix, "Annotations/"),
109-
"file_glob": "*/*.json",
109+
# Use *[0-9].json to match only annotation metadata files (e.g., foo-1.0.json)
110+
# and exclude annotation data files which have a _{shape} suffix (e.g., foo-1.0_globalcaption.json)
111+
"file_glob": "*/*[0-9].json",
110112
}
111113

112114

apiv2/db_import/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,5 @@ def expected_dataset(http_prefix: str) -> dict[str, Any]:
133133
"key_photo_url": f"{http_prefix}/{DATASET_ID}/KeyPhoto/snapshot.png",
134134
"key_photo_thumbnail_url": f"{http_prefix}/{DATASET_ID}/KeyPhoto/thumbnail.png",
135135
"deposition_id": 300,
136-
"file_size": 1374849.0,
136+
"file_size": 1375370.0,
137137
}

apiv2/db_import/tests/test_db_annotation_import.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ def expected_annotations(http_prefix: str) -> list[dict[str, Any]]:
5454
def expected_annotation_files(http_prefix: str) -> list[dict[str, Any]]:
5555
path = f"{DATASET_ID}/RUN1/Reconstructions/VoxelSpacing12.300/Annotations/"
5656
return [
57+
{
58+
"tomogram_voxel_spacing_id": TOMOGRAM_VOXEL_ID1,
59+
"s3_path": f"s3://test-public-bucket/{path}100-foo-1.0_globalcaption.json",
60+
"https_path": f"{http_prefix}/{path}100-foo-1.0_globalcaption.json",
61+
"source": "community",
62+
"format": "saber",
63+
"is_visualization_default": False,
64+
"file_size": 0,
65+
},
5766
{
5867
"tomogram_voxel_spacing_id": TOMOGRAM_VOXEL_ID1,
5968
"s3_path": f"s3://test-public-bucket/{path}100-foo-1.0_instancesegmask.mrc",

apiv2/graphql_api/types/annotation_shape.py

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apiv2/schema/schema.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ enums:
285285
Mesh:
286286
text: Mesh
287287
description: A surface mesh volumes
288+
GlobalCaption:
289+
text: GlobalCaption
290+
description: A text caption for the tomogram
288291
annotation_method_link_type_enum:
289292
name: annotation_method_link_type_enum
290293
description: Describes the type of link associated to the annotation method.
@@ -925,11 +928,11 @@ classes:
925928
annotations:
926929
cascade_delete: true
927930
shape_type:
928-
description: The shape of the annotation (SegmentationMask, OrientedPoint, Point, InstanceSegmentation, Mesh, InstanceSegmentationMask)
931+
description: The shape of the annotation (SegmentationMask, OrientedPoint, Point, InstanceSegmentation, Mesh, InstanceSegmentationMask, GlobalCaption)
929932
name: shape_type
930933
from_schema: cdp-dataset-config
931934
range: annotation_file_shape_type_enum
932-
pattern: (^SegmentationMask$)|(^OrientedPoint$)|(^Point$)|(^InstanceSegmentation$)|(^Mesh$)|(^InstanceSegmentationMask$)
935+
pattern: (^SegmentationMask$)|(^OrientedPoint$)|(^Point$)|(^InstanceSegmentation$)|(^Mesh$)|(^InstanceSegmentationMask$)|(^GlobalCaption$)
933936
Annotation:
934937
name: Annotation
935938
annotations:

apiv2/support/enums.py

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apiv2/test_infra/factories/annotation_shape.py

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"captions": [
3+
{
4+
"id": 0,
5+
"text": "A caption for tomogram X."
6+
},
7+
{
8+
"id": 1,
9+
"text": "A 2nd caption for tomogram X."
10+
},
11+
{
12+
"id": 2,
13+
"text": "A 3rd caption for tomogram X."
14+
}
15+
]
16+
}

test_infra/test_files/30001/RUN1/Reconstructions/VoxelSpacing12.300/Annotations/100/foo-1.0.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
"path": "30001/RUN1/Reconstructions/VoxelSpacing12.300/Annotations/100-foo-1.0_instancesegmask.zarr",
6767
"shape": "InstanceSegmentationMask",
6868
"is_visualization_default": false
69+
},
70+
{
71+
"format": "saber",
72+
"path": "30001/RUN1/Reconstructions/VoxelSpacing12.300/Annotations/100-foo-1.0_globalcaption.json",
73+
"shape": "GlobalCaption",
74+
"is_visualization_default": false
6975
}
7076
],
7177
"method_links": [

0 commit comments

Comments
 (0)