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

tfr_array_morlet issues with wavelet #11645

Closed
RainyMeadows opened this issue Apr 23, 2023 · 7 comments · Fixed by #12073
Closed

tfr_array_morlet issues with wavelet #11645

RainyMeadows opened this issue Apr 23, 2023 · 7 comments · Fixed by #12073
Labels
DOC EASY sprint-2023 Issues reserved for the 2023 Intermediate Dev Training

Comments

@RainyMeadows
Copy link

RainyMeadows commented Apr 23, 2023

Steps to reproduce

import numpy as np
from mne.time_frequency import tfr_array_morlet

freqs=np.arange(1, 50, 1)
power = tfr_array_morlet(Input_data, 1000, freqs, n_cycles=7.0, output='avg_power') # Input data is a 70 * 128 * 7000 array

Link to data

I can provide actual data of a single (or couple) channel(s), if necessary.

Expected results

An array of shape (n_chans, n_freqs, n_times)

Actual results

ValueError: At least one of the wavelets is longer than the signal. Use a longer signal or shorter wavelets.

The function works ONLY for n_cycles <= 4.

Additional information

Platform: Windows-10-10.0.22621-SP0
Python: 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Executable: C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe
CPU: Intel64 Family 6 Model 167 Stepping 1, GenuineIntel: 12 cores
Memory: 15.7 GB

mne: 1.3.1
numpy: 1.24.2 {unknown linalg bindings (threadpoolctl module not found: No module named 'threadpoolctl')}
scipy: 1.10.1

@welcome
Copy link

welcome bot commented Apr 23, 2023

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

@agramfort
Copy link
Member

agramfort commented Apr 23, 2023 via email

@RainyMeadows
Copy link
Author

RainyMeadows commented Apr 23, 2023

Ah, I was assuming that at lowest (1 Hz), 7 cycles equate to 7s of signal!

It appears that the minimum length, as obtained from len([mne.time_frequency.morlet(1000, np.arange(1, 50, 1), n_cycles=7.0)][0][0]) = 11141 Maybe, the error message can be a bit more suggestive in mentioning the maximum wave number feasible given the current choice of wave number, min freq, and time sample?

@agramfort
Copy link
Member

agramfort commented Apr 24, 2023 via email

@RainyMeadows
Copy link
Author

See my (edited) comment; l I did take a look!

@agramfort
Copy link
Member

@RainyMeadows would you be up for submitting a PR to update our doc? that would be much appreciated. thanks

@drammock
Copy link
Member

drammock commented Apr 25, 2023

@RainyMeadows In the code there's a comment that I think would resolve your confusion:

# time vector. We go 5 standard deviations out to make sure we're
# *very* close to zero at the ends. We also make sure that there's a
# sample at exactly t=0

In other words, the wavelet will always be 10 * sigma - 1 samples long (after converting sigma into a number of samples rather than seconds).

(If sigma isn't specified it defaults to n_cycles / (2.0 * np.pi * f))

@drammock drammock added DOC EASY and removed BUG labels Jun 21, 2023
@drammock drammock added the sprint-2023 Issues reserved for the 2023 Intermediate Dev Training label Jul 5, 2023
ruuskas added a commit to ruuskas/mne-python that referenced this issue Oct 4, 2023
This change improves the docstring of mne.time_frequency.tfr_morlet and
mne.time_frequency.tfr_array_morlet. An explanation on the length of the
Morlet wavelet for time-frequency representation is added. Closes mne-tools#11645
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DOC EASY sprint-2023 Issues reserved for the 2023 Intermediate Dev Training
Development

Successfully merging a pull request may close this issue.

3 participants