time_shift

ketos.data_handling.selection_table.time_shift(annot, time_ref, length, step, min_overlap)[source]

Create multiple instances of the same selection by stepping in time, both forward and backward.

The time-shifted instances are returned in a pandas DataFrame with the same columns as the input annotation, plus a column named ‘start_new’ containing the start times of the shifted instances.

Args:
annot: pandas Series or dict

Reference annotation. Must contain the labels/keys ‘start’ and ‘end’.

time_ref: float

Reference time used as starting point for the stepping.

length: float

Output annotation length in seconds.

step: float

Produce multiple instances of the same selection by shifting the annotation window in steps of length step (in seconds) both forward and backward in time. The default value is 0.

min_overlap: float

Minimum required overlap between the selection intervals and the original annotation, expressed as a fraction of whichever is smaller, the annotation duration or the selection length.

Results:
df: pandas DataFrame

Output annotation table. The start times of the time-shifted annotations are stored in the column ‘start_new’.

Example:
>>> import pandas as pd
>>> from ketos.data_handling.selection_table import time_shift
>>> 
>>> #Create a single 2-s long annotation
>>> annot = {'filename':'file1.wav', 'label':1, 'start':12.0, 'end':14.0}
>>>
>>> #Step across this annotation with a step size of 0.2 s, creating 1-s long annotations that 
>>> #overlap by at least 50% with the original 2-s annotation 
>>> df = time_shift(annot, time_ref=13.0, length=1.0, step=0.2, min_overlap=0.5)
>>> print(df.round(2))
    filename  label  start   end  start_new
0  file1.wav      1   12.0  14.0       11.6
1  file1.wav      1   12.0  14.0       11.8
2  file1.wav      1   12.0  14.0       12.0
3  file1.wav      1   12.0  14.0       12.2
4  file1.wav      1   12.0  14.0       12.4
5  file1.wav      1   12.0  14.0       12.6
6  file1.wav      1   12.0  14.0       12.8
7  file1.wav      1   12.0  14.0       13.0
8  file1.wav      1   12.0  14.0       13.2
9  file1.wav      1   12.0  14.0       13.4