Skip to content

Commit

Permalink
Update EEGLAB_and_python.md
Browse files Browse the repository at this point in the history
  • Loading branch information
arnodelorme authored Jan 6, 2024
1 parent 72249a4 commit 7388dec
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions others/EEGLAB_and_python.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ called from within Python using this method (change xxx to the location where EE

``` Python
# import dataset from EEGLAB
from oct2py import octave
octave.addpath('/data/matlab/eeglab/functions/guifunc');
octave.addpath('/data/matlab/eeglab/functions/popfunc');
octave.addpath('/data/matlab/eeglab/functions/adminfunc');
octave.addpath('/data/matlab/eeglab/functions/sigprocfunc');
octave.addpath('/data/matlab/eeglab/functions/miscfunc');
EEG = octave.pop_loadset('/xxxx/eeglab/sample_data/eeglab_data_epochs_ica.set');
from oct2py import octave as eeglab
path2eeglab = 'xxxxx'

eeglab.addpath(path2eeglab + '/functions/guifunc');
eeglab.addpath(path2eeglab + '/functions/popfunc');
eeglab.addpath(path2eeglab + '/functions/adminfunc');
eeglab.addpath(path2eeglab + '/functions/sigprocfunc');
eeglab.addpath(path2eeglab + '/functions/miscfunc');
eeglab.addpath(path2eeglab + '/plugins/dipfit');
EEG = eeglab.pop_loadset(path2eeglab + '/sample_data/eeglab_data_epochs_ica.set');

# plot first trial of channel 1
import matplotlib.pyplot as plt
Expand All @@ -168,6 +171,10 @@ import mne
EEG = mne.io.read_epochs_eeglab('eeglab_data_epochs_ica.set')
```

**Stability consideration:** We have found the Oct2py interface very stable. Issues usually arise when an EEGLAB function is not fully compatible with Octave (most functions should be compatible, including ICLabel; However, EEGLAB is optimized for MATLAB, not Octave).

**Speed consideration:** When using EEGLAB with this method, due to automated data conversion delay and lack of optimization in Octave, one should expect a 2x or more slowdown compared to using EEGLAB on MATLAB or native Python libraries.

### Using MATLAB runtime Engine under Python or MATLAB compiled Python library

We do not advise these solutions as EEGLAB data structures are too complex to be passed on from MATLAB to Python. When executing the Python code, you will get an error "only 1xN and Nx1 char arrays can be returned from MATLAB" (which is not technically correct as many [different data types](https://www.mathworks.com/help/matlab/matlab_external/handle-data-returned-from-matlab-to-python.html) are handled). However, the EEGLAB EEG structure contains arrays of structures for events and channels and is not handled. This has been the case for at least four years as of 2024, with no improved support in sight. Look for unsupported data types on this [page](https://www.mathworks.com/help/matlab/matlab_external/handle-data-returned-from-matlab-to-python.html) (as of 2024, the website lists "structure arrays" and "cell arrays" as unsupported data types). Note that the Oct2Py interface described above handles these data types just fine.
Expand Down

0 comments on commit 7388dec

Please sign in to comment.