Skip to content

webknossos.annotation.annotation

Annotations can contain annotated data in two forms:

Usually, annotations should be created manually in the webKnossos interface and can be downloaded using Annotation.download(). The downloaded instance is not persisted to disk automatically, please use save() for this purpose. The general purpose file format is .zip files containing an .nml file with meta-information and the skeleton data and also containing inner .zip files for the volume layers. For skeleton-only annotations without volume layers .nml files can be used directly. Both formats are compatible with the webKnossos up- and downloads.

To prepare volume annotations in the code for correction of segmentation data in the webKnossos interface, please use add_volume_layer() with the fallback_layer argument, referencing a segmentation layer that is available on webKnossos (e.g. using the Dataset upload before). Correcting segmentations using fallback layers is much more efficient, adding volume annotation data programmatically is discouraged therefore.

#   class Annotation:
#   Annotation( name: str, skeleton: webknossos.skeleton.skeleton.Skeleton = None, dataset_name: Union[str, NoneType] = None, voxel_size: Union[Tuple[float, float, float], NoneType] = None, organization_id: Union[str, NoneType] = None, description: Union[str, NoneType] = None, owner_name: Union[str, NoneType] = None, annotation_id: Union[str, NoneType] = None, time: Union[int, NoneType] = NOTHING, edit_position: Union[Tuple[float, float, float], NoneType] = None, edit_rotation: Union[Tuple[float, float, float], NoneType] = None, zoom_level: Union[float, NoneType] = None, metadata: Dict[str, str] = NOTHING, task_bounding_box: Union[webknossos.geometry.bounding_box.BoundingBox, NoneType] = None, user_bounding_boxes: List[webknossos.geometry.bounding_box.BoundingBox] = NOTHING )

To initialize a local annotation, please provide the name argument, and either the skeleton argument, or a dataset_name and voxel_size. When supplying skeleton passing dataset_name, voxel_size, organization_id or description is not allowed as the attributes of the skeleton are used in this case.

#   name: str
#   owner_name: Union[str, NoneType]
#   annotation_id: Union[str, NoneType]
#   time: Union[int, NoneType]
#   edit_position: Union[Tuple[float, float, float], NoneType]
#   edit_rotation: Union[Tuple[float, float, float], NoneType]
#   zoom_level: Union[float, NoneType]
#   metadata: Dict[str, str]
#   task_bounding_box: Union[webknossos.geometry.bounding_box.BoundingBox, NoneType]
#   username: Union[str, NoneType]

Deprecated, use owner_name instead.

#   dataset_name: str

This attribute is a proxy for skeleton.dataset_name.

#   voxel_size: Tuple[float, float, float]

This attribute is a proxy for skeleton.voxel_size.

#   scale: Tuple[float, float, float]

Deprecated, please use voxel_size.

#   organization_id: Union[str, NoneType]

This attribute is a proxy for skeleton.organization_id.

#   description: Union[str, NoneType]

This attribute is a proxy for skeleton.description.

#  
@classmethod
def load( cls, annotation_path: Union[str, os.PathLike] ) -> webknossos.annotation.annotation.Annotation:

Loads a .nml file or a .zip file containing an NML and possibly also volume layers. Returns the Annotation object.

#  
@classmethod
def download( cls, annotation_id_or_url: str, annotation_type: Union[str, webknossos.annotation.annotation.AnnotationType, NoneType] = None, webknossos_url: Union[str, NoneType] = None, *, skip_volume_data: bool = False ) -> webknossos.annotation.annotation.Annotation:
  • annotation_id_or_url may be an annotation id or a full URL to an annotation, e.g. https://webknossos.org/annotations/6114d9410100009f0096c640
  • annotation_type is no longer required and therefore deprecated and ignored
  • webknossos_url may be supplied if an annotation id was used and allows to specifiy in which webknossos instance to search for the annotation. It defaults to the url from your current webknossos_context, using https://webknossos.org as a fallback.
  • skip_volume_data can be set to True to omit downloading annotated volume data. They can still be streamed from webKnossos using annotation.get_remote_annotation_dataset().
