# epoching on epoched data

**URL:** <https://mne.discourse.group/t/epoching-on-epoched-data/3638>\
**Category:** Support & Discussions\
**Tags:** eeg, epochs, autoreject\
**Created:** [September 2, 2021, 3:58am UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638 "2021-09-02T03:58:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![apoorva6262](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@apoorva6262](https://mne.discourse.group/u/apoorva6262)\
**Post date:** [September 2, 2021, 3:58am UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/1 "2021-09-02T03:58:24Z")

</div>

Hi,

Is it possible to make fixed length epochs on existing epoched file ? I currently have an EEG file that has epochs of length 30s each. I need to preprocess this file and run autoreject. To do so, I need to make 1s length epochs and then run autoreject. Is there a way I can create more epochs on the existing file ?

Thanks,  
Apoorva.

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [September 2, 2021, 9:18am UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/2 "2021-09-02T09:18:19Z")

</div>

do you want to use autoreject local or global?

A

---

<div class="post-metadata">

**Author:** ![apoorva6262](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@apoorva6262](https://mne.discourse.group/u/apoorva6262)\
**Post date:** [September 2, 2021, 8:03pm UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/3 "2021-09-02T20:03:45Z")

</div>

global! I usually identify the global rejection threshold on the epoched EEG data and then run ICA and then compute channel level autorejections.

---

<div class="post-metadata">

**Author:** ![mainakjas](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mainakjas/32/34_2.png) [@mainakjas](https://mne.discourse.group/u/mainakjas)\
**Post date:** [September 3, 2021, 5:46pm UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/4 "2021-09-03T17:46:50Z")

</div>

Hi Apoorva,

You can do something like this:

```python
for epochs_data in epochs:
    raw_epoch = mne.io.RawArray(epochs_data, epochs.info)
    epochs_autoreject = mne.make_fixed_length_epochs(raw_epoch, duration=1, preload=True)

```

where `epochs` is your long 30 s epochs and `epochs_autoreject` are the shorter epochs. Does this work for you?

Mainak

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [September 3, 2021, 7:33pm UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/5 "2021-09-03T19:33:41Z")

</div>

ooh, that’s even better than what I came up with. @apoorva6262 and I discussed this during office hours today and I suggested

```python
data = epochs.get_data()
pseudo_raw_data = np.hstack(data)
pseudo_raw = mne.io.RawArray(pseudo_raw_data, epochs.info)
new_epochs = mne.make_fixed_length_epochs(pseudo_raw, duration=1.)

```

---

<div class="post-metadata">

**Author:** ![apoorva6262](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@apoorva6262](https://mne.discourse.group/u/apoorva6262)\
**Post date:** [September 7, 2021, 3:36am UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/6 "2021-09-07T03:36:34Z")

</div>

Thanks @drammock and @mainakjas .

For both suggestions, I get this error : numpy.ndarray’ object has no attribute ‘info’

---

<div class="post-metadata">

**Author:** ![mainakjas](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/mainakjas/32/34_2.png) [@mainakjas](https://mne.discourse.group/u/mainakjas)\
**Post date:** [September 7, 2021, 12:14pm UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/7 "2021-09-07T12:14:01Z")

</div>

Are you sure you are working with `epochs` and not `epochs.get_data()`? The second is a numpy array and no attribute info.

Mainak

---

<div class="post-metadata">

**Author:** ![apoorva6262](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@apoorva6262](https://mne.discourse.group/u/apoorva6262)\
**Post date:** [September 7, 2021, 4:49pm UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/8 "2021-09-07T16:49:36Z")

</div>

Sorry, yes I did use epochs. Then it gave me an error that it is 3d and data must be 2d. So I tried using epochs.transpose.reshape and then it gave me an error that ‘EpochsFIF’ object has no attribute ‘transpose’

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [September 7, 2021, 5:11pm UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/9 "2021-09-07T17:11:24Z")

</div>

please give us the exact lines of code that you ran as well as the error traceback. Also, some general advice:

1. different kinds of data objects have different methods. NumPy arrays allow things like `my_array.transpose()` but MNE-Python Epochs objects do not have a `.transpose()` method. If you type the name of your variable in an iPython console and push `.` and then the tab key, you can get a pop-up of all its available methods and attributes. That can help you avoid trying things that won’t work (like `my_epochs.transpose()`… because “transpose” won’t be one of the available options that pops up). Here’s an example:

 ![Screenshot_2021-09-07_12-12-48](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/239ddbc9608fc07531e970b1f36ad4973f3461a6.png)

1. in MNE-Python, the actual data (the numbers representing voltage X in channel Y at time Z) are stored in a NumPy array _that is part of a larger object_ that also contains other data (like channel positions, etc). From any MNE-Python object you can always do `my_object.get_data()` or `my_object.data` if you need direct access to the NumPy array, but do not confuse the (Raw, Epochs, Evoked) object for the data array that it contains.

---

<div class="post-metadata">

**Author:** ![apoorva6262](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@apoorva6262](https://mne.discourse.group/u/apoorva6262)\
**Post date:** [September 7, 2021, 8:00pm UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/10 "2021-09-07T20:00:58Z")

</div>

Thank you . That was helpful.  
This worked for me :

```python
sfreq=epochs.info['sfreq']
ch_names=epochs.info['ch_names']
ch_types = ['eeg'] * 22 
info = mne.create_info(ch_names=ch_names, ch_types=ch_types, sfreq=sfreq)
epoch=epochs.get_data()
n_epochs, n_channels, n_times = epoch.shape
data=epoch.transpose([1, 0, 2]).reshape((n_channels, n_epochs * n_times))
raw_epoch = mne.io.RawArray(data, info)
new_epochs = mne.make_fixed_length_epochs(raw_epoch, duration=1, preload=True)

```

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [September 7, 2021, 8:24pm UTC](https://mne.discourse.group/t/epoching-on-epoched-data/3638/11 "2021-09-07T20:24:55Z")

</div>

glad you got it working! One more tiny suggestion: instead of doing `epoch=epochs.get_data()`, use a more descriptive variable name like `epoch_data` or `data_array` or similar. Having 2 variables called “epoch” and “epochs” implies that they are both the same type of object, differing in how many trials they include. In your code, however, one is a `mne.Epochs` object and the other is a `numpy.ndarray` object, and both of them contain _all trials_… so the variable names are misleading and make it easier to get confused.
