filter_by_label

ketos.data_handling.database_interface.filter_by_label(table, label)[source]

Find all audio objects in the table with the specified label.

Args:
table: tables.Table

The table containing the annotations

label: int or list of ints

The labels to be searched

Raises:

TypeError: if label is not an int or list of ints.

Returns:
indices: list(int)

Indices of the audio objects with the specified label(s). If there are no objects that match the label, returs an empty list.

Examples:
>>> from ketos.data_handling.database_interface import open_file, open_table
>>>
>>> # Open a database and an existing table
>>> h5file = open_file("ketos/tests/assets/11x_same_spec.h5", 'r')
>>> table = open_table(h5file, "/group_1/table_annot")
>>>
>>> # Retrieve the indices for all spectrograms that contain the label 1
>>> # (all spectrograms in this table)
>>> filter_by_label(table, 2)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>>
>>> # Since none of the spectrograms in the table include the label 4, 
>>> # an empty list is returned
>>> filter_by_label(table, 4)
[]
>>> h5file.close()