mne-tools / mne-tools/mne-python
Compute TFR with fmin=0Hz
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 1.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
Description
Currently, tfr_morlet and tfr_multitaper throw an error if the minimum frequency is 0Hz:
/usr/local/lib/python3.7/site-packages/mne/time_frequency/tfr.py in morlet(sfreq, freqs, n_cycles, sigma, zero_mean)
83 # this scaling factor is proportional to (Tallon-Baudry 98):
84 # (sigma_t*sqrt(pi))^(-1/2);
---> 85 t = np.arange(0., 5. * sigma_t, 1.0 / sfreq)
86 t = np.r_[-t[::-1], t[1:]]
87 oscillation = np.exp(2.0 * 1j * np.pi * f * t)
ValueError: arange: cannot compute length
and
/usr/local/lib/python3.7/site-packages/mne/time_frequency/tfr.py in _make_dpss(sfreq, freqs, n_cycles, time_bandwidth, zero_mean)
140
141 t_win = this_n_cycles / float(f)
--> 142 t = np.arange(0., t_win, 1.0 / sfreq)
143 # Making sure wavelets are centered before tapering
144 oscillation = np.exp(2.0 * 1j * np.pi * f * (t - t_win / 2.))
ValueError: arange: cannot compute length
FWIW, tfr_stockwell works fine with 0Hz.
Maybe I'm totally misunderstanding something, but I think it would be nice if TFRs started at DC, independent of the TFR method.
MWE to reproduce:
import numpy as np
import mne
sfreq = 128
n_epochs, n_ch, n_time = 144, 2, 1921
data = np.random.randn(n_epochs, n_ch, n_time)
info = mne.create_info(n_ch, sfreq, 'eeg')
epochs = mne.EpochsArray(data, info)
freqs = np.arange(0, 4)
mne.time_frequency.tfr_morlet(epochs, freqs, n_cycles=freqs / 2) # throws error
mne.time_frequency.tfr_multitaper(epochs, freqs, n_cycles=freqs / 2) # throws error
mne.time_frequency.tfr_stockwell(epochs, fmin=0, fmax=3) # works
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the MWE with tfr_morlet and tfr_multitaper, then inspect the wavelet code in tfr.py at the failing arange calls for zero frequency. Compare their behavior with tfr_stockwell, which already accepts fmin=0. Done means both methods compute a TFR starting at 0 Hz without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100