Skip to content

Commit c13fa0f

Browse files
author
trevor.stout
committed
Plotting amplitude graphs, adjusted box slopes
1 parent c398120 commit c13fa0f

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

batbot/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def pipeline(
6868
fast_mode=False,
6969
force_overwrite=False,
7070
quiet=False,
71+
plot_uncompressed_amplitude=False,
7172
debug=False,
7273
):
7374
"""
@@ -107,6 +108,7 @@ def pipeline(
107108
fast_mode=fast_mode,
108109
force_overwrite=force_overwrite,
109110
quiet=quiet,
111+
plot_uncompressed_amplitude=plot_uncompressed_amplitude,
110112
debug=debug,
111113
)
112114

@@ -301,7 +303,7 @@ def example():
301303
output_stem = join('output', splitext(basename(wav_filepath))[0])
302304
start_time = time.time()
303305
results = pipeline(
304-
wav_filepath, out_file_stem=output_stem, fast_mode=False, force_overwrite=True
306+
wav_filepath, out_file_stem=output_stem, fast_mode=False, force_overwrite=True, plot_uncompressed_amplitude=True,
305307
)
306308
stop_time = time.time()
307309
print('Example pipeline completed in {} seconds.'.format(stop_time - start_time))

batbot/spectrogram/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def load_stft(
280280
stft_db = 10 * np.log10(abs_sq_stft / abs_sq_stft.max() + 1e-20)
281281
# Retrieve time vector in seconds corresponding to STFT
282282
time_vec = librosa.frames_to_time(
283-
range(stft_db.shape[1]), sr=sr, hop_length=hop_length, n_fft=n_fft
283+
range(stft_db.shape[1]), sr=sr, hop_length=hop_length, n_fft=win_length
284284
)
285285

286286
# Remove frequencies that we do not need [FREQ_MIN - FREQ_MAX]
@@ -1113,10 +1113,9 @@ def extract_contour_keypoints(
11131113
'slope/hi[avg].y_px/x_px': float(np.mean(der1[: knee_idx + 1])),
11141114
'slope/mid[avg].y_px/x_px': float(np.mean(der1[knee_idx : heel_idx + 1])),
11151115
'slope/lo[avg].y_px/x_px': float(np.mean(der1[heel_idx:])),
1116-
'slope[box].y_px/x_px': float(0.5 * (der1[0] + der1[-1])),
1117-
'slope/hi[box].y_px/x_px': float(0.5 * (der1[0] + der1[knee_idx])),
1118-
'slope/mid[box].y_px/x_px': float(0.5 * (der1[knee_idx] + der1[heel_idx])),
1119-
'slope/lo[box].y_px/x_px': float(0.5 * (der1[heel_idx] + der1[-1])),
1116+
'slope[box].y_px/x_px': -float((y_[-1] - y_[0]) / (x_[-1] - x_[0] + 1e-10)),
1117+
'slope/hi[box].y_px/x_px': -float((y_[fc_idx] - y_[0]) / (x_[fc_idx] - x_[0] + 1e-10)),
1118+
'slope/lo[box].y_px/x_px': -float((y_[-1] - y_[fc_idx]) / (x_[-1] - x_[fc_idx] + 1e-10)),
11201119
}
11211120

11221121
return path_, points, slopes
@@ -1405,6 +1404,7 @@ def compute_wrapper(
14051404
annotations=None,
14061405
bitdepth=16,
14071406
mask_secondary_effects=False,
1407+
plot_uncompressed_amplitude=False,
14081408
debug=False,
14091409
**kwargs,
14101410
):
@@ -1843,12 +1843,20 @@ def compute_wrapper(
18431843
datas = [
18441844
(output_paths, 'jpg', stft_db),
18451845
]
1846+
if plot_uncompressed_amplitude:
1847+
datas += [
1848+
(output_paths, 'waveplot.jpg', waveplot),
1849+
]
18461850
else:
18471851
datas = []
18481852
if 'stft_db' in segments:
18491853
datas += [
18501854
(compressed_paths, 'compressed.jpg', segments['stft_db']),
18511855
]
1856+
if 'waveplot' in segments:
1857+
datas += [
1858+
(compressed_paths, 'compressed.waveplot.jpg', segments['waveplot']),
1859+
]
18521860

18531861
# Create masked image
18541862
if 'costs' in segments and 'stft_db' in segments:

0 commit comments

Comments
 (0)