# Saving data from mne.Epochs

**URL:** <https://mne.discourse.group/t/saving-data-from-mne-epochs/520>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [December 17, 2012, 11:22pm UTC](https://mne.discourse.group/t/saving-data-from-mne-epochs/520 "2012-12-17T23:22:53Z")\
**Posts on this page:** 6\
**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:** [December 17, 2012, 11:22pm UTC](https://mne.discourse.group/t/saving-data-from-mne-epochs/520/1 "2012-12-17T23:22:53Z")

</div>

Greetings,

When running a script which contains the following line:

\<\<\<  
# Read epochs  
myepochs = mne.Epochs(raw, events, event\_id, tmin, tmax, proj=True,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;picks=picks, baseline=(None, 0), preload=True,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reject=dict(grad=4000e-13, mag=4e-12, eog=150e-6))  
outfile = myepochs.get\_data()

outfile.save('subj\_rest\_raw\_epoch.fif')

> > >

\*I receive this error message:

\*\<\<\<  
Traceback (most recent call last):  
&nbsp;&nbsp;File "resting\_V3.py", line 55, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;outfile.save('subj\_rest\_raw\_epoch.fif')  
AttributeError: 'numpy.ndarray' object has no attribute 'save'

> > >

\*Alternatively, I could forgo running epochs.get\_data and just save  
directly (epochs.save(...))\*,

but I run into the same error except it specifies "Epochs" instead of  
"numpy.ndarray" as the object with no 'save' attribute.

Is this error occurring because of a problem with my script, or might I  
have something wrong with my installation of mne-python?

Thank you in advance.

::vincent  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20121217/d4cc7216/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20121217/d4cc7216/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:** [December 18, 2012, 12:10am UTC](https://mne.discourse.group/t/saving-data-from-mne-epochs/520/2 "2012-12-18T00:10:35Z")

</div>

Hi Vincent,

the code you posted constructs an epochs object from which you get the data by calling .get\_data().  
The returned value however is not an epochs object anymore but a regular numpy array.  
For saving your epochs say:

myepochs.save('subj\_rest\_raw\_epoch.fif')

However make sure your mne-python version already supports this quite recent method.  
In IPython try myepochs. \<TAB\> and see whether 'save' is being provided.  
In case you don't use the current development master, there will be an official new relase before christmas.

I hope this helps.

Denis

Greetings,

When running a script which contains the following line:

\<\<\<  
# Read epochs  
myepochs = mne.Epochs(raw, events, event\_id, tmin, tmax, proj=True,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;picks=picks, baseline=(None, 0), preload=True,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reject=dict(grad=4000e-13, mag=4e-12, eog=150e-6))  
outfile = myepochs.get\_data()

outfile.save('subj\_rest\_raw\_epoch.fif')

> > >

I receive this error message:

\<\<\<  
Traceback (most recent call last):  
&nbsp;&nbsp;File "resting\_V3.py", line 55, in \<module\>  
&nbsp;&nbsp;&nbsp;&nbsp;outfile.save('subj\_rest\_raw\_epoch.fif')  
AttributeError: 'numpy.ndarray' object has no attribute 'save'

> > >

Alternatively, I could forgo running epochs.get\_data and just save directly (epochs.save(...)),

but I run into the same error except it specifies "Epochs" instead of "numpy.ndarray" as the object with no 'save' attribute.

Is this error occurring because of a problem with my script, or might I have something wrong with my installation of mne-python?

Thank you in advance.

::vincent

---

<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:** [February 12, 2013, 9:17pm UTC](https://mne.discourse.group/t/saving-data-from-mne-epochs/520/3 "2013-02-12T21:17:32Z")

</div>

Hello all,

I am trying to epoch resting MEG data into 4 second events, remove EOG  
artifacts, and save as a new file including only the good epochs. I've  
upgraded to the latest nightly yesterday and attempted running this script,  
but it fails to save with this error message: \*

AttributeError: 'Epochs' object has no attribute 'save'\*

Doesn't mne.epochs return an object which should be able to save as a fif  
file?

Here is my full script in case it helps to look at:

\*data\_path = '/home/vrupp/data/restMEG/'  
subj = raw\_input('Subject ID:')  
raw\_fname = data\_path + subj + '/' + subj + '\_rest\_raw\_sss.fif'  
event\_id, tmin, tmax = 1, 0.0, 4.0

# Setup for reading the raw data  
raw = fiff.Raw(raw\_fname)

# Epoch data into 4s intervals  
events = mne.make\_fixed\_length\_events(raw, 1, start=0, stop=None,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;duration=4.)

# Set up pick list: (MEG-bad channels)  
exclude = raw.info['bads']  
picks = fiff.pick\_types(raw.info, meg=True, eeg=False, stim=True, eog=True,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exclude=exclude)

# Read epochs and remove bad epochs  
epochs\_outfile = mne.Epochs(raw, events, event\_id, tmin, tmax, proj=True,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;picks=picks, baseline=(None, 0), preload=True,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reject=dict(grad=4000e-13, mag=4e-12, eog=150e-6))

# Save output file  
epochs\_outfile.save(data\_path + subj + '/' + subj + '\_rest\_raw\_epoch.fif')\*

Thanks very much for any help.

Best wishes,

Vincent Rupp

---

<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:** [February 12, 2013, 9:21pm UTC](https://mne.discourse.group/t/saving-data-from-mne-epochs/520/4 "2013-02-12T21:21:54Z")

</div>

Hey Vincent,

Yes, you should be able to save epochs with 'epochs.save()'. Could you  
double-check that "mne.\_\_version\_\_" is at '0.6.git'? That's the development  
version, and it should have support for the '.save()' method. (I think the  
most recent release version 0.5 also had it, incidentally.)

Eric

---

<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:** [February 12, 2013, 9:22pm UTC](https://mne.discourse.group/t/saving-data-from-mne-epochs/520/5 "2013-02-12T21:22:17Z")

</div>

hi Vincent,

I suspect you're not actually running the last released version. To check

> > > import mne  
> > > print mne.\_\_version\_\_

you should see 0.5 or more.

HTH  
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:** [February 12, 2013, 10:01pm UTC](https://mne.discourse.group/t/saving-data-from-mne-epochs/520/6 "2013-02-12T22:01:15Z")

</div>

Hello all,

Thanks very much for the help! I was using 0.4 and had mistakenly assumed  
MNE and mne-python were a part of the same installation package. Now the  
script runs fine. Much obliged.

Best wishes,

Vincent Rupp
