diff --git a/batbot/__init__.py b/batbot/__init__.py index 4ad55ce..9c9fe05 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,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)) diff --git a/batbot/spectrogram/__init__.py b/batbot/spectrogram/__init__.py index 8b94716..bf51efb 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,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 @@ -1405,6 +1406,7 @@ def compute_wrapper( annotations=None, bitdepth=16, mask_secondary_effects=False, + plot_uncompressed_amplitude=False, debug=False, **kwargs, ): @@ -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: @@ -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, },