question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support user-defined event fields in mne.read_epochs_eeglab()

See original GitHub issue

Hi all,

EEGLAB supports adding custom field names in the event structure, on top of the default ones (type, latency, duration, urevent, epoch) : https://sccn.ucsd.edu/wiki/Chapter_03:_Event_Processing#Event_fields

For instance I use a behaviour field to store the subjects responses on each epoch.

It would be very useful if one could somehow access those custom fields in MNE (maybe the option already exists but I haven’t found it).

Best wishes, Nicolas

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

3reactions
larsonercommented, Dec 13, 2016

We could add links to gists in the FAQ

2reactions
mmagnuskicommented, Dec 12, 2016

I have used something like this in the past to get info from the set file to a pandas dataframe:

import pandas as pd
from scipy.io import loadmat

def read_set_events(filename, ignore_fields=None):
	'''Open set file, read events and turn them into a dataframe
	Parameters
	----------
	filename: str
		Name of the set file to read (absolute or relative path)
	ignore_fields: list of str | None
		Event fields to ignore
	Returns
	-------
	df: pandas.DatFrame
		Events read into a dataframe
	'''
	EEG = loadmat(filename, uint16_codec='latin1',
				  struct_as_record=False, squeeze_me=True)['EEG']
	flds = [f for f in dir(EEG.event[0]) if not f.startswith('_')]
	events = EEG.event
	df_dict = dict()
	for f in flds:
		df_dict[f] = [ev.__getattribute__(f) for ev in events]
	df = pd.DataFrame(df_dict)

	# reorder columns:
	take_fields = ['epoch', 'type']
	ignore_fields = list() if ignore_fields is None else ignore_fields
	take_fields.extend([col for col in df.columns if not
					 (col in take_fields or col in ignore_fields)])
	return df.loc[:, take_fields]

it worked in my usecases - it goes through all EEG.event elements and extracts relevant fields so that every row in returned dataframe correspons to one EEG.event. You might not need the uint16_codec argument when reading your set files though. (and may have been more elegant with struct_as_record=True… 😃 )

Read more comments on GitHub >

github_iconTop Results From Across the Web

mne.Epochs — MNE 1.2.2 documentation - MNE-Python
Load all epochs from disk when creating the object or wait before accessing ... Plot Event Related Potential / Fields image on topographies....
Read more >
Creating epochs with variable event latencies - Support ...
How to read all fields from EEG.event / any workaround to import them from csv and then using it? ... In the discussion,...
Read more >
b. Events - EEGLAB Wiki
The EEG event structure contains records of the experimental events that occurred while the data was being recorded. To view the information for...
Read more >
Pybrain: M/EEG analysis with MNE Python - YouTube
Richard Höchenberger's workshop on MNE Python, recorded 16-17 ... raw data 01:35:57 Working with BIDS data 02:29:32 Creating epochs and ...
Read more >
Import and export data to and from MNE-Python
Therefore, we will need to import and export Raw, Epochs, and Evoked datatypes. The aim is to pass the channel=level data between FieldTrip...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found