add_detection_buffer

ketos.neural_networks.dev_utils.detection.add_detection_buffer(detections_df, buffer)[source]

Add a buffer to each detection in the DataFrame.

Args:
detections_df: pandas DataFrame

DataFrame with detections. It should have the following columns: - ‘filename’: The name of the file containing the detection. - ‘start’: The start time of the detection in seconds. - ‘end’: The end time of the detection in seconds. - ‘score’: The score associated with the detection.

buffer: float

The buffer duration to be added to each detection in seconds.

Returns:
detections_df: pandas DataFrame

DataFrame with the detections after adding the buffer.

Example:

Given a step_size of 0.5 and a DataFrame with the following format:

filename

start

end

score

file1

1

3

0.9

file2

0

2

0.8

The function would return:

filename

start

end

score

file1

0.5

3.5

1.5

file2

0

2.5

3

>>> import pandas as pd
>>> detections_df = pd.DataFrame([
...     {'filename': 'file1', 'start': 1, 'end': 3, 'score': 0.9},
...     {'filename': 'file2', 'start': 0, 'end': 2, 'score': 0.8},
... ])
>>> buffer = 0.5
>>> add_detection_buffer(detections_df, buffer)
  filename  start  end  score
0    file1    0.5  3.5    0.9
1    file2    0.0  2.5    0.8
>>> detections_df = pd.DataFrame([
...     {'filename': 'file1', 'start': 0, 'end': 5, 'score': 1.0},
...     {'filename': 'file2', 'start': 2, 'end': 4, 'score': 0.7},
... ])
>>> buffer = 1.0
>>> add_detection_buffer(detections_df, buffer)
  filename  start  end  score
0    file1    0.0  6.0    1.0
1    file2    1.0  5.0    0.7