specshow: warn when frequency axis seems implausible
See original GitHub issueDescribe the bug
librosa.display.specshow
malfunctions for y_axis=cqt_hz
. If I double the number of CQT bins in the example at librosa.display.specshow, then the y axis blows up to incorrect Hz values. If I triple it then they blow up to infinity
Reproducible example
import matplotlib.pyplot as plt
y, sr = librosa.load(librosa.util.example_audio_file())
plt.figure(figsize=(12, 8))
# Calculate CQT with twice the default frequency resolution
resolution = 2
CQT = librosa.cqt(y, sr=sr, n_bins=84*resolution, bins_per_octave=12*resolution)
CQT = librosa.amplitude_to_db(np.abs(CQT), ref=np.max)
# CQT note as y axis
plt.subplot(4, 2, 3)
librosa.display.specshow(CQT, y_axis='cqt_note')
plt.colorbar(format='%+2.0f dB')
plt.title('Constant-Q power spectrogram (note)')
# CQT Hz as y axis
plt.subplot(4, 2, 4)
librosa.display.specshow(CQT, y_axis='cqt_hz')
plt.colorbar(format='%+2.0f dB')
plt.title('Constant-Q power spectrogram (Hz)')
Outputs:
-
resolution = 1 (the example in the docs)
-
resolution = 2
-
resolution = 3
/usr/local/Caskroom/miniconda/base/envs/myproject/lib/python3.6/site-packages/librosa/core/time_frequency.py in midi_to_note(midi, octave, cents)
601 'G#', 'A', 'A#', 'B']
602
--> 603 note_num = int(np.round(midi))
604 note_cents = int(100 * np.around(midi - note_num, 2))
605
OverflowError: cannot convert float infinity to integer
Software versions
Darwin-19.4.0-x86_64-i386-64bit
Python 3.7.7 (default, Mar 10 2020, 15:43:33)
[Clang 11.0.0 (clang-1100.0.33.17)]
NumPy 1.18.4
SciPy 1.4.1
librosa 0.7.2
INSTALLED VERSIONS
------------------
python: 3.7.7 (default, Mar 10 2020, 15:43:33)
[Clang 11.0.0 (clang-1100.0.33.17)]
librosa: 0.7.2
audioread: 2.1.8
numpy: 1.18.4
scipy: 1.4.1
sklearn: 0.23.1
joblib: 0.15.1
decorator: 4.4.2
six: 1.15.0
soundfile: 0.10.3
resampy: 0.2.2
numba: 0.49.1
numpydoc: None
sphinx: None
sphinx_rtd_theme: None
sphinxcontrib.versioning: None
sphinx-gallery: None
pytest: 5.4.2
pytest-mpl: None
pytest-cov: None
matplotlib: 3.2.1
presets: None
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
librosa.display.specshow — librosa 0.10.0.dev0 documentation
Display a spectrogram/chromagram/cqt/etc. ... Range for the x- and y-axes. Valid types are: ... Frequency types: ... All frequency types are plotted in...
Read more >Scaling y-axis in Librosa spectrogram - Stack Overflow
UserWarning: Frequency axis exceeds Nyquist. Did you remember to set all spectrogram parameters in specshow? and only shows a y-shifted plot ...
Read more >gEG - River Thames Conditions
... Rohit nagpal axis bank, Fluke 773 price, Kost-kostan bebas di bandung, ... Rouge vif d'etampes translation, Alert notification ios, Rosso come il...
Read more >THE SAME SPECS, HOW COME THE PL -400 SOUNDS ...
cal changes in their frequency response ... tals seem to suffer very little in the transfer ... under the left on -axis speaker...
Read more >D-Wave: Truth finally starts to emerge - Shtetl-Optimized
since the discussion seems to have reached a point where not much ... 3-axis control, a problem that they did solve; in D-Wave's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure, I think that + a warning if the frequency range exceeds Nyquist would be easy and improve usability.
We’re not going to classes; Gael Varoquaux’s scipy 2017 keynote lays out many good arguments for why (and is full of good advice overall).
I didn’t notice until now that the function uses a sampling rate - I agree with nyquist.
It could be useful… but I agree with you about making the API as straightforward as possible, or the existing docs. Here for example, a simple note in the documentation for librosa.display.specshow would have helped. Something like:
I was actually thinking a solution could be to use classes. E.g.
But this would be a major API overhaul which would be quite a bit of work and may be frustrating for existing users. I’ve also only just started using librosa so I don’t want to crash the party and request a complete do-over haha