BaseAudioTime

class ketos.audio.base_audio.BaseAudioTime(data, time_res, filename='', offset=0, label=None, annot=None, transforms=None, transform_log=None, **kwargs)[source]

Parent class for time-series audio classes such as audio.waveform.Waveform and audio.spectrogram.Spectrogram.

Args:
data: numpy array

Data

time_res: float

Time resolution in seconds

filename: str

Filename of the original data file, if available (optional)

offset: float

Position within the original data file, in seconds measured from the start of the file. Defaults to 0 if not specified.

label: int

Spectrogram label. Optional

annot: AnnotationHandler

AnnotationHandler object. Optional

transforms: list(dict)

List of dictionaries, where each dictionary specifies the name of a transformation and its arguments, if any. For example, {“name”:”normalize”, “mean”:0.5, “std”:1.0}

Attributes:
data: numpy array

Data

ndim: int

Dimensionality of data.

time_ax: LinearAxis

Axis object for the time dimension

filename: str

Filename of the original data file, if available (optional)

offset: float

Position within the original data file, in seconds measured from the start of the file. Defaults to 0 if not specified.

label: int

Data label.

annot: AnnotationHandler or pandas DataFrame

AnnotationHandler object.

allowed_transforms: dict

Transforms that can be applied via the apply_transform method

transform_log: list

List of transforms that have been applied to this object

Methods

crop([start, end, length, make_copy])

Crop audio signal.

duration()

Data array duration in seconds

get_instance_attrs()

Get instance attributes

get_repres_attrs()

Get audio representation attributes

label_array(label)

Get an array indicating presence/absence (1/0) of the specified annotation label for each time bin.

plot([figsize, label_in_title, append_title])

Plot the data with proper axes ranges and labels.

segment(window[, step])

Divide the time axis into segments of uniform length, which may or may not be overlapping.

time_res()

Get the time resolution.

crop(start=None, end=None, length=None, make_copy=False)[source]

Crop audio signal.

Args:
start: float

Start time in seconds, measured from the left edge of spectrogram.

end: float

End time in seconds, measured from the left edge of spectrogram.

length: int

Horizontal size of the cropped image (number of pixels). If provided, the end argument is ignored.

make_copy: bool

Return a cropped copy of the spectrogra. Leaves the present instance unaffected. Default is False.

Returns:
a: BaseAudio

Cropped data array

duration()[source]

Data array duration in seconds

Returns:
: float

Duration in seconds

get_instance_attrs()[source]

Get instance attributes

get_repres_attrs()[source]

Get audio representation attributes

label_array(label)[source]

Get an array indicating presence/absence (1/0) of the specified annotation label for each time bin.

Args:
label: int

Label of interest.

Returns:
y: numpy.array

Label array

plot(figsize=(5, 4), label_in_title=True, append_title='')[source]

Plot the data with proper axes ranges and labels.

Optionally, also display annotations as boxes superimposed on the data.

Note: The resulting figure can be shown (fig.show()) or saved (fig.savefig(file_name))

Args:
figsize: tuple

Figure size

label_in_title: bool

Include label (if available) in figure title

append_title: str

Append this string to the title

Returns:
fig: matplotlib.figure.Figure

A figure object.

ax: matplotlib.axes.Axes

Axes object

segment(window, step=None)[source]

Divide the time axis into segments of uniform length, which may or may not be overlapping.

Window length and step size are converted to the nearest integer number of time steps.

If necessary, the data array will be padded with zeros at the end to ensure that all segments have an equal number of samples.

Args:
window: float

Length of each segment in seconds.

step: float

Step size in seconds.

Returns:
: list(BaseAudioTime)

Stacked data segments

time_res()[source]

Get the time resolution.

Returns:
: float

Time resolution in seconds