API convergence SWT/DWT
Hello,
Is there a chance that DWT (wavedec) and SWT (swt) would share for instance the trim_approx argument to get the same output?
C urrently wavedec returns [cAn, cDn, ..., cD2, cD1] which is the output of swt when trim_approx=TRUE otherwise swtreturns [(cAn, cDn), ..., (cA2, cD2), (cA1, cD1)]
So
- can we get a
trim_approx=FALSEargument inwavedecthat can switch to deliver[(cAn, cDn), ..., (cA2, cD2), (cA1, cD1)] - a long the same line: can we envisaged to get a "user-defined" output for instance only
[cAn,..., cA2, cA1]ie. the approximation low-freq coeff.?
Best. Jean-Eric
Note: This PR is a follow-up to the following mailing list thread: https://groups.google.com/d/msg/pywavelets/ylPRn0B9DRE/um4Qlt5kCwAJ
- can we get a trim_approx=FALSE argument in wavedec that can switch to deliver [(cAn, cDn), ..., (cA2, cD2), (cA1, cD1)]
This one is easy from an implementation standpoint. I guess it is just a matter of whether it is worth having this option or if it is too niche. I am personally not strongly for or against it.
For example, for wavedecn one would just need to have a new if statement around the following line with trim_approx=True to retain the approximation coefficients.
https://github.com/PyWavelets/pywt/blob/db0172a8ea261064bbc2f0a7b26759c6a8f71d76/pywt/_multilevel.py#L436
- a long the same line: can we envisaged to get a "user-defined" output for instance only [cAn,..., cA2, cA1] ie. the approximation low-freq coeff.?
I'm not sure exactly how that would look, but think I am -1 on doing something more custom like this for the basic DWT and SWT functions.
At least for DWT, if you want to compute only specific coefficients in a more custom fashion you could use pywt.WaveletPacket. Wavelet packets are currently available for 1D and 2D DWT-based transforms (with nD proposed in #393), although we have not implemented them for the SWT.
I gave an example in the mailing list thread of using pywt.downcoef to compute only approximation coefficients. Here is what this would look like with WaveletPacket to get [cA4, cA3, cA2, cA1].
import numpy as np
import pywt
wp = pywt.WaveletPacket(np.ones(32), wavelet='sym2')
approx_coeffs = [wp['aaaa'].data, wp['aaa'].data, wp['aa'].data, wp['a'].data]