visiannot.visiannot.components.AnnotEventWidget

Summary

Module defining AnnotEventWidget

Classes

visiannot.visiannot.components.AnnotEventWidget.AnnotEventWidget(…)

Widget for events annotation

API

Class AnnotEventWidget

class visiannot.visiannot.components.AnnotEventWidget.AnnotEventWidget(visi, widget_position, label_dict, annot_dir, flag_annot_overlap=False, **kwargs)[source]

Bases: object

Widget for events annotation

Parameters
  • visi – associated instance of ViSiAnnoT

  • widget_position (tuple or list) – position of the widget in the layout of the associated instance of ViSiAnnoT

  • label_dict (dict) – key is the label, value is the associated color (RGB or RGBA) ; in case RGB color is provided, then a transparency value of 80 is automatically added

  • annot_dir (str) – directory where the annotations are saved

  • flag_annot_overlap (bool) – specify if overlap of events annotations is enabled

  • kwargs – keyword arguments of create_widget()

Annotation management:

add(visi)

Adds an annotation to the current label

call_push_button(button_id, visi)

Callback method for managing annotation with push buttons

call_radio(ev, visi)

Callback method for changing label

change_label(visi, new_label)

Changes label and loads corresponding annotation file

check_overlap(annot_path, annot_datetime_0, …)

create_annot_duration(visi)

Creates annotation events files for the duration of each file of the reference modality (only one file if not a long recording)

delete(visi, annot_id)

Deletes a specific annotation for the current label

delete_clicked(visi, position)

Deletes an annotion that is clicked on

get_annot_id_from_position(visi, position)

Looks for the index of the annotation at the given frame for the current label

get_path(label)

Gets path to the annotation file corresponding to the input label

reset_timestamp()

Resets the timestamps of the current unsaved annotation for the current label

set_timestamp(visi, frame_id, annot_position)

Sets the start or end timestamp of the current unsaved annotation for the current label

Display management:

add_region(visi, bound_1, bound_2, **kwargs)

Displays a region in the progress bar and the signal widgets

clear_regions(visi)

Clears the display of annotations for all labels (but does not delete the annotations)

clear_regions_single_label(visi, label_id)

Clears the display of annotations for a specific label

display(visi)

Mananges the display of annotations (on/off)

plot_regions(visi)

Plots events annotations, depending on the display mode selected with button_group_radio_disp

Annotation description:

clear_descriptions(visi)

Clears the display of all the annotations descriptions

description(visi, ev, pos_frame, pos_ms)

Creates and displays text items in signal widgets with the description of the annotation that has been clicked on

Widget creation:

create_widget(lay, widget_position[, nb_table])

Creates a widget with the events annotation tool and adds it to the layout of the associated instance of ViSiAnnoT

Attributes:

empty_annotation

(str) Text for empty annotation timestamp next to push buttons “Start” and “Stop”

timestamp_format

(str) Datetime string format of the annotations timestamps

annot_dir

(str) Directory where the annotations are saved

flag_annot_overlap

(bool) Specify if overlap of events annotations is enabled

file_name_base

(str) Base name of the annotation files (to which is appended the label)

protected_label

(str) Label automatically created for getting duration of video files (or first signal if no video)

label_list

(list) Labels of the events annotation

color_list

(list) Colors of the events annotation labels

annot_array

(numpy array) Array with unsaved annotated event

description_dict

(dict) Events annotations descriptions to be displayed

path

(list) Path to the annotation file of the currently selected label

current_label_id

(int) Index of the currently selected label, with respect to the list label_list

button_group_radio_label

(QtWidgets.QButtonGroup) Set of radio buttons for selecting a label

button_group_radio_disp

(QtWidgets.QButtonGroup) Set of radio buttons for selecting a display option

button_group_check_custom

(QtWidgets.QButtonGroup) Set of check boxes for custom display

button_group_push

(QtWidgets.QButtonGroup) Set of push buttons for annotation (Sart, Stop, Add, Delete last, Display)

push_text_list

(list) Instances of QtWidgets.QLabel containing the text next to the push buttons grouped in button_group_push

region_dict

(dict) Lists of region items (pyqtgraph.LinearRegionItem) for the display of events annotations

add(visi)[source]

Adds an annotation to the current label

It sets the attribute path.

If the annotation start timestamp or end timestamp is not defined, then nothing happens.

Parameters

visi – associated instance of ViSiAnnoT

add_region(visi, bound_1, bound_2, **kwargs)[source]

Displays a region in the progress bar and the signal widgets

It converts the bounds to frame numbers and then calls the method ViSiAnnoT.add_region_to_widgets().

Parameters
call_push_button(button_id, visi)[source]

Callback method for managing annotation with push buttons

Connected to the signal buttonClicked[int] of the attribute attr:.button_group_push.

There are 5 buttons and they have an effect on the unsaved current annotation of the current label:

  • button_id == 0: set start timestamp at the current frame ViSiAnnoT.frame_id

  • button_id == 1: set ending datetime with the current frame :attr;`.ViSiAnnoT.frame_id`

  • button_id == 2: add annotation defined by the current timestamps

  • button_id == 3: delete last annotation

  • button_id == 4: on/off display

Parameters
  • button_id (int) – index of the button that has been pushed

  • visi – associated instance of ViSiAnnoT

call_radio(ev, visi)[source]

Callback method for changing label

Connected to the signal buttonClicked of button_group_radio_label.

Parameters
  • visi – associated instance of ViSiAnnoT

  • ev (QtWidgets.QRadioButton) – radio button that has been clicked

change_label(visi, new_label)[source]

Changes label and loads corresponding annotation file

It sets the value of the following attributes:

It also manages the display of the annotations.

Parameters
  • visi – associated instance of ViSiAnnoT

  • new_label (str) – new annotation label

check_overlap(annot_path, annot_datetime_0, annot_datetime_1, **kwargs)[source]
clear_descriptions(visi)[source]

Clears the display of all the annotations descriptions

Parameters

visi – associated instance of ViSiAnnoT

clear_regions(visi)[source]

Clears the display of annotations for all labels (but does not delete the annotations)

Parameters

visi – associated instance of ViSiAnnoT

clear_regions_single_label(visi, label_id)[source]

Clears the display of annotations for a specific label

Parameters
  • visi – associated instance of ViSiAnnoT

  • label_id (int) – index of the label in the list ViSiAnnoT.annotevent_label_list

create_annot_duration(visi)[source]

Creates annotation events files for the duration of each file of the reference modality (only one file if not a long recording)

Parameters

visi – associated instance of ViSiAnnoT

create_widget(lay, widget_position, nb_table=5)[source]

Creates a widget with the events annotation tool and adds it to the layout of the associated instance of ViSiAnnoT

Make sure the attribute label_list is defined before calling this method.

It sets the following attributes:

Parameters
  • lay (QtWidgets.QGridLayout) – layout of the associated instance of ViSiAnnoT

  • widget_position (list or tuple) – position of the widget in the layout, length 2 (row, col) or 4 (row, col, rowspan, colspan)

  • nb_table (int) – maximum number of radio buttons (resp. check boxes) in button_group_radio_label (resp. button_group_check_custom) on a row

delete(visi, annot_id)[source]

Deletes a specific annotation for the current label

Parameters
  • visi – associated instance of ViSiAnnoT

  • annot_id (int) – index of the annotation to delete

delete_clicked(visi, position)[source]

Deletes an annotion that is clicked on

Parameters
  • visi – associated instance of ViSiAnnoT

  • position (int) – frame number (sampled at the reference frequency ViSiAnnoT.fps) corresponding to the mouse position on the X axis of the signal widgets

description(visi, ev, pos_frame, pos_ms)[source]

Creates and displays text items in signal widgets with the description of the annotation that has been clicked on

Parameters
  • visi – associated instance of ViSiAnnoT

  • ev (QtWidgets.QRadioButton) – radio button that has been clicked

  • pos_frame (int) – frame number (sampled at the reference frequency ViSiAnnoT.fps) corresponding to the mouse position on the X axis of the signal widget

  • pos_ms (float) – mouse position on the X axis of the signal widget in milliseconds

display(visi)[source]

Mananges the display of annotations (on/off)

Parameters

visi – associated instance of ViSiAnnoT

get_annot_id_from_position(visi, position)[source]

Looks for the index of the annotation at the given frame for the current label

Parameters
  • visi – associated instance of ViSiAnnoT

  • position (int) – frame number (sampled at the reference frequency ViSiAnnoT.fps)

Returns

index of the annotation (i.e. line number in the annotation file), returns -1 if no annotation at position

Return type

int

get_path(label)[source]

Gets path to the annotation file corresponding to the input label

Parameters

label (str) – events annotation label

Returns

path

Return type

str

plot_regions(visi)[source]

Plots events annotations, depending on the display mode selected with button_group_radio_disp

Make sure that the attribute region_dict is already created.

It checks if the display mode is on before plotting.

Connected to the signal buttonClicked of button_group_radio_disp and button_group_check_custom.

Parameters

visi – associated instance of ViSiAnnoT

reset_timestamp()[source]

Resets the timestamps of the current unsaved annotation for the current label

It sets self.annot_array[self.current_label_id] to zeros.

set_timestamp(visi, frame_id, annot_position)[source]

Sets the start or end timestamp of the current unsaved annotation for the current label

It sets the values of self.annot_array[self.current_label_id, annot_position].

Parameters
  • visi – associated instance of ViSiAnnoT

  • frame_id (int) – frame number of the timestamp (sampled at the reference frequency ViSiAnnoT.fps)

  • annot_position (int) – specify if start timestamp (0) or end timestamp (1)

annot_array

(numpy array) Array with unsaved annotated event

Shape (n_{label}, 2), where n_{label} is the length of label_list. Each row corresponds to a label and is composed of the beginning datetime and ending datetime of the current annotation not saved yet.

annot_dir

(str) Directory where the annotations are saved

button_group_check_custom

(QtWidgets.QButtonGroup) Set of check boxes for custom display

button_group_push

(QtWidgets.QButtonGroup) Set of push buttons for annotation (Sart, Stop, Add, Delete last, Display)

button_group_radio_disp

(QtWidgets.QButtonGroup) Set of radio buttons for selecting a display option

button_group_radio_label

(QtWidgets.QButtonGroup) Set of radio buttons for selecting a label

color_list

(list) Colors of the events annotation labels

each element is a list of length 4 with the RGBA color

current_label_id

(int) Index of the currently selected label, with respect to the list label_list

description_dict

(dict) Events annotations descriptions to be displayed

Key is the index of a label in label_list. Value is a dictionary:

  • Key is an integer with the annotation ID (index in the annotation file)

  • Value is a list of instances of pyqtgraph.TextItem with the description, same length and order as ViSiAnnoT.wid_sig_list, so that one element corresponds to one signal widget

empty_annotation

(str) Text for empty annotation timestamp next to push buttons “Start” and “Stop”

file_name_base

(str) Base name of the annotation files (to which is appended the label)

It is defined as the basename of the annotation directory annot_dir.

flag_annot_overlap

(bool) Specify if overlap of events annotations is enabled

label_list

(list) Labels of the events annotation

path

(list) Path to the annotation file of the currently selected label

protected_label

(str) Label automatically created for getting duration of video files (or first signal if no video)

It cannot be used for manual annotation, so it is ignored if specified by the user in the keyword argument annotevent_dict of ViSiAnnoT constructor.

push_text_list

(list) Instances of QtWidgets.QLabel containing the text next to the push buttons grouped in button_group_push

region_dict

(dict) Lists of region items (pyqtgraph.LinearRegionItem) for the display of events annotations

Key is a label index. Value is a list of lists, each sublist corresponds to one annotation and contains n_{wid} + 1 region items, where n_{wid} is the length of ViSiAnnoT.wid_sig_list (number of signal widgets), the additional region item is for the progress bar (ViSiAnnoT.wid_progress).

For example, for 3 signal widgets and for a given label with 2 annotations, the value of the dictionary would be:

[
    [
        annot1_widProgress, annot1_wid1, annot1_wid2,
        annot1_wid3
    ],
    [
        annot2_widProgress, annot2_wid1, annot2_wid2,
        annot2_wid3
    ]
]
timestamp_format

(str) Datetime string format of the annotations timestamps