Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRG eeglab .set reader #2676

Merged
merged 36 commits into from Dec 23, 2015
Merged

MRG eeglab .set reader #2676

merged 36 commits into from Dec 23, 2015

Conversation

jasmainak
Copy link
Member

closes #2672

very much WIP and works only for the sample data provided by EEGLAB at the moment. If anyone has files to share, I'd be happy to try them.

TODOs

  • Fix scaling issue when plotting raw
  • Check if chanlocs already exists in the set file
  • Check if data already exists in the set file
  • Handle epochs data
  • Make it work with .dat file
  • eog topoplot

@jasmainak jasmainak force-pushed the eeglab_io branch 2 times, most recently from 2f5bced to c46bb00 Compare December 7, 2015 00:27
@@ -107,6 +107,7 @@ Functions:
read_raw_edf
read_raw_kit
read_raw_nicolet
read_raw_set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read_raw_eeglab ?

@jasmainak
Copy link
Member Author

okay guys, we have preload option now :) Thanks to @jaeilepp for debugging help. It works when data is in a separate fdt file. I have to think how we can handle preload when it's in the set file itself.

# get info
if ch_fname is not None:
ch_fname = op.join(basedir, ch_fname)
info = _get_info(eeg, eog, ch_fname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many set files already contain channel information. You can check eeg.chanlocs to see if it is true.
eeg.chanlocs is a matlab structure with following fields: labels, Y, X, Z, sph_theta, sph_phi, sph_radius, theta, radius, type, ref, urchan. If channel positions are present - all coordinate fields should be filled. labels contains channel names.
For example in matlab:

EEG.chanlocs(5)

gives:

ans = 

        labels: 'E5'
             Y: -3.0769
             X: 10.1424
             Z: 1.2423
     sph_theta: -16.8763
       sph_phi: 6.6854
    sph_radius: 10.6714
         theta: 16.8763
        radius: 0.4629
          type: ''
           ref: 'average'
        urchan: 5

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you have an example file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, I'll check

-------
raw : Instance of RawSet
A Raw object containing EEGLAB .set data.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add Notes section with versionadded directive

@larsoner
Copy link
Member

larsoner commented Dec 7, 2015

Those files add ~4MB to the repo. I think I'd rather put them in the testing dataset to avoid repo bloat. @agramfort WDYT? What's the limit on adding files?

@larsoner
Copy link
Member

larsoner commented Dec 7, 2015

@jasmainak there is no way to get segments of data using loadmat, right? I guess if data were in MATLAB's newer HDF5 .mat files we could. But since we probably can't, I think for preload=False with data in the set file you can just throw a warning if preload is not True (since memmapping probably won't be easy/worth it either) and say that it will be forced to True since data is in the set file.

def test_io_set():
"""Test importing EEGLAB .set files"""
_test_raw_reader(read_raw_set, True, fname=fname,
ch_fname=ch_fname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to test degenerate cases like not ch_fname.endswith('.locs') as well

@jasmainak
Copy link
Member Author

@Eric89GXL I was thinking maybe we could use io.whosemat to query if the eeg.data attribute is a string or an array and then try to do an fseek to that location. Wdyt?

@jasmainak
Copy link
Member Author

@Eric89GXL yeah the files are large at the moment. We can replace them with smaller files when we are closer to merging. That is why it's a separate commit. I'll overwrite the commit.

@larsoner
Copy link
Member

larsoner commented Dec 7, 2015

We could fseek and read if you can figure out how the data are actually stored in the .mat file. That would be cool.

@jasmainak jasmainak force-pushed the eeglab_io branch 3 times, most recently from 80dac1c to 1a05244 Compare December 7, 2015 16:49
@jasmainak
Copy link
Member Author

@agramfort comments addressed

@agramfort agramfort merged commit 996409a into mne-tools:master Dec 23, 2015
@agramfort
Copy link
Member

merged by rebase after my cosmit to force upper case.

@agramfort
Copy link
Member

thanks heaps @jasmainak !

@jona-sassenhagen
Copy link
Contributor

Wanna make an announcement on the EEGLAB mailing list? :)

@agramfort
Copy link
Member

Wanna make an announcement on the EEGLAB mailing list? :)

I am responsible for this ...

@jasmainak
Copy link
Member Author

awesome, looks like I missed a lot of action in a few hours AFK :) Thanks for the reviews

@teonbrooks
Copy link
Member

thanks @jasmainak! this is awesome. i know plenty of colleagues who would love to hear about this

@jona-sassenhagen
Copy link
Contributor

Okay this is possibly a stupid question, but how do I access events for a raw file? From reading the docs or code, I can't see where that would be handled, and there is no stim channel in the resulting object.

@jasmainak
Copy link
Member Author

I think you will have to use raw.set_channel_type to set the stim channel manually.

I don't think you can have raw.events. I think the cleanest solution is to handle it with this issue #2665 which many people are looking for too.

In the meanwhile. maybe you could artificially create a stim channel (if there isn't one) from the events in Matlab and add it to the data?

@agramfort
Copy link
Member

agramfort commented Dec 24, 2015 via email

@jasmainak
Copy link
Member Author

yeah, I think they will be there in the .set file. The problem however is that you don't always know the duration of the events. So, generating the stim channel from the events is an ill posed problem ;) I think the events annotation we have discussed is the correct way to go about it. It will solve many problems at once.

@jasmainak jasmainak deleted the eeglab_io branch December 24, 2015 10:13
@jona-sassenhagen
Copy link
Contributor

In the brainvision reader, if we don't know the length, we just set them to zero. The problem is rather that EEGLAB has much richer event handling, including arbitrary strings as names.

(Stimulus channels are not the EEGLAB way. Something I have to add to my EEGLAB switcher docs. @jasmainak where should I put that file btw?)

@jasmainak
Copy link
Member Author

@jona-sassenhagen feel free to share it by email or FB message as you've done previously.

@jona-sassenhagen
Copy link
Contributor

I'll try to make a PR asap. Just tell me what file to put it into.

@jasmainak
Copy link
Member Author

ah, sorry I misunderstood your question. I think it should go to the manual. A file in manual/migrating.rst? Makes sense?

@teonbrooks
Copy link
Member

i agree, there should be an auto detection option for the trigger, especially if this is in the release. all the readers have one, even it's a simplified version. as @jona-sassenhagen mentioned, if the duration is unknown we give it a duration of a sample.

@jona-sassenhagen
Copy link
Contributor

I already made a PR Teon :) I'm not sure how to create a trigger channel though, I'm too stupid to figure out that part of the BV code.

@teonbrooks
Copy link
Member

follow up to this pr: #2745

I'll join in over there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reading eeglab set files
8 participants