Skip to content

[WIP] add get_segments_for_agglomerate to RemoteAnnotation #1351

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions webknossos/webknossos/annotation/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@ def _set_annotation_info(
modified=annotation_info.modified,
data_store=annotation_info.data_store,
tracing_time=annotation_info.tracing_time,
annotation_layers=None,
),
)

Expand All @@ -1528,6 +1529,36 @@ def save(self, path: str | PathLike) -> None:
"Remote annotations cannot be saved. Changes are applied ."
)

def get_segments_for_agglomerate(self, agglomerate_id: int) -> list[int] | None:
"""Get the segment ids for a given agglomerate id.

Args:
agglomerate_id (int): The agglomerate id.

Returns:
List[int] | None: The segment ids if the agglomerate was edited, None otherwise.
"""
from ..client.context import _get_context

context = _get_context()
annotation_info = self._get_annotation_info()
assert annotation_info.annotation_layers is not None, "Annotation has no layers"
tracingstore_client = context.get_tracingstore_api_client()
volume_layer = [
layer
for layer in annotation_info.annotation_layers
if layer.typ == "Volume"
]
assert len(volume_layer) == 1, "Expected exactly one volume layer"
segment_list_result = tracingstore_client.get_segments_for_agglomerate(
volume_layer[0].tracing_id, agglomerate_id
)
segment_list = segment_list_result.segmentIds
if segment_list_result.agglomerateIdIsPresent:
return segment_list
else:
return None

def download_mesh(
self,
segment_id: int,
Expand Down
14 changes: 14 additions & 0 deletions webknossos/webknossos/client/api_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,19 @@ class ApiProjectCreate:
owner: str | None = None


@attr.s(auto_attribs=True)
class ApiAnnotationLayer:
tracing_id: str
typ: str
name: str


@attr.s(auto_attribs=True)
class ApiEditableMappingSegmentListResult:
segmentIds: list[int]
agglomerateIdIsPresent: bool


@attr.s(auto_attribs=True)
class ApiAnnotation:
id: str
Expand All @@ -366,6 +379,7 @@ class ApiAnnotation:
description: str
state: str
modified: int
annotation_layers: list[ApiAnnotationLayer] | None
data_store: ApiDataStore | None = None
tracing_time: int | None = None # millis

Expand Down
11 changes: 11 additions & 0 deletions webknossos/webknossos/client/api_client/tracingstore_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from webknossos.client.api_client.models import (
ApiAdHocMeshInfo,
ApiEditableMappingSegmentListResult,
ApiPrecomputedMeshInfo,
)

Expand All @@ -26,6 +27,16 @@ def __init__(
def url_prefix(self) -> str:
return f"{self.base_url}/tracings"

def get_segments_for_agglomerate(
self, tracing_id: str, agglomerate_id: int
) -> ApiEditableMappingSegmentListResult:
route = f"/mapping/{tracing_id}/segmentsForAgglomerate"
query: Query = {"agglomerateId": agglomerate_id}

return self._get_json(
route, query=query, response_type=ApiEditableMappingSegmentListResult
)

def annotation_download_mesh(
self,
mesh: ApiPrecomputedMeshInfo | ApiAdHocMeshInfo,
Expand Down
Loading