- MNE version: 1.0.0
- Operating system: Windows 10/11
- Python@ 3.9.7
Hello everyone,
Forewarning: I am fairly new to python so could very much be making a silly mistake.
Basically, I have EEG data for 110 individuals, each with 64 channels. I have the data as .set/.fdt files from EEGLAB, which I import (no problem there). I wanted to create a loop, that for each individual would filter all the data into select frequency bands (iter_freqs below), and then segment them into 2s epochs.
The epoching was working before I started bandpass filtering, but now the epoching outputs a ‘NoneType’ object, and I am quite stuck.
Here is the code:
# Define frequency bands
iter_freqs = [
('Delta', 0.25, 4),
('Theta', 4, 8),
('Alpha', 8, 12)
]
frequency_map = []
epochs = []
filt = []
band_dict = {}
eeg_dict = {}
for file in all_files:
for band, fmin, fmax in iter_freqs:
## Load .set file ##
raw = mne.io.read_raw_eeglab(file,preload=True)
## Resample to 100 Hz ##
raw = raw.resample(100)
## Assemble in dict
eeg_dict[file] = {
"Subject ID": file[31:39],
"Data": raw._data}
## Bandpass filter ##
filt = raw.filter(fmin, fmax,n_jobs=1,
l_trans_bandwidth = 0.25,
h_trans_bandwidth = 0.25)
frequency_map.append(((band, fmin, fmax), filt))
## Epoch in 2s segments ##
epochs = mne.make_fixed_length_epochs(raw=filt, duration = 2) # <-- THIS IS NOT WORKING, RETURNS DATA = NONE TYPE
#epochs.subtract_evoked()
band_dict[file] = {
"Subject ID": file[31:39],
"Data": epochs._data}
## Assemble power avgs in variable ##
del epochs
del raw
Would anyone be able to help?
The next thing I want to do is calculate an average power in each band in each epoch, so ideally I would have the data saved in a format that I can do this in.
My final query is that I process these in MNE and then save them to a dataset, to later feed into a machine learning algorithm. Is there a more straightforward way to do this (see code below), or is this fine?
eeg_data = pd.DataFrame.from_dict(eeg_dict,orient='index')
eeg_data = eeg_data.set_index('Subject ID')
eeg_data_rank = eeg_data.join(lang_class)
# Save EEG data output
eeg_data_rank.to_pickle("eeg_data.pkl.xz", compression="infer")
# Read eeg_data_rank
# eeg_data_rank = pd.read_pickle("eeg_data.pkl.xz", compression="infer")
# Save frequency map
file_name = "freq_map.pkl"
open_file = open(file_name, "wb")
pickle.dump(frequency_map, open_file)
open_file.close()
Thanks in advance for any help,
Maria