# Bug in Epochs.save() and Raw.save()

**URL:** <https://mne.discourse.group/t/bug-in-epochs-save-and-raw-save/6918>\
**Category:** Support & Discussions\
**Created:** [May 18, 2023, 10:22am UTC](https://mne.discourse.group/t/bug-in-epochs-save-and-raw-save/6918 "2023-05-18T10:22:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AR6789](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@AR6789](https://mne.discourse.group/u/AR6789)\
**Post date:** [May 18, 2023, 10:22am UTC](https://mne.discourse.group/t/bug-in-epochs-save-and-raw-save/6918/1 "2023-05-18T10:22:38Z")

</div>

Dear mne Forum.  
-Using mne 1.4.0

My EEG data is of the persyst type, mne.io.read\_raw\_persyst().  
I created fixed length epochs of 30 seconds and want to save them in my files.

I got an error when saving, the same error occures when i tried to save the raw\_preprocessed file.  
`epochs.save('epochs_epo.fif', overwrite = True)`

The error:

````python
AssertionError Traceback (most recent call last)
Cell In[60], line 1
----> 1 epochs.save('epochs_epo.fif', overwrite = True)

File :12, in save(self, fname, split_size, fmt, overwrite, split_naming, verbose)

File c:\Users\arons\anaconda_New3\envs\mne\lib\site-packages\mne\epochs.py:2153, in BaseEpochs.save(self, fname, split_size, fmt, overwrite, split_naming, verbose)
   2151 # avoid missing event_ids in splits
   2152 this_epochs.event_id = self.event_id
-> 2153 _save_split(
   2154 this_epochs, fname, part_idx, n_parts, fmt, split_naming, overwrite
   2155 )

File c:\Users\arons\anaconda_New3\envs\mne\lib\site-packages\mne\epochs.py:150, in _save_split(epochs, fname, part_idx, n_parts, fmt, split_naming, overwrite)
    147 next_idx = None
    149 with start_and_end_file(fname) as fid:
--> 150 _save_part(fid, epochs, fmt, n_parts, next_fname, next_idx)

File c:\Users\arons\anaconda_New3\envs\mne\lib\site-packages\mne\epochs.py:163, in _save_part(fid, epochs, fmt, n_parts, next_fname, next_idx)
    160 write_id(fid, FIFF.FIFF_PARENT_BLOCK_ID, info["meas_id"])
    162 # Write measurement info
--> 163 write_meas_info(fid, info)
    165 # One or more evoked data sets
    166 start_block(fid, FIFF.FIFFB_PROCESSED_DATA)
...
--> 121 assert len(data) == 3
    122 data_size = 4
    123 jd = np.sum(_cal_to_julian(*data))

AssertionError: 
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...```

The error occurs with the assert len(data) == 3

Is this a bug in the `Epochs.save()` format? The same error occurs when i tried saving the raw via `raw.save()`

Thanks in advance.

Kind regards,
Aron Segers
````

---

<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 19, 2023, 8:38am UTC](https://mne.discourse.group/t/bug-in-epochs-save-and-raw-save/6918/2 "2023-05-19T08:38:11Z")

</div>

Translating the error: “I expected `epochs.get_data()` to be an array with 3 dimensions, but it isn’t, and now I don’t know what to do”.

Could you check whether `epochs.get_data().shape` makes sense? It could be a bug somewhere else.

---

<div class="post-metadata">

**Author:** ![AR6789](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@AR6789](https://mne.discourse.group/u/AR6789)\
**Post date:** [May 19, 2023, 10:18am UTC](https://mne.discourse.group/t/bug-in-epochs-save-and-raw-save/6918/3 "2023-05-19T10:18:22Z")

</div>

If i run the `epochs.get_data().shape` I get a 3-dimensional array. Maybe there is a bug somewhere else than? I pasted my code and the error i recieved again

```python
epochs = mne.make_fixed_length_epochs(raw_eeg_cropped, duration=30, preload= True)
print(f'The shape of the epochs array : {epochs.get_data().shape}')
epochs.save('epochs-epo.fif')

```

```python
Not setting metadata
180 matching events found
No baseline correction applied
Created an SSP operator (subspace dimension = 1)
1 projection items activated
Using data from preloaded Raw for 180 events and 7680 original time points ...
0 bad epochs dropped
The shape of the epochs array : (180, 37, 7680)
Overwriting existing file.

---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In[25], line 3
      1 epochs = mne.make_fixed_length_epochs(raw_eeg_cropped, duration=30, preload= True)
      2 print(f'The shape of the epochs array : {epochs.get_data().shape}')
----> 3 epochs.save('epochs-epo.fif', overwrite = True)

File :12, in save(self, fname, split_size, fmt, overwrite, split_naming, verbose)

File c:\Users\arons\anaconda_New3\envs\mne\lib\site-packages\mne\epochs.py:2153, in BaseEpochs.save(self, fname, split_size, fmt, overwrite, split_naming, verbose)
   2151 # avoid missing event_ids in splits
   2152 this_epochs.event_id = self.event_id
-> 2153 _save_split(
   2154 this_epochs, fname, part_idx, n_parts, fmt, split_naming, overwrite
   2155 )

File c:\Users\arons\anaconda_New3\envs\mne\lib\site-packages\mne\epochs.py:150, in _save_split(epochs, fname, part_idx, n_parts, fmt, split_naming, overwrite)
    147 next_idx = None
    149 with start_and_end_file(fname) as fid:
--> 150 _save_part(fid, epochs, fmt, n_parts, next_fname, next_idx)

File c:\Users\arons\anaconda_New3\envs\mne\lib\site-packages\mne\epochs.py:163, in _save_part(fid, epochs, fmt, n_parts, next_fname, next_idx)
    160 write_id(fid, FIFF.FIFF_PARENT_BLOCK_ID, info["meas_id"])
    162 # Write measurement info
--> 163 write_meas_info(fid, info)
...
--> 121 assert len(data) == 3
    122 data_size = 4
    123 jd = np.sum(_cal_to_julian(*data))

AssertionError: 

```
