# using correlation as method for find\_bads\_ecg

**URL:** https://mne.discourse.group/t/using-correlation-as-method-for-find-bads-ecg/849
**Category:** Mailing List Archive (read-only)
**Tags:** list-archive
**Created:** [October 15, 2014, 10:15pm UTC](https://mne.discourse.group/t/using-correlation-as-method-for-find-bads-ecg/849 "2014-10-15T22:15:39Z")
**Posts on this page:** 8
**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: [October 15, 2014, 10:15pm UTC](https://mne.discourse.group/t/using-correlation-as-method-for-find-bads-ecg/849/1 "2014-10-15T22:15:39Z")

</div>

Dear list

I can't get the correlation method to work for find\_bads\_ecg method  
It always returns the error: ValueError: ECG003 not in channel list

method = 'correlation'

ekgEpochs = mne.preprocessing.create\_ecg\_epochs(raw)

ekgIndices, ekgScores = ica.find\_bads\_ecg(ekgEpochs, method=method)

It is in the ekgEpochs as seen below

ekgEpochs.info['ch\_names'][:4]  
Out[8]: ['EOG001', 'EOG002', 'ECG003', 'MEG0111']

it makes no difference whether I include ch\_name = 'ECG003' in  
create\_ecg\_epochs or in find\_bads\_ecg

Any thoughts on why this could be?

I'm running MNE 0.8.5 on MacOSX 10.9.5

Best

Lau  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20141015/0675da48/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20141015/0675da48/attachment.html)

---

<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: [October 16, 2014, 7:23am UTC](https://mne.discourse.group/t/using-correlation-as-method-for-find-bads-ecg/849/2 "2014-10-16T07:23:49Z")

</div>

hi Lau,

would 'ECG003' be marked as bad? is it defined as an ECG channel  
(check with pick\_types)?

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: [October 16, 2014, 7:30am UTC](https://mne.discourse.group/t/using-correlation-as-method-for-find-bads-ecg/849/3 "2014-10-16T07:30:36Z")

</div>

Out of curiosity, why would you prefer the correlation method over the default phase-locking method? The latter is more reliable and is based on a significance test.

-Denis

---

<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: [October 16, 2014, 4:50pm UTC](https://mne.discourse.group/t/using-correlation-as-method-for-find-bads-ecg/849/4 "2014-10-16T16:50:19Z")

</div>

Hi Alex and Denis

@Alex:  
picks = mne.pick\_types(ekgEpochs.info, ecg=True)  
ch\_names = np.array(ekgEpochs.info['ch\_names'])  
In [22]: ch\_names[picks][:10]  
Out[22]:  
array(['ECG003', 'MEG0111', 'MEG0112', 'MEG0113', 'MEG0121', 'MEG0122',  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'MEG0123', 'MEG0131', 'MEG0132', 'MEG0133'],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dtype='|S7')

In [23]: ekgEpochs.info['bads']  
Out[23]:

It seems to be in there and not marked as bad.

On a related note: The documentation for find\_bads\_eog refers to ecg  
instead of eog throughout.

@Denis: Actually, for no other reason that that is what I did in an earlier  
experiment, and I wanted to follow that analysis for the current experiment  
as closely as possible. But I will take your word for the ctps being more  
reliable.

Best

Lau

2014-10-16 2:30 GMT-05:00 Denis A. Engemann \<denis.engemann at gmail.com\>:

> Out of curiosity, why would you prefer the correlation method over the  
> default phase-locking method? The latter is more reliable and is based on a  
> significance test.
> 
> -Denis
> 
> \>  
> \> hi Lau,  
> \>  
> \> would 'ECG003' be marked as bad? is it defined as an ECG channel  
> \> (check with pick\_types)?  
> \>  
> \> Alex  
> \>  
> \>\> Dear list  
> \>\>  
> \>\> I can't get the correlation method to work for find\_bads\_ecg method  
> \>\> It always returns the error: ValueError: ECG003 not in channel list  
> \>\>  
> \>\> method = 'correlation'  
> \>\>  
> \>\> ekgEpochs = mne.preprocessing.create\_ecg\_epochs(raw)  
> \>\>  
> \>\> ekgIndices, ekgScores = ica.find\_bads\_ecg(ekgEpochs, method=method)  
> \>\>  
> \>\>  
> \>\> It is in the ekgEpochs as seen below  
> \>\>  
> \>\> ekgEpochs.info['ch\_names'][:4]  
> \>\> Out[8]: ['EOG001', 'EOG002', 'ECG003', 'MEG0111']  
> \>\>  
> \>\> it makes no difference whether I include ch\_name = 'ECG003' in  
> \>\> create\_ecg\_epochs or in find\_bads\_ecg  
> \>\>  
> \>\> Any thoughts on why this could be?  
> \>\>  
> \>\> I'm running MNE 0.8.5 on MacOSX 10.9.5  
> \>\>  
> \>\> Best  
> \>\>  
> \>\> Lau  
> \>\>  
> \>\>  
> \>\> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> \>\> Mne\_analysis mailing list  
> \>\> Mne\_analysis at nmr.mgh.harvard.edu  
> \>\> [Mne\_analysis Info Page](https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis)  
> \>\>  
> \>\>  
> \>\> The information in this e-mail is intended only for the person to whom  
> it is  
> \>\> addressed. If you believe this e-mail was sent to you in error and the  
> \>\> e-mail  
> \>\> contains patient information, please contact the Partners Compliance  
> \>\> HelpLine at  
> \>\> [MyComplianceReport.com: Compliance and Ethics Reporting](http://www.partners.org/complianceline) . If the e-mail was sent to you  
> in  
> \>\> error  
> \>\> but does not contain patient information, please contact the sender and  
> \>\> properly  
> \>\> dispose of the e-mail.  
> \>\>  
> \>  
> \> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> \> Mne\_analysis mailing list  
> \> Mne\_analysis at nmr.mgh.harvard.edu  
> \> [Mne\_analysis Info Page](https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis)
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Mne\_analysis mailing list  
> Mne\_analysis at nmr.mgh.harvard.edu  
> [Mne\_analysis Info Page](https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis)

-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20141016/97192734/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20141016/97192734/attachment.html)

---

<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: [October 16, 2014, 7:16pm UTC](https://mne.discourse.group/t/using-correlation-as-method-for-find-bads-ecg/849/5 "2014-10-16T19:16:55Z")

</div>

hi Lau,

can you reproduce the problem with the sample dataset?  
If not please share one of your files and the script that crashes.

Best,  
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: [October 16, 2014, 9:15pm UTC](https://mne.discourse.group/t/using-correlation-as-method-for-find-bads-ecg/849/6 "2014-10-16T21:15:20Z")

</div>

Hi Alex

I cannot reproduce the problem with the sample data set.By the way, is  
it the case that the sample data set is version 0.7? It keeps telling me  
to update, but I can't seem to get a newer version  
The code below works just fine:

import mne

import os

path = mne.datasets.sample.data\_path()

os.chdir(path + '/MEG/sample')

raw = mne.io.Raw('sample\_audvis\_filt-0-40\_raw.fif')

events = mne.read\_events('sample\_audvis\_filt-0-40\_raw-eve.fif')

eventID = {'aud\_l': 1, 'aud\_r': 2, 'vis\_l': 3, 'vis\_r': 4, 'smiley': 5,

'button': 32}

epochs = mne.Epochs(raw, events, eventID, tmin=-0.2, tmax=0.5)

ekg = mne.preprocessing.create\_ecg\_epochs(raw)

noiseCov = mne.read\_cov('sample\_audvis-cov.fif')

ica = mne.preprocessing.ICA(n\_components=0.95, n\_pca\_components=64,

max\_pca\_components=100, noise\_cov=noiseCov)

ica.fit(epochs)

ekgIndices, ekgScores = ica.find\_bads\_ecg(ekg, method='correlation')

What is the easiest way for me to share a file with you? The raw files  
as they are now are pretty big.

Best

Lau

---

<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: [October 17, 2014, 7:29am UTC](https://mne.discourse.group/t/using-correlation-as-method-for-find-bads-ecg/849/7 "2014-10-17T07:29:14Z")

</div>

hi Lau,

maybe use dropbox or google drive? don't hesitate to make a tiny file  
before sharing.

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: [October 19, 2014, 4:57pm UTC](https://mne.discourse.group/t/using-correlation-as-method-for-find-bads-ecg/849/8 "2014-10-19T16:57:43Z")

</div>

hi,

bug is fixed

[https://github.com/mne-tools/mne-python/pull/1612](https://github.com/mne-tools/mne-python/pull/1612)

thanks for the bug report.

Alex
