PyWavelets / pywt

PyWavelets - Wavelet Transforms in Python
http://pywavelets.readthedocs.org
MIT License
2.04k stars 470 forks source link

Any plans for COI? #332

Open laszukdawid opened 6 years ago

laszukdawid commented 6 years ago

Are there any plans to include automatic generation for Cone Of Influence?

rgommers commented 6 years ago

Not that I know of. Pretty much all I can find about COI is for continuous wavelets; we've only recently added support for cwt and don't have much support beyond the basic transform (even icwt is still missing).

Are you thinking of adding it? If so, any reference you'd recommend?

laszukdawid commented 6 years ago

I'm already working on some wavelet applications, so might contribute here a bit.

There's another Python wavelet package which is complimentary to this one - https://github.com/aaren/wavelets. It has implementation of COI. Maybe it would be beneficial to collaborate with these people, although they seem to be on stall.

rgommers commented 6 years ago

@aaren is also a PyWavelets contributor. Would be great to get his opinion on the split between packages.

grlee77 commented 6 years ago

I also recently saw this package for (FFT-based) continuous wavelet analysis. https://github.com/regeirk/pycwt I haven't looked into it in any detail to see what level of overlap there is between the various packages for continous wavelet transforms.

matteorr commented 5 years ago

@rgommers, @grlee77, @laszukdawid, @aaren - I wanted to follow up on this question since I really love your library but not having cone of interest or being able to do a significance analysis is very limiting.

Here's a comparison between your library and pycwt, and as you might see the results look quite different in the amount of noise outside the cone of interest.

import pywt
import pycwt as wavelet
import numpy as np
import matplotlib.pyplot as plt

num_steps = 512
x = np.arange(num_steps)
y = np.sin(2*np.pi*x/32)

delta_t = x[1] - x[0]
scales = np.arange(1,num_steps+1)

# pycwt
freqs = 1/(wavelet.Morlet().flambda() * scales)
wavelet_type = 'morlet'
coefs, scales, freqs, coi, fft, fftfreqs = wavelet.cwt(y, delta_t, wavelet=wavelet_type, freqs=freqs)
plt.matshow(coefs.real)
plt.plot(x,coi)
plt.title('pycwt')

# pywt
wavelet_type = 'morl'
coefs, freqs = pywt.cwt(y, scales, wavelet_type, delta_t)
plt.matshow(coefs)
plt.plot(x,coi)
plt.title('pywt')

plt.show()

By looking at their repo (links 1, 2) it doesn't seem to complicated to implement. Am I missing something?

I'd be happy to do a pull request and be helpful, but am I'm not an expert in the field, so don't understand the complications and am afraid I would mess up. Would you mind explaining in more details what should be done?

grlee77 commented 5 years ago

Our CWT contributor has not been active here lately. In an older issue (#315), @nabobalis also had interest in merging functionality from PyCWT but does not seem to have pursued it further. The BSD license terms of PyCWT are compatible with PyWavelets, so it should not be a problem to look at and adapt code from there as needed. I think mainly it needs someone with the time and interest to work on it. I would encourage you to go ahead and attempt it if you are interested. We may be able to find someone with expertise in the area to help review any proposed additions.

I know SciPy and @aaren's repo both have CWT code as well, but I don't know offhand the relative strengths and weaknesses of the various packages in this area. I believe some do the transform in the FFT domain while the implementation in PyWavelets is convolution-based.

rgommers commented 5 years ago

I know SciPy and @aaren's repo both have CWT code as well, but I don't know offhand the relative strengths and weaknesses of the various packages in this area.

The code in scipy.signal has more weaknesses than strengths. It's quite basic functionality that hasn't seen much maintenance; I don't expect it to be very useful.

matteorr commented 5 years ago

@grlee77 @rgommers - Thanks for your quick reply, I understand the situation. It's just a pity that there isn't one clear winner take all python repo for wavelets in the same way that the MATLAB toolbox is.

I hope this is not becoming too off topic, but do you have a general guideline for when would pywavelets be preferable over PyCWT, and viceversa?

In any case, if I keep working on this and become a bit more expert I will definitively consider contributing to the repo.