Converting epoch file to non-epoch file

Hi,

Is there a way to convert an existing epoch file(.set) to non-epoched file (.set) ?

Apoorva.

You could concatenate all epochs to a continuous 2D Numpy array and then use mne.io.RawArray to create a Raw object. Epochs.get_data() returns a 3D Numpy array of shape (n_epochs, n_channels, n_times), which you can reshape to two dimensions (n_channels, n_times_concatenated). Note that you might need to transpose the 3D array before reshaping, i.e. something along these lines (I didn’t test it so please double-check if this does what you want):

n_epochs, n_channels, n_times = epochs.shape
data = epochs.get_data()
data.transpose([1, 0, 2]).reshape((n_channels, n_epochs * n_times))

to add to this, you can then upgrade your MNE-Python installation to the current development version, and use the new export functionality to write your mne.io.RawArray to a .set file:

https://mne.tools/dev/generated/mne.export.export_raw.html#mne.export.export_raw

Thanks @cbrnr and @sappelhoff ! I tried the following and opened the file on eeglab and got an error :

sfreq=epoch_set.info['sfreq']
ch_names=epoch_set.info['ch_names']
ch_types = ['eeg'] * 32 
info = mne.create_info(ch_names=ch_names, ch_types=ch_types, sfreq=sfreq)
epoch=epoch_set.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)
export_mne_raw(raw_epoch, "filename.set")`

I got this error when I opened the filename.set on eeglab

Could you please turn your pipeline into a minimum working example? See below:

… minimal working example MWE to
replicate your problem, using one of the built-in datasets, preferably the
one called sample. If you can’t replicate on a built-in dataset, provide also
a link to a small, anonymized portion of your data that does yield the error.

Once you did that, and still replicate the error that you find on Matlab, you have everything you need to raise an issue at GitHub - jackz314/eeglabio: I/O support for EEGLAB files in Python., where this can probably be solved.

1 Like