-
Notifications
You must be signed in to change notification settings - Fork 1
/
ribbit_scoring.py
74 lines (64 loc) · 2.25 KB
/
ribbit_scoring.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 9 12:50:06 2021
@author: amandabreton
A python code used to test out Opensoundscape's RIBBIT.
You don't need to parse anything in, it's supposed to be
set to the great_plains_toad_dataset provided by Opensoundscape.
"""
# suppress warnings
import warnings
warnings.simplefilter('ignore')
# import packages
import numpy as np
from glob import glob
import pandas as pd
from matplotlib import pyplot as plt
# local imports from opensoundscape
from opensoundscape.audio import Audio
from opensoundscape.spectrogram import Spectrogram
from opensoundscape.ribbit import ribbit
from opensoundscape.helpers import run_command
# 55 set up the audio you want
audio_path = np.sort(glob('./great_plains_toad_dataset/'))[0]
# %%
# create big visuals
plt.rcParams['figure.figsize'] = [15, 8]
# using our own data: just put the audio into a folder w/ same name
# load the audio file into an OpenSoundscape Audio object
audio = Audio.from_file(audio_path)
# trim the audio to the time from 0-3 seconds for a closer look
audio = audio.trim(0, 3)
# create a Spectrogram object
spectrogram = Spectrogram.from_audio(audio)
spectrogram.plot()
# minimum and maximum rate of pulsing (pulses per second) to search for
pulse_rate_range = [10, 20]
# look for a vocalization in the range of 1000-2000 Hz
signal_band = [2000, 2500]
# subtract the amplitude signal from these frequency ranges
noise_bands = [[0, 200], [10000, 10100]]
# divides the signal into segments this many seconds long
# analyzes each independently
window_length = 2 # (seconds)
# if True, it will show the power spectrum plot for each audio segment
show_plots = True
# scoring
spec = Spectrogram.from_audio(audio.from_file(audio_path))
# run RIBBIT
scores, times = ribbit(
spec,
pulse_rate_range=pulse_rate_range,
signal_band=signal_band,
window_len=window_length,
noise_bands=noise_bands,
plot=False)
# plot the score vs time of each window
plt.scatter(times, scores)
plt.xlabel('window start time (sec)')
plt.ylabel('RIBBIT score')
plt.title('RIBBIT Scores')
print('The max score is:')
print(np.max(scores))
print('at time ' + str(np.max(times)) + ' sec')