Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: "magic number" in vocalpy.spectral.sat should be n_fft arg #100

Closed
ralphpeterson opened this issue Jan 15, 2024 · 5 comments
Closed
Labels
BUG: a bug Something isn't working

Comments

@ralphpeterson
Copy link
Contributor

I am attempting to compute acoustic features in vocalpy on some sample data and have run into an issue using the vocalpy.spectral.sat function.

>>> import numpy as np
>>> from vocalpy.spectral import sat
>>> from vocalpy import Audio

>>> data = np.load('../some_audio.npy')

>>> audio = Audio(data, 125000)

>>> sat(audio, n_fft=512, hop_length=256)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[24], [line 1]
----> [1] sat(audio, n_fft=512, hop_length=256)

File [~\Anaconda3\envs\vocalpy\lib\site-packages\vocalpy\spectral\sat.py:98], in sat(audio, n_fft, hop_length, freq_range)
        [96] windows = librosa.util.frame(audio_pad, frame_length=n_fft, hop_length=hop_length, axis=0)
        [97] tapers = scipy.signal.windows.dpss(400, 1.5, Kmax=2)
---->   [98] windows1 = windows * tapers[0, :]
        [99] windows2 = windows * tapers[1, :]
        [101] spectra1 = np.fft.fft(windows1, n=n_fft)

ValueError: operands could not be broadcast together with shapes (138,512) (400,) 

tapers and windows shapes aren't compatible. How are the params being selected for scipy.signal.windows.dpss here, @NickleDave? It looks like the first argument is window size in the time domain, so maybe 400 is hard coded, as it is the default value of n_fft in the sat function? I confirmed that the function runs locally after changing 400 to n_fft. Not positive what the other arguments are doing. Happy to fix this if it's a bug, or even happier to be told that this is a simple user error.

@NickleDave
Copy link
Contributor

😳 This is definitely a bug! Thank you for catching it @ralphpeterson.

Yes, can you fix that hard-coded 400 in line 97 so that it's n_fft instead?

tapers = scipy.signal.windows.dpss(400, 1.5, Kmax=2)

We should also add a unit test that varies this parameter. I can add that in the PR if you make the fix.

@NickleDave NickleDave added the BUG: a bug Something isn't working label Jan 15, 2024
@NickleDave
Copy link
Contributor

@all-contributors please add @ralphpeterson for bug

Copy link
Contributor

@NickleDave

I've put up a pull request to add @ralphpeterson! 🎉

@NickleDave NickleDave changed the title computing acoustic features with vocalpy.spectral.sat BUG: "magic number" in vocalpy.spectral.sat should be n_fft arg Jan 16, 2024
@ralphpeterson
Copy link
Contributor Author

yep, will fix and submit a pull request

@NickleDave
Copy link
Contributor

NickleDave commented Jan 16, 2024

🙏 thank you

Just icymi I'm fixing a couple other things in #108 so you'll want to sync your fork.

Very very minor detail but if you don't mind giving your branch a semantically meaningful name like fix-n_fft-arg-fixes-#100, that just helps keep track of what's what.

Really appreciating your help!

edit: nevermind I lied -- I'm going to hold off on bumping the minimum version of Python until numba supports Python 3.12
#108 (comment)

Once we get your bugfix in I'll release a new patch version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG: a bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants