mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.68k stars 1.31k forks source link

Retrieving channel adjacencies for our standard montages #10747

Open hoechenberger opened 2 years ago

hoechenberger commented 2 years ago

I'd like to be able to do something like the following:

# %%
import mne

montage_name = 'easycap-M1'

m = mne.channels.make_standard_montage(montage_name)
adj = m.get_adjacency()

i.e., if I'm using one of our built-in montages and we are shipping a matching adjacency matrix, I want to be able to retrieve this matrix without having to worry about ch_names etc in the way I have to when using the current approach:

# %%
import mne

m = mne.channels.make_standard_montage('easycap-M1')
adj, ch_names = m.get_adjacency('easycapM1')  # now what do I even do with those ch_names? match them up with those in `m`??

Alternatively, we could have support for make_standard_montage(..., return_adjacency=True) to return the matrix alongside the montage.

WDYT?

cc @mmagnuski @sappelhoff @cbrnr

sappelhoff commented 2 years ago

I like your first suggestion -- that seems like a reasonable method to have!

hoechenberger commented 2 years ago

I like your first suggestion -- that seems like a reasonable method to have!

But it implies that the DigMontage "knows" it was created from one of our standard montages (and which). There is currently no way to store that information, or is there?

sappelhoff commented 2 years ago

But it implies that the DigMontage "knows" it was created from one of our standard montages (and which). There is currently no way to store that information, or is there?

it could simply look for an exact match of channels between montage and "adjacency", right? 🤔

hoechenberger commented 2 years ago

it could simply look for an exact match of channels between montage and "adjacency", right? 🤔

I'm not so sure, as there might be different adjacency matrices for the exact same list of channel names! At least in theory... no?

Also we'd have to load all adjacency matrices one by one until we find a match, this seems quite inefficient?

sappelhoff commented 2 years ago

How about a private attribute in the montage class then?

hoechenberger commented 2 years ago

I am not sure it's so easy, as we store montages as FIFF files and you know how it is with this standard :/

Or could we maybe transition to something else? HDF5 or so? @larsoner

But then how would we store a montage that has been applied to data... 🤔

mmagnuski commented 2 years ago

I'm not sure that makes things so much easier. If you have montage name, you can just do:

montage_name = 'easycap-M1'

m = mne.channels.make_standard_montage(montage_name)
adj = mne.channels.read_ch_adjacency(montage_name)

assuming read_ch_adjacency can do it. If it can't it would be nice if it could. :)

mmagnuski commented 2 years ago

(ah, ok I get your point with ch_names)

hoechenberger commented 2 years ago

assuming read_ch_adjacency can do it. If it can't it would be nice if it could. :)

don't forget about #10746 💩

larsoner commented 2 years ago

I am not sure it's so easy, as we store montages as FIFF files and you know how it is with this standard :/

I we could perhaps add a FIFF_DESCRIPTION or FIFF_NAME to the DigMontage read/write round-trip without needing to add anything to the FIF standard