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

non-existent field 'ref' #1

Closed
drammock opened this issue May 10, 2021 · 20 comments
Closed

non-existent field 'ref' #1

drammock opened this issue May 10, 2021 · 20 comments

Comments

@drammock
Copy link

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

@drammock
Copy link
Author

cc @apoorva6262

@jackz314
Copy link
Owner

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?

@apoorva6262
Copy link

@jackz314 , yeah I did perform average referencing on my dataset.

@cbrnr
Copy link

cbrnr commented May 11, 2021

@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
Copy link
Owner

@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?

@apoorva6262
Copy link

@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").

@jackz314
Copy link
Owner

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?

@jackz314
Copy link
Owner

@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'.

@apoorva6262
Copy link

Do I need to reinstall the eeglabio package ?

@jackz314
Copy link
Owner

You should be able to install like this

pip install https://github.com/jackz314/eeglabio/archive/main.zip

@apoorva6262
Copy link

still the same error

@apoorva6262
Copy link

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 :
Screenshot 2021-05-11 at 00 50 36

@jackz314
Copy link
Owner

I just added explicit type conversion so the second error shouldn't appear again, but I'm not sure about the ref error.

@cbrnr
Copy link

cbrnr commented May 11, 2021

@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.

@cbrnr
Copy link

cbrnr commented May 11, 2021

Also, I'm pretty sure "common" also refers to average reference (some people call it common average reference).

@jackz314
Copy link
Owner

@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.

@cbrnr
Copy link

cbrnr commented May 11, 2021

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.

@jackz314
Copy link
Owner

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.

@cbrnr
Copy link

cbrnr commented May 11, 2021

OK, so setting it to 'common' makes sense as otherwise EEGLAB should have done it anyway.

@apoorva6262
Copy link

works now! thank you so much!

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

No branches or pull requests

4 participants