mne-bids
mne-bids copied to clipboard
Bipolar electrode recordings and "electrodes.tsv"
When working on the impedances PR, I was working with data that included EOG and ECG channels.
(see electrode vs channel disambiguation in the entry paragraph of the BIDS EEG spec)
Each of these channels is coming from a set of two electrodes with bipolar referencing scheme.
E.g. ECG
= ECG+
- ECG-
.
In BIDS, the electrodes.tsv
file is there to record electrodes, not channels. Yet, MNE-BIDS writes bipolar channels as a single row to electrodes.tsv
.
Furthermore, Ground and Reference would each need a row in electrodes.tsv
as well.
https://bids-specification.readthedocs.io/en/stable/04-modality-specific-files/03-electroencephalography.html#electrodes-description-_electrodestsv
I am aware that this is really hard to automate ... the reasons for that are twofold as far as I can see:
- MNE-Python has no representation of how each channel was referenced
- Many data formats "drop" information about Ground and Reference electrodes before saving the data
some hints to see how mne-python still can help.
https://mne.tools/dev/generated/mne.set_eeg_reference.html https://mne.tools/dev/generated/mne.set_bipolar_reference.html https://mne.tools/dev/generated/mne.set_bipolar_reference.html#mne.set_bipolar_reference
I am pretty sure that some references choices can be undone.
in chs['loc'] the first three value is the position of the electrode and the next 3 the position of the reference electrode.
In the FIF format EEG000 is the dig is the reference electrode
maybe this can help
@sappelhoff In BIDS, is there a way to define which electrodes were combined (and how) to form a channel in channels.tsv
, and to do that in an automatable fashion?
For a bipolar channel created from two unipolar electrodes, how you would specify the reference in channels.tsv
?
The spec is very unclear on this:
_ieeg.json
:

_channels.tsv
:

