Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion batbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def pipeline(
fast_mode=False,
force_overwrite=False,
quiet=False,
plot_uncompressed_amplitude=False,
debug=False,
):
"""
Expand Down Expand Up @@ -107,6 +108,7 @@ def pipeline(
fast_mode=fast_mode,
force_overwrite=force_overwrite,
quiet=quiet,
plot_uncompressed_amplitude=plot_uncompressed_amplitude,
debug=debug,
)

Expand Down Expand Up @@ -301,7 +303,11 @@ def example():
output_stem = join('output', splitext(basename(wav_filepath))[0])
start_time = time.time()
results = pipeline(
wav_filepath, out_file_stem=output_stem, fast_mode=False, force_overwrite=True
wav_filepath,
out_file_stem=output_stem,
fast_mode=False,
force_overwrite=True,
plot_uncompressed_amplitude=True,
)
stop_time = time.time()
print('Example pipeline completed in {} seconds.'.format(stop_time - start_time))
Expand Down
26 changes: 19 additions & 7 deletions batbot/spectrogram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def load_stft(
stft_db = 10 * np.log10(abs_sq_stft / abs_sq_stft.max() + 1e-20)
# Retrieve time vector in seconds corresponding to STFT
time_vec = librosa.frames_to_time(
range(stft_db.shape[1]), sr=sr, hop_length=hop_length, n_fft=n_fft
range(stft_db.shape[1]), sr=sr, hop_length=hop_length, n_fft=win_length
)

# Remove frequencies that we do not need [FREQ_MIN - FREQ_MAX]
Expand Down Expand Up @@ -1113,10 +1113,11 @@ def extract_contour_keypoints(
'slope/hi[avg].y_px/x_px': float(np.mean(der1[: knee_idx + 1])),
'slope/mid[avg].y_px/x_px': float(np.mean(der1[knee_idx : heel_idx + 1])),
'slope/lo[avg].y_px/x_px': float(np.mean(der1[heel_idx:])),
'slope[box].y_px/x_px': float(0.5 * (der1[0] + der1[-1])),
'slope/hi[box].y_px/x_px': float(0.5 * (der1[0] + der1[knee_idx])),
'slope/mid[box].y_px/x_px': float(0.5 * (der1[knee_idx] + der1[heel_idx])),
'slope/lo[box].y_px/x_px': float(0.5 * (der1[heel_idx] + der1[-1])),
'slope[box].y_px/x_px': -float((y_[-1] - y_[0]) / (x_[-1] - x_[0] + 1e-10)),
'slope/hi[box].y_px/x_px': -float((y_[fc_idx] - y_[0]) / (x_[fc_idx] - x_[0] + 1e-10)),
'slope/lo[box].y_px/x_px': -float(
(y_[-1] - y_[fc_idx]) / (x_[-1] - x_[fc_idx] + 1e-10)
),
}

return path_, points, slopes
Expand Down Expand Up @@ -1405,6 +1406,7 @@ def compute_wrapper(
annotations=None,
bitdepth=16,
mask_secondary_effects=False,
plot_uncompressed_amplitude=False,
debug=False,
**kwargs,
):
Expand Down Expand Up @@ -1839,16 +1841,24 @@ def compute_wrapper(
compressed_paths = []
mask_paths = []
masked_paths = []
waveplot_compressed_paths = []
waveplot_plots = []
if not fast_mode:
datas = [
(output_paths, 'jpg', stft_db),
]
else:
datas = []
if plot_uncompressed_amplitude:
datas += [
(waveplot_plots, 'waveplot.jpg', waveplot),
]
if 'stft_db' in segments:
datas += [
(compressed_paths, 'compressed.jpg', segments['stft_db']),
]
if 'waveplot' in segments:
datas += [
(waveplot_compressed_paths, 'compressed.waveplot.jpg', segments['waveplot']),
]

# Create masked image
if 'costs' in segments and 'stft_db' in segments:
Expand Down Expand Up @@ -1887,6 +1897,8 @@ def compute_wrapper(
'spectrogram': {
'uncompressed.path': output_paths,
'compressed.path': compressed_paths,
'waveplot.path': waveplot_plots,
'waveplot.compressed.path': waveplot_compressed_paths,
'mask.path': mask_paths,
'masked.path': masked_paths,
},
Expand Down
Loading