bids-standard / bids-specification

Brain Imaging Data Structure (BIDS) Specification
https://bids-specification.readthedocs.io/
Creative Commons Attribution 4.0 International
273 stars 157 forks source link

electrodes.tsv for simultaneous MEG/EEG data #1550

Closed MatthiasSure closed 1 year ago

MatthiasSure commented 1 year ago

Hello all,

I want to bring MEG and LFP data recorded over the same amplifier into BIDS format. Since the data is in one fif file (from the Neuromag system), everything is stored under /meg. However, with the *electrodes.tsv it comes to an error message:

( [Code 1] NOT_INCLUDED)

with the BIDS validator. In the specification description, I could not recognize a section to the *electrodes.tsv with MEG. Is this, therefore, not provided by MEG, or is there a solution for this problem?

Many greetings and thanks, Matthias

effigies commented 1 year ago

The spec says:

Furthermore, the EEG sensor coordinates SHOULD be specified using MEG-specific coordinate systems (see coordinates section below and the Coordinate Systems Appendix).

It's not clear to me whether "EEG sensor coordinates" refers to the electrodes.tsv file. If so, changing it to "the EEG sensor coordinates recorded in an electrodes.tsv file SHOULD ..." would make this unambiguous. Updating the validator would be pretty straightforward, but are there additional checks that would be required? Is there a way to distinguish between meg/ with pure MEG or simultaneous MEG/EEG, which would allow us to make this file conditionally permissible?

MatthiasSure commented 1 year ago

Hi,

Thank you very much for the reply.

To check if it is pure MEG or MEG/EEG data, the ChannelFile is sufficient. In the ChannelFile it is distinguished whether it is MEG, EEG, ECG, etc. channel. However, I have direct experience here only with the Neuromag MEG system and for other systems only second-hand information.
To create the BIDS data structure, I used data2bids from Fieldtrip. Here it is recognized whether also EEG was used and automatically the *electrodes.tsv file is created. Therefore I do not assume that further checks are necessary.

I hope that could help.

Greetings, Matthias

effigies commented 1 year ago

cc @robertoostenveld I think you would be a definitive authority here.

dorahermes commented 1 year ago

We have concurrent iEEG/EEG data that are similarly recorded in one ieeg data file. In the _channels.tsv we include EEG and SEEG electrodes. The _electrodes.tsv has the corresponding electrode positions for each ieeg electrode, but does not contain the EEG positions or specify the type again (for an example, see subject 2 in doi:10.18112/openneuro.ds004457.v1.0.2).

robertoostenveld commented 1 year ago

In a MEG dataset there can be EEG channels (or EOG, or ECG, or iEEG) for which the electrodes are not specified, but in the presence of EEG channels I agree that electrodes.tsv SHOULD be present (especially since in the neuromag system these EEG electrodes are measured with a polhemus in the default procedure).

For the validator I recommend making it conditional on the EEGChannelCount in the meg.json; if that field is present and larger than 0, then electrodes.tsv should be present.

effigies commented 1 year ago

Okay. So for the legacy validator, let's simply make electrodes.tsv permissible. Adding SHOULD/MUST (NOT) rules is going to be easier in the schema.

Should it be disallowed (or discouraged) if EEGChannelCount is 0 or absent?

effigies commented 1 year ago

Interested parties, please review:

MatthiasSure commented 1 year ago

Thanks for the effort. In my opinion, it would also make sense to add electrodes.tsv even if you make it conditional on the SEEGChannelCount being greater than 0 In Neuromag, subcortical electrodes are indeed counted as EEG, but subsequent labeling as SEEG makes more sense to better illustrate the location of the electrodes. If you reconstruct the position of the electrodes via CT/MRI, you could also store the coordinates in electrodes.tsv. In case of doubt, however, only one condition for the EEGChannelCount is sufficient.

effigies commented 1 year ago

Okay, so if EEGChannelCount can be zero and electrodes.tsv still be a good idea, then we should definitely not disallow it.

sappelhoff commented 1 year ago

I have a questions about these two comments by @robertoostenveld and @MatthiasSure:

In a MEG dataset there can be EEG channels (or EOG, or ECG, or iEEG)

and

In my opinion, it would also make sense to add electrodes.tsv even if you make it conditional on the SEEGChannelCount being greater than 0

in both of these cases we are talking about iEEG data. Is it true that iEEG data may be collected simultaneously with MEG data? And is this the problem that you are currently dealing with @MatthiasSure?

Because if that is the case, the PR by @effigies in #1555 needs to be generalized from what it currently addresses (only EEG) to also encompass iEEG.

Furthermore, if we are fine with this solution (and it does look good to me so far), then perhaps we should add a section about electrodes.tsv to the MEG section of the BIDS specification, and make corresponding schema adjustments. This would clear up confusions that have already arisen, see:

In the specification description, I could not recognize a section to the *electrodes.tsv with MEG.


Finally, for the record, I want to provide my interpretation of this problem mentioned above:

The spec says:

Furthermore, the EEG sensor coordinates SHOULD be specified using MEG-specific coordinate systems (see coordinates section below and the Coordinate Systems Appendix).

It's not clear to me whether "EEG sensor coordinates" refers to the electrodes.tsv file.

I think the original intent here was that EEG (or iEEG, ...) positions were supposed to be specified in the MEG specific file formats that specify sensor locations. For more information, see:

