table_description

ketos.data_handling.database_interface.table_description(data_shape, data_name=None, include_label=True, include_source=True, attrs=None, filename_len=100, return_data_name=False)[source]

Description of table structure for storing audio signals or spectrograms.

Args:
data_shape: tuple (ints) or numpy array or audio.base_audio.BaseAudio or list

The shape of the waveform or spectrogram to be stored in the table. If a numpy array is provided, the shape is deduced from this array. If an instance of BaseAudio is provided, the shape is deduced from the data attribute. It is also possible to specify a list of data shapes, in which case the table will have multiple data columns.

data_name: str or list(str)

Name(s) of the data columns. If None is specified, the data column is named ‘data’, or ‘data0’, ‘data1’, … if the table contains multiple data columns.

include_label: bool

Include integer label column. Default is True.

include_source: bool

If True, the name of the wav file from which the audio signal or spectrogram was generated and the placement within that file, is saved to the table. Default is True.

attrs: list()

Specify additional attributes that you want saved to the table. For each attribute, provide the name, shape, and type, in the form of a dictionary, e.g., {‘name’:’confidence’, ‘shape’:() ‘type’:’float’}

filename_len: int

Maximum allowed length of filename. Only used if include_source is True.

return_data_name: bool

Return the names of the columns used to store the data arrays.

Returns:
TableDescription: class (tables.IsDescription)

The class describing the table structure.

data_name: list(str)

The names of the columns used to store the data arrays. Only returned if return_data_name=True.

Examples:
>>> import numpy as np
>>> from ketos.data_handling.database_interface import table_description
>>> 
>>> #Create a 64 x 20 image
>>> spec = np.random.random_sample((64,20))
>>>
>>> #Create a table description for weakly labeled spectrograms of this shape
>>> descr = table_description(spec)
>>>
>>> #Inspect the table structure
>>> cols = descr.columns
>>> for key in sorted(cols.keys()):
...     print("%s: %s" % (key, cols[key]))
data: Float32Col(shape=(64, 20), dflt=0.0, pos=None)
filename: StringCol(itemsize=100, shape=(), dflt=b'', pos=None)
id: UInt32Col(shape=(), dflt=0, pos=None)
label: UInt8Col(shape=(), dflt=0, pos=None)
offset: Float64Col(shape=(), dflt=0.0, pos=None)
>>>
>>> #Create a table description for strong annotations
>>> descr_annot =  table_description_annot()
>>>
>>> #Inspect the annotation table structure
>>> cols = descr_annot.columns
>>> for key in sorted(cols.keys()):
...     print("%s: %s" % (key, cols[key]))
data_index: UInt32Col(shape=(), dflt=0, pos=None)
end: Float64Col(shape=(), dflt=0.0, pos=None)
label: UInt8Col(shape=(), dflt=0, pos=None)
start: Float64Col(shape=(), dflt=0.0, pos=None)