# Filtering with EpochsArray

**URL:** <https://mne.discourse.group/t/filtering-with-epochsarray/1057>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [August 10, 2016, 12:01pm UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057 "2016-08-10T12:01:20Z")\
**Posts on this page:** 14\
**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 10, 2016, 12:01pm UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/1 "2016-08-10T12:01:20Z")

</div>

Hello,

I have built my epochs with EpochsArray and I would like to apply a  
low-pass filter. But when I tried to do this:

epochs = mne.EpochsArray(ElectrodeArray, info=info, baseline = (None, 0.04))  
epochs.filter(l\_freq=None, h\_freq=25.0)

I get the error the following error: "AttributeError: 'EpochsArray' object  
has no attribute 'filter'".

How can I solve this issue?

Many thanks,  
Emanuela Liaci  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20160810/00ed047e/attachment-0001.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160810/00ed047e/attachment-0001.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:** [August 10, 2016, 12:43pm UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/2 "2016-08-10T12:43:09Z")

</div>

Hi Emanuela,

We recommend not applying filter on epoched data, as the epochs edges  
generate important artifacts. Instead, you can apply filters on the raw  
data using raw.filter()

If you really want to apply in on epochs data, you can retrieve the data  
array, and pass it to mne.filter functions: e.g.

epochs\_data = epochs.get\_data()  
low, high = 10., 30.  
epochs\_data\_filt = mne.filter.band\_pass\_filter(epochs\_data,  
epochs.info['sfreq'],  
low, high)  
epochs\_filt = mne.EpochsArray(epochs\_data\_filt, epochs.info)

Hope that helps,

Best,

Jean-R?mi

---

<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 10, 2016, 1:06pm UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/3 "2016-08-10T13:06:06Z")

</div>

Hi,

thanks for your response. The problem is that the format of my raw data is  
not available in mne python and for this reason I created a 3d array for my  
epochs. So I don't have raw data.

Cheers,  
Emanuela Liaci

---

<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 10, 2016, 1:10pm UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/4 "2016-08-10T13:10:18Z")

</div>

If it is a file type which is not supported, could you open an issue on  
Github?

If you have the continuous raw data in an array format, you can recreate a  
raw with mne.io.RawArray

Else, well, good luck 😉

JR

---

<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 11, 2016, 1:51pm UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/5 "2016-08-11T13:51:30Z")

</div>

Hello,

can someone tell me what the problem might be here? When trying to  
plot annotations, I get an IndexError in the file annotations.py:

--\> 122 meas\_date = meas\_date[0] + meas\_date[1] / 1000000.

My commands are:

onset = [1] # also tried [1 + raw.first\_samp]  
dur = [5]  
raw.annotations = mne.Annotations(onset, dur, 'bad')  
raw.plot() # here comes the error

The raw file here is fif. I saved an edf using raw.save, cutting parts  
from the beginning and the end of the recording. In the edf file there  
is no error.

Thanks,  
Nico

---

<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 12, 2016, 5:47pm UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/6 "2016-08-12T17:47:29Z")

</div>

Hi Nico,

Before we try to debug any further, can you let us know what  
raw.info['meas\_date']  
looks like in your data?

Mainak

---

<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 12, 2016, 7:53pm UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/7 "2016-08-12T19:53:11Z")

</div>

Hello,

I get:  
array([1463353331])

Nico

Quoting Mainak Jas \<mainakjas at [gmail.com](http://gmail.com)\>:

---

<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 12, 2016, 8:30pm UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/8 "2016-08-12T20:30:25Z")

</div>

okay. There seems to be some problem with the date in your measurement info.

This should fix it:

raw.info['meas\_date'] = np.array([1463353331, 0], dtype=int32)

Let us know if you still get the error after that.

Mainak

---

<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 13, 2016, 2:21pm UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/9 "2016-08-13T14:21:18Z")

</div>

For me it now says that the name 'int32' is not defined. When I  
exclude the dtype parameter, I get no error when plotting. 🙂 But now  
I also don't see any annotations in the plot.

Quoting Mainak Jas \<mainakjas at [gmail.com](http://gmail.com)\>:

---

<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 14, 2016, 6:56am UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/10 "2016-08-14T06:56:53Z")

</div>

Hi Nico,

Since the annotations object accepts time in seconds, the correct input  
should be:

onset = [1 + raw.first\_samp / raw.info['sfreq']]

