# Splitting epoch data

**URL:** <https://mne.discourse.group/t/splitting-epoch-data/11177>\
**Category:** Support & Discussions\
**Tags:** epochs\
**Created:** [May 6, 2025, 4:05pm UTC](https://mne.discourse.group/t/splitting-epoch-data/11177 "2025-05-06T16:05:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyrion1803](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/tyrion1803/32/4309_2.png) [@Tyrion1803](https://mne.discourse.group/u/Tyrion1803)\
**Post date:** [May 6, 2025, 4:05pm UTC](https://mne.discourse.group/t/splitting-epoch-data/11177/1 "2025-05-06T16:05:11Z")

</div>

- MNE version:1.9
- operating system: macOS 15

I have managed to read my EEG data with mne.io.read\_raw\_egi, managed to setup the montage with raw\_data\_t1.set\_montage. From talking to the PI, it is my understanding that the recording is broken into an initial setup, then the recording starts (denoted by DIN1), then a transition of some sort happens during which the recording is still going on and then the second part of the experiment begins (denoted by DIN2). When I create the epochs I do it using 1 second based events per the PI instructions -which I have done with mne.make\_fixed\_length\_events. The PI now wants the epochs based on the times the experiment was running - say DIN1 to about 3 minutes (180 seconds) and DIN2 to the end basically skipping the gap while some transition was going on. What is the best way to achieve this? I was thinking you can create raw objects based on the two events an then create the epochs -which seems cumbersome, or create the epochs and then split the data somehow. Any ideas?

```python
	input_fname_t1 = data_path + t1_file

	# Load the raw data files 
	raw_data_t1 = mne.io.read_raw_egi(input_fname_t1, eog=None, misc=None, include=None, exclude=None, preload=True, channel_naming='E%d', events_as_annotations=True, verbose=None)
	     						   	     						   	
    t1_DIN1 = mne.find_events(raw_data_t1, stim_channel='DIN1', output='onset')
	t1_DIN2 = mne.find_events(raw_data_t1, stim_channel='DIN2', output='onset')

    raw_data_t1.set_montage(montage, match_alias=True, match_case=False, on_missing='warn') 

    epoch_events = mne.make_fixed_length_events(raw_data_t1, id=1, start=0, stop=None, duration=1.0, first_samp=True)

    epoch_t1 = mne.Epochs(raw_data_t1_DIN1, events=epoch_events, event_id=None, tmin=0, tmax=1, baseline=(None, None), picks=None, preload=True, reject=None, flat=None, proj=True, decim=1, reject_tmin=None, reject_tmax=None, detrend=None, on_missing='raise', reject_by_annotation=False, metadata=None, event_repeated='error', verbose=None)

```

Thanks

---

<div class="post-metadata">

**Author:** ![Tyrion1803](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/tyrion1803/32/4309_2.png) [@Tyrion1803](https://mne.discourse.group/u/Tyrion1803)\
**Post date:** [May 6, 2025, 5:59pm UTC](https://mne.discourse.group/t/splitting-epoch-data/11177/2 "2025-05-06T17:59:07Z")

</div>

btw I tried doing something like …

```python
t1_onset_DIN1 = t1_DIN1[0][0]/1000
print(f"Onset for t1_DIN1: {t1_onset_DIN1}")

test = epoch_t1[round(t1_onset_DIN1):180]

```

My thinking is this would go from the onset on DN1 (aprox 16 seconds into the recording to the 3 minute mark, but I am unsure if this is indeed what I need to do -i.e. all events in the epoch between DN1 and the 180 seconds mark.

---

<div class="post-metadata">

**Author:** ![wmvanvliet](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/wmvanvliet/32/100_2.png) [@wmvanvliet](https://mne.discourse.group/u/wmvanvliet)\
**Post date:** [May 12, 2025, 9:17am UTC](https://mne.discourse.group/t/splitting-epoch-data/11177/3 "2025-05-12T09:17:17Z")

</div>

I think you got it correct. You can always use `raw.plot(events=events)` to visualize the continuous data with event markers annotated (pay attention to the DIN1 and DIN2 channels). Compare that with `epochs.plot()` to see which epochs you have extracted to make sure you have the right segments.

---

<div class="post-metadata">

**Author:** ![Tyrion1803](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/tyrion1803/32/4309_2.png) [@Tyrion1803](https://mne.discourse.group/u/Tyrion1803)\
**Post date:** [May 12, 2025, 5:44pm UTC](https://mne.discourse.group/t/splitting-epoch-data/11177/4 "2025-05-12T17:44:18Z")

</div>

Does this returnee a figure I can plot? My apologies for the question, I am running python from the command line trying to figure out all the details.

---

<div class="post-metadata">

**Author:** ![wmvanvliet](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/wmvanvliet/32/100_2.png) [@wmvanvliet](https://mne.discourse.group/u/wmvanvliet)\
**Post date:** [May 13, 2025, 5:11am UTC](https://mne.discourse.group/t/splitting-epoch-data/11177/5 "2025-05-13T05:11:55Z")

</div>

if you’re running from the command line (instead of an interactive console like `ipython`), then add the following parameter: `epochs.plot(block=True)`. The script will show the plot and only continue after you have closed it.

---

<div class="post-metadata">

**Author:** ![Tyrion1803](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/tyrion1803/32/4309_2.png) [@Tyrion1803](https://mne.discourse.group/u/Tyrion1803)\
**Post date:** [May 13, 2025, 2:12pm UTC](https://mne.discourse.group/t/splitting-epoch-data/11177/6 "2025-05-13T14:12:20Z")

</div>

Thanks. That seems to almost have done the job but I got an error

```python
/mne_qt_browser/_pg_figure.py:4903: RuntimeWarning: Precision loss occurred in moment calculation due to catastrophic cancellation. This occurs when the data are nearly identical. Results may be unreliable.
  z = zscore(data, axis=1)

```

I would like to see the data so I can understand what is happening as data is processed, this is a bit of a mystery box so far. Thanks for the help though.