In your example with the two ECG channels, one would need to create an entry in channels.tsv
that probably looks something like this:
name type units reference status status_description
ECG ECG mV bipolar: ECG+ - ECG- good n/a
But this is not mentioned in the specs. -> As I see it, there is currently no way in BIDS to specify a bipolar reference scheme per channel.
What one could do is:
name type units reference status status_description
ECG+ ECG mV ECG- good n/a
but this would be an ugly hack, and the virtual bipolar channel would assume the location of the ECG-
electrode, which is not really what we want, right?
cc @adam2392
and the virtual bipolar channel would assume the location of the
ECG-
electrode, which is not really what we want, right?
Thinking about it, I guess this would be okay in principle. What still bothers me is that the channel name would always be equal to the name of that one electrode.
Yes, that bothers me as well.
I like your proposal here:
name type units reference status status_description
ECG ECG mV bipolar: ECG+ - ECG- good n/a
Perhaps we can propose this syntax or some variant of this to be included in BIDS as a recommendation for bipolar referencing schemes.
Of course one would then have to be sure to find ECG+
and ECG-
in electrodes.tsv
and it doesn't solve the issue for mne-bids, because MNE-Python just reads the "ECG" channel and has no clue that it was made out of two electrodes that are not channels. :thinking:
re: coordinates --> I think these types of electrodes are seldom digitized (i have never seen that), EOG, ECG, ... so I think a n/a
location would be fine for these.
and it doesn't solve the issue for mne-bids, because MNE-Python just reads the "ECG" channel and has no clue that it was made out of two electrodes that are not channels. 🤔
I think this is a shortcoming on the BIDS side: if one insists on making the distinction between electrodes and channels, then it should be absolutely clear how electrodes shall be combined / mapped to form channels.
Things could be pretty straightforward:
- Raw data must contain data for all electrodes (not channels); reference electrodes would simply be kept to 0 at all times
- in MNE-BIDS, we first read electrodes.tsv (instead of channels.tsv) and create channels for each electode
- in a second step, we combine those electrodes to form the actual channels, and remove the "electrode channels" from the data
- profit 💰
Alas, this is probably not going to happen…
I think I've got an idea how to solve the issue within the existing specs.
Starting from the thought about how "ordinary" EEG channels are handled. We always have an EEG reference – either an actual electrode, or a sum or mean of the signal across all channels, created inside the amplifier. Meaning that, in principle, each channel would use a bipolar referencing scheme: Channel - Reference
.
Yet, we simply refer to those channels as Channel
, not as Channel based on bipolar reference scheme Channel - Reference
. Additionally, Channel
gets to keep its location coordinates.
Transferring this approach to your ECG example, what we'd want to do is, instead of thinking within the boundaries of:
ECG = ECG+ - ECG-.
I suggest we think of this as:
ECG = ECG - ECG Reference
Now, electrodes.tsv
would contain two electrodes, ECG
and ECG Reference
. channels.tsv
, on the other hand, would only contain an ECG
channel:
name type units reference status status_description
ECG ECG mV ECG Reference good n/a
Now there's 3 possibilities that could occur when dealing with the corresponding raw data:
- only the already-referenced
ECG
channel is present - the already-referenced
ECG
channel and both electrodes are present - only the two electrodes are present
Case 1: Nothing to do! This is precisely how we currently deal with EEG data: the reference electrode typically doesn't appear as a channel by default
Case 2:
Naming conflict incoming: ECG
channel vs ECG
electrode -> this case could simply be excluded by disallowing this (redundant) kind of data storage
Case 3:
It's trivial to create the bipolar ECG
channel and drop the electrodes from the data
cc @agramfort
The first part of your idea sounds reasonable to me, i.e., renaming ECG+
and ECG-
to ECG
and ECG_reference
--- and then having ECG
in channels.tsv
and ECG
& ECG_reference
in electrodes.tsv
.
The second part of what you write sounds like you are thinking more about a "read" or "read-BIDS" perspective. And I don't see where you refer to raw files (assuming you got only a single .edf
file), and where to BIDS files (assuming you got the .edf
, but also channels.tsv
, electrodes.tsv
, coordsystem.json
, eeg.json
)
How would we write data to BIDS in your proposed setup, given that we only get an .edf
file?
Regarding your cases: I guess the only file format that stores the data (i.e., a row in the channels x timepoints matrix) from electrodes, as opposed to from channels is Biosemi, as their referencing scheme is somehow "reference-free" (I never worked with that though). All other data formats typically store channels. I think case 2 (storing both channels and electrodes) would never happen.
I guess the only file format that stores the data (i.e., a row in the channels x timepoints matrix) from electrodes, as opposed to from channels is Biosemi, as their referencing scheme is somehow "reference-free" (I never worked with that though).
We followed the same approach using our BrainProducts amplifier when recording data via PyCorder :) It can use a virtual internal reference (inside the amplifier)
The second part of what you write sounds like you are thinking more about a "read" or "read-BIDS" perspective. And I don't see where you refer to raw files (assuming you got only a single
.edf
file), and where to BIDS files (assuming you got the.edf
, but alsochannels.tsv
,electrodes.tsv
,coordsystem.json
,eeg.json
)How would we write data to BIDS in your proposed setup, given that we only get an
.edf
file?
If we have data for individual electrodes, each electrode becomes a separate channel in the Raw file. Only when reading, we populate the "true" channels based on the information in channels.tsv
Does that make sense? Or did I misunderstand your question?
Okay, now I know what you mean --> but the reality is probably (?) that Raw files do not contain data for each electrode. And that also clashes with the rule that channels.tsv should mirror the channels in the raw file :see_no_evil: man I feel this is more complicated than it needs to be.
Okay, now I know what you mean --> but the reality is probably (?) that Raw files do not contain data for each electrode.
This is fine too. In that case, we don't populate channels from electrodes.
And that also clashes with the rule that channels.tsv should mirror the channels in the raw file 🙈
This rule would need to be lifted, yes.
man I feel this is more complicated than it needs to be.
Yes. It's due to the (imho) arbitrary distinction between "channels" and "electrodes", which almost nobody seems to understand anyway.
If you ask me, electrodes.tsv
shouldn't exist; its contents should be entirely contained in channels.tsv
. Ground electrodes would get type = GND
, reference electrodes that are not supposed to show up as channels would have type = REF
. This would solve all issues, including for the bipolar reference schemes we described earlier:
name type units reference status status_description
EEG EEG µV EEG Reference good n/a
EEG Reference REF µV n/a n/a n/a
EEG Ground GND n/a n/a n/a n/a
ECG ECG mV ECG Reference good n/a
ECG Reference REF mV n/a n/a n/a
(edited above example channels.tsv a bunch of times)