and not

onset = [1 + raw.first\_samp] # here you are adding an index to seconds

Let us know if that works.

Best regards,  
Mainak

---

<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 14, 2016, 7:00am UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/11 "2016-08-14T07:00:22Z")

</div>

> For me it now says that the name 'int32' is not defined.

You might have to do np,int32 then.

Mainak

> When I  
> exclude the dtype parameter, I get no error when plotting. 🙂 But now  
> I also don't see any annotations in the plot.
> 
> Quoting Mainak Jas \<mainakjas at gmail.com\>:
> 
> \> okay. There seems to be some problem with the date in your measurement  
> info.  
> \>  
> \> This should fix it:  
> \>  
> \> raw.info['meas\_date'] = np.array([1463353331, 0], dtype=int32)  
> \>  
> \> Let us know if you still get the error after that.  
> \>  
> \> Mainak  
> \>  
> \>  
> \>\> Hello,  
> \>\>  
> \>\> I get:  
> \>\> array([1463353331])  
> \>\>  
> \>\> Nico  
> \>\>  
> \>\>  
> \>\> Quoting Mainak Jas \<mainakjas at gmail.com\>:  
> \>\>  
> \>\> \> Hi Nico,  
> \>\> \>  
> \>\> \> Before we try to debug any further, can you let us know what  
> \>\> \> raw.info['meas\_date']  
> \>\> \> looks like in your data?  
> \>\> \>  
> \>\> \> Mainak  
> \>\> \>  
> \>\> \>  
> \>\> \>\> Hello,  
> \>\> \>\>  
> \>\> \>\> can someone tell me what the problem might be here? When trying to  
> \>\> \>\> plot annotations, I get an IndexError in the file annotations.py:  
> \>\> \>\>  
> \>\> \>\> --\> 122 meas\_date = meas\_date[0] + meas\_date[1] / 1000000.  
> \>\> \>\>  
> \>\> \>\> My commands are:  
> \>\> \>\>  
> \>\> \>\> onset = [1] # also tried [1 + raw.first\_samp]  
> \>\> \>\> dur = [5]  
> \>\> \>\> raw.annotations = mne.Annotations(onset, dur, 'bad')  
> \>\> \>\> raw.plot() # here comes the error  
> \>\> \>\>  
> \>\> \>\> The raw file here is fif. I saved an edf using raw.save, cutting  
> parts  
> \>\> \>\> from the beginning and the end of the recording. In the edf file  
> there  
> \>\> \>\> is no error.  
> \>\> \>\>  
> \>\> \>\> Thanks,  
> \>\> \>\> Nico  
> \>\> \>\>  
> \>\> \>\> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> \>\> \>\> 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/20160814/af79213a/attachment-0001.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20160814/af79213a/attachment-0001.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:** [August 14, 2016, 10:33am UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/12 "2016-08-14T10:33:00Z")

</div>

Fantastic, it works. Thanks a lot for the help and support! 🙂

Another issue unrelated to annotations: When I choose two channels and  
plot them, the second channel looks actually exactly like a mirrored  
version of the first. But it seems that it is only plotting and only  
when I pick 2 channels, not 3 or another number. This is my code:

raw = mne.io.read\_raw\_fif(path+fname, preload=True)  
ch = ['F3','F4']  
raw.pick\_channels(ch)  
raw.plot() # 2nd channel looks exactly mirrored  
# I think it is an issue of plotting, not on the data-level:  
probe1 = raw[0][0][0][0] + raw[1][0][0][0]  
probe2 = raw[0][0][0][10] + raw[1][0][0][10]  
print(probe1 - probe2) # not zero

This is not urgent, but I'm curious if this is a known issue.

Nico

Quoting Mainak Jas \<mainakjas at [gmail.com](http://gmail.com)\>:

---

<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 14, 2016, 10:52am UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/13 "2016-08-14T10:52:27Z")

</div>

This might be an issue with the EEG average reference.

Can you turn of proj and see if you still have the same problem? The button  
is at the lower right corner.

Mainak

---

<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 14, 2016, 11:10am UTC](https://mne.discourse.group/t/filtering-with-epochsarray/1057/14 "2016-08-14T11:10:40Z")

</div>

Ah, I see. Now they are looking correct. Thank you!

Quoting Mainak Jas \<mainakjas at [gmail.com](http://gmail.com)\>:
