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
EEG .set files can contain ICA results. Related data are populated in fields icaweights, icasphere, and icawinv as far as I know. Although users can build mne.preprocessing.ICA objects by hand from these fields, as proposed in here, this requires a good knowledge of the internals of MNE to deal correctly with pre-whitening and similar preprocessing steps such that the results obtained in EEGLAB are reproducible in MNE. It is also error-prone.
Describe your solution
To add an import function to MNE to import ICA components from EEGLAB .set files in a transparent manner.
Let me know how it goes. I will need this pretty soon for my analyses so I can code it if needed and share the piece of code I'll come up with. But if you already have some useful code lying around, let me know. It would save me a bit of head-scratching!
Not sure I got right the MNE-EEGLAB correspondence for ICA properties. However, I am not even sure that it is possible to have a perfect correspondence because EEGLAB does not export variables expected by MNE such as the pca_mean_ values and because of differences in preprocessing (e.g., sphering versus whitening and such... as discussed in here ). Anyway, this code runs but its output is not really tested yet. I'll work on coding tests to compare results in EEGLAB and MNE but I thought that I would post this preliminary snippet in case more knowledgeable people (e.g., @cbrnr, @agramfort, @larsoner ) have comments that could save me lot of time investigating obvious issues that I would take a long time to debug because of my limited knowledge about ICA algorithms and MNE internals.
One hint is that we use mne.externals.pymatreader.read_mat to unify over old-style and new-style .mat files. Regarding the other stuff I'm not sure offhand, hopefully your investigations plus our documentation can make things clear.
Thanks for the hint @larsoner . I replaced eegip.utils.loadmat by mne.externals.pymatreader.read_mat and it works without issues with the rest of the snippet. I'll be happy to drop eegip.utils.loadmat and not have to care for this code anymore.
I wil prepare the PR but I wont include this test in it because of the dependance on the ap82.set and Matlab. A possibility would be to add both ap82.set and ap82.cleaned.set to the testing datasets of MNE but since it involves adding about 200 MB of data, I do not think it is a good idea. Something with a smaller file could probably be prepared. Alternatively, a test could depend only on ap82.set and a Matlab-python interface library like this one but I do not like the idea of adding an additionnal dependency and a dependency on Matlab.
OK. Just seen your comments @larsoner after creating the PR. I can create a separate PR for the tests (or look at how to modify the current PR to include it).
Yes... so I would need to add two files "test_epochs.cleaned.fdt" and "test_epochs.cleaned.set" based on the Matlab code. I think that this is MUCH better than creating some dependencies on Matlab to generate these files within MNE test suite. I'll look into it.
@larsoner OK, I pushed the dataset. If I understand well your procedure ("Once your PR is merged, ask a maintainer to cut a new release of the testing data"), I need to wait for one of you to merge this PR request to run my tests. I check to hack the value returned by mne.datasets.testing.data_path(verbose=True) to point it to my git repository of mne-testing-data but this code seems a bit involved.
On a side note, the instructions to run the test does not seems to work on my setup
Activity
cbrnr commentedon Oct 5, 2019
I'll take a look.
christian-oreilly commentedon Oct 5, 2019
Let me know how it goes. I will need this pretty soon for my analyses so I can code it if needed and share the piece of code I'll come up with. But if you already have some useful code lying around, let me know. It would save me a bit of head-scratching!
christian-oreilly commentedon Oct 7, 2019
A small tentative snippet of code.
A few things. The loadmat function is just a version of
scipy.io.loadmatthat does a better job at reading mat files, in line of what is discussed here https://stackoverflow.com/a/29126361/1825043Not sure I got right the MNE-EEGLAB correspondence for ICA properties. However, I am not even sure that it is possible to have a perfect correspondence because EEGLAB does not export variables expected by MNE such as the pca_mean_ values and because of differences in preprocessing (e.g., sphering versus whitening and such... as discussed in here ). Anyway, this code runs but its output is not really tested yet. I'll work on coding tests to compare results in EEGLAB and MNE but I thought that I would post this preliminary snippet in case more knowledgeable people (e.g., @cbrnr, @agramfort, @larsoner ) have comments that could save me lot of time investigating obvious issues that I would take a long time to debug because of my limited knowledge about ICA algorithms and MNE internals.
larsoner commentedon Oct 7, 2019
One hint is that we use
mne.externals.pymatreader.read_matto unify over old-style and new-style.matfiles. Regarding the other stuff I'm not sure offhand, hopefully your investigations plus our documentation can make things clear.christian-oreilly commentedon Oct 7, 2019
Thanks for the hint @larsoner . I replaced eegip.utils.loadmat by mne.externals.pymatreader.read_mat and it works without issues with the rest of the snippet. I'll be happy to drop eegip.utils.loadmat and not have to care for this code anymore.
agramfort commentedon Oct 7, 2019
christian-oreilly commentedon Oct 7, 2019
@agramfort I'll be happy to open a PR when I'll have something suffiently well tested if you think it can help.
agramfort commentedon Oct 8, 2019
christian-oreilly commentedon Oct 9, 2019
I got some code that I'll prepare for PR. It has been tested using
The file used for testing has been downloaded here and processed in Matlab using
I wil prepare the PR but I wont include this test in it because of the dependance on the ap82.set and Matlab. A possibility would be to add both ap82.set and ap82.cleaned.set to the testing datasets of MNE but since it involves adding about 200 MB of data, I do not think it is a good idea. Something with a smaller file could probably be prepared. Alternatively, a test could depend only on ap82.set and a Matlab-python interface library like this one but I do not like the idea of adding an additionnal dependency and a dependency on Matlab.
larsoner commentedon Oct 9, 2019
We already have these test files
https://github.com/mne-tools/mne-testing-data/tree/master/EEGLAB
If you adapt your code to run on these, then we don't have to add any new data.
larsoner commentedon Oct 9, 2019
... oh, except I guess the bits needed to reconstruct the
ICAfrom what you compute in MATLABchristian-oreilly commentedon Oct 9, 2019
OK. Just seen your comments @larsoner after creating the PR. I can create a separate PR for the tests (or look at how to modify the current PR to include it).
Yes... so I would need to add two files "test_epochs.cleaned.fdt" and "test_epochs.cleaned.set" based on the Matlab code. I think that this is MUCH better than creating some dependencies on Matlab to generate these files within MNE test suite. I'll look into it.
larsoner commentedon Oct 9, 2019
Yes please do modify the branch in your PR directly. See instructions for adding new test data:
https://github.com/mne-tools/mne-testing-data#add-or-change-files-in-the-repo-for-use-with-mne
christian-oreilly commentedon Oct 9, 2019
@larsoner OK, I pushed the dataset. If I understand well your procedure ("Once your PR is merged, ask a maintainer to cut a new release of the testing data"), I need to wait for one of you to merge this PR request to run my tests. I check to hack the value returned by mne.datasets.testing.data_path(verbose=True) to point it to my git repository of mne-testing-data but this code seems a bit involved.
On a side note, the instructions to run the test does not seems to work on my setup
You have an idea how to get around this? I'd like to run the tests in their current state before adding my new test...
larsoner commentedon Oct 9, 2019
You probably do not have
pytest-covinstalledlarsoner commentedon Oct 9, 2019
... and to test your specific one you should really do something more like:
Doing
make testwill take forever.Then do
make flakeandmake docstylebefore pushing your commits to your PR branch. That way you ensure style compliance.FYI the md5sum I get for testing 0.75 is 51d2ca16c449bbb27a54f53590283f16
[-]Import ICA results form EEGLAB[/-][+]Import ICA results from EEGLAB[/+]