#   def save(self, path: Union[str, os.PathLike]) -> None:

Stores the annotation as a zip or nml at the given path.

#   def upload(self) -> str:

Uploads the annotation to your current webknossos_context.

#   def get_remote_annotation_dataset(self) -> webknossos.dataset.dataset.Dataset:

Returns a streamed dataset of the annotation as shown in webknossos, incorporating fallback layers and potentially mappings. A mapping is currently only incorporated if it is a pinned agglomerate mapping. After an agglomerate mapping was activated in webKnossos, it is pinned as soon as the first volume editing action is done. Note that this behavior might change in the future.

#   def get_remote_base_dataset( self, sharing_token: Union[str, NoneType] = None, webknossos_url: Union[str, NoneType] = None ) -> webknossos.dataset.dataset.RemoteDataset:
#   def get_volume_layer_names(self) -> Iterable[str]:
#   def add_volume_layer( self, name: str, fallback_layer: Union[webknossos.dataset.layer.Layer, str, NoneType] = None, volume_layer_id: Union[int, NoneType] = None ) -> None:

Adds a volume layer to the annotation, without manual annotations but possibly referring to segmentation data using the fallback_layer. To prepare volume annotations in the code for correction of segmentation data in the webKnossos interface, please use the fallback_layer argument, referencing a segmentation layer that is available on webKnossos (e.g. using the Dataset upload before). Correcting segmentations using fallback layers is much more efficient, adding volume annotation data programmatically is discouraged therefore.

#   def delete_volume_layer( self, volume_layer_name: Union[str, NoneType] = None, volume_layer_id: Union[int, NoneType] = None ) -> None:
#   def export_volume_layer_to_dataset( self, dataset: webknossos.dataset.dataset.Dataset, layer_name: str = 'volume_layer', largest_segment_id: Union[int, NoneType] = None, volume_layer_name: Union[str, NoneType] = None, volume_layer_id: Union[int, NoneType] = None ) -> webknossos.dataset.layer.SegmentationLayer:

Given a dataset, this method will export the specified volume annotation of this annotation into that dataset by creating a new layer. The largest_segment_id is computed automatically, unless provided explicitly.

volume_layer_name or volume_layer_id has to be provided, if the annotation contains multiple volume layers. Use get_volume_layer_names() to look up available layers.

#  
@contextmanager
def temporary_volume_layer_copy( self, volume_layer_name: Union[str, NoneType] = None, volume_layer_id: Union[int, NoneType] = None ) -> Iterator[webknossos.dataset.layer.SegmentationLayer]:

Given a volume annotation path, create a temporary dataset which contains the volume annotation. Returns the corresponding Layer.

volume_layer_name or volume_layer_id has to be provided, if the annotation contains multiple volume layers.

#   class AnnotationType(enum.Enum):

Annotations can be of different types which has to be specified when using Annotation.download() with an annotation id.

#   EXPLORATIONAL = <AnnotationType.EXPLORATIONAL: 'Explorational'>

Explorational annotations are all annotations created without the task system, e.g. by uploading an annotation or using the "Create Annotation" Button in the dataset view in webknossos.

#   TASK = <AnnotationType.TASK: 'Task'>

The Task type is automatically assigned to all annotations that are instances of a task. See also Task.

Inherited Members
enum.Enum
name
value
#   class AnnotationState(enum.Enum):

This Enum contains the state of annotations belonging to tasks. Can be retrieved via Task instances, getting AnnotationInfo from task.get_annotation_infos().

#   FINISHED = <AnnotationState.FINISHED: 'Finished'>
#   ACTIVE = <AnnotationState.ACTIVE: 'Active'>
#   CANCELLED = <AnnotationState.CANCELLED: 'Cancelled'>
#   INITIALIZING = <AnnotationState.INITIALIZING: 'Initializing'>
Inherited Members
enum.Enum
name
value
#   def open_annotation( annotation_path: Union[str, os.PathLike] ) -> webknossos.annotation.annotation.Annotation:

Deprecated.

Back to top