Repository: mne-tools/mne-python

Issue:
Can't import data from EEG-LAB
Hello, 

I'm having issues importing raw EEG data with mne.io.read_raw_eeglab(set_filename)

It seems to be related with the events on the file:

![eeglab-import](https://cloud.githubusercontent.com/assets/1205576/15614009/b474010e-240c-11e6-9798-3e775db81231.png)

I tried importing the data by hand and seems to be working. 

![eeg-lab-import-2](https://cloud.githubusercontent.com/assets/1205576/15614090/28c90694-240d-11e6-879c-fd9a81be6515.png)

Any ideas? 

mne.**version**
'0.12.0'

Thanks!



Discussion:
How was the EEGLAB .set file created?

Some older eeglab files may have event type as integer. It is not allowed in current eeglab version (if I remember correctly). `eeg_checkset` (in matlab) should turn these to string.

This could be easily fixed by forcing events to be str, but I'm not sure we should support old EEGLAB version files. Any opinions?

is there a way to check what is the EEGLAB version from the `.set` file?

Casting to string seems fine to me, assuming the older files otherwise work. But maybe we should emit a warning about old files if we can get the version as @jasmainak asked

pbrusco can you make the file in question available somehow?

Thanks for the fast answers (I think the files are a little bit old, but not too much)

@jona-sassenhagen here are the examples :)

https://dl.dropboxusercontent.com/u/43547597/test1.set
https://dl.dropboxusercontent.com/u/43547597/test1.fdt

@jasmainak do you want to do it or should I?

@jona-sassenhagen feel free to take a stab at it. Thanks!

@jasmainak, in the mean time, do you recommend me to download the mne source code and just change cast events to string? Thanks :)

Sorry, I'll try and get something done today. 

How do we go about testing for this? Probably don't want to add a new EEGLAB data file just for this.

@pbrusco in the meantime, I'd try loading and re-saving the file in a current version of EEGLAB.

@jona-sassenhagen Ok, good idea ;), thanks!

@pbrusco I think I don't understand your EEGLAB test file. It has only 1 trial?

pbrusco was using `mne.io.read_raw_eeglab` so it is probably a raw file.

Haha I'm stupid.


Resolving patch:
diff --git a/mne/io/eeglab/eeglab.py b/mne/io/eeglab/eeglab.py
--- a/mne/io/eeglab/eeglab.py
+++ b/mne/io/eeglab/eeglab.py
@@ -526,7 +526,7 @@ def _read_eeglab_events(eeg, event_id=None, event_id_func='strip_to_integer'):
         event_id = dict()
 
     if isinstance(eeg.event, np.ndarray):
-        types = [event.type for event in eeg.event]
+        types = [str(event.type) for event in eeg.event]
         latencies = [event.latency for event in eeg.event]
     else:
         # only one event - TypeError: 'mat_struct' object is not iterable


Test patch:
diff --git a/mne/io/eeglab/tests/test_eeglab.py b/mne/io/eeglab/tests/test_eeglab.py
--- a/mne/io/eeglab/tests/test_eeglab.py
+++ b/mne/io/eeglab/tests/test_eeglab.py
@@ -12,6 +12,7 @@
 from mne import write_events, read_epochs_eeglab, Epochs, find_events
 from mne.io import read_raw_eeglab
 from mne.io.tests.test_raw import _test_raw_reader
+from mne.io.eeglab.eeglab import _read_eeglab_events
 from mne.datasets import testing
 from mne.utils import _TempDir, run_tests_if_main, requires_version
 
@@ -62,6 +63,13 @@ def test_io_set():
         # 1 for preload=False / str with fname_onefile, 3 for dropped events
         raw0.filter(1, None)  # test that preloading works
 
+    # test old EEGLAB version event import
+    eeg = io.loadmat(raw_fname, struct_as_record=False,
+                     squeeze_me=True)['EEG']
+    for event in eeg.event:  # old version allows integer events
+        event.type = 1
+    assert_equal(_read_eeglab_events(eeg)[-1, -1], 1)
+
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter('always')
         epochs = read_epochs_eeglab(epochs_fname)