Skip to content

Annotation Framework Client

Akhilesh Halageri edited this page Jan 4, 2021 · 3 revisions

Using the client | Documentation

The following is adapted from FrameworkClientExamples.

Authentication and authorization:

Get an auth token from either of the following:

They both point to the same server. First one is provided for compatibilty with annotationframeworkclient.

The path prefix /<group> (/wclee in this example) is currently used for directing users to relevant resources in the backend.

In the future it will also be used to manage permissions for <group>.

For invalidating all existing tokens (for security), visit https://api.zetta.ai/auth/logout. This will discard all tokens in the system for the given user.

Initializing the client:

from annotationframeworkclient import FrameworkClient

auth_token = "<your_token>"
datastack_name = 'vnc_v0' # from https://api.zetta.ai/wclee/info/

client = FrameworkClient(
    datastack_name,
    server_address = "https://api.zetta.ai/wclee",
    auth_token = auth_token
)

print(f"The image source is: {client.info.image_source()}")
> The image source is: precomputed://gs://zetta_lee_fly_vnc_001_precomputed/vnc1_full_v3align_2/realigned_v1

Working with state (neuroglancer JSON)

example_id = 495722871693421950
example_state = client.state.get_state_json(example_id)

example_state['layers'][0]['name'] = 'renamed'
new_id = client.state.upload_state_json(example_state)

new_state = client.state.get_state_json(new_id)
print(new_state['layers'][0]['name'])
> 'renamed'

url = client.state.build_neuroglancer_url(state_id=new_id)
print(url)
> https://neuromancer-seung-import.appspot.com/?json_url=https://api.zetta.ai/wclee/nglstate/api/v1/<new_state_id>

Info Service:

Available datastacks are listed on the InfoService portal.

New datastacks can be created by admins at admin portal. Permissiongroup and Tablemapping tabs on the page are not relevant at this time.

ChunkedGraph:

sv_id = 72835911972360756
client.chunkedgraph.get_root_id(supervoxel_id=sv_id)

root_id = 648518346677614825
leaves = client.chunkedgraph.get_leaves(root_id)
print(len(leaves))
> 52863

Annotation Engine:

table_name = "test_table" # fails if already exists
client.annotation.create_table(
    table_name = table_name,
    schema_name = "microns_func_coreg",
    description = "this is a test"
)

new_data = {
    "type": "microns_func_coreg",
    "pt": { "position": [1,2,3] },
    "func_id": 0
}

client.annotation.post_annotation(table_name=table_name, data=[new_data])

The new table can be viewed at Annotation Engine portal.

EMAnnotation Schemas:

Schema portal.

example_schema = client.schema.schema_definition('microns_func_coreg')
example_schema['definitions']['FunctionalCoregistration']

This will output:

{'properties': {'func_id': {'title': 'func_id',
   'type': 'number',
   'format': 'integer',
   'description': 'functional cell ID'},
  'pt': {'type': 'object',
   '$ref': '#/definitions/BoundSpatialPoint',
   'description': 'location of cell body of functional cell'},
  'valid': {'title': 'valid',
   'type': ['boolean', 'null'],
   'default': False,
   'description': 'is this annotation valid'}},
 'required': ['func_id', 'pt'],
 'type': 'object',
 'additionalProperties': True}