-
Notifications
You must be signed in to change notification settings - Fork 97
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
Auto-scales failure with short inputs, default configs #90
Comments
Thanks for the report, you've reproduced an edge case with short inputs. Until it's fixed, try one of: 1) higher |
Thank you for the response and the suggestions. It does work with longer data indeed. In this case, setting a higher nv parameter or the scales='log' still gives errors. Adding them here for convenience:
---> 80 icwt(cwt, wavelet=wavelet, nv=40) File /opt/conda/envs/gst/lib/python3.8/site-packages/ssqueezepy/_cwt.py:380, in icwt(Wx, wavelet, scales, nv, one_int, x_len, x_mean, padtype, rpadded, l1_norm) AssertionError: 276 != 222
File /opt/conda/envs/gst/lib/python3.8/site-packages/ssqueezepy/_cwt.py:380, in icwt(Wx, wavelet, scales, nv, one_int, x_len, x_mean, padtype, rpadded, l1_norm) AssertionError: 168 != 222 Please, let me know if I'm missing something. Again, great library :) |
Right, I meant in |
Description
Hi. Thanks for the library, is being really handy!
I found a way to crash the icwt function in the current version - 0.6.3
Provided are the time series and code required to reproduce the issue
data
Error message:
ValueError Traceback (most recent call last)
Input In [2], in <cell line: 80>()
76 wavelet = 'morlet'
78 _, cwt, _, scales = ssq_cwt(data, wavelet=wavelet)
---> 80 icwt(cwt, wavelet=wavelet, scales=scales)
File /opt/conda/envs/gst/lib/python3.8/site-packages/ssqueezepy/_cwt.py:391, in icwt(Wx, wavelet, scales, nv, one_int, x_len, x_mean, padtype, rpadded, l1_norm)
389 idx = logscale_transition_idx(scales)
390 x = icwt(Wx[:idx], scales=scales[:idx], **kw)
--> 391 x += icwt(Wx[idx:], scales=scales[idx:], **kw)
392 return x
393 ##########################################################################
394
395 #### Invert ##############################################################
File /opt/conda/envs/gst/lib/python3.8/site-packages/ssqueezepy/_cwt.py:378, in icwt(Wx, wavelet, scales, nv, one_int, x_len, x_mean, padtype, rpadded, l1_norm)
376 wavelet = Wavelet._init_if_not_isinstance(wavelet)
377 # will override
nv
to matchscales
's--> 378 scales, scaletype, _, nv = process_scales(scales, x_len, wavelet, nv=nv,
379 get_params=True)
380 assert (len(scales) == na), "%s != %s" % (len(scales), na)
382 #### Handle piecewise scales case ########################################
383 #
nv
must be left unspecified so it's inferred automatically fromscales
384 # in
process_scales
for each piecewise caseFile /opt/conda/envs/gst/lib/python3.8/site-packages/ssqueezepy/utils/cwt_utils.py:247, in process_scales(scales, N, wavelet, nv, get_params, use_padded_N)
244 nv = int(nv)
245 return scaletype, nv, preset
--> 247 scaletype, nv, preset = _process_args(scales, nv, wavelet)
248 if isinstance(scales, (np.ndarray, torch.Tensor)):
249 scales = scales.reshape(-1, 1)
File /opt/conda/envs/gst/lib/python3.8/site-packages/ssqueezepy/utils/cwt_utils.py:228, in process_scales.._process_args(scales, nv, wavelet)
225 if scales.squeeze().ndim != 1:
226 raise ValueError("
scales
, if array, must be 1D "227 "(got shape %s)" % str(scales.shape))
--> 228 scaletype, _nv = infer_scaletype(scales)
229 if scaletype == 'log':
230 if nv is not None and _nv != nv:
File /opt/conda/envs/gst/lib/python3.8/site-packages/ssqueezepy/utils/cwt_utils.py:289, in infer_scaletype(scales)
286 # ceil to avoid faulty float-int roundoffs
287 nv = int(np.round(1 / np.diff(np.log2(scales), axis=0)[0]))
--> 289 elif logscale_transition_idx(scales) is None:
290 raise ValueError("could not infer
scaletype
fromscales
; "291 "
scales
array must be linear or exponential. "292 "(got diff(scales)=%s..." % np.diff(scales, axis=0)[:4])
294 else:
File /opt/conda/envs/gst/lib/python3.8/site-packages/ssqueezepy/utils/cwt_utils.py:380, in logscale_transition_idx(scales)
378 scales = asnumpy(scales)
379 scales_diff2 = np.abs(np.diff(np.log(scales), 2, axis=0))
--> 380 idx = np.argmax(scales_diff2) + 2
381 diff2_max = scales_diff2.max()
382 # every other value must be zero, assert it is so
File <array_function internals>:180, in argmax(*args, **kwargs)
File /opt/conda/envs/gst/lib/python3.8/site-packages/numpy/core/fromnumeric.py:1216, in argmax(a, axis, out, keepdims)
1129 """
1130 Returns the indices of the maximum values along an axis.
1131
(...)
1213 (2, 1, 4)
1214 """
1215 kwds = {'keepdims': keepdims} if keepdims is not np._NoValue else {}
-> 1216 return _wrapfunc(a, 'argmax', axis=axis, out=out, **kwds)
File /opt/conda/envs/gst/lib/python3.8/site-packages/numpy/core/fromnumeric.py:57, in _wrapfunc(obj, method, *args, **kwds)
54 return _wrapit(obj, method, *args, **kwds)
56 try:
---> 57 return bound(*args, **kwds)
58 except TypeError:
59 # A TypeError occurs if the object does have such a method in its
60 # class, but its signature is not identical to that of NumPy's. This
(...)
64 # Call _wrapit from within the except clause to ensure a potential
65 # exception has a traceback chain.
66 return _wrapit(obj, method, *args, **kwds)
ValueError: attempt to get argmax of an empty sequence
Code for reproduction
The text was updated successfully, but these errors were encountered: