OverLordGoldDragon / ssqueezepy

Synchrosqueezing, wavelet transforms, and time-frequency analysis in Python
MIT License
644 stars 96 forks source link

0.6.1 - can't input `ssq_freqs` into `ssq_stft` #34

Closed ARBolton96 closed 3 years ago

ARBolton96 commented 3 years ago

Hello,

You may be aware of this, and I apologize if this is redundant or if I'm using the code improperly. I upgraded from ssqueezepy 0.6.0 to 0.6.1 today but am running into an issue with ssq_stft input parameter ssq_freqs. I am using a numpy ndarray of frequencies of interest, but in 0.6.1 I get the following error:

File "/home/user/ssqtest.py", line 90, in SSQ_Tvst, Sxo, ssq_freqs, scaleS = ssq.ssq_stft(xo, ssq_freqs=fcm, fs=10, t=time)

File "/home/user/anaconda3/envs/base/lib/python3.7/site-packages/ssqueezepy/_ssq_stft.py", line 112, in ssq_stft maprange='maximal', transform='stft')

File "/home/user/anaconda3/envs/base/lib/python3.7/site-packages/ssqueezepy/ssqueezing.py", line 204, in ssqueeze _ssqueeze(Tx, w, Wx, dWx, *args)

File "/home/user/anaconda3/envs/base/lib/python3.7/site-packages/ssqueezepy/ssqueezing.py", line 143, in _ssqueeze gamma, out=Tx, Sfs=Sfs)

File "/home/user/anaconda3/envs/base/lib/python3.7/site-packages/ssqueezepy/algos.py", line 149, in ssqueeze_fast fn(*args, **params)

TypeError: missing argument 'vmin'

I did some poking around in algos.py and to me it looks like **params has a vlmin and dvl, rather than the vmin and dv required for the _ssq_stft function. However, if I simply change the input parameter names to match (aka vmin --> vlmin and dv --> dvl), I get the same error as above with the added errors:

File "/home/user/anaconda3/envs/base/lib/python3.7/site-packages/numba/core/dispatcher.py", line 420, in _compile_for_args error_rewrite(e, 'typing')

File "/home/user/anaconda3/envs/base/lib/python3.7/site-packages/numba/core/dispatcher.py", line 361, in error_rewrite raise e.with_traceback(None)

TypingError: Cannot determine Numba type of <class 'numba.core.ir.UndefinedType'>

I wasn't sure what to do with this error. Thanks!

OverLordGoldDragon commented 3 years ago

Thanks for the report. I'm unable to reproduce the error; please include minimal code that errors.

ARBolton96 commented 3 years ago

Hello,

The below code gets the error on my machine.

import ssqueezepy as ssq import numpy as np

N = 8401 t = np.linspace(0, 10, N, endpoint=False)

xo = np.cos(2 np.pi 2 * (np.exp(t / 2.2) - 1))

fc1 = 1/80; fc2 = 1/3; df = 0.025; width = 0.07; dt = 10

iterator = np.arange(np.log10(fc1), np.log10(fc2), df) fcm = np.zeros_like(iterator)

nkfil = 0 for kfil in iterator: fc1 = 10(kfil-width) fc2 = 10(kfil+width) fcm[nkfil] = (fc2 + fc1) / 2 nkfil += 1

SSQ_Tvst, Sxo, ssq_freqs, scales = ssq.ssq_stft(xo, fs=10, t=t) # Runs

SSQ_Tvst, Sxo, ssq_freqs, scales = ssq.ssq_stft(xo, fs=dt, t=t, ssq_freqs=fcm) # Doesn't run

I noticed today that my fcm parameter seems to be causing the issue - if I replace the parameter with iterator, the ssq_stft works fine. My assumption is that this is because fcm is equally spaced in log-space, rather than linear-space. Thanks.

OverLordGoldDragon commented 3 years ago

Confirming this is expected behavior, but should error more informatively. I've never seen nor thought of a use case for logscale ssq_stft; could you describe the application? I might implement it in the future, but currently only linear ssq_freqs is supported for ssq_stft.

Note STFT will remain linear along frequencies (by definition), so you'll be reassigning a linear distribution onto an exponential.

ARBolton96 commented 3 years ago

In seismology, surface wave dispersion group velocities are often computed using frequency windows that are evenly-space in log. In all honesty though, I was completely misusing the ssq_stft - I learned that it's not applicable to the problem I was trying to force it to solve.

OverLordGoldDragon commented 3 years ago

windows that are evenly-space in log

This is exactly CWT (so use ssq_cwt).

P.S. if this is an ML task, I also recommend scattering.