Closed drammock closed 3 years ago
cc @apoorva6262
Correct me if I'm wrong, but I don't think MNE actually saves any referencing info unless it's an average reference in projection mode. So I think the best way to resolve this for export_mne_xxx
is to just save 'common' in the ref
field for now since that seems to be the default for EEGLAB. Then for the other methods, we could have another optional parameter that takes in the ref
.
We should probably also call apply_proj
on MNE instances just in case there are any projected references that aren't applied yet (I don't think EEGLAB supports projection)
Since @cbrnr worked on EEGLAB exports before, any thoughts on this? Maybe we should add a field to MNE like EEGLAB to store referencing info?
@jackz314 , yeah I did perform average referencing on my dataset.
@jackz314 can you reproduce with one of your test files? It is strange that we did not notice before.
You are right that currently MNE doesn't store the reference, although this has been discussed before (and I think it should be added). If setting ref
to "common"
works this is probably fine, but maybe you can also set it to something empty (e.g. empty string, empty list, None
)?
@jackz314 can you reproduce with one of your test files? It is strange that we did not notice before.
The weird thing is all the files exported from my test files work fine in EEGLAB even without the ref field, the field seems to be created automatically by EEGLAB if it doesn't exist in the set file. I'm not sure what exactly happened here though, maybe it's the EEGLAB version? Or maybe there are some extra steps involved in getting this error? Either way, I think setting the ref
field will be a safer bet.
@apoorva6262 can you provide some details on how you're getting the error? Is it just by loading in the set file alone? What version of the EEGLAB are you using?
@jackz314 , I actually opened a .set file that I initially saved on EEGLAB. I read this file on MNE , performed average referencing, filtering and ICA and then saved the file as .set and just loaded it on EEGLAB.
I use EEGLAB v2020.0 version. I get this error when using export_mne_epochs(epochs, "file_name.set") and export_mne_raw(raw, "file_name.set").
I pushed a fix that just adds the ref field to the set file, it's on the main branch, can you try it and see if it works?
@cbrnr I confirmed that if you leave the ref field as an empty string, or nothing at all just like before, EEGLAB (v2021.0) will create the ref field and set it to 'common'.
Do I need to reinstall the eeglabio package ?
You should be able to install like this
pip install https://github.com/jackz314/eeglabio/archive/main.zip
still the same error
I saved a different file using that using export_mne_raw(raw, "file_name.set", and loaded it on eeglab and that gave me this error :
I just added explicit type conversion so the second error shouldn't appear again, but I'm not sure about the ref error.
@jackz314 but why did the error happen in the first place if the ref
field gets created automatically? I think we should find out why @apoorva6262 encountered this issue and then implement a fix. If none of your test files produced the error, then we don't know the cause and implementing changes might be detrimental. I wouldn't set ref
to "common"
because we don't know if this is the true reference; EEGLAB will set this field automatically it seems.
Also, I'm pretty sure "common"
also refers to average reference (some people call it common average reference).
@apoorva6262 I just downloaded the older version of EEGLAB (v2020.0) and tested out some of my exported files, it seems like the ref error is no longer thrown if the ref field is added. Can you verify that you actually installed the latest version of eeglabio? What might have happened is pip didn't install the latest version of the code because there's already a version with the same major version installed, so you might need to uninstall the existing eeglabio first before installing again.
@cbrnr I looked at the older version of EEGLAB's code and it doesn't create the ref field automatically, hence the error. The field is only created automatically in the 2021 version it seems.
I'm not sure why common is used as the default value by EEGLAB, but at least in EEGLAB there're "common" and "average" two different types.
I looked at the older version of EEGLAB's code and it doesn't create the ref field automatically, hence the error. The field is only created automatically in the 2021 version it seems.
Alright then!
I'm not sure why common is used as the default value by EEGLAB, but at least in EEGLAB there're "common" and "average" two different types.
OK, that's strange.
In EEGLAB, the code to add the default ref field is:
if ~isfield(EEG, 'ref')
EEG.ref = 'common';
end
in the old version it has this code as well, but it also in some conditions (when chanlocs
exists) reference the ref field before actually creating it, so that's probably why the error occurs.
OK, so setting it to 'common'
makes sense as otherwise EEGLAB should have done it anyway.
works now! thank you so much!
FYI @jackz314 there's a report of a possible bug on the MNE forum: https://mne.discourse.group/t/opening-set-files-on-eeglab/3108