CAVEconnectome / CAVEclient

This is the python client for accessing REST APIs within the Connectome Annotation Versioning Engine.
https://caveconnectome.github.io/CAVEclient/
MIT License
19 stars 12 forks source link

StagedAnnotations #74

Closed ceesem closed 2 years ago

ceesem commented 2 years ago

Adds a StagedAnnotation class that can be spawned from tables or schema names via client.annotation.stage_annotations("my_table_name"). This class helps produce, validate, and upload annotations.

Annotations are staged by using the add function to add to the class.

stage = client.annotation.stage_annotations("my_table_name")
stage.add(field1=1, field2=2)

Each annotation is validated via JSONschema on adding.

If the annotations to be staged are updates instead of new annotations, the update=True flag can be set:

update_stage = client.annotation.stage_annotations("my_table_name")
update_stage.add(id=100, field1=1, field2=2)

This adds an id field that is required to be an int. Adding an id field to new annotations can be accomplished by setting id_field=True when creating the stage object.

After staging annotations based on a table name, they can be uploaded with:

client.annotation.upload_staged_annotations(stage)

which uses the table name and update Boolean to determine where to send the annotations and whether to use post_annotations or update_annotations.

Staged annotations can be seen with stage.annotation_list or stage.annotation_dataframe.

Additionally, spatial point resolution can be specified on both the table (retrieved automatically) and annotation addition side of things, to avoid having to double check potential mismatches.

Tests on the annotation client are also included which effectively cover posting and updating annotations as well as getting table metadata.