You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
support user-defined event fields in mne.read_epochs_eeglab() #3837
@jona-sassenhagen it sounds like we might need a specialized read_events_eeglab or something to give full access to the information, since we currently simplify it?
It could be exposed via a property of the EpochsEEGLAB class, sure. But whatever it is, ideally it would contain all of the same data that EEGLAB exposes, and be complete. Maybe a numpy structured array?
I have used something like this in the past to get info from the set file to a pandas dataframe:
importpandasaspdfromscipy.ioimportloadmatdefread_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= [fforfindir(EEG.event[0]) ifnotf.startswith('_')]
events=EEG.eventdf_dict=dict()
forfinflds:
df_dict[f] = [ev.__getattribute__(f) forevinevents]
df=pd.DataFrame(df_dict)
# reorder columns:take_fields= ['epoch', 'type']
ignore_fields=list() ifignore_fieldsisNoneelseignore_fieldstake_fields.extend([colforcolindf.columnsifnot
(colintake_fieldsorcolinignore_fields)])
returndf.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... :) )
We don't want a dependency on pandas. Could we get away with a simple structured array, e.g. what loadmat returns in the first line (but with struct_as_record=True)?
@nbara - that is correct :) But I was joking, eeglab was not really designed to have a clean API (it is mostly GUI-centered) so its internals can be a bit messy. In eeglab urevents are the original, untouched events - which means that if you remove some epochs or time segments your events change, but urevents stay the same (so you can for example later compare events and urevents and infer which epochs were removed - as this information is not saved in eeglab files etc.). original_events is fine, really.
Etymology lessons on MNE :) @Eric89GXL have we considered putting some of these useful scripts (like the one from @mmagnuski ) in one place? It's probably nice to point users towards them when an issue crops up without necessarily having to make a PR for everything. I know that such scripts also exist for mangling data from FieldTrip into MNE ...
Let's not point users to a private functions, it encourages bad behavior. If there is some functionality there that we need, we should make a public API.
Activity
agramfort commentedon Dec 12, 2016
nbara commentedon Dec 12, 2016
Hi @agramfort, thanks for the fast response!
Actually I use more than one custom field in my event structure in EEGLAB. Here's a MATLAB screenshot:

Also, in python the second column of my

epochs.eventsarray is only 0s (aftermne.read_epochs_eeglab()):jona-sassenhagen commentedon Dec 12, 2016
You can set the middle value to whatever you want.
One option if you have more than 1 value to store is to set the middle column to an index, and then retrieve from a pandas dataframe using that index.
E.g.
For legacy reasons, the events array will not be extented beyond a 3-column integer array.
nbara commentedon Dec 12, 2016
Hi @jona-sassenhagen, I'm not sure I understand what you mean.
I would like to import my custom event fields from my
.setfile, how do I do that?For instance, in the screenshot above, my EEGLAB/Matlab's
eventstructure has fields namedvalue,conf_task.How do I access them in python/mne? This info seems to be lost using
epochs = mne.read_epochs_eeglab('eeglabfile.set')larsoner commentedon Dec 12, 2016
@jona-sassenhagen it sounds like we might need a specialized
read_events_eeglabor something to give full access to the information, since we currently simplify it?nbara commentedon Dec 12, 2016
@Eric89GXL Could it possibly stored in
epochs.drop_eventor something similar?larsoner commentedon Dec 12, 2016
It could be exposed via a property of the
EpochsEEGLABclass, sure. But whatever it is, ideally it would contain all of the same data that EEGLAB exposes, and be complete. Maybe a numpy structured array?mmagnuski commentedon Dec 12, 2016
I have used something like this in the past to get info from the set file to a pandas dataframe:
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_codecargument when reading your set files though.(and may have been more elegant with
struct_as_record=True... :) )larsoner commentedon Dec 12, 2016
We don't want a dependency on pandas. Could we get away with a simple structured array, e.g. what
loadmatreturns in the first line (but withstruct_as_record=True)?mmagnuski commentedon Dec 12, 2016
@Eric89GXL Yes - I was not proposing to put something like this in mne :) only trying help @nbara. Structured array should work well.
larsoner commentedon Dec 12, 2016
@mmagnuski any preference on what such a property would be called?
EpochsEEGLAB.original_eventsor something?mmagnuski commentedon Dec 12, 2016
It would be eeglabish to call it
urevents(but misleading and ugly 😄).original_eventsare ok for me.larsoner commentedon Dec 12, 2016
Yikes. What is that short for?
user_events? If so then we can just use that name.nbara commentedon Dec 12, 2016
i think 'ur' stands for 'original' (in which case it has German origins https://en.wiktionary.org/wiki/ur-#Etymology) but I can't be sure...
mmagnuski commentedon Dec 12, 2016
@nbara - that is correct :) But I was joking, eeglab was not really designed to have a clean API (it is mostly GUI-centered) so its internals can be a bit messy. In eeglab urevents are the original, untouched events - which means that if you remove some epochs or time segments your
eventschange, butureventsstay the same (so you can for example later compare events and urevents and infer which epochs were removed - as this information is not saved in eeglab files etc.).original_eventsis fine, really.jasmainak commentedon Dec 12, 2016
Etymology lessons on MNE :) @Eric89GXL have we considered putting some of these useful scripts (like the one from @mmagnuski ) in one place? It's probably nice to point users towards them when an issue crops up without necessarily having to make a PR for everything. I know that such scripts also exist for mangling data from FieldTrip into MNE ...
mmagnuski commentedon Dec 12, 2016
@jasmainak - this is a good point, maybe mne-sandbox? + something like FAQ with links/examples (in the long run)?
larsoner commentedon Dec 13, 2016
We could add links to gists in the FAQ
jasmainak commentedon Dec 13, 2016
Actually, I just found this page on the wiki which appears to be extremely underutilized.
mmagnuski commentedon Dec 13, 2016
@jasmainak my guess is that most users go to online docs and rarely visit mne github wiki.
jona-sassenhagen commentedon Mar 28, 2017
We could have the EEGLAB reader warn if events are dropped and point to
_read_eeglab_eventsfor reading in the raw event structure.larsoner commentedon Mar 28, 2017
Let's not point users to a private functions, it encourages bad behavior. If there is some functionality there that we need, we should make a public API.
jona-sassenhagen commentedon Apr 12, 2017
Edit: this is actually the wrong issue I think.