and in particular see the information here: https://bids-specification.readthedocs.io/en/latest/modality-specific-files/magnetoencephalography.html#head-shape-and-electrode-description-_headshapeextension quoting:

The 3-D locations of points that describe the head shape and/or EEG electrode locations can be digitized and stored in separate files.

having that said, I think a potential duplication of that information in electrodes.tsv files would be fine, but perhaps all of you want to think about this again given this information.


PS: this discussion also lead me to identify a potential MEG spec bug:

MatthiasSure commented 1 year ago

Is it true that iEEG data may be collected simultaneously with MEG data? And is this the problem that you are currently dealing with @MatthiasSure?

yes exactly. In my case, these are electrodes for deep brain stimulation which are externalized and connected to the EEG amplifier of the Neuromag MEG and thus recorded simultaneously with the MEG signal. The signal is therefore stored in the fif file as an EEG signal but is technically an iEEG signal. In the further proceeding, I will then label the channels concerned as SEEG or iEEG. I am currently out of the office for the next four weeks, hence the short answer. I hope the answer helps a little anyway.

sappelhoff commented 1 year ago

Okay, thanks @MatthiasSure -- so you technically have the electrode positions in your .fif file, right?

Is there a way to change the channel type within the .fif file to iEEG?

I am asking these questions to see whether we have actually don't have a problem here, and whether the original intent (IMHO) of the spec suffices as a solution:

I think the original intent here was that EEG (or iEEG, ...) positions were supposed to be specified in the MEG specific file formats that specify sensor locations.

(see my comment above for crosslinks to context and more info)

@robertoostenveld do you agree with my comment from above?

effigies commented 1 year ago

It sounds like there is not a problem here. electrodes.tsv is REQUIRED for EEG, and OPTIONAL for MEG and iEEG. For MEG where EEGChannelCount > 0, it becomes RECOMMENDED because it is probably needed to correctly interpret the EEG channels, but remains optional for SEEGChannelCount > 0 for the same reasons it is optional for iEEG.

I believe #1555 and bids-standard/bids-validator#1738 can move ahead.

Or are we coming around to it should always be OPTIONAL for MEG?

sappelhoff commented 1 year ago

I'll try to come back to this soon (around 1 week), please wait with going ahead, I want to give this a double check.

sappelhoff commented 1 year ago

electrodes.tsv is REQUIRED for EEG

Is this the current state? Where does it say that? I think electrodes.tsv should be OPTIONAL for EEG as well. Sometimes you just don't have any information to disclose about the electrodes.

OPTIONAL for MEG

In the current state of the spec, electrodes.tsv files are not permissible for MEG data.

I'm okay with allowing this from now on, ...

although I still think that the original intent of the spec was that in an MEG sesion, all data recorded from electrodes via the same system as the MEG signal, should go into the MEG specific file formats like directly in the .fif file in the case for the Elekta/Neuromag/MEGIN format, or into a _headshape.ext file for other formats (like CTF). See my reasoning here:

Or are we coming around to it should always be OPTIONAL for MEG?

IMHO it should always be optional for MEG, EEG, iEEG.

I believe https://github.com/bids-standard/bids-specification/pull/1555 and https://github.com/bids-standard/bids-validator/pull/1738 can move ahead.

+1 to move ahead with the legacy validator PR. However, the schema PR (#1555) needs small adjustments and an addition to the spec text, I think (will comment there).

robertoostenveld commented 1 year ago

Regarding

... all data recorded from electrodes via the same system as the MEG signal, should go into the MEG specific file formats like directly in the .fif file

Please note that afaik the neuromag system is the only with a well-integrated electrode acquisition strategy (using the same software as for MEG acquisition) and thereby the only that stores electrode information in the fif file. The others record and store it with separate systems in separate files.

My preference would therefore be for electrodes.tsv in EEG, iEEG and MEG to be treated the same, i.e., always optional (or recommended).

MatthiasSure commented 1 year ago

Hi, thanks for working on the problem and sorry for the long break. I would go along with this:

My preference would therefore be for electrodes.tsv in EEG, iEEG and MEG to be treated the same, i.e., always optional (or recommended).

Back to this question:

Okay, thanks @MatthiasSure -- so you technically have the electrode positions in your .fif file, right?

The position of subcortical electrodes as used for LFP recordings via DBS electrodes is set to 0. However, using methods for the reconstruction of the location of electrodes it is possible to add this information later. That is what I'm doing.

sappelhoff commented 1 year ago

Thanks! I think we're all on the same page now and we can proceed to finish up the PR in #1555 and eventually merge it + merge the accompanying legacy bids-validator PR right now: https://github.com/bids-standard/bids-validator/pull/1738

dorahermes commented 1 year ago

I think that the _electrodes.tsv file should be RECOMMENDED (or REQUIRED) for iEEG data. Sharing iEEG data without electrode positions is like sharing voxel timeseries that are randomly shuffled without labeling, where you may be able to use a drawing or photograph with half legible labels to understand where 256 dots were positioned. Making _electrodes.tsv fully OPTIONAL for iEEG data will result in datasets that are being shared that are not interpretable or reusable.

I am noting that in the original iEEG-BIDS extension on google doc, the _electrodes.tsv file was listed as REQUIRED for iEEG data, which is what the iEEG community agreed on (many iEEG community members are clinicians and are not on github).