spindoctor.annotation

class Annotation(obs: ObsSnapshot, overlay: NDArray[bool], overlay_color: tuple[int, int, int], *, thicken_overlay: int = 0, text_info: AnnotationTextInfo | list[AnnotationTextInfo] | tuple[AnnotationTextInfo, ...] | None = None, avoid_mask: NDArray[bool] | None = None, config: Config | None = None)[source]

Bases: object

Represents an annotation for an observation image.

This class handles overlays and text annotations to be displayed on observation images.

Parameters:
  • obs – The observation snapshot to annotate

  • overlay – Boolean mask indicating where the overlay should appear

  • overlay_color – RGB color tuple for the overlay

  • thicken_overlay – Number of pixels to thicken the overlay by

  • text_info – Text annotation information

  • avoid_mask – Boolean mask indicating areas where text should not be placed

  • config – Configuration object

add_text_info(text_info: AnnotationTextInfo | list[AnnotationTextInfo] | tuple[AnnotationTextInfo, ...]) None[source]

Adds text annotation information to this annotation.

Parameters:

text_info – One or more text annotation information objects to add

property avoid_mask: NDArray[bool] | None

Returns the mask indicating areas where text should not be placed, if any.

property config: Config

Returns the configuration object for this annotation.

property obs: ObsSnapshot

Returns the observation snapshot associated with this annotation.

property overlay: NDArray[bool]

Returns the boolean mask representing the overlay area.

property overlay_color: tuple[int, int, int]

Returns the RGB color tuple for the overlay.

property text_info_list: list[AnnotationTextInfo]

Returns the list of text annotation information objects.

class Annotations(*, config: Config | None = None)[source]

Bases: NavBase

Manages a collection of annotation objects for an observation.

This class provides functionality to combine multiple annotations into a single overlay image and handle text placement.

add_annotations(annotations: Annotation | list[Annotation] | Annotations | None) None[source]

Adds one or more annotations to this collection.

Parameters:

annotations – The annotation(s) to add. Can be a single Annotation, a list of Annotations, another Annotations object, or None.

Raises:
  • ValueError – If an annotation is for a different observation than existing

  • annotations.

property annotations: list[Annotation]

Return the list of annotations.

combine(offset: tuple[float, float] = (0.0, 0.0), include_text: bool = True, text_use_avoid_mask: bool = True, text_avoid_other_text: bool = True, text_show_all_positions: bool = False) NDArray[integer[Any]] | None[source]

Combines all annotations into a single graphic overlay image.

Parameters:
  • offset – Optional offset (dv,du) to apply to all annotations

  • include_text – Whether to include text annotations

  • text_use_avoid_mask – Whether to use avoid masks for text placement

  • text_avoid_other_text – Whether text should avoid other text

  • text_show_all_positions – Whether to show all possible text positions

Returns:

A combined RGB array containing all annotations, or None if no annotations exist.

class AnnotationTextInfo(text: str, text_loc: list[TextLocInfo], ref_vu: tuple[int, int] | None, *, color: tuple[int, ...], font: str, font_size: int)[source]

Bases: object

__repr__() str[source]

Returns a string representation of the text annotation information.

__str__() str[source]

Returns a string representation of the text annotation information.

property color: tuple[int, ...]

Returns the RGB or RGBA color tuple for the text.

property font: str

Returns the font filename used for rendering the text.

property font_size: int

Returns the font size in points.

property ref_vu: tuple[int, int] | None

Returns the reference point (v, u) that the text is associated with.

property text: str

Returns the annotation text.

property text_loc: list[TextLocInfo]

Returns the list of possible text locations.

class TextLocInfo(label, label_v, label_u)

Bases: tuple

label

Alias for field number 0

label_u

Alias for field number 2

label_v

Alias for field number 1