# \[mne-python\] tfr\_morlet to return single epochs

**URL:** <https://mne.discourse.group/t/mne-python-tfr-morlet-to-return-single-epochs/810>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [August 29, 2014, 11:41am UTC](https://mne.discourse.group/t/mne-python-tfr-morlet-to-return-single-epochs/810 "2014-08-29T11:41:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [August 29, 2014, 11:41am UTC](https://mne.discourse.group/t/mne-python-tfr-morlet-to-return-single-epochs/810/1 "2014-08-29T11:41:16Z")

</div>

Dear mne-list,

I would like to make a morlet wavelet on single epochs but as I  
understand the tfr\_morlet, it returns the average power for all the  
epochs. If this is correct is there a way to make tfr\_morlet return the  
single epochs or is there another function that can?

thanks,  
mads

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [August 29, 2014, 4:32pm UTC](https://mne.discourse.group/t/mne-python-tfr-morlet-to-return-single-epochs/810/2 "2014-08-29T16:32:37Z")

</div>

hi Mads,

yes you can. Just call tfr\_morlet on epochs[k] to compute it on one epochs.

You can index epochs like arrays with MNE-Python

Alex

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [August 29, 2014, 6:25pm UTC](https://mne.discourse.group/t/mne-python-tfr-morlet-to-return-single-epochs/810/3 "2014-08-29T18:25:11Z")

</div>

hi Alex,

thanks for the reply. I afraid cannot make it work, I get the following  
error:

Traceback (most recent call last):

&nbsp;&nbsp;&nbsp;File "\<ipython-input-9-1e05100b604d\>", line 30, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return\_itc=True, decim=3, n\_jobs=1)

&nbsp;&nbsp;&nbsp;File  
"/home/mje/Toolboxes/anaconda/lib/python2.7/site-packages/mne-0.9.git-py2.7.egg/mne/time\_frequency/tfr.py",  
line 892, in tfr\_morlet  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data = data[:, picks, :]

IndexError: too many indice

I just used to the code from the example  
"time\_frequency/plot\_time\_frequency\_sensors.py" and changed the:  
power, itc = tfr\_morlet(epochs, freqs=freqs, n\_cycles=n\_cycles,  
use\_fft=False,  
to:  
power, itc = tfr\_morlet(epochs[0], freqs=freqs, n\_cycles=n\_cycles,  
use\_fft=False,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return\_itc=True, decim=3, n\_jobs=1)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return\_itc=True, decim=3, n\_jobs=1)

the full code is below,

any thoughts?  
best regards,  
mads

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [August 30, 2014, 9:52am UTC](https://mne.discourse.group/t/mne-python-tfr-morlet-to-return-single-epochs/810/4 "2014-08-30T09:52:42Z")

</div>

Hi Mads,

there was 2 problems:

- epochs[0] was a bad epoch so you need to preload epochs or call  
epochs.drop\_bad\_epochs() to make sure epochs[0] is good.

- a bug in mne-python I just fixed  
[https://github.com/mne-tools/mne-python/pull/1543](https://github.com/mne-tools/mne-python/pull/1543)

I will be in our bug fix release of 0.8 in the next few weeks. You can  
also use current development version.

thanks for the bug report

Alex

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [August 30, 2014, 7:31pm UTC](https://mne.discourse.group/t/mne-python-tfr-morlet-to-return-single-epochs/810/5 "2014-08-30T19:31:38Z")

</div>

Hi Alex,

thanks for the update and fix (I'm using the git version)

best,  
mads
