# Load raw data
data_path = '/MNE/BrainVision/3.vhdr'
raw = mne.io.read_raw_brainvision(data_path, preload=True, verbose=False)
raw.info['line_freq'] = 50.
#raw.ch_names[28] = "AFz"
#raw.ch_names[60] = "Fpz"
raw.set_channel_types({'EOGr': 'eog', 'EOGl': 'eog'})
# Set montage
montage = mne.channels.make_standard_montage('easycap-M1')
raw.set_montage(montage, on_missing = 'ignore', match_case=False, verbose=False)
# Re-reference
raw.set_eeg_reference('average', projection=False, verbose=False)
raw.filter(l_freq=1, h_freq=45, fir_design='firwin', verbose=False)
# Construct epochs
# read events
events, event_id = mne.events_from_annotations(raw, verbose=False)
raw.info["events"] = events
raw.info["events_id"] = event_id
# Epoching
tmin, tmax = -1., 1. # in s
baseline = None
epochs = mne.Epochs(
raw, events=events,
event_id=[event_id['Stimulus/A']], tmin=tmin,
tmax=tmax, baseline=baseline, verbose=False)
#Save
root = '/MNE/BrainVision'
epochs.save(pathlib.Path(root) / 'epochs-epo.fif', overwrite = True)
Greeting,
After running the above code (which simply load brain vision EEG data ‘.vhdr’, set montage, reref, epoch, and save it ), I get the below error:
Traceback (most recent call last):
File “”, line 1, in
File “”, line 22, in save
File “/MNE/BrainVision/venv/lib/python3.6/site-packages/mne/epochs.py”, line 1814, in save
_save_split(this_epochs, fname, part_idx, n_parts, fmt)
File “/MNE/BrainVision/venv/lib/python3.6/site-packages/mne/epochs.py”, line 99, in _save_split
_save_part(fid, epochs, fmt, n_parts, next_fname, next_idx)
File “/MNE/BrainVision/venv/lib/python3.6/site-packages/mne/epochs.py”, line 112, in _save_part
write_meas_info(fid, info)
File “/MNE/BrainVision/venv/lib/python3.6/site-packages/mne/io/meas_info.py”, line 1584, in write_meas_info
if event.get(‘channels’) is not None:
AttributeError: ‘numpy.ndarray’ object has no attribute ‘get’
Could you please help what the source of problem might be…
Sincerely
Emanuel
The problem is one of these two lines
raw.info["events"] = events
raw.info["events_id"] = event_id
(probably the first one). generally speaking you should not stick things into the raw.info
dictionary manually. Quoting from the API documentation:
The only entries that should be manually changed by the user are info['bads']
and info['description']
. All other entries should be considered read-only, though they can be modified by various MNE-Python functions or methods (which have safeguards to ensure all fields remain in sync).
Incidentally, after a quick look at your data, you may want to consider marking some bad channels (before you do your average reference); maybe:
raw.info['bads'] = ['C1', 'CP3', 'C5']
Although I recommend you look at the data yourself using raw.plot()
and click channel names to mark as bad interactively.