-
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
Optionally output frequencies rather than scales (or provide a function to convert) #46
Comments
Good request, it's on TODO. For now, let me know if this code works. |
Thanks for sharing that. Unfortunately, it's not working for me at the moment due to assertion errors. My code looks like this ( import ssqueezepy as ssp
from scale_to_freq import scale_to_freq
error_data = np.loadtxt('ErrorData.csv')
sample_spacing = 150e-6
wavelet = 'gmw'
Wx, scales = ssp.cwt(error_data, wavelet=wavelet, fs=1/sample_spacing)
# N=1024 chosen as it's the default in Wavelet class init function
frequencies = scale_to_freq(scales, wavelet, N=1024, fs=1/sample_spacing) The error I get is:
If I comment out the two checks on
Do you have any idea what I might be able to do about this? |
Similar edge case;
before passing to |
Thanks! Changing I also had to tweak the min and max as mentioned. |
Actually, it worked with gmw (with the tweak), but not with morlet - the bound is further out:
It looks like it's not just the first one that is outside the bounds |
Could you share code to reproduce the error? Data can be |
Error data is attached. This sample script produces the error: #!/usr/bin/python
# vim: set fileencoding=utf-8 :
#%% Scientific Python Imports
import numpy as np # analysis:ignore
import matplotlib.pyplot as plt
#%%
import ssqueezepy as ssp
from scale_to_freq import scale_to_freq
#%%
generate_data = False
if generate_data:
error_data = np.random.randn(173043)
np.save('error_data.npy', error_data)
else:
error_data = np.load('error_data.npy')
sample_spacing = 150e-6
#%%
def plot_cwt(error_data, sample_spacing, wavelet='gmw', ax=None, linestyle='b-'):
print(wavelet)
if ax is None:
fig, ax = plt.subplots()
else:
fig = None
Wx, scales = ssp.cwt(error_data, wavelet=wavelet, fs=1/sample_spacing)
means = np.mean(np.abs(Wx), axis=1)
scales[0] *= 1.01
scales[1] /= 1.01
frequencies = scale_to_freq(scales, wavelet, N=len(error_data), fs=1/sample_spacing)
wavelengths = 1.0/frequencies
ax.plot(wavelengths, means, linestyle, label=wavelet)
ax.set_yscale('log')
ax.set_xscale('log')
ax.set_xlabel('Wavelength (mm)')
ax.set_ylabel('nm')
ax.grid(True, which='both')
return fig, ax
fig, ax = plot_cwt(error_data, sample_spacing, 'gmw')
plot_cwt(error_data, sample_spacing, 'morlet', ax=ax, linestyle='r-')
plot_cwt(error_data, sample_spacing, 'bump', ax=ax, linestyle='k-') |
I see the problem; this version should work, but only with psis = wavelet(scale=scales)
ssq.visuals.plot(psis[-5:].T, show=1)
ssq.visuals.plot(psis[:5].T, show=1)
|
That's brilliant, and working really well (I'm using Scale-to-freq 1.0). It would be great to see this integrated into the library at some point. Out of interest I had a go with the synchrosqueezed versions as well to compare. For these it looks like producing the same plots is much simpler as frequency data is provided. What I found slightly odd though is that the returned frequencies ( Tx, Wx, ssq_freqs, scales = ssp.ssq_cwt(error_data, wavelet='gmw', fs=1/sample_spacing)
# Not sure why we need to flip this, but if we don't then it looks very wrong compared to the `cwt` plot!
wavelengths = 1.0/np.flip(ssq_freqs)
means = np.mean(np.abs(Tx), axis=1)
ax.plot(wavelengths, means) Is that intentional? |
It's something I never looked much into. It follows the original MATLAB toolbox - I suppose the idea's to sort lowest to highest, but this does not match the actual output indexing, which I think is more important. Might change in a future version. |
I take this Issue's resolved, feel free to open another. |
In the Matlab cwt documentation, it gives this useful example (emphasis added by me):
In this example, if you provide the sampling frequency, then the frequencies are returned. It would be really useful if ssqueezepy could do this too (or at least provide a scale2frequency function to do the required conversion with the specified wavelet).
The text was updated successfully, but these errors were encountered: