You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While it may not make much sense to interpret the DC component of an EEG spectrum, technically this should be well defined - it is the mean of the signal. Also, tfr_stockwell can deal with 0Hz components and I don't see why the other two FFT-based methods don't work.
I could work on this if you want.
So basically, both of these errors are in fact ZeroDivisionErrors, created if f = 0 in sigma_t = this_n_cycles / (2.0 * np.pi * f) and this_n_cycles / float(f).
So the options probably would be:
Print a meaningful error like raise ValueError("All frequencies must be greater than 0")
Mask the case f = 0 with something like f = 1e-300 (Which worked for me practically, anyhow, i'm not sure how you feel about this)
Setting a minimum frequency of 0 to DC offset (if i understood your intention right?) would not solve the particular case if DC offset is also 0.
I'd prefer an error message if it is technically not possible to compute the DC component.
Well, it surely is technically possible to do so, but seems not to be directly related to the issue that morlet and multitaper can't be computed with fmin=0Hz.
Was your intention to remove DC offset from each channel by subtracting the mean before calculating the TFR, or would you like a frequency freqs = [0] to be corrected to DC each time it is passed?
I would like a frequency of 0 to mean DC so that all TFRs behave like tfr_stockwell (or any other FFT-based method, where 0Hz does not produce an error).
ok, so i listed some examples below, where i manually set freq = 0 to DC (outside the function). As you can see, this would not solve the problem for all cases.
importnumpyasnpimportmnesfreq=128n_epochs, n_ch, n_time=1, 1, 2048info=mne.create_info(n_ch, sfreq, 'eeg')
freqs=np.arange(0, 4)
# 1. case with small dcdata1=np.random.randn(n_epochs, n_ch, n_time) # random channelepochs1=mne.EpochsArray(data1, info)
dc1=np.mean(epochs1._data)
freqs1=np.where(freqs==0, dc1, freqs) # replace freq == 0 with dctfr1, _=mne.time_frequency.tfr_morlet(epochs1,
freqs1, n_cycles=freqs1/2) # this workstfr1.freqs# of course now freqs would be inconsistent# 2. case with large dcdata2=np.random.randn(n_epochs, n_ch, n_time) +2# introduce high offsetepochs2=mne.EpochsArray(data2, info)
dc2=np.mean(epochs2._data)
freqs2=np.where(freqs==0, dc2, freqs) # replace freq == 0 with dctfr2, _=mne.time_frequency.tfr_morlet(epochs2,
freqs2, n_cycles=freqs2/2) # this workstfr2.freqs# but this will be extremely confusing# 3. case in which dc == 0data3=np.ones([n_epochs,n_ch,n_time])
data3[:,:,::2] =-1# oscillating channel with mean = 0epochs3=mne.EpochsArray(data3, info)
dc3=np.mean(epochs3._data)
freqs3=np.where(freqs==0, dc3, freqs) # replace freq == 0 with dctfr3, _=mne.time_frequency.tfr_morlet(epochs3,
freqs3, n_cycles=freqs3/2) # this still won't work
That's the reason i'm kind of hesitating with this, since doing it would not solve ALL the cases, while simultaneously introducing inconsistencies in the frequency intervals.
The reason that 0 Hz frequencies can be passed into stockwell but not multitaper or morlet, is (in my understanding) only based on the fact that in multitaper & morlet, we come along a xy/ freq situation, that results in a ZeroDivisionError, while in stockwell and ffts we don't. Therefore a direct solution to this would rather be to try and deal with these fractions than setting fmin to dc.
Activity
agramfort commentedon Nov 13, 2018
cbrnr commentedon Nov 14, 2018
While it may not make much sense to interpret the DC component of an EEG spectrum, technically this should be well defined - it is the mean of the signal. Also,
tfr_stockwellcan deal with 0Hz components and I don't see why the other two FFT-based methods don't work.agramfort commentedon Nov 14, 2018
DiGyt commentedon Apr 17, 2019
@cbrnr @agramfort
I could work on this if you want.
So basically, both of these errors are in fact ZeroDivisionErrors, created if
f = 0insigma_t = this_n_cycles / (2.0 * np.pi * f)andthis_n_cycles / float(f).So the options probably would be:
raise ValueError("All frequencies must be greater than 0")Setting a minimum frequency of 0 to DC offset (if i understood your intention right?) would not solve the particular case if DC offset is also 0.
DiGyt commentedon Apr 17, 2019
BTW, here's how this Error occurs:
cbrnr commentedon Apr 17, 2019
I'd prefer an error message if it is technically not possible to compute the DC component.
DiGyt commentedon Apr 18, 2019
Well, it surely is technically possible to do so, but seems not to be directly related to the issue that morlet and multitaper can't be computed with fmin=0Hz.
Was your intention to remove DC offset from each channel by subtracting the mean before calculating the TFR, or would you like a frequency
freqs = [0]to be corrected to DC each time it is passed?cbrnr commentedon Apr 18, 2019
I would like a frequency of 0 to mean DC so that all TFRs behave like
tfr_stockwell(or any other FFT-based method, where 0Hz does not produce an error).DiGyt commentedon Apr 24, 2019
ok, so i listed some examples below, where i manually set
freq = 0to DC (outside the function). As you can see, this would not solve the problem for all cases.That's the reason i'm kind of hesitating with this, since doing it would not solve ALL the cases, while simultaneously introducing inconsistencies in the frequency intervals.
The reason that 0 Hz frequencies can be passed into stockwell but not multitaper or morlet, is (in my understanding) only based on the fact that in multitaper & morlet, we come along a
xy/ freqsituation, that results in a ZeroDivisionError, while in stockwell and ffts we don't. Therefore a direct solution to this would rather be to try and deal with these fractions than setting fmin to dc.