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.

Vector3 = typing.Tuple[float, float, float]
Vector4 = typing.Tuple[float, float, float, float]
MAG_RE = '((\\d+-\\d+-)?\\d+)'
SEP_RE = '(\\/|\\\\)'
CUBE_RE = 'z\\d+(\\/|\\\\)y\\d+(\\/|\\\\)x\\d+\\.wkw'
ANNOTATION_WKW_PATH_RE = re.compile('((\\d+-\\d+-)?\\d+)(\\/|\\\\)(header\\.wkw|z\\d+(\\/|\\\\)y\\d+(\\/|\\\\)x\\d+\\.wkw)')
class SegmentInformation:
SegmentInformation( name: Union[str, NoneType], anchor_position: Union[webknossos.geometry.vec3_int.Vec3Int, NoneType], color: Union[Tuple[float, float, float, float], NoneType])

Method generated by attrs for class SegmentInformation.

name: Union[str, NoneType]
anchor_position: Union[webknossos.geometry.vec3_int.Vec3Int, NoneType]
color: Union[Tuple[float, float, float, float], NoneType]
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.nd_bounding_box.NDBoundingBox, NoneType] = None, user_bounding_boxes: List[webknossos.geometry.nd_bounding_box.NDBoundingBox] = 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.nd_bounding_box.NDBoundingBox, 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, _return_context: bool = False) -> Union[webknossos.annotation.annotation.Annotation, tuple[webknossos.annotation.annotation.Annotation, AbstractContextManager[NoneType]]]:
  • 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().
  • _return_context should not be set.
@classmethod
def open_as_remote_dataset( cls, annotation_id_or_url: str, annotation_type: Union[str, webknossos.annotation.annotation.AnnotationType, NoneType] = None, webknossos_url: Union[str, NoneType] = None) -> webknossos.dataset.dataset.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', 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, read_only: bool = True) -> 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.

def get_volume_layer_segments( self, volume_layer_name: Union[str, NoneType] = None, volume_layer_id: Union[int, NoneType] = None) -> Dict[int, webknossos.annotation.annotation.SegmentInformation]:

Returns a dict mapping from segment ids to SegmentInformation. The dict is mutable, changes to the returned instance are saved in the local annotation. Changes in a downloaded annotation that are done online in webknossos are not reflected automatically, the annotation needs to be re-downloaded.

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.