Skip to content

Commit f271eb7

Browse files
authored
Merge pull request #39 from Kitware/tas/update-metadata
Plotting amplitude graphs, adjusted box slopes
2 parents c398120 + 5fd3093 commit f271eb7

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

batbot/__init__.py

Lines changed: 7 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,11 @@ 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,
307+
out_file_stem=output_stem,
308+
fast_mode=False,
309+
force_overwrite=True,
310+
plot_uncompressed_amplitude=True,
305311
)
306312
stop_time = time.time()
307313
print('Example pipeline completed in {} seconds.'.format(stop_time - start_time))

batbot/spectrogram/__init__.py

Lines changed: 19 additions & 7 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,11 @@ 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(
1119+
(y_[-1] - y_[fc_idx]) / (x_[-1] - x_[fc_idx] + 1e-10)
1120+
),
11201121
}
11211122

11221123
return path_, points, slopes
@@ -1405,6 +1406,7 @@ def compute_wrapper(
14051406
annotations=None,
14061407
bitdepth=16,
14071408
mask_secondary_effects=False,
1409+
plot_uncompressed_amplitude=False,
14081410
debug=False,
14091411
**kwargs,
14101412
):
@@ -1839,16 +1841,24 @@ def compute_wrapper(
18391841
compressed_paths = []
18401842
mask_paths = []
18411843
masked_paths = []
1844+
waveplot_compressed_paths = []
1845+
waveplot_plots = []
18421846
if not fast_mode:
18431847
datas = [
18441848
(output_paths, 'jpg', stft_db),
18451849
]
1846-
else:
1847-
datas = []
1850+
if plot_uncompressed_amplitude:
1851+
datas += [
1852+
(waveplot_plots, 'waveplot.jpg', waveplot),
1853+
]
18481854
if 'stft_db' in segments:
18491855
datas += [
18501856
(compressed_paths, 'compressed.jpg', segments['stft_db']),
18511857
]
1858+
if 'waveplot' in segments:
1859+
datas += [
1860+
(waveplot_compressed_paths, 'compressed.waveplot.jpg', segments['waveplot']),
1861+
]
18521862

18531863
# Create masked image
18541864
if 'costs' in segments and 'stft_db' in segments:
@@ -1887,6 +1897,8 @@ def compute_wrapper(
18871897
'spectrogram': {
18881898
'uncompressed.path': output_paths,
18891899
'compressed.path': compressed_paths,
1900+
'waveplot.path': waveplot_plots,
1901+
'waveplot.compressed.path': waveplot_compressed_paths,
18901902
'mask.path': mask_paths,
18911903
'masked.path': masked_paths,
18921904
},

0 commit comments

Comments
 (0)