When Using easyEEG to import mne.epochs subjects, there is a problem. The Codes and output were as follows:
Codes:
#%%
import mne
sample_data_folder = r'C:\Users\Administrator\mne_data\MNE-sample-data'
sample_data_raw_file = r'C:\Users\Administrator\mne_data\MNE-sample-data\MEG\sample\sample_audvis_raw.fif'
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False,preload=True).crop(tmax=60)
events = mne.find_events(raw, stim_channel="STI 014")
event_dict = {
"auditory/left": 1,
"auditory/right": 2,
"visual/left": 3,
"visual/right": 4,
"face": 5,
"buttonpress": 32,
}
picks = mne.pick_types(raw.info,meg=False,eeg=True,stim=False,eog=False,ecg=False,misc=False)
raw.filter(0.1,30,n_jobs=2,fir_design='firwin')
epochs = mne.Epochs(raw, events, tmin=-0.3, tmax=0.7, event_id=event_dict, preload=True)
print(epochs.event_id)
del raw # we're done with raw, free up some memory
#%%
epochs.resample(1000.00)
#epochs.rename_channels(ch_name_dic)
epochs.set_eeg_reference(ref_channels='average', projection=True)
epochs.apply_proj()
eeg_reject = dict(eeg=200e-6)
epochs.drop_bad(reject=eeg_reject, flat=None, verbose=None)
epochs.save(r'E:\TLE\test\test-epo.fif')
#%%
import easyEEG
path = r'E:\TLE\test\test-epo.fif'
epochs = easyEEG.io.load_mne_fif(path)
Output:
86 events found
Event IDs: [ 1 2 3 4 5 32]
Filtering raw data in 1 contiguous segment
Setting up band-pass filter from 0.1 - 30 Hz
FIR filter parameters
Designing a one-pass, zero-phase, non-causal bandpass filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Lower passband edge: 0.10
- Lower transition bandwidth: 0.10 Hz (-6 dB cutoff frequency: 0.05 Hz)
- Upper passband edge: 30.00 Hz
- Upper transition bandwidth: 7.50 Hz (-6 dB cutoff frequency: 33.75 Hz)
- Filter length: 19821 samples (33.001 s)
[Parallel(n_jobs=2)]: Using backend LokyBackend with 2 concurrent workers.
[Parallel(n_jobs=2)]: Done 16 tasks | elapsed: 4.1s
[Parallel(n_jobs=2)]: Done 358 tasks | elapsed: 10.5s
[Parallel(n_jobs=2)]: Done 366 out of 366 | elapsed: 10.6s finished
Not setting metadata
86 matching events found
Setting baseline interval to [-0.2996928197375818, 0.0] s
Applying baseline correction (mode: mean)
Created an SSP operator (subspace dimension = 3)
3 projection items activated
Using data from preloaded Raw for 86 events and 601 original time points ...
1 bad epochs dropped
{'auditory/left': 1, 'auditory/right': 2, 'visual/left': 3, 'visual/right': 4, 'face': 5, 'buttonpress': 32}
Sampling frequency of the instance is already 1000.0, returning unmodified.
EEG channel type selected for re-referencing
Adding average EEG reference projection.
1 projection items deactivated
Average reference projection was added, but has not been applied yet. Use the apply_proj method to apply it.
Created an SSP operator (subspace dimension = 4)
4 projection items activated
SSP projectors applied...
0 bad epochs dropped
Reading E:\TLE\test\test-epo.fif ...
Read a total of 4 projection items:
PCA-v1 (1 x 102) active
PCA-v2 (1 x 102) active
PCA-v3 (1 x 102) active
Average EEG reference (1 x 59) active
Found the data of interest:
t = -300.00 ... 700.00 ms
0 CTF compensation matrices available
Not setting metadata
85 matching events found
No baseline correction applied
Created an SSP operator (subspace dimension = 4)
4 projection items activated
KeyError Traceback (most recent call last)
Untitled-1 in line 6
33 path = r'E:\TLE\test\test-epo.fif'
34 #fif_list =
----> 36 epochs = easyEEG.io.load_mne_fif(path)
37 epochs.save('DATAS/EasyEEG_paper/data.h5')
File d:\miniconda\lib\site-packages\easyEEG\io\load.py:228, in load_mne_fif(files, path, subjIDs, montage_path)
225 else:
226 raise ValueError('Parameter [files] should be path(s)')
--> 228 return from_mne_epochs(subj_datas,subjIDs=[],montage_path='standard-10-5-cap385')
File d:\miniconda\lib\site-packages\easyEEG\io\load.py:24, in from_mne_epochs(subj_datas, subjIDs, montage_path)
21 sr = epoch_raw.info['sfreq']
22 channel_names = epoch_raw.info['ch_names']
---> 24 epochs_data_each_subj = epoch_raw.to_data_frame().stack('signal').unstack('time')
25 index_new = [(subjID, condition, trial_num_for_subjects[subjID] + trial, channel) for condition, trial, channel in epochs_data_each_subj.index.tolist()]
26 trial_num_for_subjects[subjID] = max([trial for subjID, condition, trial, channel in index_new])
File d:\miniconda\lib\site-packages\pandas\core\frame.py:8764, in DataFrame.stack(self, level, dropna)
8762 result = stack_multiple(self, level, dropna=dropna)
8763 else:
-> 8764 result = stack(self, level, dropna=dropna)
8766 return result.finalize(self, method="stack")
...
-> 1910 raise KeyError(
1911 f"Requested level ({level}) does not match index name ({self.name})"
1912 )
KeyError: 'Requested level (signal) does not match index name (None)'
Since there is no index called 'signal' in the results of epochs.to_data_frame, what is the 'signal' this function needed?