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

Bipolar electrode recordings and "electrodes.tsv" #485

Open
sappelhoff opened this issue Jul 27, 2020 · 14 comments
Open

Bipolar electrode recordings and "electrodes.tsv" #485

sappelhoff opened this issue Jul 27, 2020 · 14 comments

Comments

@sappelhoff
Copy link
Member

sappelhoff commented Jul 27, 2020

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:

  1. MNE-Python has no representation of how each channel was referenced
  2. Many data formats "drop" information about Ground and Reference electrodes before saving the data
@agramfort
Copy link
Member

agramfort commented Jul 27, 2020 via email

@hoechenberger
Copy link
Member

hoechenberger commented Feb 10, 2021

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

Screen Shot 2021-02-10 at 22 26 52

_channels.tsv:

Screen Shot 2021-02-10 at 22 14 09

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.

@hoechenberger
Copy link
Member

hoechenberger commented Feb 10, 2021

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?

@hoechenberger
Copy link
Member

cc @adam2392

@hoechenberger
Copy link
Member

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.

@sappelhoff
Copy link
Member Author

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

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.

@hoechenberger
Copy link
Member

hoechenberger commented Feb 11, 2021

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:

  1. Raw data must contain data for all electrodes (not channels); reference electrodes would simply be kept to 0 at all times
  2. in MNE-BIDS, we first read electrodes.tsv (instead of channels.tsv) and create channels for each electode
  3. in a second step, we combine those electrodes to form the actual channels, and remove the "electrode channels" from the data
  4. profit 💰

Alas, this is probably not going to happen…

@hoechenberger
Copy link
Member

hoechenberger commented Feb 11, 2021

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:

  1. only the already-referenced ECG channel is present
  2. the already-referenced ECG channel and both electrodes are present
  3. 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

@sappelhoff
Copy link
Member Author

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 .edffile), 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.

@hoechenberger
Copy link
Member

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)

@hoechenberger
Copy link
Member

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 .edffile), 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?

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?

@sappelhoff
Copy link
Member Author

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 🙈 man I feel this is more complicated than it needs to be.

@hoechenberger
Copy link
Member

hoechenberger commented Feb 11, 2021

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

@hoechenberger
Copy link
Member

(edited above example channels.tsv a bunch of times)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants