From c13fa0fc2bf0f98375a1f4a78116fef582e20303 Mon Sep 17 00:00:00 2001 From: "trevor.stout" Date: Mon, 16 Mar 2026 13:27:00 -0400 Subject: [PATCH 1/4] Plotting amplitude graphs, adjusted box slopes --- batbot/__init__.py | 4 +++- batbot/spectrogram/__init__.py | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/batbot/__init__.py b/batbot/__init__.py index 4ad55ce..7e30003 100644 --- a/batbot/__init__.py +++ b/batbot/__init__.py @@ -68,6 +68,7 @@ def pipeline( fast_mode=False, force_overwrite=False, quiet=False, + plot_uncompressed_amplitude=False, debug=False, ): """ @@ -107,6 +108,7 @@ def pipeline( fast_mode=fast_mode, force_overwrite=force_overwrite, quiet=quiet, + plot_uncompressed_amplitude=plot_uncompressed_amplitude, debug=debug, ) @@ -301,7 +303,7 @@ 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)) diff --git a/batbot/spectrogram/__init__.py b/batbot/spectrogram/__init__.py index 8b94716..a73ecc1 100644 --- a/batbot/spectrogram/__init__.py +++ b/batbot/spectrogram/__init__.py @@ -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] @@ -1113,10 +1113,9 @@ 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 @@ -1405,6 +1404,7 @@ def compute_wrapper( annotations=None, bitdepth=16, mask_secondary_effects=False, + plot_uncompressed_amplitude=False, debug=False, **kwargs, ): @@ -1843,12 +1843,20 @@ def compute_wrapper( datas = [ (output_paths, 'jpg', stft_db), ] + if plot_uncompressed_amplitude: + datas += [ + (output_paths, 'waveplot.jpg', waveplot), + ] else: datas = [] if 'stft_db' in segments: datas += [ (compressed_paths, 'compressed.jpg', segments['stft_db']), ] + if 'waveplot' in segments: + datas += [ + (compressed_paths, 'compressed.waveplot.jpg', segments['waveplot']), + ] # Create masked image if 'costs' in segments and 'stft_db' in segments: From 5e04bc7b8d25b71e7a27ba54e96171d41969d0bd Mon Sep 17 00:00:00 2001 From: "trevor.stout" Date: Mon, 16 Mar 2026 13:34:08 -0400 Subject: [PATCH 2/4] Linting --- batbot/__init__.py | 6 +++++- batbot/spectrogram/__init__.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/batbot/__init__.py b/batbot/__init__.py index 7e30003..9c9fe05 100644 --- a/batbot/__init__.py +++ b/batbot/__init__.py @@ -303,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, plot_uncompressed_amplitude=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)) diff --git a/batbot/spectrogram/__init__.py b/batbot/spectrogram/__init__.py index a73ecc1..4dc583e 100644 --- a/batbot/spectrogram/__init__.py +++ b/batbot/spectrogram/__init__.py @@ -1115,7 +1115,9 @@ def extract_contour_keypoints( 'slope/lo[avg].y_px/x_px': float(np.mean(der1[heel_idx:])), '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)), + 'slope/lo[box].y_px/x_px': -float( + (y_[-1] - y_[fc_idx]) / (x_[-1] - x_[fc_idx] + 1e-10) + ), } return path_, points, slopes From a450bf8f922acda17a2ef6f61abe2c2c102e7b9b Mon Sep 17 00:00:00 2001 From: Bryon Lewis Date: Mon, 16 Mar 2026 14:43:27 -0400 Subject: [PATCH 3/4] restructure waveplot output --- batbot/spectrogram/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/batbot/spectrogram/__init__.py b/batbot/spectrogram/__init__.py index 4dc583e..1545847 100644 --- a/batbot/spectrogram/__init__.py +++ b/batbot/spectrogram/__init__.py @@ -1841,13 +1841,15 @@ def compute_wrapper( compressed_paths = [] mask_paths = [] masked_paths = [] + waveplot_compressed_paths = [] + waveplot_plots = [] if not fast_mode: datas = [ (output_paths, 'jpg', stft_db), ] if plot_uncompressed_amplitude: datas += [ - (output_paths, 'waveplot.jpg', waveplot), + (waveplot_plots, 'waveplot.jpg', waveplot), ] else: datas = [] @@ -1857,7 +1859,7 @@ def compute_wrapper( ] if 'waveplot' in segments: datas += [ - (compressed_paths, 'compressed.waveplot.jpg', segments['waveplot']), + (waveplot_compressed_paths, 'compressed.waveplot.jpg', segments['waveplot']), ] # Create masked image @@ -1897,6 +1899,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, }, From c8438bceddb553d13341b745a9e15c7db1e49e21 Mon Sep 17 00:00:00 2001 From: Bryon Lewis Date: Tue, 17 Mar 2026 08:54:18 -0400 Subject: [PATCH 4/4] prevent not including uncompressed amplitude from removing uncompressed spectrogram --- batbot/spectrogram/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/batbot/spectrogram/__init__.py b/batbot/spectrogram/__init__.py index 1545847..bf51efb 100644 --- a/batbot/spectrogram/__init__.py +++ b/batbot/spectrogram/__init__.py @@ -1851,8 +1851,6 @@ def compute_wrapper( datas += [ (waveplot_plots, 'waveplot.jpg', waveplot), ] - else: - datas = [] if 'stft_db' in segments: datas += [ (compressed_paths, 'compressed.jpg', segments['stft_db']),