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

reconstruction from array_to_coeff and waverec #357

Closed
SylvainLan opened this issue Mar 9, 2018 · 3 comments
Closed

reconstruction from array_to_coeff and waverec #357

SylvainLan opened this issue Mar 9, 2018 · 3 comments
Milestone

Comments

@SylvainLan
Copy link
Contributor

Hello,

I am getting an error while running the following code

x = np.random.randn(256)
w = pywt.wavedec(x, wavelet='haar', level=3)
w_arr, w_cs = pywt.coeffs_to_array(w)
w2 = pywt.array_to_coeffs(w_arr, w_cs)
x_recon = pywt.waverec(w2, wavelet='haar')

The error message is

~/anaconda3/lib/python3.6/site-packages/pywt/_multilevel.py in waverec(coeffs, wavelet, mode, axis)
    145         if (a is not None) and (d is not None):
    146             try:
--> 147                 if a.shape[axis] == d.shape[axis] + 1:
    148                     a = a[[slice(s) for s in d.shape]]
    149                 elif a.shape[axis] != d.shape[axis]:

AttributeError: 'dict' object has no attribute 'shape'

The code runs if I change waverec to waverecn however.

I can try to look at this soon but I'm new to pywavelet so I don't know how long it will take me !

Syl

@grlee77
Copy link
Contributor

grlee77 commented Mar 9, 2018

array_to_coeffs defaults to returning coeficients compatibile with wavedecn. For use with waverec you have to provide an additional argument:

w2 = pywt.array_to_coeffs(w_arr, w_cs, output_format='wavedec')

The reason for this is that it is not possible to tell from the concatenated array which transform generated the data. Perhaps it would have been better to make output_format a required argument (although at this point I would vote to leave it as is for backward compatibility)?

@grlee77
Copy link
Contributor

grlee77 commented Mar 9, 2018

This is not a bug, but it is perhaps worth adding a check in wavedec itself to return a more informative error message if the coefficients received are not of the proper format. As is, the attribute error that occurred in your case is not helpful in diagnosing the problem.

@SylvainLan SylvainLan mentioned this issue Mar 12, 2018
@SylvainLan
Copy link
Contributor Author

I changed the error message in waverec, is that what you meant ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants