Skip to content

OMERO helpers

Connections

omero_annotate_ai.omero.simple_connection.SimpleOMEROConnection

SimpleOMEROConnection()

Simple OMERO connection manager with keychain support for passwords.

Initialize the connection manager.

connect

connect(host: str, username: str, password: str, group: str | None = None, secure: bool = True, verbose: bool = True, port: int | None = None) -> Any

Create OMERO connection.

Parameters:

Name Type Description Default
host str

OMERO server host, or a websocket URL (wss://server/omero-ws)

required
username str

OMERO username

required
password str

OMERO password

required
group str | None

OMERO group (optional)

None
secure bool

Keep data transfer encrypted after login (default True). False switches to plain TCP after an encrypted login, which cannot work over a websocket, so it is ignored for URL hosts.

True
verbose bool

Print connection messages (default True)

True
port int | None

OMERO server port. Ignored for URL hosts, which carry their own.

None

Returns:

Type Description
Any

The connected BlitzGateway.

Raises:

Type Description
ConnectionFailed

The server cannot be reached or the login failed.

load_config_files

load_config_files() -> dict[str, Any]

Load configuration from .env, connection history and .ezomero files.

Priority order: .env -> connection history -> .ezomero

The returned dictionary never contains a password. Passwords are only ever read from the keychain, via :meth:load_password.

Returns:

Type Description
dict[str, Any]

Dictionary with configuration parameters

save_password

save_password(host: str, username: str, password: str, expire_hours: int | None = None) -> bool

Save password to keychain with optional expiration.

Parameters:

Name Type Description Default
host str

OMERO server host

required
username str

OMERO username

required
password str

OMERO password

required
expire_hours int | None

Hours until password expires (None = never expires)

None

Returns:

Type Description
bool

True if saved successfully, False otherwise

load_password

load_password(host: str, username: str) -> str | None

Load password from keychain and check expiration.

Parameters:

Name Type Description Default
host str

OMERO server host

required
username str

OMERO username

required

Returns:

Type Description
str | None

Password if found and not expired, None otherwise

Tracking tables and configs

omero_annotate_ai.omero.omero_functions.list_annotation_tables

list_annotation_tables(conn, container_type: str, container_id: int) -> list[dict[str, Any]]

Find all tables attached to a container.

Parameters:

Name Type Description Default
conn

OMERO connection

required
container_type str

Type of container ('project', 'dataset', 'plate', 'screen')

required
container_id int

Container ID to search in

required

Returns:

Type Description
list[dict[str, Any]]

List of dictionaries with table information, sorted newest first

omero_annotate_ai.omero.omero_functions.read_tracking_table

read_tracking_table(conn, table_id: int) -> pd.DataFrame

Read a tracking table (0.5+ only) with link columns named image_id / roi_id.

omero_annotate_ai.omero.omero_functions.read_table_rows

read_table_rows(conn, table_id: int) -> list[Row]

A tracking table's rows.

Raises instead of returning quietly: a resume that cannot read its table must stop, never carry on as if the table were empty.

omero_annotate_ai.omero.omero_functions.find_annotation_config_for_table

find_annotation_config_for_table(conn, table_id: int) -> AnnotationConfig | None

The config YAML a training set keeps on OMERO, looked up by table ID.

Returns:

Type Description
AnnotationConfig | None

The AnnotationConfig, or None if the set has no config on OMERO.

Deleting a training set

omero_annotate_ai.omero.omero_functions.delete_training_set

delete_training_set(conn, table_id: int, container_type: str | None = None, container_id: int | None = None, dry_run: bool = True, force_others: bool = False) -> dict[str, Any]

Delete a tracking table and everything a run created for it.

Everything is found by ID or by the set's tag (omero-annotate-ai:<table_id>:), never by name, so another training set's objects are never touched:

  • rois: the roi_id of each row, plus ROIs on the set's images whose description carries the tag (uploads a crash left untracked).
  • labels: the label_id of each row, plus tagged label files.
  • annotation_inputs: the annotation_input_id of each row.
  • configs: the set's config YAML(s), annotation_config_table_<id>.yaml.
  • table: the tracking table FileAnnotation, deleted last.

Objects are looked up in every group the user can see and deleted in the table's group. Objects owned by another user (possible in read-write groups) are listed under others and block the deletion unless force_others is True.

Parameters:

Name Type Description Default
conn

OMERO connection

required
table_id int

Tracking table (FileAnnotation) ID

required
container_type str | None

Container to search for configs; defaults to every container the table is linked to

None
container_id int | None

Container ID that goes with container_type

None
dry_run bool

When True (default) nothing is deleted; the report says what would be.

True
force_others bool

Also delete objects owned by other users.

False

Returns:

Type Description
dict[str, Any]

Report dict with the IDs per kind, missing (IDs in the table that

dict[str, Any]

no longer exist), others (IDs owned by another user),

dict[str, Any]

containers searched, and deleted (False on a dry run).

Raises:

Type Description
PermissionError

Objects belong to another user and force_others is False (nothing is deleted).

CmdError

The server reported an error while deleting, or did not finish in time.