API#

cytomine_utils._utils#

Utility functions used throughout the project.

cytomine_utils._utils.backup_annotations(project_name, backup_json)#

Retrieve annotations from project and save them to file. Right now it does not write in GeoJSON format.

Parameters:
  • project_name (str) – Name of project to retieve annotations from.

  • backup_json (Path) – Path to file to write annotations to.

Return type:

None

cytomine_utils._utils.connect()#

Use a client to connect to Cytomine

Return type:

bool

cytomine_utils._utils.delete_annotations(image_name)#

Delete all annotations of an image from Cytomine server.

Parameters:

image_name (str) – Name of image to delete annotations from.

cytomine_utils._utils.delete_image(image_name)#

Delete image from Cytomine server.

Parameters:

image_name (str | int) – Name or ID of image to delete.

cytomine_utils._utils.get_all_images()#

Retrieve all images across all projects.

Return type:

list[ImageInstance]

cytomine_utils._utils.get_annotations(project_name)#

Retrieve annotations from all images in a project.

Parameters:

project_name (str) – Name of project to retrieve annotations from.

Return type:

list[Annotation]

cytomine_utils._utils.get_annotations_from_image(image_name)#

Retrieve annotations from image.

Parameters:

image_name (str) – Name of image to retrieve annotations from.

Return type:

list[Annotation]

cytomine_utils._utils.get_client(verbosity='ERROR')#

Get a Cytomine client.

Return type:

Cytomine

Parameters:

verbosity (str)

cytomine_utils._utils.get_credentials(keys_file=None)#

Retrieve credentials from a key file.

Parameters:

keys_file (Optional[Path]) – JSON file with credential information. Default is file present in ~/.cytomine.auth.json.

Return type:

dict[str, str]

cytomine_utils._utils.get_current_user()#

Retrieve current user model.

Return type:

User

cytomine_utils._utils.get_image_by_id(id)#

Retrieve image based on its ID.

Parameters:

id (int) – ID of the image to retrieve.

Return type:

ImageInstance

cytomine_utils._utils.get_image_by_name(image_name)#

Retrieve image based on its name.

Parameters:

image_name (str) – Name of the image to retrieve.

Return type:

ImageInstance

cytomine_utils._utils.get_images_of_project(project_name, **attributes)#

Retrieve all images associated with a project.

Parameters:
  • project_name (str) – Name of project to retrieve images for.

  • attributes (dict[str, Any]) – Additional parameters are passed to ImageInstanceCollection and can be used for additional filtering.

Return type:

list[ImageInstance]

cytomine_utils._utils.get_ontologies()#

Retrieve ontologies across all projects.

Return type:

list[Ontology]

cytomine_utils._utils.get_project(name)#

Retrieve a project from a Cytomine instance based on its name.

Parameters:

name (str) – Name of project to retrieve.

Return type:

Project

cytomine_utils._utils.get_projects()#

Retrieve all projects in Cytomine instance.

Return type:

list[Project]

cytomine_utils._utils.get_storage()#

Retrieve the user storage from a Cytomine instance.

Return type:

Storage

cytomine_utils._utils.get_term_by_id(id)#

Retrieve term based on its ID.

Parameters:

id (int) – ID of the term to retrieve.

Return type:

Term

cytomine_utils._utils.get_term_by_name(term_name)#

Retrieve ontology term based on its name.

Parameters:

term_name (str) – Name of the term to retrieve.

Return type:

Term

cytomine_utils._utils.get_term_id_mapping()#

Retrieve mapping of ontology terms and their IDs. Works across all ontologies.

Return type:

dict[str, int]

cytomine_utils._utils.get_user_by_id(id)#

Retrieve user based on id.

Parameters:

id (int) – ID of user.

Return type:

User

cytomine_utils._utils.upload_annotations(geojson, project_name, image_file, dimensions)#

Upload annotations of an image to Cytomine.

Parameters:
  • geojson (dict[str, Union[str, Any]]) – Annotations to add in GeoJSON format.

  • project_name (str) – Name of project to associate annotations with (should be the project of the image)

  • image_file (str) – Image to associate annotations with.

  • dimensions (tuple[int, int]) – Shape of image.

Return type:

None

cytomine_utils._utils.upload_image(image_file, project_name, **attributes)#

Upload image to Cytomine instance..

Parameters:
  • image_file (Path) – Path to file to upload. Can be of several formats.

  • project_name (str) – Name of project to associate image with.

  • attributes (dict[str, str]) – Additional attributes to add to the image.

Return type:

None